Modified: incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java?view=diff&rev=491941&r1=491940&r2=491941 ============================================================================== --- incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java (original) +++ incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateComponentsMojo.java Tue Jan 2 13:22:22 2007 @@ -15,39 +15,26 @@ */ package org.apache.myfaces.trinidadbuild.plugin.faces; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.StringWriter; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; +import org.apache.myfaces.trinidadbuild.plugin.faces.generator.component.ComponentGenerator; +import org.apache.myfaces.trinidadbuild.plugin.faces.generator.component.MyFacesComponentGenerator; +import org.apache.myfaces.trinidadbuild.plugin.faces.generator.component.TrinidadComponentGenerator; import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter; import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean; -import org.apache.myfaces.trinidadbuild.plugin.faces.parse.EventBean; -import org.apache.myfaces.trinidadbuild.plugin.faces.parse.EventRefBean; import org.apache.myfaces.trinidadbuild.plugin.faces.parse.FacesConfigBean; -import org.apache.myfaces.trinidadbuild.plugin.faces.parse.FacetBean; -import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean; import org.apache.myfaces.trinidadbuild.plugin.faces.util.ComponentFilter; import org.apache.myfaces.trinidadbuild.plugin.faces.util.FilteredIterator; -import org.apache.myfaces.trinidadbuild.plugin.faces.util.PropertyFilter; import org.apache.myfaces.trinidadbuild.plugin.faces.util.SourceTemplate; import org.apache.myfaces.trinidadbuild.plugin.faces.util.Util; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringWriter; +import java.lang.reflect.Modifier; +import java.util.Iterator; + /** * @version $Id$ * @requiresDependencyResolution compile @@ -75,7 +62,7 @@ /** * Generates parsed components. */ - private void _generateComponents() throws IOException + private void _generateComponents() throws IOException, MojoExecutionException { // Make sure generated source directory // is added to compilation source path @@ -123,13 +110,24 @@ * @param component the parsed component metadata */ private void _generateComponent( - ComponentBean component) + ComponentBean component) throws MojoExecutionException { + ComponentGenerator generator; + String fullClassName = component.getComponentClass(); - + + if (component.isTrinidadComponent()) + { + generator = new TrinidadComponentGenerator(getLog(), _is12()); + } + else + { + generator = new MyFacesComponentGenerator(getLog(),_is12() ); + } + try { - getLog().debug("Generating " + fullClassName); + getLog().debug("Generating " + fullClassName+", with generator: "+generator.getClass().getName()); String sourcePath = Util.convertClassToSourcePath(fullClassName, ".java"); File targetFile = new File(generatedSourceDirectory, sourcePath); @@ -142,8 +140,8 @@ if (componentFamily == null) { - getLog().error("Missing <component-family> for \"" + - fullClassName + "\""); + getLog().warn("Missing <component-family> for \"" + + fullClassName + "\", generation of this Component is skipped"); } else { @@ -189,21 +187,21 @@ out.println(); // imports - _writeImports(out, template, packageName, + generator.writeImports(out, template, packageName, fullSuperclassName, superclassName, component); // class - _writeClassBegin(out, className, superclassName, component, template); + generator.writeClassBegin(out, className, superclassName, component, template); // static final constants - _writePropertyValueConstants(out, component); - _writePropertyConstants(out, superclassName, component); - _writeFacetConstants(out, component); - _writeGenericConstants(out, componentFamily, componentType); + generator.writePropertyValueConstants(out, component); + generator.writePropertyConstants(out, superclassName, component); + generator.writeFacetConstants(out, component); + generator.writeGenericConstants(out, componentFamily, componentType); // public constructors and methods - _writeConstructor(out, component, Modifier.PUBLIC); + generator.writeConstructor(out, component, Modifier.PUBLIC); // insert template code if (template != null) @@ -212,24 +210,30 @@ template.close(); } - _writeFacetMethods(out, component); - _writePropertyMethods(out, component); + generator.writeFacetMethods(out, component); + if (template == null) + { + generator.writePropertyMethods(out, component); + } + else + { + generator.writePropertyMethods(out, component, template.getIgnoreMethods()); + } + if (!suppressListenerMethods) - _writeListenerMethods(out, component); + generator.writeListenerMethods(out, component); + + generator.writeStateManagementMethods(out, component); - _writeGetFamily(out); + generator.writeGetFamily(out); // protected constructors and methods // TODO: reverse this order, to make protected constructor go first // for now we want consistency with previous code generation - _writeGetBeanType(out); - _writeConstructor(out, component, Modifier.PROTECTED); + generator.writeOther(out, component); - // static initializer - _writeTypeLock(out, component); - - _writeClassEnd(out); + generator.writeClassEnd(out); out.close(); @@ -251,1066 +255,6 @@ } } - private void _writeClassBegin( - PrettyWriter out, - String className, - String superclassName, - ComponentBean component, - SourceTemplate template) - { - out.println("/**"); - - // TODO: restore description (needs escaping?) -// String description = component.getDescription(); -// if (description != null) -// { -// out.println(" *"); -// out.println(" * " + convertMultilineComment(description)); -// } - - String longDescription = component.getLongDescription(); - if (longDescription != null) - { - out.println(" *"); - out.println(" * " + convertMultilineComment(longDescription)); - } - - if (component.hasEvents(true)) - { - // the events javadoc - out.println(" *"); - out.println(" * <h4>Events:</h4>"); - out.println(" * <table border=\"1\" width=\"100%\" cellpadding=\"3\" summary=\"\">"); - out.println(" * <tr bgcolor=\"#CCCCFF\" class=\"TableHeadingColor\">"); - out.println(" * <th align=\"left\">Type</th>"); - out.println(" * <th align=\"left\">Phases</th>"); - out.println(" * <th align=\"left\">Description</th>"); - out.println(" * </tr>"); - Iterator events = component.events(true); - while (events.hasNext()) - { - EventRefBean eventRef = (EventRefBean)events.next(); - EventBean event = eventRef.resolveEventType(); - if (event != null) - { - String eventClass = event.getEventClass(); - String[] eventPhases = eventRef.getEventDeliveryPhases(); - String eventDescription = event.getDescription(); - out.println(" * <tr class=\"TableRowColor\">"); - out.println(" * <td valign=\"top\"><code>" + eventClass + "</code></td>"); - out.print(" * <td valign=\"top\" nowrap>"); - if (eventPhases != null) - { - for (int i=0; i < eventPhases.length; i++) - { - if (i > 0) - out.print("<br>"); - out.print(eventPhases[i]); - } - } - out.println("</td>"); - out.println(" * <td valign=\"top\">" + eventDescription + "</td>"); - out.println(" * </tr>"); - } - } - out.println(" * </table>"); - } - - if (!component.hasChildren()) - { - out.println(" * <p>"); - out.println(" * It does not support any children."); - } - - out.println(" */"); - - // TODO: eliminate <mfp:component-class-modifier> metadata - int modifiers = component.getComponentClassModifiers(); - String classStart = Modifier.toString(modifiers); - // TODO: use canonical ordering - classStart = classStart.replaceAll("public abstract", "abstract public"); - out.println(classStart + " class " + className + - " extends " + superclassName); - - Set interfaces = new HashSet(); - if (template != null) - interfaces.addAll(template.getImplements()); - - if (component.isNamingContainer()) - interfaces.add("javax.faces.component.NamingContainer"); - - Iterator events = component.events(); - while (events.hasNext()) - { - EventRefBean eventRef = (EventRefBean)events.next(); - EventBean event = eventRef.resolveEventType(); - if (event != null) - { - if (!eventRef.isIgnoreSourceInterface()) - { - String source = event.getEventSourceInterface(); - if (source != null) - interfaces.add(Util.getClassFromFullClass(source)); - } - } - } - - if (!interfaces.isEmpty()) - { - Set implementsSet = new HashSet(); - for (Iterator iter=interfaces.iterator(); iter.hasNext();) - { - String fcqn = (String)iter.next(); - implementsSet.add(Util.getClassFromFullClass(fcqn)); - } - - // implements clause spans multiple lines - char[] indent = new char[classStart.length() + - " class ".length() + - className.length() + 1]; - Arrays.fill(indent, ' '); - out.print(indent); - out.print("implements "); - for (Iterator iter=implementsSet.iterator(); iter.hasNext();) - { - out.print((String)iter.next()); - if (iter.hasNext()) - { - out.println(","); - out.print(indent); - out.print(" "); // same length as "implements " - } - } - out.println(); - } - - out.println("{"); - out.indent(); - } - - private void _writeClassEnd( - PrettyWriter out) - { - out.unindent(); - out.println("}"); - } - - private void _writeImports( - PrettyWriter out, - SourceTemplate template, - String packageName, - String fullSuperclassName, - String superclassName, - ComponentBean component) - { - Set imports = new TreeSet(); - - // Use the template imports - if (template != null) - imports.addAll(template.getImports()); - - // FacesBean is always needed to define the TYPE - imports.add("org.apache.myfaces.trinidad.bean.FacesBean"); - - // Detect NamingContainer - if (component.isNamingContainer()) - imports.add("javax.faces.component.NamingContainer"); - - Iterator properties = component.properties(); - properties = new FilteredIterator(properties, new NonVirtualFilter()); - // PropertyKey only needed if there are properties - if (properties.hasNext()) - { - imports.add("org.apache.myfaces.trinidad.bean.PropertyKey"); - - PropertyFilter resolvable = new ResolvableTypeFilter(); - while (properties.hasNext()) - { - PropertyBean property = (PropertyBean)properties.next(); - String propertyClass = property.getPropertyClass(); - if (propertyClass != null) - { - imports.add(propertyClass); - // Check for generics - String[] types = property.getAttributeClassParameters(); - if(types != null) - { - for(int i = types.length - 1; i >= 0; i--) - { - _addGenericImports(imports, types[i]); - } - } - } - - // ComponentUtils only needed for resolvable properties - if (resolvable.accept(property)) - imports.add("org.apache.myfaces.trinidad.util.ComponentUtils"); - } - } - - Iterator facets = component.facets(); - // UIComponent needed if there are facets - if (facets.hasNext()) - imports.add("javax.faces.component.UIComponent"); - - Iterator events = component.events(); - while (events.hasNext()) - { - EventRefBean eventRef = (EventRefBean)events.next(); - EventBean event = eventRef.resolveEventType(); - - if (event == null) - { - getLog().warn("Unknown event type \"" + eventRef.getEventType() + "\""+ - " in component:"+component.getComponentType()); - } - else - { - String listenerClass = event.getEventListenerClass(); - if (listenerClass != null) - imports.add(listenerClass); - - if (!eventRef.isIgnoreSourceInterface()) - { - String sourceInterface = event.getEventSourceInterface(); - if (sourceInterface != null) - imports.add(sourceInterface); - } - } - } - - // Import causes a collision if className and superclassName are equal - if (!superclassName.equals(fullSuperclassName)) - { - String superPackageName = Util.getPackageFromFullClass(fullSuperclassName); - // component superclass only needed if not in - // same package as component class - if (superPackageName != packageName) - imports.add(fullSuperclassName); - } - - // do not import implicit types! - imports.removeAll(Util.PRIMITIVE_TYPES); - - writeImports(out, packageName, imports); - } - - private void _addGenericImports(Set imports, String type) - { - Matcher matcher = _GENERIC_TYPE.matcher(type); - if(matcher.matches()) - { - // Generic type - imports.add(matcher.group(1)); - String[] types = matcher.group(2).split(","); - for(int i = types.length - 1; i >= 0; i--) - { - _addGenericImports(imports, types[i]); - } - } - else - { - // Non-generic type - imports.add(type); - } - } - - private void _writeGenericConstants( - PrettyWriter out, - String componentFamily, - String componentType) throws IOException - { - out.println(); - out.println("static public final String COMPONENT_FAMILY ="); - out.println(" \"" + componentFamily + "\";"); - out.println("static public final String COMPONENT_TYPE ="); - out.println(" \"" + componentType + "\";"); - } - - private void _writePropertyConstants( - PrettyWriter out, - String superclassName, - ComponentBean component) throws IOException - { - out.println("static public final FacesBean.Type TYPE = new FacesBean.Type("); - out.indent(); - out.println(superclassName + ".TYPE);"); - out.unindent(); - - // component property keys - Iterator properties = component.properties(); - properties = new FilteredIterator(properties, new NonVirtualFilter()); - while (properties.hasNext()) - { - PropertyBean property = (PropertyBean)properties.next(); - String propName = property.getPropertyName(); - String propKey = Util.getConstantNameFromProperty(propName, "_KEY"); - String propAlias = property.getAliasOf(); - - out.println("static public final PropertyKey " + propKey + " ="); - out.indent(); - if (propAlias != null) - { - String aliasKey = Util.getConstantNameFromProperty(propAlias, "_KEY"); - out.print("TYPE.registerAlias(" + aliasKey + ", \"" + propName + "\");"); - } - else - { - out.print("TYPE.registerKey(\"" + propName + "\""); - - // property class - String propFullClass = property.getPropertyClass(); - String propClass = Util.getClassFromFullClass(propFullClass); - if (propClass == null) - { - propClass = "String"; - } - String propDefault = property.getDefaultValue(); - - if (!"Object".equals(propClass) || propDefault != null) - { - // TODO: do not use boxed class here - String boxedClass = Util.getBoxedClass(propClass); - out.print(", " + boxedClass + ".class"); - } - - if (propDefault != null) - { - out.print(", " + _convertStringToBoxedLiteral(propClass, propDefault)); - } - - // property capabilities - String propCaps = _getPropertyCapabilities(property); - if (propCaps != null) - out.print(", " + propCaps); - out.println(");"); - } - out.unindent(); - } - } - - private void _writePropertyValueConstants( - PrettyWriter out, - ComponentBean component) throws IOException - { - // component property keys - Iterator properties = component.properties(); - properties = new FilteredIterator(properties, new NonVirtualFilter()); - while (properties.hasNext()) - { - PropertyBean property = (PropertyBean)properties.next(); - String[] propertyValues = property.getPropertyValues(); - - if (propertyValues != null) - { - String propName = property.getPropertyName(); - - for (int i=0; i < propertyValues.length; i++) - { - String propValue = propertyValues[i]; - String propValueName = propName + - Character.toUpperCase(propValue.charAt(0)) + - propValue.substring(1); - String propValueKey = Util.getConstantNameFromProperty(propValueName); - - out.println("static public final String " + propValueKey + " = \"" + propValue + "\";"); - } - - } - } - } - - private void _writeFacetConstants( - PrettyWriter out, - ComponentBean component) throws IOException - { - Iterator facets = component.facets(); - while (facets.hasNext()) - { - FacetBean facet = (FacetBean)facets.next(); - String facetName = facet.getFacetName(); - String facetKey = Util.getConstantNameFromProperty(facetName, "_FACET"); - out.println("static public final " + - "String " + facetKey + " = \"" + facetName + "\";"); - } - } - - private String _convertStringToBoxedLiteral( - String className, - String value) - { - if (value == null) - { - return null; - } - else if ("String".equals(className)) - { - return "\"" + value.replaceAll("\'", "\\'") + "\""; - } - else if ("boolean".equals(className)) - { - return ("true".equals(value)) ? "Boolean.TRUE" : "Boolean.FALSE"; - } - else if ("char".equals(className)) - { - return "new Character('" + value.replaceAll("\'", "\\'") + "')"; - } - else if ("int".equals(className)) - { - return "new Integer(" + value + ")"; - } - else if ("double".equals(className)) - { - return "new Double(" + value + ")"; - } - else if ("float".equals(className)) - { - return "new Float(" + value + ")"; - } - else if ("Number".equals(className)) - { - if(value.indexOf(".") == -1) - { - return "new Integer(" + value + ")"; - } - else - { - return "new Double(" + value + ")"; - } - } - else - { - throw new IllegalStateException("property-class " + className + " not supported for default-value"); - } - } - - private void _writeConstructor( - PrettyWriter out, - ComponentBean component, - int modifiers) throws IOException - { - String fullClassName = component.getComponentClass(); - String className = Util.getClassFromFullClass(fullClassName); - - if (Modifier.isPublic(modifiers)) - { - // TODO: eliminate this inconsistency - if (!Modifier.isAbstract(component.getComponentClassModifiers())) - { - String rendererType = component.getRendererType(); - - if (rendererType != null) - rendererType = _convertStringToBoxedLiteral("String", rendererType); - - out.println(); - out.println("/**"); - // TODO: restore this correctly phrased comment (tense vs. command) - //out.println(" * Constructs an instance of " + className + "."); - out.println(" * Construct an instance of the " + className + "."); - out.println(" */"); - out.println("public " + className + "()"); - out.println("{"); - out.indent(); - out.println("super(" + rendererType + ");"); - out.unindent(); - out.println("}"); - } - } - else if (Modifier.isProtected(modifiers)) - { - out.println(); - out.println("/**"); - // TODO: restore this more descriptive comment with param docs - //out.println(" * Construct an instance of the " + className); - //out.println(" * with the specified renderer type."); - //out.println(" * "); - //out.println(" * @param rendererType the renderer type"); - out.println(" * Construct an instance of the " + className + "."); - out.println(" */"); - out.println("protected " + className + "("); - out.indent(); - out.println("String rendererType"); - out.println(")"); - out.unindent(); - out.println("{"); - out.indent(); - out.println("super(rendererType);"); - out.unindent(); - out.println("}"); - - // TODO: eliminate this inconsistency - if (Modifier.isAbstract(component.getComponentClassModifiers())) - { - out.println(); - out.println("/**"); - // TODO: restore this correctly phrased comment (tense vs. command) - //out.println(" * Constructs an instance of " + className + "."); - out.println(" * Construct an instance of the " + className + "."); - out.println(" */"); - out.println("protected " + className + "()"); - out.println("{"); - out.indent(); - out.println("this(null);"); - out.unindent(); - out.println("}"); - } - } - } - - private void _writeGetFamily( - PrettyWriter out) throws IOException - { - out.println(); - out.println("@Override"); - out.println("public String getFamily()"); - out.println("{"); - out.indent(); - out.println("return COMPONENT_FAMILY;"); - out.unindent(); - out.println("}"); - } - - private void _writeGetBeanType( - PrettyWriter out) throws IOException - { - out.println(); - out.println("@Override"); - out.println("protected FacesBean.Type getBeanType()"); - out.println("{"); - out.indent(); - out.println("return TYPE;"); - out.unindent(); - out.println("}"); - } - - private void _writePropertyMethods( - PrettyWriter out, - ComponentBean component) throws IOException - { - Iterator properties = component.properties(); - properties = new FilteredIterator(properties, new NonVirtualFilter()); - while (properties.hasNext()) - { - PropertyBean property = (PropertyBean)properties.next(); - if (property.isList()) - _writePropertyListMethods(out, property); - else - { - _writePropertyGet(out, property); - _writePropertySet(out, property); - } - } - } - - private void _writePropertyListMethods( - PrettyWriter out, - PropertyBean property) throws IOException - { - String propName = property.getPropertyName(); - String propKey = Util.getConstantNameFromProperty(propName, "_KEY"); - String propertyClass = property.getPropertyClass(); - if (!"java.util.List".equals(propertyClass)) - { - getLog().error("Invalid list type: " + propertyClass); - return; - } - - // Look for the generic type - if it doesn't exist, then - // we'll be an Object. - String[] params = property.getPropertyClassParameters(); - if ((params == null) || (params.length == 0)) - propertyClass = "java.lang.Object"; - else - propertyClass = params[0]; - - propertyClass = Util.getClassFromFullClass(propertyClass); - - String singularName = _getSingular(propName); - String propVar = Util.getVariableFromName(singularName); - String description = property.getDescription(); - String addMethod = Util.getPrefixedPropertyName("add", singularName); - String removeMethod = Util.getPrefixedPropertyName("remove", singularName); - String getMethod = Util.getPrefixedPropertyName("get", propName); - - out.println(); - out.println("/**"); - if (description != null) - { - out.println(" * Adds a " + convertMultilineComment(description)); - } - out.println(" */"); - out.println("final public void " + addMethod + "(" + propertyClass + " " + - propVar + ")"); - out.println("{"); - out.indent(); - out.println("if (" + propVar + " == null)"); - out.println(" throw new NullPointerException();"); - out.println(); - out.println("getFacesBean().addEntry(" + propKey + ", " + propVar + ");"); - out.unindent(); - out.println("}"); - - out.println(); - out.println("/**"); - if (description != null) - { - out.println(" * Removes a " + convertMultilineComment(description)); - } - out.println(" */"); - out.println("final public void " + removeMethod + "(" + propertyClass + " " + - propVar + ")"); - out.println("{"); - out.indent(); - out.println("if (" + propVar + " == null)"); - out.println(" throw new NullPointerException();"); - out.println(); - out.println("getFacesBean().removeEntry(" + propKey + ", " + propVar + ");"); - out.unindent(); - out.println("}"); - - out.println(); - out.println("/**"); - if (description != null) - { - out.println(" * Gets all " + convertMultilineComment(description)); - } - out.println(" */"); - out.println("final public " + propertyClass + "[] " + getMethod + "()"); - out.println("{"); - out.indent(); - out.println("return (" + propertyClass + "[]) getFacesBean().getEntries("); - out.println(" " + propKey + ", " + propertyClass + ".class);"); - out.unindent(); - out.println("}"); - } - - static private String _getSingular(String plural) - { - if (plural.endsWith("s")) - return plural.substring(0, plural.length() - 1); - return plural; - } - - private void _writePropertySet( - PrettyWriter out, - PropertyBean property) throws IOException - { - String propertyClass = Util.getPropertyClass(property); - _writePropertySet(out, property, propertyClass); - - if (property.getAlternateClass() != null) - { - String alternateClass = Util.getAlternatePropertyClass(property); - _writePropertySet(out, property, alternateClass); - } - } - - private void _writePropertySet( - PrettyWriter out, - PropertyBean property, - String propertyClass) throws IOException - { - String propName = property.getPropertyName(); - String propKey = Util.getConstantNameFromProperty(propName, "_KEY"); - String propVar = Util.getVariableFromName(propName); - String description = property.getDescription(); - String setMethod = Util.getPrefixedPropertyName("set", propName); - - out.println(); - out.println("/**"); - if (description != null) - { - out.println(" * Sets " + convertMultilineComment(description)); - } - // TODO: restore this comment. -// if (property.isRequired()) -// { -// out.println(" * <p>"); -// out.println(" * This is a required property on the component."); -// } - // TODO: put this back in - //out.println(" * "); - //out.println(" * @param " + propName + " the new " + propName + " value"); - out.println(" */"); - - out.println("final public void " + setMethod + "(" + propertyClass + " " + propVar + ")"); - out.println("{"); - out.indent(); - if (Util.isPrimitiveClass(propertyClass)) - { - // TODO: use UIXComponentBase setXXXProperty methods when possible - if (propertyClass.equals("boolean")) - { - // TODO: add back space before ternary operator - out.println("setProperty(" + propKey + ", " + propVar + "? Boolean.TRUE : Boolean.FALSE);"); - } - else - { - String boxedClass = Util.getBoxedClass(propertyClass); - out.println("setProperty(" + propKey + ", new " + boxedClass + "(" + propVar + "));"); - } - } - else - { - out.println("setProperty(" + propKey + ", (" + propVar + "));"); - } - out.unindent(); - out.println("}"); - } - - private void _writePropertyGet( - PrettyWriter out, - PropertyBean property) throws IOException - { - String propName = property.getPropertyName(); - String propKey = Util.getConstantNameFromProperty(propName, "_KEY"); - String propertyFullClass = property.getPropertyClass(); - String propertyClass = Util.getClassFromFullClass(propertyFullClass); - String description = property.getDescription(); - String getMethod = Util.getMethodReaderFromProperty(propName, propertyClass); - - boolean isUnchecked = false; - String[] genericTypes = property.getPropertyClassParameters(); - if(genericTypes != null && genericTypes.length > 0) - { - isUnchecked = true; - propertyClass = Util.getPropertyClass(property); - } - - out.println(); - out.println("/**"); - if (description != null) - { - out.println(" * Gets " + convertMultilineComment(description)); - } - if (property.isRequired()) - { - out.println(" * <p>"); - out.println(" * This is a required property on the component."); - out.println(" * </p>"); - } - // TODO: put this back in - //out.println(" *"); - //out.println(" * @return the new " + propName + " value"); - out.println(" */"); - - if(isUnchecked) - { - out.println("@SuppressWarnings(\"unchecked\")"); - } - - out.println("final public " + propertyClass + " " + getMethod + "()"); - out.println("{"); - out.indent(); - - String resolvableType = _resolveType(propertyFullClass); - if (resolvableType != null) - { - // TODO: change signature of ComponentUtils.resolveCharacter - // to take Object instead of Character - if (resolvableType.equals("Character")) - { - out.println("return ComponentUtils.resolveCharacter((Character)getProperty(" + propKey + "));"); - } - else - { - // TODO: stop specifying default values in the getters - String resolveMethod = Util.getPrefixedPropertyName("resolve", resolvableType); - String propertyDefault = property.getDefaultValue(); - out.print("return ComponentUtils." + resolveMethod + "(getProperty(" + propKey + ")"); - if (propertyDefault != null) - { - out.print(", " + convertStringToLiteral(propertyClass, - propertyDefault)); - } - out.println(");"); - } - } - else - { - if(propertyClass.equals("Object")) - { - // Cast is not necessary if the property class is Object - out.println("return getProperty(" + propKey + ");"); - } - else - { - out.println("return (" + propertyClass + ")" + - "getProperty(" + propKey + ");"); - } - } - out.unindent(); - out.println("}"); - } - - private void _writeFacetMethods( - PrettyWriter out, - ComponentBean component) throws IOException - { - Iterator facets = component.facets(); - while (facets.hasNext()) - { - FacetBean facet = (FacetBean)facets.next(); - _writeFacetGet(out, facet); - _writeFacetSet(out, facet); - } - } - - private void _writeFacetSet( - PrettyWriter out, - FacetBean facet) throws IOException - { - String facetName = facet.getFacetName(); - // TODO: drop the unnecessary "Facet" suffix - String facetVar = facetName + "Facet"; - String facetKey = Util.getConstantNameFromProperty(facetName, "_FACET"); - String setMethod = Util.getPrefixedPropertyName("set", facetName); - String description = facet.getDescription(); - - out.println(); - out.println("/**"); - if (description != null) - { - out.println(" * " + convertMultilineComment(description)); - } - if (facet.isRequired()) - { - out.println(" * <p>"); - out.println(" * This is a required facet on the component."); - } - // TODO: put this back in - //out.println(" * "); - //out.println(" * @param " + facetVar + " the new " + facetName + " facet"); - out.println(" */"); - - // Remove type safety warning since getFacets is not generics enabled - // under JSF 1.1 spec - // TODO: Remove this line when Trinidad switch to JSF 1.2 - out.println("@SuppressWarnings(\"unchecked\")"); - - out.println("final public void " + setMethod + "(UIComponent " + facetVar + ")"); - out.println("{"); - out.indent(); - out.println("getFacets().put(" + facetKey + ", " + facetVar + ");"); - out.unindent(); - out.println("}"); - } - - private void _writeFacetGet( - PrettyWriter out, - FacetBean facet) throws IOException - { - String facetName = facet.getFacetName(); - String facetKey = Util.getConstantNameFromProperty(facetName, "_FACET"); - String getMethod = Util.getPrefixedPropertyName("get", facetName); - String description = facet.getDescription(); - - out.println(); - out.println("/**"); - if (description != null) - { - out.println(" * " + convertMultilineComment(description)); - } - if (facet.isRequired()) - { - out.println(" * <p>"); - out.println(" * This is a required facet on the component."); - } - // TODO: put this back in - //out.println(" * "); - //out.println(" * @return the " + facetName + " facet"); - out.println(" */"); - - out.println("final public UIComponent " + getMethod + "()"); - out.println("{"); - out.indent(); - out.println("return getFacet(" + facetKey + ");"); - out.unindent(); - out.println("}"); - } - - private void _writeListenerMethods( - PrettyWriter out, - ComponentBean component) throws IOException - { - Iterator events = component.events(); - while (events.hasNext()) - { - EventRefBean eventRef = (EventRefBean)events.next(); - EventBean event = eventRef.resolveEventType(); - if (event != null) - { - _writeListenerAdd(out, event); - _writeListenerRemove(out, event); - _writeListenersGet(out, event); - } - } - } - - private void _writeListenerAdd( - PrettyWriter out, - EventBean event) throws IOException - { - String listenerFullClass = event.getEventListenerClass(); - String listenerClass = Util.getClassFromFullClass(listenerFullClass); - - String eventName = event.getEventName(); - String addMethod = Util.getMethodNameFromEvent("add", eventName, "Listener"); - - out.println(); - out.println("/**"); - out.println(" * Adds a " + eventName + " listener."); - out.println(" *"); - out.println(" * @param listener the " + eventName + " listener to add"); - out.println(" */"); - - out.println("final public void " + addMethod + "("); - out.indent(); - out.println(listenerClass + " listener)"); - out.unindent(); - out.println("{"); - out.indent(); - out.println("addFacesListener(listener);"); - out.unindent(); - out.println("}"); - } - - private void _writeListenerRemove( - PrettyWriter out, - EventBean event) throws IOException - { - String listenerFullClass = event.getEventListenerClass(); - String listenerClass = Util.getClassFromFullClass(listenerFullClass); - - String eventName = event.getEventName(); - String removeMethod = Util.getMethodNameFromEvent("remove", eventName, "Listener"); - - out.println(); - out.println("/**"); - out.println(" * Removes a " + eventName + " listener."); - out.println(" *"); - out.println(" * @param listener the " + eventName + " listener to remove"); - out.println(" */"); - - out.println("final public void " + removeMethod + "("); - out.indent(); - out.println(listenerClass + " listener)"); - out.unindent(); - out.println("{"); - out.indent(); - out.println("removeFacesListener(listener);"); - out.unindent(); - out.println("}"); - } - - private void _writeListenersGet( - PrettyWriter out, - EventBean event) throws IOException - { - String listenerFullClass = event.getEventListenerClass(); - String listenerClass = Util.getClassFromFullClass(listenerFullClass); - - String eventName = event.getEventName(); - String getMethod = Util.getMethodNameFromEvent("get", eventName, "Listeners"); - - out.println(); - out.println("/**"); - out.println(" * Returns an array of attached " + eventName + " listeners."); - out.println(" *"); - out.println(" * @return an array of attached " + eventName + " listeners."); - out.println(" */"); - - out.println("final public " + listenerClass + "[] " + getMethod + "()"); - out.println("{"); - out.indent(); - out.println("return (" + listenerClass + "[])" + - "getFacesListeners(" + listenerClass + ".class);"); - out.unindent(); - out.println("}"); - } - - private void _writeTypeLock( - PrettyWriter out, ComponentBean component) throws IOException - { - out.println(); - out.println("static"); - out.println("{"); - out.indent(); - String rendererType = component.getRendererType(); - if (rendererType == null) - { - out.println("TYPE.lock();"); - } - else - { - String componentFamily = component.findComponentFamily(); - out.println("TYPE.lockAndRegister(\"" + componentFamily + "\"," + - "\"" + rendererType + "\");"); - } - - out.unindent(); - out.println("}"); - } - - private String _getPropertyCapabilities( - PropertyBean property) - { - List caps = new ArrayList(); - - if (property.isMethodBinding() || - property.isLiteralOnly()) - { - caps.add("PropertyKey.CAP_NOT_BOUND"); - } - - if (property.isStateHolder()) - { - caps.add("PropertyKey.CAP_STATE_HOLDER"); - } - - if (property.isTransient()) - { - caps.add("PropertyKey.CAP_TRANSIENT"); - } - - if (property.isList()) - { - caps.add("PropertyKey.CAP_LIST"); - } - - if (caps.isEmpty()) - return null; - - StringBuffer sb = new StringBuffer(); - for (int i=0; i < caps.size(); i++) - { - if (i > 0) - sb.append(" | "); - sb.append(caps.get(i)); - } - return sb.toString(); - } - - private class NonVirtualFilter extends PropertyFilter - { - protected boolean accept( - PropertyBean property) - { - return (!property.isVirtual()); - } - } - - private class ResolvableTypeFilter extends PropertyFilter - { - protected boolean accept( - PropertyBean property) - { - String propertyClass = property.getPropertyClass(); - String resolvableType = _resolveType(propertyClass); - return (resolvableType != null); - } - } - private class IfModifiedFilter extends ComponentFilter { protected boolean accept( @@ -1328,32 +272,11 @@ } } - static private String _resolveType( - String className) + private boolean _is12() { - return (String)_RESOLVABLE_TYPES.get(className); - } - - static private Map _createResolvableTypes() - { - Map resolvableTypes = new HashMap(); - - resolvableTypes.put("boolean", "Boolean"); - resolvableTypes.put("char", "Character"); - // TODO: put this back in - //resolvableTypes.put("java.util.Date", "Date"); - resolvableTypes.put("int", "Integer"); - resolvableTypes.put("float", "Float"); - resolvableTypes.put("double", "Double"); - resolvableTypes.put("java.util.Locale", "Locale"); - resolvableTypes.put("long", "Long"); - resolvableTypes.put("java.lang.String", "String"); - // TODO: put this back in - //resolvableTypes.put("java.lang.String[]", "StringArray"); - resolvableTypes.put("java.util.TimeZone", "TimeZone"); - - return Collections.unmodifiableMap(resolvableTypes); + return "1.2".equals(jsfVersion) || "12".equals(jsfVersion); } + /** * @parameter expression="${project}" @@ -1401,6 +324,8 @@ */ private boolean suppressListenerMethods; - static private final Pattern _GENERIC_TYPE = Pattern.compile("([^<]+)<(.+)>"); - static final private Map _RESOLVABLE_TYPES = _createResolvableTypes(); + /** + * @parameter + */ + private String jsfVersion; }
Modified: incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateFacesConfigMojo.java URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateFacesConfigMojo.java?view=diff&rev=491941&r1=491940&r2=491941 ============================================================================== --- incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateFacesConfigMojo.java (original) +++ incubator/adffaces/branches/faces-1_2-070102/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateFacesConfigMojo.java Tue Jan 2 13:22:22 2007 @@ -15,46 +15,28 @@ */ package org.apache.myfaces.trinidadbuild.plugin.faces; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.sax.SAXSource; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; - -import org.apache.myfaces.trinidadbuild.plugin.faces.util.XIncludeFilter; - import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; - +import org.apache.myfaces.trinidadbuild.plugin.faces.util.XIncludeFilter; import org.w3c.dom.Document; import org.w3c.dom.Element; - import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; +import javax.xml.parsers.*; +import javax.xml.transform.*; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import java.io.*; +import java.net.URL; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + /** * @version $Id$ * @requiresDependencyResolution compile @@ -159,7 +141,12 @@ Result mergedResult = new StreamResult(resultStream); - URL xslURL = getClass().getResource("resources/transform.xsl"); + URL xslURL; + if (_is12()) + xslURL = getClass().getResource("resources/transform12.xsl"); + else + xslURL = getClass().getResource("resources/transform.xsl"); + InputStream xsl = xslURL.openStream(); StreamSource xslSource = new StreamSource(xsl); Transformer transformer = transFactory.newTransformer(xslSource); @@ -217,6 +204,12 @@ } } + private boolean _is12() + { + return "1.2".equals(jsfVersion) || "12".equals(jsfVersion); + } + + /** * @parameter expression="${project}" * @readonly @@ -239,6 +232,7 @@ */ private String packageContains = ""; + /** * @parameter expression="${project.build.directory}/maven-faces-plugin/main/resources" * @required @@ -257,9 +251,8 @@ /** * @parameter - * @required */ - private String typePrefix; + private String typePrefix = ""; /** * Name of an XSLT stylesheet in src/main/conf that will be applied @@ -268,4 +261,9 @@ * @parameter */ private String transformStylesheet; + + /** + * @parameter + */ + private String jsfVersion; }
