[CJ-dev] commonjava-projects/commonjava-opl/projects/opl-xdoclet/src/java/org/commonjava/opl/xdoclet
Brought to you by:
johnqueso
From: <joh...@co...> - 2004-03-08 23:31:19
|
Update of /cvsroot/commonjava/commonjava-projects/commonjava-opl/projects/opl-xdoclet/src/java/org/commonjava/opl/xdoclet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15540/projects/opl-xdoclet/src/java/org/commonjava/opl/xdoclet Modified Files: OplNodeParserPlugin.java OplNodeParserPlugin.vm Log Message: enhanced/fixed the generation of NodeParsers. Index: OplNodeParserPlugin.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/projects/opl-xdoclet/src/java/org/commonjava/opl/xdoclet/OplNodeParserPlugin.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- OplNodeParserPlugin.java 8 Mar 2004 14:36:34 -0000 1.1 +++ OplNodeParserPlugin.java 8 Mar 2004 23:06:40 -0000 1.2 @@ -38,6 +38,72 @@ return jc.getTagByName("opl.parser") != null; } + public boolean shouldGenerateLocalPropertyContainer(Object metadata){ + JavaClass jc = (JavaClass)metadata; + DocletTag pcTag = jc.getTagByName("opl.properties-container"); + if(pcTag == null){ + return false; + } + else if("true".equals(pcTag.getNamedParameter("delegate"))){ + return false; + } + else{ + return true; + } + } + + public boolean shouldGenerateDelegatedPropertyContainerGetter(Object metadata){ + JavaClass jc = (JavaClass)metadata; + DocletTag pcTag = jc.getTagByName("opl.properties-container"); + if(pcTag == null){ + return false; + } + else if("true".equals(pcTag.getNamedParameter("delegate"))){ + JavaMethod[] methods = jc.getMethods(); + boolean getDelegated = false; + + for (int i = 0; i < methods.length; i++) { + JavaMethod method = methods[i]; + if(method.getTagByName("opl.delegate") != null){ + if("getProperties".equals(method.getName())){ + getDelegated = true; + } + } + } + + return !getDelegated; + } + else{ + return false; + } + } + + public boolean shouldGenerateDelegatedPropertyContainerSetter(Object metadata){ + JavaClass jc = (JavaClass)metadata; + DocletTag pcTag = jc.getTagByName("opl.properties-container"); + if(pcTag == null){ + return false; + } + else if("true".equals(pcTag.getNamedParameter("delegate"))){ + JavaMethod[] methods = jc.getMethods(); + boolean setDelegated = false; + + for (int i = 0; i < methods.length; i++) { + JavaMethod method = methods[i]; + if(method.getTagByName("opl.delegate") != null){ + if("setProperties".equals(method.getName())){ + setDelegated = true; + } + } + } + + return !setDelegated; + } + else{ + return false; + } + } + public String getAttributeConstant(Object metadata){ JavaMethod jm = (JavaMethod)metadata; String name = jm.getNamedParameter("opl.attribute", "name"); @@ -57,6 +123,12 @@ buffer.append("OPLModelRoot, "); } + DocletTag pcTag = jc.getTagByName("opl.properties-container"); + System.out.println("properties-container tag: " + pcTag); + if(pcTag != null){ + buffer.append("PropertiesContainer, "); + } + if(buffer.length() > 0){ buffer.setLength(buffer.length() -2); return "implements " + buffer.toString(); Index: OplNodeParserPlugin.vm =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/projects/opl-xdoclet/src/java/org/commonjava/opl/xdoclet/OplNodeParserPlugin.vm,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- OplNodeParserPlugin.vm 8 Mar 2004 14:36:34 -0000 1.1 +++ OplNodeParserPlugin.vm 8 Mar 2004 23:06:40 -0000 1.2 @@ -8,21 +8,29 @@ #if($class.getNamedParameter("opl.parser", "root")) import org.commonjava.opl.OPLModelRoot; #end +#if($class.getTagByName("opl.properties-container")) +import org.commonjava.opl.generics.properties.PropertiesContainer; + +import java.util.Properties; +#end #foreach($import in $class.getTagsByName("opl.aux-import")) import $import.getNamedParameter("import"); #end public class ${plugin.getDestinationClassname($class)} extends NodeParser - ${plugin.buildImplementsClause($class)} + ${plugin.buildImplementsClause($class)} { -#foreach($method in $class.methods) - #if($method.getNamedParameter("opl.attribute", "name")) + #foreach($method in $class.methods) + #if($method.getNamedParameter("opl.attribute", "name")) private static final String ${plugin.getAttributeConstant($method)} = "${method.getNamedParameter("opl.attribute", "name")}"; + + #end #end -#end - private ${class.fullyQualifiedName} instance = new ${class.fullyQualifiedName}(); + #if($plugin.shouldGenerateLocalPropertyContainer($class)) + private Properties properties = new Properties(); + #end public ${plugin.getDestinationClassname($class)}(OPLContext ctx, NodeParser parent){ super(ctx, parent); @@ -45,17 +53,49 @@ protected final void doBeforeChildren(ElementInfo info) throws ParseException{ #foreach($method in $class.methods) #if($method.getNamedParameter("opl.attribute", "before-children") == "true") + try{ #set($attrName = $method.getNamedParameter("opl.attribute", "name")) - String $attrName = getAttribute(${plugin.getAttributeConstant($method)}, info, ${method.getNamedParameter("opl.attribute", "resolve-value")}); + String $attrName = getAttribute(${plugin.getAttributeConstant($method)}, info, ${method.getNamedParameter("opl.attribute", "resolve-value")}); #set($extractor = $method.getNamedParameter("opl.attribute", "extractor")) + #set($validator = $method.getNamedParameter("opl.attribute", "validator")) #if($extractor) - if($attrName != null){ - #set($ex = ${extractor.replaceAll("value", "${attrName}")}) - instance.$method.callSignature.replaceAll("param", "${ex}"); - } + if($attrName != null){ + #set($ex = ${extractor.replaceAll("value", $attrName)}) + #if($validator) + if(${validator.replaceAll("value", ${ex})}){ + instance.${method.callSignature.replaceAll("param", $ex)}; + } + else{ + throw new ParseException("Validation of ${attrName} failed."); + } + #else + instance.${method.callSignature.replaceAll("param", $ex)}; + #end + } #else - instance.$method.callSignature.replaceAll("param", "${attrName}"); + #if($validator) + if(${validator.replaceAll("value", ${attrName})}){ + instance.${method.callSignature.replaceAll("param", $attrName)}; + } + else{ + throw new ParseException("Validation of ${attrName} failed."); + } + #else + instance.${method.callSignature.replaceAll("param", $attrName)}; + #end #end + } + catch(ParseException e){ + throw e; + } + catch(Exception e){ + if(e instanceof RuntimeException){ + throw (RuntimeException)e; + } + else{ + throw new ParseException("Error parsing node.", e); + } + } #end #end } @@ -63,21 +103,52 @@ protected final void doAfterChildren(ElementInfo info, String bodyText) throws ParseException{ #foreach($method in $class.methods) #if($method.getNamedParameter("opl.attribute", "before-children") == "false") + try{ #set($attrName = $method.getNamedParameter("opl.attribute", "name")) - String $attrName = getAttribute(${plugin.getAttributeConstant($method)}, info, $method.getNamedParameter("opl.attribute", "resolve-value")); + String $attrName = getAttribute(${plugin.getAttributeConstant($method)}, info, $method.getNamedParameter("opl.attribute", "resolve-value")); #set($extractor = $method.getNamedParameter("opl.attribute", "extractor")) + #set($validator = $method.getNamedParameter("opl.attribute", "validator")) #if($extractor) - if($attrName != null){ - #set($ex = ${extractor.replaceAll("value", "${attrName}")}) - instance.$method.callSignature.replaceAll("param", "${ex}"); - } + if($attrName != null){ + #set($ex = ${extractor.replaceAll("value", $attrName)}) + #if($validator) + if(${validator.replaceAll("value", ${ex})}){ + instance.${method.callSignature.replaceAll("param", $ex)}; + } + else{ + throw new ParseException("Validation of ${attrName} failed."); + } + #else + instance.${method.callSignature.replaceAll("param", $ex)}; + #end + } #else - instance.$method.callSignature.replaceAll("param", "${attrName}"); + #if($validator) + if(${validator.replaceAll("value", ${attrName})}){ + instance.${method.callSignature.replaceAll("param", $attrName)}; + } + else{ + throw new ParseException("Validation of ${attrName} failed."); + } + #else + instance.${method.callSignature.replaceAll("param", $attrName)}; + #end #end + } + catch(ParseException e){ + throw e; + } + catch(Exception e){ + if(e instanceof RuntimeException){ + throw (RuntimeException)e; + } + else{ + throw new ParseException("Error parsing node.", e); + } + } #end #end - #foreach($childOfTag in $class.getTagsByName("opl.child-of")) #set($required = ${childOfTag.getNamedParameter("required")}) $childOfTag.getNamedParameter("class") container$velocityCount = @@ -95,18 +166,45 @@ #end } -#foreach($method in $class.methods) - #if($method.getTagByName("opl.delegate")) + #if($plugin.shouldGenerateLocalPropertyContainer($class)) + public void setProperties(Properties properties){ + this.properties = properties; + } + + public Properties getProperties(){ + return this.properties; + } + + #else + #if($plugin.shouldGenerateDelegatedPropertyContainerGetter($class)) + public Properties getProperties(){ + return instance.getProperties(); + } + + #end + #if($plugin.shouldGenerateDelegatedPropertyContainerSetter($class)) + public void setProperties(Properties properties){ + instance.setProperties(properties); + } + + #end + #end + #foreach($method in $class.methods) + #if($method.getTagByName("opl.delegate")) ${method.getDeclarationSignature(true)}{ + #if($method.returns.value != "void") + return instance.${method.callSignature}; + #else instance.${method.callSignature}; + #end } - #end + #end -#end -#if($class.getNamedParameter("opl.parser", "root") == "true") + #end + #if($class.getNamedParameter("opl.parser", "root") == "true") public Object getParsedObject(){ return instance; } -#end + #end } |