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 2011/11/02 03:31:54 UTC

svn commit: r1196438 - in /myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder: model/ qdox/ qdox/parse/

Author: lu4242
Date: Wed Nov  2 02:31:54 2011
New Revision: 1196438

URL: http://svn.apache.org/viewvc?rev=1196438&view=rev
Log:
MYFACES-3381 Add @JSFFaceletFunction annotation

Added:
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/FaceletFunctionMeta.java   (with props)
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/parse/FaceletFunctionParsingStrategy.java   (with props)
Modified:
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/Model.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java

Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/FaceletFunctionMeta.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/FaceletFunctionMeta.java?rev=1196438&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/FaceletFunctionMeta.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/FaceletFunctionMeta.java Wed Nov  2 02:31:54 2011
@@ -0,0 +1,215 @@
+/*
+ *  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.model;
+
+import org.apache.commons.digester.Digester;
+import org.apache.commons.lang.StringUtils;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.io.XmlWriter;
+
+/**
+ * 
+ * @since 1.0.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 796607 $ $Date: 2009-07-21 22:00:30 -0500 (mar, 21 jul 2009) $
+ */
+public class FaceletFunctionMeta
+{
+    private String _modelId;
+    private String _longDescription;
+    private String _description;
+    private String _name;
+
+    private String _signature;
+    private String _declaredSignature;
+    private String _sourceClassName;
+
+    public FaceletFunctionMeta()
+    {
+    }
+    
+    public FaceletFunctionMeta(FaceletFunctionMeta pm)
+    {
+        _modelId = pm._modelId;
+        _name = pm._name;
+        _description = pm._description;
+        _longDescription = pm._longDescription;
+        _signature = pm._signature;
+        _sourceClassName = pm._sourceClassName;
+        _declaredSignature = pm._declaredSignature;
+    }
+    
+    protected void writeXml(XmlWriter out)
+    {
+        writeXml(out, this);
+    }
+    
+    /**
+     * Write this model out as xml.
+     */
+    public static void writeXml(XmlWriter out, FaceletFunctionMeta pm)
+    {
+        out.beginElement("faceletFunction");
+        out.writeElement("modelId", pm._modelId);
+        out.writeElement("name", pm._name);
+        out.writeElement("desc", pm._description);
+        out.writeElement("longDesc", pm._longDescription);
+        out.writeElement("sourceClassName", pm._sourceClassName);
+        out.writeElement("signature", pm._signature);
+        out.writeElement("declaredSignature", pm._declaredSignature);
+        out.endElement("faceletFunction");
+    }
+
+    /**
+     * Add digester rules to repopulate a Model instance from an xml file.
+     */
+    public static void addXmlRules(Digester digester, String prefix)
+    {
+        String newPrefix = prefix + "/faceletFunction";
+
+        digester.addObjectCreate(newPrefix, FaceletFunctionMeta.class);
+        digester.addSetNext(newPrefix, "addFaceletFunction");
+        digester.addBeanPropertySetter(newPrefix + "/modelId");
+        digester.addBeanPropertySetter(newPrefix + "/name");
+        digester.addBeanPropertySetter(newPrefix + "/sourceClassName");
+        digester.addBeanPropertySetter(newPrefix + "/desc", "description");
+        digester.addBeanPropertySetter(newPrefix + "/longDesc", "longDescription");
+        digester.addBeanPropertySetter(newPrefix + "/signature");
+        digester.addBeanPropertySetter(newPrefix + "/declaredSignature");
+    }
+
+    /**
+     * Merge the data in the specified other property into this one, throwing an
+     * exception if there is an incompatibility.
+     */
+    public void merge(FaceletFunctionMeta other)
+    {
+        // Merge className does not harm, since you cannot
+        //use polymorphism on a jsf component.
+        _name = ModelUtils.merge(this._name, other._name);
+        _modelId = ModelUtils.merge(this._modelId, other._modelId);
+        _description = ModelUtils.merge(this._description, other._description);
+        _longDescription = ModelUtils.merge(this._longDescription, other._longDescription);
+        _sourceClassName = ModelUtils.merge(this._sourceClassName, other._sourceClassName);
+        _signature = ModelUtils.merge(this._signature, other._signature);
+        _declaredSignature = ModelUtils.merge(this._declaredSignature, other._declaredSignature);
+    }
+
+    /**
+     * Indicates which "group" of metadata this class belongs to.
+     * <p>
+     * Projects can inherit metadata from other projects, in which case
+     * all the ClassMeta objects end up in one big collection. But for
+     * some purposes it is necessary to iterate over the objects belonging
+     * to only one project (eg when generating components). This return
+     * value can be tested to check which "group" (project) a particular
+     * instance belongs to.
+     */
+    public String getModelId()
+    {
+        return _modelId;
+    }
+
+    public void setModelId(String modelId)
+    {
+        this._modelId = modelId;
+    }
+
+    /**
+     * Set the name that users refer to this property by.
+     * <p>
+     * This sets the name of xml tag attributes, and the base names of generated
+     * getter/setter methods.
+     */
+    public void setName(String name)
+    {
+        _name = name;
+    }
+
+    public String getName()
+    {
+        return _name;
+    }
+
+    public void setDescription(String desc)
+    {
+        _description = desc;
+    }
+
+    public String getDescription()
+    {
+        return _description;
+    }
+
+    public void setLongDescription(String desc)
+    {
+        _longDescription = desc;
+    }
+
+    public String getLongDescription()
+    {
+        return _longDescription;
+    }
+    
+    /**
+     * Utility method to return just the packagename part of the className
+     * attribute.
+     */
+    public String getSourcePackageName()
+    {
+        return StringUtils.substring(getSourceClassName(), 0, StringUtils.lastIndexOf(getSourceClassName(), '.'));
+    }
+
+    /**
+     * Return the className of the real java class from which this metadata was gathered.
+     * <p>
+     * This is mostly used for documentation. However when generating code in "template mode",
+     * this is used to locate the original class in order to find the source code to copy.
+     * It is also used for some reason in MakeComponentsMojo when determining whether to
+     * generate a class or not - this is probably wrong.
+     */
+    public String getSourceClassName()
+    {
+        return _sourceClassName;
+    }
+
+    public void setSourceClassName(String sourceClassName)
+    {
+        this._sourceClassName = sourceClassName;
+    }
+    
+    public void setSignature(String signature)
+    {
+      _signature = signature;
+    }
+
+    public String getSignature()
+    {
+      return _signature;
+    }
+    
+    public void setDeclaredSignature(String signature)
+    {
+      _declaredSignature = signature;
+    }
+
+    public String getDeclaredSignature()
+    {
+      return _declaredSignature;
+    }
+}

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

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/Model.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/Model.java?rev=1196438&r1=1196437&r2=1196438&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/Model.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/Model.java Wed Nov  2 02:31:54 2011
@@ -40,6 +40,7 @@ public class Model
     private List _renderKits = new ArrayList(100);
     private List _tags = new ArrayList(100);
     private List _faceletTags = new ArrayList(100);
