incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bara...@apache.org
Subject svn commit: r468935 [2/2] - in /incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces: ./ generator/ parse/ util/
Date Sun, 29 Oct 2006 16:49:56 GMT
Added: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java?view=auto&rev=468935
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java
(added)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java
Sun Oct 29 08:49:55 2006
@@ -0,0 +1,382 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.trinidadbuild.plugin.faces.generator;
+
+import org.apache.maven.plugin.logging.Log;
+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.Util;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+import java.io.IOException;
+import java.lang.reflect.Modifier;
+
+public class TrinidadComponentGenerator extends AbstractComponentGenerator
+{
+    public TrinidadComponentGenerator(Log log)
+    {
+        super(log);
+    }
+
+    protected void addSpecificImports(Set imports, ComponentBean component)
+    {
+        // FacesBean is always needed to define the TYPE
+
+        imports.add("org.apache.myfaces.trinidad.bean.FacesBean");
+
+        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();
+
+                // ComponentUtils only needed for resolvable properties
+                if (resolvable.accept(property))
+                    imports.add("org.apache.myfaces.trinidad.util.ComponentUtils");
+            }
+        }
+    }
+
+    protected void writeConstructorContent(PrettyWriter out,
+                                           ComponentBean component,
+                                           int modifiers,
+                                           String rendererType) throws IOException
+    {
+        out.println("super("+rendererType+");");
+    }
+
+    public 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();
+        }
+    }
+
+    protected void writePropertyDeclaration(PrettyWriter out, PropertyBean property) throws
IOException
+    {
+        // nothing
+    }
+
+    protected void writePropertySetterContent(PrettyWriter out,
+                                              PropertyBean property,
+                                              String propertyClass) throws IOException
+    {
+        String propName = property.getPropertyName();
+        String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
+        String propVar = Util.getVariableFromName(propName);
+
+        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 + "));");
+        }
+    }
+
+    protected void writePropertyGetterContent(
+            PrettyWriter out,
+            PropertyBean property) throws IOException
+    {
+        String propName = property.getPropertyName();
+        String propertyFullClass = property.getPropertyClass();
+        String propertyClass = Util.getClassFromFullClass(propertyFullClass);
+        String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
+
+        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(", " + Util.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 + ");");
+            }
+        }
+    }
+
+    public 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("}");
+    }
+
+
+    public void writeOther(PrettyWriter out, ComponentBean component) throws IOException
+    {
+        _writeGetBeanType(out);
+
+        writeConstructor(out, component, Modifier.PROTECTED);
+
+        _writeTypeLock(out, component);        
+    }
+
+    protected 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 _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();
+    }
+}

Propchange: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/TrinidadComponentGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java?view=diff&rev=468935&r1=468934&r2=468935
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java
Sun Oct 29 08:49:55 2006
@@ -917,6 +917,14 @@
   }
 
   /**
+   * Checks if any of the component superclasses is UIXComponentBase
+   */
+  public boolean isTrinidadComponent()
+  {
+      return (_TRINIDAD_COMPONENT_BASE.equals(findComponentSuperclass()));
+  }
+
+  /**
    * Finds the component class in the component inheritance
    * hierarchy.
    *

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java?view=diff&rev=468935&r1=468934&r2=468935
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java
Sun Oct 29 08:49:55 2006
@@ -340,8 +340,33 @@
     return _jspPropertyName;
   }
 
+  /**
+   * Sets the field name of this property, when not generating Trinidad components
+   *
+   * @param fieldPropertyName  the field property name
+   */
+  public void setFieldPropertyName(
+    String fieldPropertyName)
+  {
+    _fieldPropertyName = fieldPropertyName;
+  }
+
+  /**
+   * Returns the field name of this property, when not generating Trinidad components
+   *
+   * @return  the field property name
+   */
+  public String getFieldPropertyName()
+  {
+    if (_fieldPropertyName == null)
+      return "_"+getPropertyName();
+
+    return _fieldPropertyName;
+  }
+
   private String  _aliasOf;
   private String  _jspPropertyName;
+  private String  _fieldPropertyName;
   private boolean _required;
   private boolean _literalOnly;
   private boolean _stateHolder;

Modified: incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java?view=diff&rev=468935&r1=468934&r2=468935
==============================================================================
--- incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java
(original)
+++ incubator/adffaces/branches/myfaces-1_2-maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java
Sun Oct 29 08:49:55 2006
@@ -19,10 +19,12 @@
 import java.util.Collections;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.Iterator;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
+import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
 
 public class Util
 {
@@ -252,6 +254,64 @@
       name = name + "Param";
 
     return name;
+  }
+
+  static public String convertStringToLiteral(String value)
+  {
+    return convertStringToLiteral("String", value);
+  }
+
+  static public String convertStringToLiteral(String className, String value)
+  {
+    if (value == null)
+    {
+      return null;
+    }
+    else if ("String".equals(className))
+    {
+      return "\"" + value.replaceAll("\'", "\\'") + "\"";
+    }
+    else
+    {
+      return value;
+    }
+  }
+
+  static public void writeImports(
+    PrettyWriter out,
+    String       packageName,
+    Set          imports)
+  {
+    Iterator iterator = imports.iterator();
+    iterator = new FilteredIterator(iterator,
+                                    new PackageImportsFilter(packageName));
+    while (iterator.hasNext())
+    {
+      String className = (String)iterator.next();
+      out.println("import " + className + ";");
+    }
+
+    out.println();
+  }
+
+  static private class PackageImportsFilter implements Filter
+  {
+    public PackageImportsFilter(
+      String packageName)
+    {
+      _packageName = packageName;
+    }
+
+    public boolean accept(
+      Object object)
+    {
+      String className = (String)object;
+      String packageName = Util.getPackageFromFullClass(className);
+      return (!packageName.equals(_packageName) &&
+              !packageName.equals("java.lang"));
+    }
+
+    private final String _packageName;
   }
 
   static private void _buildPropertyClass(StringBuffer buffer, String type)



Mime
View raw message