You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/06/17 00:10:57 UTC

svn commit: r668331 - in /myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main: java/org/apache/myfaces/buildtools/maven2/plugin/builder/ java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ java/org/apache/myface...

Author: lu4242
Date: Mon Jun 16 15:10:56 2008
New Revision: 668331

URL: http://svn.apache.org/viewvc?rev=668331&view=rev
Log:
TOMAHAWK-1285 Add validator property generation using abstract pattern like components using myfaces-builder-plugin

Added:
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java   (with props)
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/validatorClass11.vm
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/validatorClassMacros11.vm
Modified:
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ValidatorMeta.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/UnpackMojo.java

Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java?rev=668331&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java Mon Jun 16 15:10:56 2008
@@ -0,0 +1,375 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.builder;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ValidatorMeta;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.utils.BuildException;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.utils.MyfacesUtils;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
+import com.thoughtworks.qdox.JavaDocBuilder;
+import com.thoughtworks.qdox.model.AbstractJavaEntity;
+import com.thoughtworks.qdox.model.Annotation;
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaField;
+import com.thoughtworks.qdox.model.JavaMethod;
+import com.thoughtworks.qdox.model.Type;
+
+/**
+ * Maven goal to generate java source code for Validator classes.
+ * 
+ * @version $Id$
+ * @requiresDependencyResolution compile
+ * @goal make-validators
+ * @phase generate-sources
+ */
+public class MakeValidatorsMojo extends AbstractMojo
+{
+    final Logger log = Logger.getLogger(MakeValidatorsMojo.class.getName());
+
+    /**
+     * Injected Maven project.
+     * 
+     * @parameter expression="${project}"
+     * @readonly
+     */
+    private MavenProject project;
+
+    /**
+     * @parameter expression="${project.build.directory}/maven-faces-plugin/main/resources"
+     * @readonly
+     */
+    private File buildDirectory;
+
+    /**
+     * Injected name of file generated by earlier run of BuildMetaDataMojo goal.
+     * 
+     * @parameter
+     */
+    private String metadataFile = "META-INF/myfaces-metadata.xml";
+
+    /**
+     * @parameter expression="src/main/resources/META-INF"
+     */
+    private File templateSourceDirectory;
+
+    /**
+     * @parameter expression="${project.build.directory}/maven-faces-plugin/main/java"
+     */
+    private File generatedSourceDirectory;
+
+    /**
+     * @parameter
+     */
+    private String packageContains;
+
+    /**
+     * @parameter
+     */
+    private boolean force;
+
+    /**
+     * @parameter
+     */
+    private boolean suppressListenerMethods;
+
+    /**
+     * @parameter
+     */
+    private String jsfVersion;
+    
+    /**
+     * @parameter
+     */
+    private List modelIds;
+
+    /**
+     * @parameter 
+     */
+    private String templateValidatorName;
+    
+    /**
+     * This param is used to search in this folder if some file to
+     * be generated exists and avoid generation and duplicate exception.
+     * 
+     * @parameter expression="src/main/java"
+     */    
+    private File mainSourceDirectory;
+    
+    /**
+     * This param is used to search in this folder if some file to
+     * be generated exists and avoid generation and duplicate exception.
+     * 
+     * @parameter
+     */        
+    private File mainSourceDirectory2;
+
+    /**
+     * Execute the Mojo.
+     */
+    public void execute() throws MojoExecutionException
+    {
+        // This command makes Maven compile the generated source:
+        // getProject().addCompileSourceRoot( absoluteGeneratedPath.getPath() );
+        
+        try
+        {
+            project.addCompileSourceRoot( generatedSourceDirectory.getCanonicalPath() );
+            
+            if (modelIds == null){
+                modelIds = new ArrayList();
+                modelIds.add(project.getArtifactId());
+            }
+            Model model = IOUtils.loadModel(new File(buildDirectory,
+                    metadataFile));
+            new Flattener(model).flatten();
+            generateValidators(model);
+        }
+        catch (IOException e)
+        {
+            throw new MojoExecutionException("Error generating validators", e);
+        }
+        catch (BuildException e)
+        {
+            throw new MojoExecutionException("Error generating validators", e);
+        }
+    }
+    
+    
+    private VelocityEngine initVelocity() throws MojoExecutionException
+    {
+
+        Properties p = new Properties();
+
+        p.setProperty( "resource.loader", "file, class" );
+        p.setProperty( "file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
+        p.setProperty( "file.resource.loader.path", templateSourceDirectory.getPath());
+        p.setProperty( "class.resource.loader.class", "org.apache.myfaces.buildtools.maven2.plugin.builder.utils.RelativeClasspathResourceLoader" );
+        p.setProperty( "class.resource.loader.path", "META-INF");            
+        p.setProperty( "velocimacro.library", "validatorClassMacros11.vm");
+        p.setProperty( "velocimacro.permissions.allow.inline","true");
+        p.setProperty( "velocimacro.permissions.allow.inline.local.scope", "true");
+        p.setProperty( "directive.foreach.counter.initial.value","0");
+        p.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
+        "org.apache.myfaces.buildtools.maven2.plugin.builder.utils.ConsoleLogSystem" );
+        
+        File template = new File(templateSourceDirectory, _getTemplateName());
+        
+        if (template.exists())
+        {
+            log.info("Using template from file loader: "+template.getPath());
+        }
+        else
+        {
+            log.info("Using template from class loader: META-INF/"+_getTemplateName());
+        }
+                
+        VelocityEngine velocityEngine = new VelocityEngine();
+                
+        try
+        {
+            velocityEngine.init(p);
+        }
+        catch (Exception e)
+        {
+            throw new MojoExecutionException("Error creating VelocityEngine", e);
+        }
+        
+        return velocityEngine;
+    }
+    
+
+    /**
+     * Generates parsed validators.
+     */
+    private void generateValidators(Model model) throws IOException,
+            MojoExecutionException
+    {
+        // Make sure generated source directory 
+        // is added to compilation source path 
+        //project.addCompileSourceRoot(generatedSourceDirectory.getCanonicalPath());
+        
+        //Init Qdox for extract code 
+        JavaDocBuilder builder = new JavaDocBuilder();
+        
+        List sourceDirs = project.getCompileSourceRoots();
+        
+        // need a File object representing the original source tree
+        for (Iterator i = sourceDirs.iterator(); i.hasNext();)
+        {
+            String srcDir = (String) i.next();
+            builder.addSourceTree(new File(srcDir));
+        }        
+        
+        //Init velocity
+        VelocityEngine velocityEngine = initVelocity();
+
+        VelocityContext baseContext = new VelocityContext();
+        baseContext.put("utils", new MyfacesUtils());
+        
+        for (Iterator it = model.getValidators().iterator(); it.hasNext();)
+        {
+            ValidatorMeta validator = (ValidatorMeta) it.next();
+            
+            if (validator.getClassName() != null)
+            {
+                File f = new File(mainSourceDirectory, StringUtils.replace(
+                    validator.getClassName(), ".", "/")+".java");
+                                
+                if (!f.exists() && canGenerateValidator(validator))
+                {
+                    if (mainSourceDirectory2 != null){
+                        File f2 = new File(mainSourceDirectory2, StringUtils.replace(
+                                validator.getClassName(), ".", "/")+".java");
+                        if (f2.exists())
+                        {
+                            //Skip
+                            continue;
+                        }
+                    }
+                    log.info("Generating validator class:"+validator.getClassName());
+                    _generateValidator(velocityEngine, builder,validator,baseContext);
+                }
+            }
+        }        
+    }
+    
+    public boolean canGenerateValidator(ValidatorMeta validator)
+    {
+        if ( modelIds.contains(validator.getModelId())
+                && includePackage(validator))
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+    
+    public boolean includePackage(ValidatorMeta validator)
+    {
+        if (packageContains != null)
+        {
+            if (MyfacesUtils.getPackageFromFullClass(validator.getClassName()).startsWith(packageContains))
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        else
+        {
+            return true;
+        }        
+    }
+    
+    
+    /**
+     * Generates a parsed validator.
+     * 
+     * @param validator
+     *            the parsed validator metadata
+     */
+    private void _generateValidator(VelocityEngine velocityEngine,
+            JavaDocBuilder builder,
+            ValidatorMeta validator, VelocityContext baseContext)
+            throws MojoExecutionException
+    {
+        Context context = new VelocityContext(baseContext);
+        context.put("validator", validator);
+        
+        Writer writer = null;
+        File outFile = null;
+
+        try
+        {
+            outFile = new File(generatedSourceDirectory, StringUtils.replace(
+                    validator.getClassName(), ".", "/")+".java");
+
+            if ( !outFile.getParentFile().exists() )
+            {
+                outFile.getParentFile().mkdirs();
+            }
+
+            writer = new OutputStreamWriter(new FileOutputStream(outFile));
+
+            Template template = velocityEngine.getTemplate(_getTemplateName());
+                        
+            template.merge(context, writer);
+
+            writer.flush();
+        }
+        catch (Exception e)
+        {
+            throw new MojoExecutionException(
+                    "Error merging velocity templates: " + e.getMessage(), e);
+        }
+        finally
+        {
+            IOUtil.close(writer);
+            writer = null;
+        }
+    }
+                
+    private String _getTemplateName(){
+        if (templateValidatorName == null){
+            if (_is12()){
+                return "validatorClass12.vm";
+            }else{
+                return "validatorClass11.vm";
+            }
+        }
+        else
+        {
+            return templateValidatorName;
+        }
+    }
+    
+    private boolean _is12()
+    {
+        return "1.2".equals(jsfVersion) || "12".equals(jsfVersion);
+    }
+
+}

Propchange: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeValidatorsMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ValidatorMeta.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ValidatorMeta.java?rev=668331&r1=668330&r2=668331&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ValidatorMeta.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ValidatorMeta.java Mon Jun 16 15:10:56 2008
@@ -51,6 +51,7 @@
     private String _tagSuperclass;
     private String _serialuidtag;
     
+    private Boolean _generatedComponentClass;
     private Boolean _generatedTagClass;
     private Boolean _configExcluded;
     
@@ -73,6 +74,7 @@
         out.writeElement("tagClass", vm._tagClass);
         out.writeElement("tagSuperclass", vm._tagSuperclass);
         out.writeElement("serialuidtag", vm._serialuidtag);
+        out.writeElement("generatedComponentClass", vm._generatedComponentClass);
         out.writeElement("generatedTagClass", vm._generatedTagClass);
         out.writeElement("configExcluded", vm._configExcluded);
 
@@ -108,6 +110,7 @@
         digester.addBeanPropertySetter(newPrefix + "/tagClass");
         digester.addBeanPropertySetter(newPrefix + "/tagSuperclass");
         digester.addBeanPropertySetter(newPrefix + "/serialuidtag");
+        digester.addBeanPropertySetter(newPrefix + "/generatedComponentClass");
         digester.addBeanPropertySetter(newPrefix + "/generatedTagClass");
         digester.addBeanPropertySetter(newPrefix + "/configExcluded");
         
@@ -324,6 +327,16 @@
         return _serialuidtag;
     }
     
+    public void setGeneratedComponentClass(Boolean generatedComponentClass)
+    {
+        _generatedComponentClass = generatedComponentClass;
+    }
+
+    public Boolean isGeneratedComponentClass()
+    {
+        return ModelUtils.defaultOf(_generatedComponentClass,false);
+    }
+
     public void setGeneratedTagClass(Boolean generatedTagClass)
     {
         _generatedTagClass = generatedTagClass;
@@ -403,5 +416,21 @@
         }
         return _propertyTagList;
     }