+    private List _faceletFunctions = new ArrayList(100);
     private List _webConfigs = new ArrayList(10);
 
     private Map _componentsByClass = new TreeMap();
@@ -51,6 +52,7 @@ public class Model
     private Map _faceletTagsByClass =  new TreeMap();
     private Map _componentsByTagClass = new TreeMap();
     private Map _faceletTagsByName = new TreeMap();
+    private Map _faceletFunctionsByName = new TreeMap();
     private Map _webConfigsByModelId = new TreeMap();
     
     private Map _componentsByType = new TreeMap();
@@ -116,6 +118,12 @@ public class Model
             WebConfigMeta c = (WebConfigMeta) i.next();
             c.writeXml(out);
         }
+        
+        for (Iterator i = model._faceletFunctions.iterator(); i.hasNext();)
+        {
+            FaceletFunctionMeta c = (FaceletFunctionMeta) i.next();
+            c.writeXml(out);
+        }
 
         out.endElement("model");
     }
@@ -143,6 +151,7 @@ public class Model
         TagMeta.addXmlRules(digester, prefix);
         FaceletTagMeta.addXmlRules(digester, prefix);
         WebConfigMeta.addXmlRules(digester, prefix);
+        FaceletFunctionMeta.addXmlRules(digester, prefix);
     }
     
     /**
@@ -215,6 +224,16 @@ public class Model
             }
         }
         
+        for (Iterator it = other.getFaceletFunctions().iterator(); it.hasNext();)
+        {
+            FaceletFunctionMeta faceletTag = (FaceletFunctionMeta) it.next();
+            
+            if (this.findFaceletFunctionByName(faceletTag.getName())== null)
+            {
+                this.addFaceletFunction(faceletTag);
+            }
+        }        
+        
         for (Iterator it = other.getWebConfigs().iterator(); it.hasNext();)
         {
             WebConfigMeta webConfig = (WebConfigMeta) it.next();
@@ -498,6 +517,49 @@ public class Model
     }
     
     /**
+     * Adds a tag to this faces config document.
+     * 
+     * @since 1.0.10
+     * @param tag
+     *            the tag to add
+     */
+    public void addFaceletFunction(FaceletFunctionMeta tag)
+    {
+        _faceletFunctions.add(tag);
+        if (tag.getName() != null)
+        {
+            _faceletFunctionsByName.put(tag.getName(), tag);
+        }
+    }
+
+    /**
+     * Returns all tags
+     * @since 1.0.10
+     */
+    public List getFaceletFunctions()
+    {
+        return _faceletFunctions;
+    }
+
+    /**
+     * Returns an iterator for all tags.
+     * @since 1.0.10
+     */
+    public Iterator faceletFunctions()
+    {
+        return _faceletFunctions.iterator();
+    }
+
+    /**
+     * @since 1.0.10
+     */
+    public FaceletFunctionMeta findFaceletFunctionByName(String name)
+    {
+        return (FaceletFunctionMeta) _faceletFunctionsByName.get(name);
+    }
+
+    
+    /**
      * @since 1.0.4
      */
     public List getWebConfigs()

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=1196438&r1=1196437&r2=1196438&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 Wed Nov  2 02:31:54 2011
@@ -43,6 +43,7 @@ import org.apache.myfaces.buildtools.mav
 import org.apache.myfaces.buildtools.maven2.plugin.builder.qdox.parse.ClientBehaviorRendererParsingStrategy;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.qdox.parse.ComponentParsingStrategy;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.qdox.parse.ConverterParsingStrategy;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.qdox.parse.FaceletFunctionParsingStrategy;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.qdox.parse.FaceletTagParsingStrategy;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.qdox.parse.JspTagParsingStrategy;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.qdox.parse.RenderKitParsingStrategy;
