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 2013/09/24 16:32:45 UTC

svn commit: r1525898 - in /myfaces/core/trunk: impl/src/main/java/org/apache/myfaces/el/unified/resolver/ impl/src/main/java/org/apache/myfaces/view/facelets/ impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/ impl/src/main/java/org/apa...

Author: lu4242
Date: Tue Sep 24 14:32:45 2013
New Revision: 1525898

URL: http://svn.apache.org/r1525898
Log:
small improvement refactor and move method from facelets/FaceletViewDeclarationLanguage.java to shared-public ClassUtils, remove duplicate file in shared

Added:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/util/FaceletsViewDeclarationLanguageUtils.java
Removed:
    myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/CompositeComponentELResolver.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/AttributeHandler.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeMetadataTargetImpl.java
    myfaces/core/trunk/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/CompositeComponentELResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/CompositeComponentELResolver.java?rev=1525898&r1=1525897&r2=1525898&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/CompositeComponentELResolver.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/CompositeComponentELResolver.java Tue Sep 24 14:32:45 2013
@@ -36,7 +36,7 @@ import javax.faces.context.FacesContext;
 import javax.faces.el.CompositeComponentExpressionHolder;
 
 import org.apache.myfaces.shared.config.MyfacesConfig;
-import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
+import org.apache.myfaces.shared.util.ClassUtils;
 import org.apache.myfaces.view.facelets.tag.composite.CompositeComponentBeanInfo;
 
 /**
@@ -144,7 +144,7 @@ public final class CompositeComponentELR
                 {
                     try
                     {
-                        type = FaceletViewDeclarationLanguage._javaTypeToClass((String)type);
+                        type = ClassUtils.javaDefaultTypeToClass((String)type);
                     }
                     catch (ClassNotFoundException e)
                     {

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java?rev=1525898&r1=1525897&r2=1525898&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java Tue Sep 24 14:32:45 2013
@@ -24,7 +24,6 @@ import java.beans.PropertyDescriptor;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.Writer;
-import java.lang.reflect.Array;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -147,6 +146,7 @@ import org.apache.myfaces.view.facelets.
 import org.apache.myfaces.view.facelets.tag.jsf.PartialMethodExpressionValidator;
 import org.apache.myfaces.view.facelets.tag.jsf.PartialMethodExpressionValueChangeListener;
 import org.apache.myfaces.view.facelets.tag.jsf.PassThroughLibrary;
+import org.apache.myfaces.view.facelets.util.FaceletsViewDeclarationLanguageUtils;
 
 /**
  * This class represents the abstraction of Facelets as a ViewDeclarationLanguage.
@@ -1269,8 +1269,9 @@ public class FaceletViewDeclarationLangu
                         methodSignature = methodSignature.trim();
                         methodExpression = context.getApplication().getExpressionFactory().
                                 createMethodExpression(elContext,
-                                        attributeExpressionString, _getReturnType(methodSignature),
-                                        _getParameters(methodSignature));
+                                        attributeExpressionString, 
+                                        FaceletsViewDeclarationLanguageUtils.getReturnType(methodSignature),
+                                        FaceletsViewDeclarationLanguageUtils.getParameters(methodSignature));
 
                         methodExpression = reWrapMethodExpression(methodExpression, attributeNameValueExpression);
 
@@ -1756,113 +1757,6 @@ public class FaceletViewDeclarationLangu
     }
 
     /**
-     * This method is similar to shared ClassUtils.javaTypeToClass,
-     * but the default package is java.lang
-     * TODO: Move to shared project
-     *
-     * @param type
-     * @return
-     * @throws ClassNotFoundException
-     */
-    public static Class _javaTypeToClass(String type)
-            throws ClassNotFoundException
-    {
-        if (type == null)
-        {
-            throw new NullPointerException("type");
-        }
-
-        // try common types and arrays of common types first
-        Class clazz = (Class) ClassUtils.COMMON_TYPES.get(type);
-        if (clazz != null)
-        {
-            return clazz;
-        }
-
-        int len = type.length();
-        if (len > 2 && type.charAt(len - 1) == ']' && type.charAt(len - 2) == '[')
-        {
-            String componentType = type.substring(0, len - 2);
-            Class componentTypeClass = ClassUtils.classForName(componentType);
-            return Array.newInstance(componentTypeClass, 0).getClass();
-        }
-
-        if (type.indexOf('.') == -1)
-        {
-            type = "java.lang." + type;
-        }
-        return ClassUtils.classForName(type);
-    }
-
-    private Class _getReturnType(String signature)
-    {
-        int endName = signature.indexOf('(');
-        if (endName < 0)
-        {
-            throw new FacesException("Invalid method signature:" + signature);
-        }
-        int end = signature.lastIndexOf(' ', endName);
-        if (end < 0)
-        {
-            throw new FacesException("Invalid method signature:" + signature);
-        }
-        try
-        {
-            return _javaTypeToClass(signature.substring(0, end));
-        }
-        catch (ClassNotFoundException e)
-        {
-            throw new FacesException("Invalid method signature:" + signature);
-        }
-    }
-
-    /**
-     * Get the parameters types from the function signature.
-     *
-     * @return An array of parameter class names
-     */
-    private Class[] _getParameters(String signature) throws FacesException
-    {
-        ArrayList<Class> params = new ArrayList<Class>();
-        // Signature is of the form
-        // <return-type> S <method-name S? '('
-        // < <arg-type> ( ',' <arg-type> )* )? ')'
-        int start = signature.indexOf('(') + 1;
-        boolean lastArg = false;
-        while (true)
-        {
-            int p = signature.indexOf(',', start);
-            if (p < 0)
-            {
-                p = signature.indexOf(')', start);
-                if (p < 0)
-                {
-                    throw new FacesException("Invalid method signature:" + signature);
-                }
-                lastArg = true;
-            }
-            String arg = signature.substring(start, p).trim();
-            if (!"".equals(arg))
-            {
-                try
-                {
-                    params.add(_javaTypeToClass(arg));
-                }
-                catch (ClassNotFoundException e)
-                {
-                    throw new FacesException("Invalid method signature:" + signature);
-                }
-            }
-            if (lastArg)
-            {
-                break;
-            }
-            start = p + 1;
-        }
-        return params.toArray(new Class[params.size()]);
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/AttributeHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/AttributeHandler.java?rev=1525898&r1=1525897&r2=1525898&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/AttributeHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/AttributeHandler.java Tue Sep 24 14:32:45 2013
@@ -36,8 +36,8 @@ import javax.faces.view.facelets.TagHand
 
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
+import org.apache.myfaces.shared.util.ClassUtils;
 import org.apache.myfaces.view.facelets.FaceletCompositionContext;
-import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
 
 /**
  * @author Leonardo Uribe (latest modification by $Author$)
@@ -335,7 +335,7 @@ public class AttributeHandler extends Ta
                     {
                         try
                         {
-                            clazz = FaceletViewDeclarationLanguage._javaTypeToClass(type);
+                            clazz = ClassUtils.javaDefaultTypeToClass(type);
                         }
                         catch (ClassNotFoundException e)
                         {

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeMetadataTargetImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeMetadataTargetImpl.java?rev=1525898&r1=1525897&r2=1525898&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeMetadataTargetImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeMetadataTargetImpl.java Tue Sep 24 14:32:45 2013
@@ -28,8 +28,8 @@ import java.util.Map;
 import javax.el.ValueExpression;
 import javax.faces.view.facelets.MetadataTarget;
 import javax.faces.context.FacesContext;
+import org.apache.myfaces.shared.util.ClassUtils;
 
-import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
 
 /**
  * Like MetadataTargetImpl but integrate composite component bean info
@@ -82,7 +82,7 @@ final class CompositeMetadataTargetImpl 
                 {
                     try
                     {
-                        type = FaceletViewDeclarationLanguage._javaTypeToClass((String)type);
+                        type = ClassUtils.javaDefaultTypeToClass((String)type);
                     }
                     catch (ClassNotFoundException e)
                     {

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/util/FaceletsViewDeclarationLanguageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/util/FaceletsViewDeclarationLanguageUtils.java?rev=1525898&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/util/FaceletsViewDeclarationLanguageUtils.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/util/FaceletsViewDeclarationLanguageUtils.java Tue Sep 24 14:32:45 2013
@@ -0,0 +1,101 @@
+/*
+ * 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.view.facelets.util;
+
+import java.util.ArrayList;
+import javax.faces.FacesException;
+import org.apache.myfaces.shared.util.ClassUtils;
+
+/**
+ * Utility methods used in FaceletsViewDeclarationLanguage
+ *
+ * @author Leonardo Uribe
+ */
+public class FaceletsViewDeclarationLanguageUtils
+{
+    public static Class getReturnType(String signature)
+    {
+        int endName = signature.indexOf('(');
+        if (endName < 0)
+        {
+            throw new FacesException("Invalid method signature:" + signature);
+        }
+        int end = signature.lastIndexOf(' ', endName);
+        if (end < 0)
+        {
+            throw new FacesException("Invalid method signature:" + signature);
+        }
+        try
+        {
+            return ClassUtils.javaDefaultTypeToClass(signature.substring(0, end));
+        }
+        catch (ClassNotFoundException e)
+        {
+            throw new FacesException("Invalid method signature:" + signature);
+        }
+    }
+
+    /**
+     * Get the parameters types from the function signature.
+     *
+     * @return An array of parameter class names
+     */
+    public static Class[] getParameters(String signature) throws FacesException
+    {
+        ArrayList<Class> params = new ArrayList<Class>();
+        // Signature is of the form
+        // <return-type> S <method-name S? '('
+        // < <arg-type> ( ',' <arg-type> )* )? ')'
+        int start = signature.indexOf('(') + 1;
+        boolean lastArg = false;
+        while (true)
+        {
+            int p = signature.indexOf(',', start);
+            if (p < 0)
+            {
+                p = signature.indexOf(')', start);
+                if (p < 0)
+                {
+                    throw new FacesException("Invalid method signature:" + signature);
+                }
+                lastArg = true;
+            }
+            String arg = signature.substring(start, p).trim();
+            if (!"".equals(arg))
+            {
+                try
+                {
+                    params.add(ClassUtils.javaDefaultTypeToClass(arg));
+                }
+                catch (ClassNotFoundException e)
+                {
+                    throw new FacesException("Invalid method signature:" + signature);
+                }
+            }
+            if (lastArg)
+            {
+                break;
+            }
+            start = p + 1;
+        }
+        return params.toArray(new Class[params.size()]);
+    }
+
+
+}

Modified: myfaces/core/trunk/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java?rev=1525898&r1=1525897&r2=1525898&view=diff
==============================================================================
--- myfaces/core/trunk/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java (original)
+++ myfaces/core/trunk/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java Tue Sep 24 14:32:45 2013
@@ -262,6 +262,43 @@ public final class ClassUtils
         
     }
 
+    /**
+     * This method is similar to shared ClassUtils.javaTypeToClass,
+     * but the default package for the type is java.lang
+     *
+     * @param type
+     * @return
+     * @throws ClassNotFoundException
+     */
+    public static Class javaDefaultTypeToClass(String type)
+            throws ClassNotFoundException
+    {
+        if (type == null)
+        {
+            throw new NullPointerException("type");
+        }
+
+        // try common types and arrays of common types first
+        Class clazz = (Class) ClassUtils.COMMON_TYPES.get(type);
+        if (clazz != null)
+        {
+            return clazz;
+        }
+
+        int len = type.length();
+        if (len > 2 && type.charAt(len - 1) == ']' && type.charAt(len - 2) == '[')
+        {
+            String componentType = type.substring(0, len - 2);
+            Class componentTypeClass = ClassUtils.classForName(componentType);
+            return Array.newInstance(componentTypeClass, 0).getClass();
+        }
+
+        if (type.indexOf('.') == -1)
+        {
+            type = "java.lang." + type;
+        }
+        return ClassUtils.classForName(type);
+    }
 
     /**
      * Same as {@link #javaTypeToClass(String)}, but throws a RuntimeException