-    
+
+    private List _propertyValidatorList = null; 
+
+    public Collection getPropertyValidatorList(){
+        if (_propertyValidatorList == null){
+            _propertyValidatorList = new ArrayList();
+            for (Iterator it = _properties.values().iterator(); it.hasNext();){
+                PropertyMeta prop = (PropertyMeta) it.next();
+                if (!prop.isInherited().booleanValue() && prop.isGenerated().booleanValue()){
+                    _propertyValidatorList.add(prop);
+                }
+            }
+            
+        }
+        return _propertyValidatorList;
+    }
+
 }

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java?rev=668331&r1=668330&r2=668331&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java Mon Jun 16 15:10:56 2008
@@ -159,6 +159,11 @@
         {
             ValidatorMeta validator = (ValidatorMeta) it.next();
             validator.setModelId(model.getModelId());
+            //Check if the component class file exists
+            if (!IOUtils.existsSourceFile(StringUtils.replace(
+                    validator.getClassName(),".","/")+".java", sourceDirs)){
+                validator.setGeneratedComponentClass(Boolean.TRUE);
+            }
             //Check if the validator tag class file exists
             if (validator.getTagClass() != null && 
                     !IOUtils.existsSourceFile(StringUtils.replace(
@@ -579,6 +584,14 @@
             }
         }
         
+        // If the validatorClass is not the same as the class with
+        // @JSFValidator annotation, the validator class is generated 
+        if (!clazz.getFullyQualifiedName().equals(validatorClass)){
+            //There is only one type of generation for validators
+            //(use abstract pattern), so this sets automatically the
+            //superClass
+            superClassName = getString(clazz,"superClass",props,clazz.getFullyQualifiedName());
+        }
 
         ValidatorMeta validator = new ValidatorMeta();
         validator.setName(componentName);

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/UnpackMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/UnpackMojo.java?rev=668331&r1=668330&r2=668331&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/UnpackMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/unpack/UnpackMojo.java Mon Jun 16 15:10:56 2008
@@ -289,6 +289,13 @@
 
                 if (validator.getModelId().equals(model.getModelId())){
                     
+                    if (validator.isGeneratedComponentClass().booleanValue())
+                    {
+                        getLog().info("Adding Generated: "+ validator.getClassName());
+                        exclusions.add(StringUtils.replace(
+                                validator.getClassName(), ".", "/")
+                                + ".java");
+                    }
                     if (validator.isGeneratedTagClass().booleanValue())
                     {
                         getLog().info("Adding Generated: "+ validator.getTagClass());

Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/validatorClass11.vm
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/validatorClass11.vm?rev=668331&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/validatorClass11.vm (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/validatorClass11.vm Mon Jun 16 15:10:56 2008
@@ -0,0 +1,216 @@
+## Velocity template used to generate JSF1.1-compatible validator classes
+## from validator meta-data.
+##
+## Note that there are only one type of validator generation:
+##  * "subclass mode" (use annotated class as a parent class)
+##
+## Variable $validator refers to a ComponentMeta object to process
+## Variable $utils refers to an instance of MyfacesUtils.
+##
+## When "template mode" is being used then variable $innersource
+## holds a String containing all the non-abstract functions defined
+## in the annotated class.
+##
+## The java package of the generated class is always the same as
+## the package in which the annotated class exists.
+##
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package ${validator.packageName};
+
+import javax.faces.el.ValueBinding;
+import javax.faces.context.FacesContext;
+$utils.importTagClasses($validator)
+
+// generated from class $validator.classSource
+// WARNING: This file was automatically generated. Do not edit it directly,
+//          or you will lose your changes.
+public class ${utils.getClassFromFullClass($validator.className)} extends $validator.superClassName
+#if ($validator.implements)
+    implements $validator.implements
+#end
+{
+
+#if ($validator.validatorId)
+    static public final String VALIDATOR_ID = 
+        "$validator.validatorId";
+#end
+
+    public ${utils.getClassFromFullClass($validator.className)}()
+    {
+    }
+    
+#set ($propertyList = ${validator.propertyValidatorList})
+
+#foreach( $property in $propertyList )
+#set ($field = $property.fieldName)
+#set ($type = $utils.getClassFromFullClass($property.className))
+#if($utils.getDefaultValueField($property)) 
+#set ($defaultValue = $utils.getDefaultValueField($property))
+#else
+#set ($defaultValue = false)
+#end
+    // Property: $property.name
+#if ($property.isLiteralOnly() || $property.isTagExcluded() )
+    private $type $field #if($defaultValue) = $defaultValue;#{else};#{end}
+
+     
+#else
+    private $type $field;
+    
+#end
+#if($utils.isPrimitiveClass($type) && !$property.isTagExcluded() )
+    private boolean ${field}Set;
+    
+#if ($property.isSetMethod())
+    $property.setMethodScope boolean $utils.getPrefixedPropertyName("isSet", $property.name)()
+    {
+        return ${field}Set;
+    }
+#end
+#end
+#if($property.isLocalMethod())
+#if("boolean" == $type)
+#set ($methodName = $utils.getPrefixedPropertyName("isLocal", $property.name))
+#else
+#set ($methodName = $utils.getPrefixedPropertyName("getLocal", $property.name))
+#end
+    final $property.localMethodScope $type ${methodName}()
+    {
+        return $field;
+    }
+     
+#end
+    public $type $utils.getMethodReaderFromProperty($property.name, $type)()
+    {
+#if ($property.isTagExcluded() || $property.isLiteralOnly())
+        return $field;
+#else
+#if ($utils.isPrimitiveClass($type))
+        if (${field}Set)
+#else
+        if ($field != null)
+#end
+        {
+            return $field;
+        }
+        ValueBinding vb = getValueBinding("$property.name");
+        if (vb != null)
+        {
+#if ($utils.isPrimitiveClass($type))
+            return ($utils.castIfNecessary($type) vb.getValue(getFacesContext())).${type}Value();
+#else
+#set ($pritype = $utils.getPrimitiveType($property.className))
+#if ($utils.isPrimitiveClass($pritype))
+            Object value = vb == null ? null : vb.getValue(getFacesContext());
+            if (!(value instanceof $type)){
+                value = ${type}.valueOf(value.toString());
+            }            
+            return $utils.castIfNecessary($type) value;
+#else
+            return $utils.castIfNecessary($type) vb.getValue(getFacesContext());
+#end
+#end
+        }
+#if ($defaultValue)
+        return $defaultValue; 
+#elseif ($utils.isPrimitiveClass($type))
+        return $utils.primitiveDefaultValue($type);
+#else       
+        return null;
+#end
+#end
+    }
+
+    public void $utils.getPrefixedPropertyName("set", $property.name)($type $utils.getVariableFromName($property.name))
+    {
+        this.$field = $utils.getVariableFromName($property.name);
+#if ($utils.isPrimitiveClass($type) && !$property.isTagExcluded() )
+        this.${field}Set = true;        
+#end
+    }
+#end
+
+    public Object saveState(FacesContext facesContext)
+    {
+#set ($primitiveCount = $propertyList.size() + 1)
+#foreach( $property in $propertyList )
+#if($utils.isPrimitiveClass($property.className))
+#set ($primitiveCount = $primitiveCount + 1)
+#end
+#end
+        Object[] values = new Object[$primitiveCount];
+        values[0] = super.saveState(facesContext);
+#set ($arrayIndex = 0)
+#foreach( $property in $propertyList )
+#set ($field = $property.fieldName)
+#set ($type = $property.className)
+#set ($arrayIndex = $arrayIndex + 1)
+#if ($property.jspName == "validator" && $property.isMethodBinding() )
+        values[$arrayIndex] = saveAttachedState(facesContext,${field}List);
+#elseif ( $property.isStateHolder() )## || $utils.isConverter($type)
+        values[$arrayIndex] = saveAttachedState(facesContext,$field);
+#elseif($utils.isPrimitiveClass($type))
+#if ($type == "boolean")
+        values[$arrayIndex] = ${utils.getBoxedClass($type)}.valueOf($field);
+#else
+        values[$arrayIndex] = new ${utils.getBoxedClass($type)}($field);
+#end
+#else
+        values[$arrayIndex] = $field;
+#end
+#if($utils.isPrimitiveClass($type) && !$property.isTagExcluded())
+#set ($arrayIndex = $arrayIndex + 1)
+        values[$arrayIndex] = Boolean.valueOf(${field}Set);
+#end
+#end
+        return values; 
+    }
+
+    public void restoreState(FacesContext facesContext, Object state)
+    {
+        Object[] values = (Object[])state;
+        super.restoreState(facesContext,values[0]);
+#set ($arrayIndex = 0)
+#foreach( $property in $propertyList )
+#set ($field = $property.fieldName)
+#set ($type = $property.className)
+#set ($arrayIndex = $arrayIndex + 1)
+#if ( $property.isStateHolder() )
+#if ($property.jspName == "validator" && $property.isMethodBinding() )
+        ${field}List = (List<Validator>) restoreAttachedState(facesContext,values[$arrayIndex]);
+#elseif ($utils.isList($type))
+        $field = (List) restoreAttachedState(facesContext,values[$arrayIndex]);
+#else
+        $field = $utils.castIfNecessary($type) restoreAttachedState(facesContext,values[$arrayIndex]); 
+#end
+#elseif ($utils.isConverter($type)) 
+        $field = (Converter) restoreAttachedState(facesContext,values[$arrayIndex]);
+#elseif ($utils.isPrimitiveClass($type))
+        $field = ($utils.castIfNecessary($type) values[$arrayIndex]).${type}Value();
+#else
+        $field = $utils.castIfNecessary($type) values[$arrayIndex];
+#end
+#if($utils.isPrimitiveClass($type) && !$property.isTagExcluded() )
+#set ($arrayIndex = $arrayIndex + 1)
+        ${field}Set = ((Boolean) values[$arrayIndex]).booleanValue();
+#end
+#end
+    }
+}

Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/validatorClassMacros11.vm
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/validatorClassMacros11.vm?rev=668331&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/validatorClassMacros11.vm (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/validatorClassMacros11.vm Mon Jun 16 15:10:56 2008
@@ -0,0 +1,4 @@
+## Macro definitions for component class definition
+##
+## Velocity macros defined in this file will be available when executing
+## the componentClass11.vm template file.
\ No newline at end of file