@@ -256,6 +257,7 @@ public class QdoxModelBuilder implements
         context.addStrategy(new RenderKitParsingStrategy());
         context.addStrategy(new ValidatorParsingStrategy());
         context.addStrategy(new WebConfigParamParsingStrategy());
+        context.addStrategy(new FaceletFunctionParsingStrategy());
         
         context.parseClass(clazz, model);
     }

Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/parse/FaceletFunctionParsingStrategy.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/parse/FaceletFunctionParsingStrategy.java?rev=1196438&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/parse/FaceletFunctionParsingStrategy.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/parse/FaceletFunctionParsingStrategy.java Wed Nov  2 02:31:54 2011
@@ -0,0 +1,136 @@
+/*
+ *  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.qdox.parse;
+
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.model.FaceletFunctionMeta;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.qdox.QdoxHelper;
+
+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.JavaMethod;
+import com.thoughtworks.qdox.model.JavaParameter;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ * @since 1.0.10
+ *
+ */
+public class FaceletFunctionParsingStrategy implements JavaClassParsingStrategy
+{
+    private static final String DOC_FACELET_FUNCTION = "JSFFaceletFunction";
+
+    public void parseClass(JavaClass clazz, Model model)
+    {
+        JavaMethod[] methods = clazz.getMethods();
+        for (int i = 0; i < methods.length; ++i)
+        {
+            JavaMethod method = methods[i];
+
+            DocletTag tag = method.getTagByName(DOC_FACELET_FUNCTION);
+            if (tag != null)
+            {
+                Map props = tag.getNamedParameterMap();
+                processFaceletFunction(props, (AbstractJavaEntity)tag.getContext(), clazz,
+                        method, model);
+            }
+
+            Annotation anno = QdoxHelper.getAnnotation(method, DOC_FACELET_FUNCTION);
+            if (anno != null)
+            {
+                Map props = anno.getNamedParameterMap();
+                processFaceletFunction(props, (AbstractJavaEntity)anno.getContext(), clazz,
+                        method, model);
+            }
+        }
+    }
+    
+    private void processFaceletFunction(Map props, AbstractJavaEntity ctx,
+            JavaClass clazz, JavaMethod method, Model model)
+    {
+        String name = QdoxHelper.getString(clazz, "name", props, null);
+        String longDescription = method.getComment();
+        String descDflt = QdoxHelper.getFirstSentence(longDescription);
+        if ((descDflt == null) || (descDflt.length() < 2))
+        {
+            descDflt = "no description";
+        }
+        String shortDescription = QdoxHelper.getString(clazz, "desc", props, descDflt);
+        
+        // Check for both "class" and "clazz" in order to support
+        // doclet and real annotations.
+        String classNameOverride = QdoxHelper.getString(clazz, "class", props, null);
+        classNameOverride = QdoxHelper.getString(clazz,"clazz",props,classNameOverride);
+        
+        String signature = QdoxHelper.getString(clazz,"signature",props, null);
+        if (signature == null)
+        {
+            StringBuilder sb = new StringBuilder();
+            sb.append(method.getReturnType().getJavaClass().getFullyQualifiedName());
+            sb.append(' ');
+            sb.append(method.getName());
+            sb.append('(');
+            sb.append(' ');
+            JavaParameter[] jp = method.getParameters();
+            for (int i = 0; i < jp.length ; i++)
+            {
+                sb.append(jp[i].getType().getJavaClass().getFullyQualifiedName());
+                if (i+1 < jp.length)
+                {
+                    sb.append(',');
+                    sb.append(' ');
+                }
+            }
+            sb.append(')');
+            signature = sb.toString();
+        }
+        
+        String declaredSignature = QdoxHelper.getString(clazz,"declaredSignature",props, null);
+        if (declaredSignature == null)
+        {
+            declaredSignature = method.getDeclarationSignature(false);
+        }
+
+        FaceletFunctionMeta ffm = new FaceletFunctionMeta();
+
+        // JSF Entity class.
+        if (StringUtils.isEmpty(classNameOverride))
+        {
+            ffm.setSourceClassName(clazz.getFullyQualifiedName());
+        }
+        else
+        {
+            ffm.setSourceClassName(classNameOverride);
+        }
+        
+        ffm.setModelId(model.getModelId());
+        ffm.setSignature(signature);
+        ffm.setDeclaredSignature(declaredSignature);
+        ffm.setName(name);
+        ffm.setLongDescription(longDescription);
+        ffm.setDescription(shortDescription);
+        model.addFaceletFunction(ffm);
+    }
+}

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