commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1103095 [17/24] - in /incubator/ognl/trunk/src: main/java/org/apache/commons/ognl/ main/java/org/apache/commons/ognl/enhance/ main/java/org/apache/commons/ognl/internal/ test/java/org/apache/commons/ognl/ test/java/org/apache/commons/ognl/...
Date Sat, 14 May 2011 13:18:36 GMT
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java Sat May 14 13:18:29 2011
@@ -55,16 +55,16 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-
 /**
- * Responsible for managing/providing functionality related to compiling generated java source
- * expressions via bytecode enhancements for a given ognl expression.
+ * Responsible for managing/providing functionality related to compiling generated java source expressions via bytecode
+ * enhancements for a given ognl expression.
  */
-public class ExpressionCompiler implements OgnlExpressionCompiler {
+public class ExpressionCompiler
+    implements OgnlExpressionCompiler
+{
 
     /**
-     * Key used to store any java source string casting statements in the {@link OgnlContext} during
-     * class compilation.
+     * Key used to store any java source string casting statements in the {@link OgnlContext} during class compilation.
      */
     public static final String PRE_CAST = "_preCast";
 
@@ -88,96 +88,87 @@ public class ExpressionCompiler implemen
     }
 
     /**
-     * Used by {@link #castExpression(org.apache.commons.ognl.OgnlContext, org.apache.commons.ognl.Node, String)} to store the cast java
-     * source string in to the current {@link org.apache.commons.ognl.OgnlContext}. This will either add to the existing
-     * string present if it already exists or create a new instance and store it using the static key
-     * of {@link #PRE_CAST}.
-     *
-     * @param context
-     *          The current execution context.
-     * @param cast
-     *          The java source string to store in to the context.
+     * Used by {@link #castExpression(org.apache.commons.ognl.OgnlContext, org.apache.commons.ognl.Node, String)} to
+     * store the cast java source string in to the current {@link org.apache.commons.ognl.OgnlContext}. This will either
+     * add to the existing string present if it already exists or create a new instance and store it using the static
+     * key of {@link #PRE_CAST}.
+     * 
+     * @param context The current execution context.
+     * @param cast The java source string to store in to the context.
      */
-    public static void addCastString(org.apache.commons.ognl.OgnlContext context, String cast)
+    public static void addCastString( org.apache.commons.ognl.OgnlContext context, String cast )
     {
-        String value = (String) context.get(PRE_CAST);
+        String value = (String) context.get( PRE_CAST );
 
-        if (value != null)
+        if ( value != null )
             value = cast + value;
         else
             value = cast;
 
-        context.put(PRE_CAST, value);
+        context.put( PRE_CAST, value );
     }
 
-
     /**
      * Returns the appropriate casting expression (minus parens) for the specified class type.
-     *
      * <p/>
-     * For instance, if given an {@link Integer} object the string <code>"java.lang.Integer"</code>
-     * would be returned. For an array of primitive ints <code>"int[]"</code> and so on..
+     * For instance, if given an {@link Integer} object the string <code>"java.lang.Integer"</code> would be returned.
+     * For an array of primitive ints <code>"int[]"</code> and so on..
      * </p>
-     *
+     * 
      * @param type The class to cast a string expression for.
      * @return The converted raw string version of the class name.
      */
-    public static String getCastString(Class type)
+    public static String getCastString( Class type )
     {
-        if (type == null)
+        if ( type == null )
             return null;
-        
+
         return type.isArray() ? type.getComponentType().getName() + "[]" : type.getName();
     }
 
     /**
      * Convenience method called by many different property/method resolving AST types to get a root expression
-     * resolving string for the given node.  The callers are mostly ignorant and rely on this method to properly
+     * resolving string for the given node. The callers are mostly ignorant and rely on this method to properly
      * determine if the expression should be cast at all and take the appropriate actions if it should.
-     *
-     * @param expression
-     *          The node to check and generate a root expression to if necessary.
-     * @param root
-     *          The root object for this execution.
-     * @param context
-     *          The current execution context.
-     * @return Either an empty string or a root path java source string compatible with javassist compilations
-     *          from the root object up to the specified {@link Node}.
+     * 
+     * @param expression The node to check and generate a root expression to if necessary.
+     * @param root The root object for this execution.
+     * @param context The current execution context.
+     * @return Either an empty string or a root path java source string compatible with javassist compilations from the
+     *         root object up to the specified {@link Node}.
      */
-    public static String getRootExpression(Node expression, Object root, OgnlContext context)
+    public static String getRootExpression( Node expression, Object root, OgnlContext context )
     {
         String rootExpr = "";
 
-        if (!shouldCast(expression))
+        if ( !shouldCast( expression ) )
             return rootExpr;
 
-        if ((!ASTList.class.isInstance(expression)
-             && !ASTVarRef.class.isInstance(expression)
-             && !ASTStaticMethod.class.isInstance(expression)
-             && !ASTStaticField.class.isInstance(expression)
-             && !ASTConst.class.isInstance(expression)
-             && !ExpressionNode.class.isInstance(expression)
-             && !ASTCtor.class.isInstance(expression)
-             && !ASTStaticMethod.class.isInstance(expression)
-             && root != null) || (root != null && ASTRootVarRef.class.isInstance(expression))) {
-
-            Class castClass = OgnlRuntime.getCompiler().getRootExpressionClass(expression, context);
-            
-            if (castClass.isArray() || ASTRootVarRef.class.isInstance(expression)
-                || ASTThisVarRef.class.isInstance(expression))
+        if ( ( !ASTList.class.isInstance( expression ) && !ASTVarRef.class.isInstance( expression )
+            && !ASTStaticMethod.class.isInstance( expression ) && !ASTStaticField.class.isInstance( expression )
+            && !ASTConst.class.isInstance( expression ) && !ExpressionNode.class.isInstance( expression )
+            && !ASTCtor.class.isInstance( expression ) && !ASTStaticMethod.class.isInstance( expression ) && root != null )
+            || ( root != null && ASTRootVarRef.class.isInstance( expression ) ) )
+        {
+
+            Class castClass = OgnlRuntime.getCompiler().getRootExpressionClass( expression, context );
+
+            if ( castClass.isArray() || ASTRootVarRef.class.isInstance( expression )
+                || ASTThisVarRef.class.isInstance( expression ) )
             {
-                rootExpr = "((" + getCastString(castClass) + ")$2)";
+                rootExpr = "((" + getCastString( castClass ) + ")$2)";
 
-                if (ASTProperty.class.isInstance(expression) && !((ASTProperty) expression).isIndexedAccess())
+                if ( ASTProperty.class.isInstance( expression ) && !( (ASTProperty) expression ).isIndexedAccess() )
                     rootExpr += ".";
-            } else if ((ASTProperty.class.isInstance(expression)
-                        && ((ASTProperty) expression).isIndexedAccess())
-                       || ASTChain.class.isInstance(expression))
+            }
+            else if ( ( ASTProperty.class.isInstance( expression ) && ( (ASTProperty) expression ).isIndexedAccess() )
+                || ASTChain.class.isInstance( expression ) )
             {
-                rootExpr = "((" + getCastString(castClass) + ")$2)";
-            } else
+                rootExpr = "((" + getCastString( castClass ) + ")$2)";
+            }
+            else
             {
-                rootExpr = "((" + getCastString(castClass) + ")$2).";
+                rootExpr = "((" + getCastString( castClass ) + ")$2).";
             }
         }
 
@@ -185,182 +176,177 @@ public class ExpressionCompiler implemen
     }
 
     /**
-     * Used by {@link #getRootExpression(org.apache.commons.ognl.Node, Object, org.apache.commons.ognl.OgnlContext)} to determine if the expression
-     * needs to be cast at all.
-     *
-     * @param expression
-     *          The node to check against.
+     * Used by {@link #getRootExpression(org.apache.commons.ognl.Node, Object, org.apache.commons.ognl.OgnlContext)} to
+     * determine if the expression needs to be cast at all.
+     * 
+     * @param expression The node to check against.
      * @return Yes if the node type should be cast - false otherwise.
      */
-    public static boolean shouldCast(Node expression)
+    public static boolean shouldCast( Node expression )
     {
-        if (ASTChain.class.isInstance(expression))
+        if ( ASTChain.class.isInstance( expression ) )
         {
-            Node child = expression.jjtGetChild(0);
-            if (ASTConst.class.isInstance(child)
-                || ASTStaticMethod.class.isInstance(child)
-                || ASTStaticField.class.isInstance(child)
-                || (ASTVarRef.class.isInstance(child) && !ASTRootVarRef.class.isInstance(child)))
+            Node child = expression.jjtGetChild( 0 );
+            if ( ASTConst.class.isInstance( child ) || ASTStaticMethod.class.isInstance( child )
+                || ASTStaticField.class.isInstance( child )
+                || ( ASTVarRef.class.isInstance( child ) && !ASTRootVarRef.class.isInstance( child ) ) )
                 return false;
         }
 
-        return !ASTConst.class.isInstance(expression);
+        return !ASTConst.class.isInstance( expression );
     }
 
-    public String castExpression(OgnlContext context, Node expression, String body)
+    public String castExpression( OgnlContext context, Node expression, String body )
     {
         // ok - so this looks really f-ed up ...and it is ..eh if you can do it better I'm all for it :)
 
-        if (context.getCurrentAccessor() == null
+        if ( context.getCurrentAccessor() == null
             || context.getPreviousType() == null
-            || context.getCurrentAccessor().isAssignableFrom(context.getPreviousType())
-            || (context.getCurrentType() != null
-                && context.getCurrentObject() != null
-                && context.getCurrentType().isAssignableFrom(context.getCurrentObject().getClass())
-                && context.getCurrentAccessor().isAssignableFrom(context.getPreviousType()))
-            || body == null || body.trim().length() < 1
-            || (context.getCurrentType() != null && context.getCurrentType().isArray()
-                && (context.getPreviousType() == null || context.getPreviousType() != Object.class))
-            || ASTOr.class.isInstance(expression)
-            || ASTAnd.class.isInstance(expression)
-            || ASTRootVarRef.class.isInstance(expression)
+            || context.getCurrentAccessor().isAssignableFrom( context.getPreviousType() )
+            || ( context.getCurrentType() != null && context.getCurrentObject() != null
+                && context.getCurrentType().isAssignableFrom( context.getCurrentObject().getClass() ) && context.getCurrentAccessor().isAssignableFrom( context.getPreviousType() ) )
+            || body == null
+            || body.trim().length() < 1
+            || ( context.getCurrentType() != null && context.getCurrentType().isArray() && ( context.getPreviousType() == null || context.getPreviousType() != Object.class ) )
+            || ASTOr.class.isInstance( expression )
+            || ASTAnd.class.isInstance( expression )
+            || ASTRootVarRef.class.isInstance( expression )
             || context.getCurrentAccessor() == Class.class
-            || (context.get(ExpressionCompiler.PRE_CAST) != null && ((String) context.get(ExpressionCompiler.PRE_CAST)).startsWith("new"))
-            || ASTStaticField.class.isInstance(expression)
-            || ASTStaticMethod.class.isInstance(expression)
-            || (OrderedReturn.class.isInstance(expression) && ((OrderedReturn) expression).getLastExpression() != null))
+            || ( context.get( ExpressionCompiler.PRE_CAST ) != null && ( (String) context.get( ExpressionCompiler.PRE_CAST ) ).startsWith( "new" ) )
+            || ASTStaticField.class.isInstance( expression )
+            || ASTStaticMethod.class.isInstance( expression )
+            || ( OrderedReturn.class.isInstance( expression ) && ( (OrderedReturn) expression ).getLastExpression() != null ) )
             return body;
 
-/*         System.out.println("castExpression() with expression " + expression + " expr class: " + expression.getClass() + " currentType is: " + context.getCurrentType()
-                      + " previousType: " + context.getPreviousType()
-                      + "\n current Accessor: " + context.getCurrentAccessor()
-                      + " previous Accessor: " + context.getPreviousAccessor()
-                      + " current object " + context.getCurrentObject());*/
+        /*
+         * System.out.println("castExpression() with expression " + expression + " expr class: " + expression.getClass()
+         * + " currentType is: " + context.getCurrentType() + " previousType: " + context.getPreviousType() +
+         * "\n current Accessor: " + context.getCurrentAccessor() + " previous Accessor: " +
+         * context.getPreviousAccessor() + " current object " + context.getCurrentObject());
+         */
 
-        ExpressionCompiler.addCastString(context, "((" + ExpressionCompiler.getCastString(context.getCurrentAccessor()) + ")");
+        ExpressionCompiler.addCastString( context,
+                                          "((" + ExpressionCompiler.getCastString( context.getCurrentAccessor() ) + ")" );
 
         return ")" + body;
     }
 
-    public String getClassName(Class clazz)
+    public String getClassName( Class clazz )
     {
-        if (clazz.getName().equals("java.util.AbstractList$Itr"))
+        if ( clazz.getName().equals( "java.util.AbstractList$Itr" ) )
             return Iterator.class.getName();
 
-        if (Modifier.isPublic(clazz.getModifiers()) && clazz.isInterface())
+        if ( Modifier.isPublic( clazz.getModifiers() ) && clazz.isInterface() )
             return clazz.getName();
 
         Class[] intf = clazz.getInterfaces();
 
-        for (int i = 0; i < intf.length; i++)
+        for ( int i = 0; i < intf.length; i++ )
         {
-            if (intf[i].getName().indexOf("util.List") > 0)
+            if ( intf[i].getName().indexOf( "util.List" ) > 0 )
                 return intf[i].getName();
-            else if (intf[i].getName().indexOf("Iterator") > 0)
+            else if ( intf[i].getName().indexOf( "Iterator" ) > 0 )
                 return intf[i].getName();
         }
 
-        if (clazz.getSuperclass() != null && clazz.getSuperclass().getInterfaces().length > 0)
-            return getClassName(clazz.getSuperclass());
+        if ( clazz.getSuperclass() != null && clazz.getSuperclass().getInterfaces().length > 0 )
+            return getClassName( clazz.getSuperclass() );
 
         return clazz.getName();
     }
 
-    public Class getSuperOrInterfaceClass(Method m, Class clazz)
+    public Class getSuperOrInterfaceClass( Method m, Class clazz )
     {
-        if (clazz.getInterfaces() != null && clazz.getInterfaces().length > 0)
+        if ( clazz.getInterfaces() != null && clazz.getInterfaces().length > 0 )
         {
             Class[] intfs = clazz.getInterfaces();
             Class intClass;
 
-            for (int i = 0; i < intfs.length; i++)
+            for ( int i = 0; i < intfs.length; i++ )
             {
-                intClass = getSuperOrInterfaceClass(m, intfs[i]);
+                intClass = getSuperOrInterfaceClass( m, intfs[i] );
 
-                if (intClass != null)
+                if ( intClass != null )
                     return intClass;
 
-                if (Modifier.isPublic(intfs[i].getModifiers()) && containsMethod(m, intfs[i]))
+                if ( Modifier.isPublic( intfs[i].getModifiers() ) && containsMethod( m, intfs[i] ) )
                     return intfs[i];
             }
         }
 
-        if (clazz.getSuperclass() != null)
+        if ( clazz.getSuperclass() != null )
         {
-            Class superClass = getSuperOrInterfaceClass(m, clazz.getSuperclass());
+            Class superClass = getSuperOrInterfaceClass( m, clazz.getSuperclass() );
 
-            if (superClass != null)
+            if ( superClass != null )
                 return superClass;
         }
 
-        if (Modifier.isPublic(clazz.getModifiers()) && containsMethod(m, clazz))
+        if ( Modifier.isPublic( clazz.getModifiers() ) && containsMethod( m, clazz ) )
             return clazz;
 
         return null;
     }
 
     /**
-     * Helper utility method used by compiler to help resolve class->method mappings
-     * during method calls to {@link OgnlExpressionCompiler#getSuperOrInterfaceClass(java.lang.reflect.Method, Class)}.
-     *
-     * @param m
-     *          The method to check for existance of.
-     * @param clazz
-     *          The class to check for the existance of a matching method definition to the method passed in.
+     * Helper utility method used by compiler to help resolve class->method mappings during method calls to
+     * {@link OgnlExpressionCompiler#getSuperOrInterfaceClass(java.lang.reflect.Method, Class)}.
+     * 
+     * @param m The method to check for existance of.
+     * @param clazz The class to check for the existance of a matching method definition to the method passed in.
      * @return True if the class contains the specified method, false otherwise.
      */
-    public boolean containsMethod(Method m, Class clazz)
+    public boolean containsMethod( Method m, Class clazz )
     {
         Method[] methods = clazz.getMethods();
 
-        if (methods == null)
+        if ( methods == null )
             return false;
 
-        for (int i = 0; i < methods.length; i++)
+        for ( int i = 0; i < methods.length; i++ )
         {
-            if (methods[i].getName().equals(m.getName())
-                && methods[i].getReturnType() == m.getReturnType())
+            if ( methods[i].getName().equals( m.getName() ) && methods[i].getReturnType() == m.getReturnType() )
             {
                 Class[] parms = m.getParameterTypes();
-                if (parms == null)
+                if ( parms == null )
                     continue;
 
                 Class[] mparms = methods[i].getParameterTypes();
-                if (mparms == null || mparms.length != parms.length)
+                if ( mparms == null || mparms.length != parms.length )
                     continue;
 
                 boolean parmsMatch = true;
-                for (int p = 0; p < parms.length; p++)
+                for ( int p = 0; p < parms.length; p++ )
                 {
-                    if (parms[p] != mparms[p])
+                    if ( parms[p] != mparms[p] )
                     {
                         parmsMatch = false;
                         break;
                     }
                 }
 
-                if (!parmsMatch)
+                if ( !parmsMatch )
                     continue;
 
                 Class[] exceptions = m.getExceptionTypes();
-                if (exceptions == null)
+                if ( exceptions == null )
                     continue;
 
                 Class[] mexceptions = methods[i].getExceptionTypes();
-                if (mexceptions == null || mexceptions.length != exceptions.length)
+                if ( mexceptions == null || mexceptions.length != exceptions.length )
                     continue;
 
                 boolean exceptionsMatch = true;
-                for (int e = 0; e < exceptions.length; e++)
+                for ( int e = 0; e < exceptions.length; e++ )
                 {
-                    if (exceptions[e] != mexceptions[e])
+                    if ( exceptions[e] != mexceptions[e] )
                     {
                         exceptionsMatch = false;
                         break;
                     }
                 }
 
-                if (!exceptionsMatch)
+                if ( !exceptionsMatch )
                     continue;
 
                 return true;
@@ -370,45 +356,44 @@ public class ExpressionCompiler implemen
         return false;
     }
 
-    public Class getInterfaceClass(Class clazz)
+    public Class getInterfaceClass( Class clazz )
     {
-        if (clazz.getName().equals("java.util.AbstractList$Itr"))
+        if ( clazz.getName().equals( "java.util.AbstractList$Itr" ) )
             return Iterator.class;
 
-        if (Modifier.isPublic(clazz.getModifiers())
-            && clazz.isInterface() || clazz.isPrimitive())
+        if ( Modifier.isPublic( clazz.getModifiers() ) && clazz.isInterface() || clazz.isPrimitive() )
             return clazz;
 
         Class[] intf = clazz.getInterfaces();
 
-        for (int i = 0; i < intf.length; i++)
+        for ( int i = 0; i < intf.length; i++ )
         {
-            if (List.class.isAssignableFrom(intf[i]))
+            if ( List.class.isAssignableFrom( intf[i] ) )
                 return List.class;
-            else if (Iterator.class.isAssignableFrom(intf[i]))
+            else if ( Iterator.class.isAssignableFrom( intf[i] ) )
                 return Iterator.class;
-            else if (Map.class.isAssignableFrom(intf[i]))
+            else if ( Map.class.isAssignableFrom( intf[i] ) )
                 return Map.class;
-            else if (Set.class.isAssignableFrom(intf[i]))
+            else if ( Set.class.isAssignableFrom( intf[i] ) )
                 return Set.class;
-            else if (Collection.class.isAssignableFrom(intf[i]))
+            else if ( Collection.class.isAssignableFrom( intf[i] ) )
                 return Collection.class;
         }
 
-        if (clazz.getSuperclass() != null && clazz.getSuperclass().getInterfaces().length > 0)
-            return getInterfaceClass(clazz.getSuperclass());
+        if ( clazz.getSuperclass() != null && clazz.getSuperclass().getInterfaces().length > 0 )
+            return getInterfaceClass( clazz.getSuperclass() );
 
         return clazz;
     }
 
-    public Class getRootExpressionClass(Node rootNode, OgnlContext context)
+    public Class getRootExpressionClass( Node rootNode, OgnlContext context )
     {
-        if (context.getRoot() == null)
+        if ( context.getRoot() == null )
             return null;
 
         Class ret = context.getRoot().getClass();
 
-        if (context.getFirstAccessor() != null && context.getFirstAccessor().isInstance(context.getRoot()))
+        if ( context.getFirstAccessor() != null && context.getFirstAccessor().isInstance( context.getRoot() ) )
         {
             ret = context.getFirstAccessor();
         }
@@ -416,199 +401,204 @@ public class ExpressionCompiler implemen
         return ret;
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
      * @see ognl.enhance.OgnlExpressionCompiler#compileExpression(ognl.OgnlContext, ognl.Node, java.lang.Object)
      */
-    public void compileExpression(OgnlContext context, Node expression, Object root)
-            throws Exception
+    public void compileExpression( OgnlContext context, Node expression, Object root )
+        throws Exception
     {
-//        System.out.println("Compiling expr class " + expression.getClass().getName() + " and root " + root);
+        // System.out.println("Compiling expr class " + expression.getClass().getName() + " and root " + root);
 
-        if (expression.getAccessor() != null)
+        if ( expression.getAccessor() != null )
             return;
 
         String getBody, setBody;
 
-        EnhancedClassLoader loader = getClassLoader(context);
-        ClassPool pool = getClassPool(context, loader);
-
-        CtClass newClass = pool.makeClass(expression.getClass().getName() + expression.hashCode() + _classCounter++ + "Accessor");
-        newClass.addInterface(getCtClass(ExpressionAccessor.class));
+        EnhancedClassLoader loader = getClassLoader( context );
+        ClassPool pool = getClassPool( context, loader );
 
-        CtClass ognlClass = getCtClass(OgnlContext.class);
-        CtClass objClass = getCtClass(Object.class);
-
-        CtMethod valueGetter = new CtMethod(objClass, "get", new CtClass[]{ognlClass, objClass}, newClass);
-        CtMethod valueSetter = new CtMethod(CtClass.voidType, "set", new CtClass[]{ognlClass, objClass, objClass}, newClass);
+        CtClass newClass =
+            pool.makeClass( expression.getClass().getName() + expression.hashCode() + _classCounter++ + "Accessor" );
+        newClass.addInterface( getCtClass( ExpressionAccessor.class ) );
+
+        CtClass ognlClass = getCtClass( OgnlContext.class );
+        CtClass objClass = getCtClass( Object.class );
+
+        CtMethod valueGetter = new CtMethod( objClass, "get", new CtClass[] { ognlClass, objClass }, newClass );
+        CtMethod valueSetter =
+            new CtMethod( CtClass.voidType, "set", new CtClass[] { ognlClass, objClass, objClass }, newClass );
 
         CtField nodeMember = null; // will only be set if uncompilable exception is thrown
 
-        CtClass nodeClass = getCtClass(Node.class);
+        CtClass nodeClass = getCtClass( Node.class );
         CtMethod setExpression = null;
 
-        try {
+        try
+        {
 
-            getBody = generateGetter(context, newClass, objClass, pool, valueGetter, expression, root);
+            getBody = generateGetter( context, newClass, objClass, pool, valueGetter, expression, root );
 
-        } catch (UnsupportedCompilationException uc)
+        }
+        catch ( UnsupportedCompilationException uc )
         {
-            //uc.printStackTrace();
+            // uc.printStackTrace();
 
-            nodeMember = new CtField(nodeClass, "_node", newClass);
-            newClass.addField(nodeMember);
+            nodeMember = new CtField( nodeClass, "_node", newClass );
+            newClass.addField( nodeMember );
 
-            getBody = generateOgnlGetter(newClass, valueGetter, nodeMember);
+            getBody = generateOgnlGetter( newClass, valueGetter, nodeMember );
 
-            if (setExpression == null)
+            if ( setExpression == null )
             {
-                setExpression = CtNewMethod.setter("setExpression", nodeMember);
-                newClass.addMethod(setExpression);
+                setExpression = CtNewMethod.setter( "setExpression", nodeMember );
+                newClass.addMethod( setExpression );
             }
         }
-        
-        try {
 
-            setBody = generateSetter(context, newClass, objClass, pool,  valueSetter, expression, root);
+        try
+        {
+
+            setBody = generateSetter( context, newClass, objClass, pool, valueSetter, expression, root );
 
-        } catch (UnsupportedCompilationException uc)
+        }
+        catch ( UnsupportedCompilationException uc )
         {
 
-            //uc.printStackTrace();
+            // uc.printStackTrace();
 
-            if (nodeMember == null)
+            if ( nodeMember == null )
             {
-                nodeMember = new CtField(nodeClass, "_node", newClass);
-                newClass.addField(nodeMember);
+                nodeMember = new CtField( nodeClass, "_node", newClass );
+                newClass.addField( nodeMember );
             }
 
-            setBody = generateOgnlSetter(newClass, valueSetter, nodeMember);
+            setBody = generateOgnlSetter( newClass, valueSetter, nodeMember );
 
-            if (setExpression == null)
+            if ( setExpression == null )
             {
-                setExpression = CtNewMethod.setter("setExpression", nodeMember);
-                newClass.addMethod(setExpression);
+                setExpression = CtNewMethod.setter( "setExpression", nodeMember );
+                newClass.addMethod( setExpression );
             }
         }
 
-        try {
-            newClass.addConstructor(CtNewConstructor.defaultConstructor(newClass));
+        try
+        {
+            newClass.addConstructor( CtNewConstructor.defaultConstructor( newClass ) );
 
-            Class clazz = pool.toClass(newClass);
+            Class clazz = pool.toClass( newClass );
             newClass.detach();
 
-            expression.setAccessor((ExpressionAccessor) clazz.newInstance());
+            expression.setAccessor( (ExpressionAccessor) clazz.newInstance() );
 
             // need to set expression on node if the field was just defined.
 
-            if (nodeMember != null)
+            if ( nodeMember != null )
             {
-                expression.getAccessor().setExpression(expression);
+                expression.getAccessor().setExpression( expression );
             }
 
-        } catch (Throwable t) {
-            //t.printStackTrace();
+        }
+        catch ( Throwable t )
+        {
+            // t.printStackTrace();
 
-            throw new RuntimeException("Error compiling expression on object " + root
-                                       + " with expression node " + expression + " getter body: " + getBody
-                                       + " setter body: " + setBody, t);
+            throw new RuntimeException( "Error compiling expression on object " + root + " with expression node "
+                + expression + " getter body: " + getBody + " setter body: " + setBody, t );
         }
 
     }
 
-    protected String generateGetter(OgnlContext context, CtClass newClass, CtClass objClass, ClassPool pool,
-                                    CtMethod valueGetter, Node expression, Object root)
-            throws Exception
+    protected String generateGetter( OgnlContext context, CtClass newClass, CtClass objClass, ClassPool pool,
+                                     CtMethod valueGetter, Node expression, Object root )
+        throws Exception
     {
         String pre = "";
         String post = "";
         String body;
 
-        context.setRoot(root);
+        context.setRoot( root );
 
-        // the ExpressionAccessor API has to reference the generic Object class for get/set operations, so this sets up that known
+        // the ExpressionAccessor API has to reference the generic Object class for get/set operations, so this sets up
+        // that known
         // type beforehand
 
-        context.remove(PRE_CAST);
+        context.remove( PRE_CAST );
 
         // Recursively generate the java source code representation of the top level expression
 
-        String getterCode = expression.toGetSourceString(context, root);
+        String getterCode = expression.toGetSourceString( context, root );
 
-        if (getterCode == null || getterCode.trim().length() <= 0
-                                  && !ASTVarRef.class.isAssignableFrom(expression.getClass()))
+        if ( getterCode == null || getterCode.trim().length() <= 0
+            && !ASTVarRef.class.isAssignableFrom( expression.getClass() ) )
             getterCode = "null";
 
-        String castExpression = (String) context.get(PRE_CAST);
+        String castExpression = (String) context.get( PRE_CAST );
 
-        if (context.getCurrentType() == null
-            || context.getCurrentType().isPrimitive()
-            || Character.class.isAssignableFrom(context.getCurrentType())
-            || Object.class == context.getCurrentType())
+        if ( context.getCurrentType() == null || context.getCurrentType().isPrimitive()
+            || Character.class.isAssignableFrom( context.getCurrentType() ) || Object.class == context.getCurrentType() )
         {
             pre = pre + " ($w) (";
             post = post + ")";
         }
 
-        String rootExpr = !getterCode.equals("null") ? getRootExpression(expression, root, context) : "";
+        String rootExpr = !getterCode.equals( "null" ) ? getRootExpression( expression, root, context ) : "";
 
-        String noRoot = (String) context.remove("_noRoot");
-        if (noRoot != null)
+        String noRoot = (String) context.remove( "_noRoot" );
+        if ( noRoot != null )
             rootExpr = "";
 
-        createLocalReferences(context, pool, newClass, objClass, valueGetter.getParameterTypes());
+        createLocalReferences( context, pool, newClass, objClass, valueGetter.getParameterTypes() );
 
-        if (OrderedReturn.class.isInstance(expression) && ((OrderedReturn) expression).getLastExpression() != null)
+        if ( OrderedReturn.class.isInstance( expression ) && ( (OrderedReturn) expression ).getLastExpression() != null )
         {
-            body = "{ "
-                   + (ASTMethod.class.isInstance(expression) || ASTChain.class.isInstance(expression) ? rootExpr : "")
-                   + (castExpression != null ? castExpression : "")
-                   + ((OrderedReturn) expression).getCoreExpression()
-                   + " return " + pre + ((OrderedReturn) expression).getLastExpression()
-                   + post
-                   + ";}";
-
-        } else {
-
-            body = "{  return "
-                   + pre
-                   + (castExpression != null ? castExpression : "")
-                   + rootExpr
-                   + getterCode
-                   + post
-                   + ";}";
-        }
-
-        body = body.replaceAll("\\.\\.", ".");
-
-//        System.out.println("Getter Body: ===================================\n" + body);
-        valueGetter.setBody(body);
-        newClass.addMethod(valueGetter);
+            body =
+                "{ "
+                    + ( ASTMethod.class.isInstance( expression ) || ASTChain.class.isInstance( expression ) ? rootExpr
+                                    : "" ) + ( castExpression != null ? castExpression : "" )
+                    + ( (OrderedReturn) expression ).getCoreExpression() + " return " + pre
+                    + ( (OrderedReturn) expression ).getLastExpression() + post + ";}";
+
+        }
+        else
+        {
+
+            body =
+                "{  return " + pre + ( castExpression != null ? castExpression : "" ) + rootExpr + getterCode + post
+                    + ";}";
+        }
+
+        body = body.replaceAll( "\\.\\.", "." );
+
+        // System.out.println("Getter Body: ===================================\n" + body);
+        valueGetter.setBody( body );
+        newClass.addMethod( valueGetter );
 
         return body;
     }
 
-    public String createLocalReference(OgnlContext context, String expression, Class type)
+    public String createLocalReference( OgnlContext context, String expression, Class type )
     {
         String referenceName = "ref" + context.incrementLocalReferenceCounter();
-        context.addLocalReference(referenceName, new LocalReferenceImpl(referenceName, expression, type));
+        context.addLocalReference( referenceName, new LocalReferenceImpl( referenceName, expression, type ) );
 
         String castString = "";
-        if (!type.isPrimitive())
-            castString = "(" + ExpressionCompiler.getCastString(type) + ") ";
+        if ( !type.isPrimitive() )
+            castString = "(" + ExpressionCompiler.getCastString( type ) + ") ";
 
         return castString + referenceName + "($$)";
     }
 
-    void createLocalReferences(OgnlContext context, ClassPool pool, CtClass clazz, CtClass objClass, CtClass[] params)
-            throws CannotCompileException, NotFoundException
+    void createLocalReferences( OgnlContext context, ClassPool pool, CtClass clazz, CtClass objClass, CtClass[] params )
+        throws CannotCompileException, NotFoundException
     {
         Map referenceMap = context.getLocalReferences();
-        if (referenceMap == null || referenceMap.size() < 1)
+        if ( referenceMap == null || referenceMap.size() < 1 )
             return;
 
         Iterator it = referenceMap.values().iterator();
 
-        while (it.hasNext())
+        while ( it.hasNext() )
         {
             LocalReference ref = (LocalReference) it.next();
 
@@ -618,173 +608,155 @@ public class ExpressionCompiler implemen
             body += " return  " + widener + ref.getExpression() + ";";
             body += "}";
 
-            body = body.replaceAll("\\.\\.", ".");
+            body = body.replaceAll( "\\.\\.", "." );
 
-//            System.out.println("adding method " + ref.getName() + " with body:\n" + body + " and return type: " + ref.getType());
+            // System.out.println("adding method " + ref.getName() + " with body:\n" + body + " and return type: " +
+            // ref.getType());
 
-            CtMethod method = new CtMethod(pool.get(getCastString(ref.getType())), ref.getName(), params, clazz);
-            method.setBody(body);
+            CtMethod method = new CtMethod( pool.get( getCastString( ref.getType() ) ), ref.getName(), params, clazz );
+            method.setBody( body );
 
-            clazz.addMethod(method);
+            clazz.addMethod( method );
 
             it.remove();
         }
     }
 
-    protected String generateSetter(OgnlContext context, CtClass newClass, CtClass objClass, ClassPool pool,
-                                    CtMethod valueSetter, Node expression, Object root)
-            throws Exception
-    {
-        if (ExpressionNode.class.isInstance(expression)
-            || ASTConst.class.isInstance(expression))
-            throw new UnsupportedCompilationException("Can't compile expression/constant setters.");
+    protected String generateSetter( OgnlContext context, CtClass newClass, CtClass objClass, ClassPool pool,
+                                     CtMethod valueSetter, Node expression, Object root )
+        throws Exception
+    {
+        if ( ExpressionNode.class.isInstance( expression ) || ASTConst.class.isInstance( expression ) )
+            throw new UnsupportedCompilationException( "Can't compile expression/constant setters." );
 
-        context.setRoot(root);
-        context.remove(PRE_CAST);
+        context.setRoot( root );
+        context.remove( PRE_CAST );
 
         String body;
 
-        String setterCode = expression.toSetSourceString(context, root);
-        String castExpression = (String) context.get(PRE_CAST);
+        String setterCode = expression.toSetSourceString( context, root );
+        String castExpression = (String) context.get( PRE_CAST );
 
-        if (setterCode == null || setterCode.trim().length() < 1)
-            throw new UnsupportedCompilationException("Can't compile null setter body.");
+        if ( setterCode == null || setterCode.trim().length() < 1 )
+            throw new UnsupportedCompilationException( "Can't compile null setter body." );
 
-        if (root == null)
-            throw new UnsupportedCompilationException("Can't compile setters with a null root object.");
+        if ( root == null )
+            throw new UnsupportedCompilationException( "Can't compile setters with a null root object." );
 
-        String pre = getRootExpression(expression, root, context);
+        String pre = getRootExpression( expression, root, context );
 
-        String noRoot = (String) context.remove("_noRoot");
-        if (noRoot != null)
+        String noRoot = (String) context.remove( "_noRoot" );
+        if ( noRoot != null )
             pre = "";
 
-        createLocalReferences(context, pool, newClass, objClass, valueSetter.getParameterTypes());
+        createLocalReferences( context, pool, newClass, objClass, valueSetter.getParameterTypes() );
 
-        body = "{"
-               + (castExpression != null ? castExpression : "")
-               + pre
-               + setterCode + ";}";
+        body = "{" + ( castExpression != null ? castExpression : "" ) + pre + setterCode + ";}";
 
-        body = body.replaceAll("\\.\\.", ".");
+        body = body.replaceAll( "\\.\\.", "." );
 
-//        System.out.println("Setter Body: ===================================\n" + body);
+        // System.out.println("Setter Body: ===================================\n" + body);
 
-        valueSetter.setBody(body);
-        newClass.addMethod(valueSetter);
+        valueSetter.setBody( body );
+        newClass.addMethod( valueSetter );
 
         return body;
     }
 
     /**
      * Fail safe getter creation when normal compilation fails.
-     *
-     * @param clazz
-     *          The javassist class the new method should be attached to.
-     * @param valueGetter
-     *          The method definition the generated code will be contained within.
-     * @param node
-     *          The root expression node.
-     * @return The generated source string for this method, the method will still be
-     *          added via the javassist API either way so this is really a convenience
-     *          for exception reporting / debugging.
-     * @throws Exception
-     *          If a javassist error occurs.
+     * 
+     * @param clazz The javassist class the new method should be attached to.
+     * @param valueGetter The method definition the generated code will be contained within.
+     * @param node The root expression node.
+     * @return The generated source string for this method, the method will still be added via the javassist API either
+     *         way so this is really a convenience for exception reporting / debugging.
+     * @throws Exception If a javassist error occurs.
      */
-    protected String generateOgnlGetter(CtClass clazz, CtMethod valueGetter, CtField node)
-            throws Exception
+    protected String generateOgnlGetter( CtClass clazz, CtMethod valueGetter, CtField node )
+        throws Exception
     {
         String body = "return " + node.getName() + ".getValue($1, $2);";
 
-        valueGetter.setBody(body);
-        clazz.addMethod(valueGetter);
+        valueGetter.setBody( body );
+        clazz.addMethod( valueGetter );
 
         return body;
     }
 
     /**
      * Fail safe setter creation when normal compilation fails.
-     *
-     * @param clazz
-     *          The javassist class the new method should be attached to.
-     * @param valueSetter
-     *          The method definition the generated code will be contained within.
-     * @param node
-     *          The root expression node.
-     * @return The generated source string for this method, the method will still be
-     *          added via the javassist API either way so this is really a convenience
-     *          for exception reporting / debugging.
-     * @throws Exception
-     *          If a javassist error occurs.
+     * 
+     * @param clazz The javassist class the new method should be attached to.
+     * @param valueSetter The method definition the generated code will be contained within.
+     * @param node The root expression node.
+     * @return The generated source string for this method, the method will still be added via the javassist API either
+     *         way so this is really a convenience for exception reporting / debugging.
+     * @throws Exception If a javassist error occurs.
      */
-    protected String generateOgnlSetter(CtClass clazz, CtMethod valueSetter, CtField node)
-            throws Exception
+    protected String generateOgnlSetter( CtClass clazz, CtMethod valueSetter, CtField node )
+        throws Exception
     {
         String body = node.getName() + ".setValue($1, $2, $3);";
 
-        valueSetter.setBody(body);
-        clazz.addMethod(valueSetter);
+        valueSetter.setBody( body );
+        clazz.addMethod( valueSetter );
 
         return body;
     }
 
     /**
-     * Creates a {@link ClassLoader} instance compatible with the javassist classloader and normal
-     * OGNL class resolving semantics.
-     *
-     * @param context
-     *          The current execution context.
-     *
+     * Creates a {@link ClassLoader} instance compatible with the javassist classloader and normal OGNL class resolving
+     * semantics.
+     * 
+     * @param context The current execution context.
      * @return The created {@link ClassLoader} instance.
      */
-    protected EnhancedClassLoader getClassLoader(OgnlContext context)
+    protected EnhancedClassLoader getClassLoader( OgnlContext context )
     {
-        EnhancedClassLoader ret = (EnhancedClassLoader) _loaders.get(context.getClassResolver());
+        EnhancedClassLoader ret = (EnhancedClassLoader) _loaders.get( context.getClassResolver() );
 
-        if (ret != null)
+        if ( ret != null )
             return ret;
 
-        ClassLoader classLoader = new ContextClassLoader(OgnlContext.class.getClassLoader(), context);
+        ClassLoader classLoader = new ContextClassLoader( OgnlContext.class.getClassLoader(), context );
 
-        ret = new EnhancedClassLoader(classLoader);
-        _loaders.put(context.getClassResolver(), ret);
+        ret = new EnhancedClassLoader( classLoader );
+        _loaders.put( context.getClassResolver(), ret );
 
         return ret;
     }
 
     /**
      * Loads a new class definition via javassist for the specified class.
-     *
-     * @param searchClass
-     *          The class to load.
+     * 
+     * @param searchClass The class to load.
      * @return The javassist class equivalent.
-     *
      * @throws NotFoundException When the class definition can't be found.
      */
-    protected CtClass getCtClass(Class searchClass)
-            throws NotFoundException
+    protected CtClass getCtClass( Class searchClass )
+        throws NotFoundException
     {
-        return _pool.get(searchClass.getName());
+        return _pool.get( searchClass.getName() );
     }
 
     /**
-     * Gets either a new or existing {@link ClassPool} for use in compiling javassist
-     * classes.  A new class path object is inserted in to the returned {@link ClassPool} using
-     * the passed in <code>loader</code> instance if a new pool needs to be created.
-     *
-     * @param context
-     *          The current execution context.
-     * @param loader
-     *          The {@link ClassLoader} instance to use - as returned by {@link #getClassLoader(org.apache.commons.ognl.OgnlContext)}.
+     * Gets either a new or existing {@link ClassPool} for use in compiling javassist classes. A new class path object
+     * is inserted in to the returned {@link ClassPool} using the passed in <code>loader</code> instance if a new pool
+     * needs to be created.
+     * 
+     * @param context The current execution context.
+     * @param loader The {@link ClassLoader} instance to use - as returned by
+     *            {@link #getClassLoader(org.apache.commons.ognl.OgnlContext)}.
      * @return The existing or new {@link ClassPool} instance.
      */
-    protected ClassPool getClassPool(OgnlContext context, EnhancedClassLoader loader)
+    protected ClassPool getClassPool( OgnlContext context, EnhancedClassLoader loader )
     {
-        if (_pool != null)
+        if ( _pool != null )
             return _pool;
 
         _pool = ClassPool.getDefault();
-        _pool.insertClassPath(new LoaderClassPath(loader.getParent()));
+        _pool.insertClassPath( new LoaderClassPath( loader.getParent() ) );
 
         return _pool;
     }

Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/LocalReference.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/LocalReference.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/LocalReference.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/LocalReference.java Sat May 14 13:18:29 2011
@@ -20,26 +20,28 @@
 package org.apache.commons.ognl.enhance;
 
 /**
- * Container class for {@link OgnlExpressionCompiler} generated local method
- * block references.
+ * Container class for {@link OgnlExpressionCompiler} generated local method block references.
  */
-public interface LocalReference {
+public interface LocalReference
+{
 
     /**
      * The name of the assigned variable reference.
-     *
+     * 
      * @return The name of the reference as it will be when compiled.
      */
     String getName();
 
     /**
      * The expression that sets the value, ie the part after <code><class type> refName = <expression></code>.
+     * 
      * @return The setting expression.
      */
     String getExpression();
 
     /**
      * The type of reference.
+     * 
      * @return The type.
      */
     Class getType();

Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/LocalReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/LocalReferenceImpl.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/LocalReferenceImpl.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/LocalReferenceImpl.java Sat May 14 13:18:29 2011
@@ -20,15 +20,19 @@
 package org.apache.commons.ognl.enhance;
 
 /**
- * Implementation of {@link LocalReference}. 
+ * Implementation of {@link LocalReference}.
  */
-public class LocalReferenceImpl implements LocalReference {
+public class LocalReferenceImpl
+    implements LocalReference
+{
 
     String _name;
+
     Class _type;
+
     String _expression;
 
-    public LocalReferenceImpl(String name, String expression, Class type)
+    public LocalReferenceImpl( String name, String expression, Class type )
     {
         _name = name;
         _type = type;
@@ -50,16 +54,21 @@ public class LocalReferenceImpl implemen
         return _type;
     }
 
-    public boolean equals(Object o)
+    public boolean equals( Object o )
     {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
+        if ( this == o )
+            return true;
+        if ( o == null || getClass() != o.getClass() )
+            return false;
 
         LocalReferenceImpl that = (LocalReferenceImpl) o;
 
-        if (_expression != null ? !_expression.equals(that._expression) : that._expression != null) return false;
-        if (_name != null ? !_name.equals(that._name) : that._name != null) return false;
-        if (_type != null ? !_type.equals(that._type) : that._type != null) return false;
+        if ( _expression != null ? !_expression.equals( that._expression ) : that._expression != null )
+            return false;
+        if ( _name != null ? !_name.equals( that._name ) : that._name != null )
+            return false;
+        if ( _type != null ? !_type.equals( that._type ) : that._type != null )
+            return false;
 
         return true;
     }
@@ -67,21 +76,15 @@ public class LocalReferenceImpl implemen
     public int hashCode()
     {
         int result;
-        result = (_name != null ? _name.hashCode() : 0);
-        result = 31 * result + (_type != null ? _type.hashCode() : 0);
-        result = 31 * result + (_expression != null ? _expression.hashCode() : 0);
+        result = ( _name != null ? _name.hashCode() : 0 );
+        result = 31 * result + ( _type != null ? _type.hashCode() : 0 );
+        result = 31 * result + ( _expression != null ? _expression.hashCode() : 0 );
         return result;
     }
 
     public String toString()
     {
-        return "LocalReferenceImpl[" +
-               "_name='" + _name + '\'' +
-               '\n' +
-               ", _type=" + _type +
-               '\n' +
-               ", _expression='" + _expression + '\'' +
-               '\n' +
-               ']';
+        return "LocalReferenceImpl[" + "_name='" + _name + '\'' + '\n' + ", _type=" + _type + '\n' + ", _expression='"
+            + _expression + '\'' + '\n' + ']';
     }
 }

Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/OgnlExpressionCompiler.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/OgnlExpressionCompiler.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/OgnlExpressionCompiler.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/OgnlExpressionCompiler.java Sat May 14 13:18:29 2011
@@ -30,118 +30,99 @@ import java.lang.reflect.Method;
 /**
  * Core interface implemented by expression compiler instances.
  */
-public interface OgnlExpressionCompiler {
+public interface OgnlExpressionCompiler
+{
 
     /** Static constant used in conjunction with {@link OgnlContext} to store temporary references. */
     String ROOT_TYPE = "-ognl-root-type";
 
     /**
-     * The core method executed to compile a specific expression.  It is expected that this expression
-     * always return a {@link Node} with a non null {@link org.apache.commons.ognl.Node#getAccessor()} instance - unless an exception
-     * is thrown by the method or the statement wasn't compilable in this instance because of missing/null objects
-     * in the expression.  These instances may in some cases continue to call this compilation method until the expression
-     * is resolvable.
-     * 
-     * @param context
-     *          The context of execution.
-     * @param expression
-     *          The pre-parsed root expression node to compile.
-     * @param root
-     *          The root object for the expression - may be null in many instances so some implementations
-     *          may exit
-     * @throws Exception
-     *          If an error occurs compiling the expression and no strategy has been implemented to handle incremental
-     *          expression compilation for incomplete expression members.
-     */
-    void compileExpression(OgnlContext context, Node expression, Object root)
-            throws Exception;
-
-    /**
-     * Gets a javassist safe class string for the given class instance.  This is especially
-     * useful for handling array vs. normal class casting strings.
-     *
-     * @param clazz
-     *          The class to get a string equivalent javassist compatible string reference for.
-     *
+     * The core method executed to compile a specific expression. It is expected that this expression always return a
+     * {@link Node} with a non null {@link org.apache.commons.ognl.Node#getAccessor()} instance - unless an exception is
+     * thrown by the method or the statement wasn't compilable in this instance because of missing/null objects in the
+     * expression. These instances may in some cases continue to call this compilation method until the expression is
+     * resolvable.
+     * 
+     * @param context The context of execution.
+     * @param expression The pre-parsed root expression node to compile.
+     * @param root The root object for the expression - may be null in many instances so some implementations may exit
+     * @throws Exception If an error occurs compiling the expression and no strategy has been implemented to handle
+     *             incremental expression compilation for incomplete expression members.
+     */
+    void compileExpression( OgnlContext context, Node expression, Object root )
+        throws Exception;
+
+    /**
+     * Gets a javassist safe class string for the given class instance. This is especially useful for handling array vs.
+     * normal class casting strings.
+     * 
+     * @param clazz The class to get a string equivalent javassist compatible string reference for.
      * @return The string equivalent of the class.
      */
-    String getClassName(Class clazz);
+    String getClassName( Class clazz );
 
     /**
-     * Used in places where the preferred {@link #getSuperOrInterfaceClass(java.lang.reflect.Method, Class)} isn't possible
-     * because the method isn't known for a class.  Attempts to upcast the given class to the next available non-private accessible
-     * class so that compiled expressions can reference the interface class of an instance so as not to be compiled in to overly
-     * specific statements.
-     *
-     * @param clazz
-     *          The class to attempt to find a compatible interface for.
+     * Used in places where the preferred {@link #getSuperOrInterfaceClass(java.lang.reflect.Method, Class)} isn't
+     * possible because the method isn't known for a class. Attempts to upcast the given class to the next available
+     * non-private accessible class so that compiled expressions can reference the interface class of an instance so as
+     * not to be compiled in to overly specific statements.
+     * 
+     * @param clazz The class to attempt to find a compatible interface for.
      * @return The same class if no higher level interface could be matched against or the interface equivalent class.
      */
-    Class getInterfaceClass(Class clazz);
+    Class getInterfaceClass( Class clazz );
 
     /**
      * For the given {@link Method} and class finds the highest level interface class this combination can be cast to.
-     *
-     * @param m
-     *          The method the class must implement.
-     * @param clazz
-     *          The current class being worked with.
+     * 
+     * @param m The method the class must implement.
+     * @param clazz The current class being worked with.
      * @return The highest level interface / class that the referenced {@link Method} is declared in.
      */
-    Class getSuperOrInterfaceClass(Method m, Class clazz);
+    Class getSuperOrInterfaceClass( Method m, Class clazz );
 
     /**
-     * For a given root object type returns the base class type to be used in root referenced expressions.  This
-     * helps in some instances where the root objects themselves are compiled javassist instances that need more generic
-     * class equivalents to cast to.
-     *
-     * @param rootNode
-     *          The root expression node.
-     * @param context
-     *          The current execution context.
+     * For a given root object type returns the base class type to be used in root referenced expressions. This helps in
+     * some instances where the root objects themselves are compiled javassist instances that need more generic class
+     * equivalents to cast to.
+     * 
+     * @param rootNode The root expression node.
+     * @param context The current execution context.
      * @return The root expression class type to cast to for this node.
      */
-    Class getRootExpressionClass(Node rootNode, OgnlContext context);
+    Class getRootExpressionClass( Node rootNode, OgnlContext context );
 
     /**
-     * Used primarily by AST types like {@link org.apache.commons.ognl.ASTChain} where <code>foo.bar.id</code> type references
-     * may need to be cast multiple times in order to properly resolve the members in a compiled statement.
-     *
+     * Used primarily by AST types like {@link org.apache.commons.ognl.ASTChain} where <code>foo.bar.id</code> type
+     * references may need to be cast multiple times in order to properly resolve the members in a compiled statement.
      * <p>
-     * This method should be using the various {@link org.apache.commons.ognl.OgnlContext#getCurrentType()} / {@link org.apache.commons.ognl.OgnlContext#getCurrentAccessor()} methods
-     * to inspect the type stack and properly cast to the right classes - but only when necessary.
+     * This method should be using the various {@link org.apache.commons.ognl.OgnlContext#getCurrentType()} /
+     * {@link org.apache.commons.ognl.OgnlContext#getCurrentAccessor()} methods to inspect the type stack and properly
+     * cast to the right classes - but only when necessary.
      * </p>
-     *
-     * @param context
-     *          The current execution context.
-     * @param expression
-     *          The node being checked for casting.
-     * @param body
-     *          The java source string generated by the given node.
-     * @return The body string parameter plus any additional casting syntax needed to make the expression
-     *          resolvable. 
-     */
-    String castExpression(OgnlContext context, Node expression, String body);
-
-    /**
-     * Method is used for expressions where multiple inner parameter method calls in generated java source strings
-     * cause javassit failures.  It is hacky and cumbersome to have to generate expressions this way but it's the only
-     * current known way to make javassist happy.
-     *
+     * 
+     * @param context The current execution context.
+     * @param expression The node being checked for casting.
+     * @param body The java source string generated by the given node.
+     * @return The body string parameter plus any additional casting syntax needed to make the expression resolvable.
+     */
+    String castExpression( OgnlContext context, Node expression, String body );
+
+    /**
+     * Method is used for expressions where multiple inner parameter method calls in generated java source strings cause
+     * javassit failures. It is hacky and cumbersome to have to generate expressions this way but it's the only current
+     * known way to make javassist happy.
      * <p>
      * Takes an expression block generated by a node and creates a new method on the base object being compiled so that
-     * sufficiently complicated sub expression blocks can be broken out in to distinct methods to be referenced by the core
-     * accessor / setter methods in the base compiled root object.
+     * sufficiently complicated sub expression blocks can be broken out in to distinct methods to be referenced by the
+     * core accessor / setter methods in the base compiled root object.
      * </p>
-     *
-     * @param context
-     *          The current execution context.
-     * @param expression
-     *          The java source expression to dump in to a seperate method reference.
-     * @param type
-     *          The return type that should be specified for the new method.
+     * 
+     * @param context The current execution context.
+     * @param expression The java source expression to dump in to a seperate method reference.
+     * @param type The return type that should be specified for the new method.
      * @return The method name that will be used to reference the sub expression in place of the actual sub expression
-     *          itself.
+     *         itself.
      */
-    String createLocalReference(OgnlContext context, String expression, Class type);
+    String createLocalReference( OgnlContext context, String expression, Class type );
 }

Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/OrderedReturn.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/OrderedReturn.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/OrderedReturn.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/OrderedReturn.java Sat May 14 13:18:29 2011
@@ -21,22 +21,20 @@ package org.apache.commons.ognl.enhance;
 
 import org.apache.commons.ognl.Node;
 
-
 /**
- * Marks an ognl expression {@link Node} as needing to have the return portion of a 
- * getter method happen in a specific part of the generated expression vs just having
- * the whole expression returned in one chunk.
+ * Marks an ognl expression {@link Node} as needing to have the return portion of a getter method happen in a specific
+ * part of the generated expression vs just having the whole expression returned in one chunk.
  */
 public interface OrderedReturn
 {
-    
+
     /**
      * Get the core expression to execute first before any return foo logic is started.
      * 
      * @return The core standalone expression that shouldn't be pre-pended with a return keyword.
      */
     String getCoreExpression();
-    
+
     /**
      * Gets the last expression to be pre-pended with a return &lt;expression&gt; block.
      * 

Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/UnsupportedCompilationException.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/UnsupportedCompilationException.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/UnsupportedCompilationException.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/enhance/UnsupportedCompilationException.java Sat May 14 13:18:29 2011
@@ -19,30 +19,26 @@
  */
 package org.apache.commons.ognl.enhance;
 
-
-
 /**
- * Thrown during bytecode enhancement conversions of ognl expressions to indicate
- * that a certain expression isn't currently supported as a pure java bytecode enhanced
- * version. 
- * 
+ * Thrown during bytecode enhancement conversions of ognl expressions to indicate that a certain expression isn't
+ * currently supported as a pure java bytecode enhanced version.
  * <p>
- *  If this exception is thrown it is expected that ognl will fall back to default ognl 
- *  evaluation of the expression.
+ * If this exception is thrown it is expected that ognl will fall back to default ognl evaluation of the expression.
  * </p>
  * 
  * @author jkuhnert
  */
-public class UnsupportedCompilationException extends RuntimeException
+public class UnsupportedCompilationException
+    extends RuntimeException
 {
-    
-    public UnsupportedCompilationException(String message)
+
+    public UnsupportedCompilationException( String message )
     {
-        super(message);
+        super( message );
     }
 
-    public UnsupportedCompilationException(String message, Throwable cause)
+    public UnsupportedCompilationException( String message, Throwable cause )
     {
-        super(message, cause);
+        super( message, cause );
     }
 }

Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/ClassCache.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/ClassCache.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/ClassCache.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/ClassCache.java Sat May 14 13:18:29 2011
@@ -24,15 +24,16 @@ import org.apache.commons.ognl.ClassCach
 /**
  * This is a highly specialized map for storing values keyed by Class objects.
  */
-public interface ClassCache {
+public interface ClassCache
+{
 
-    void setClassInspector(ClassCacheInspector inspector);
+    void setClassInspector( ClassCacheInspector inspector );
 
     void clear();
 
     int getSize();
 
-    Object get(Class key);
+    Object get( Class key );
 
-    Object put(Class key, Object value);
+    Object put( Class key, Object value );
 }

Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/ClassCacheImpl.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/ClassCacheImpl.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/ClassCacheImpl.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/ClassCacheImpl.java Sat May 14 13:18:29 2011
@@ -26,15 +26,20 @@ import java.util.Arrays;
 /**
  * Implementation of {@link ClassCache}.
  */
-public class ClassCacheImpl implements ClassCache {
+public class ClassCacheImpl
+    implements ClassCache
+{
 
     /* this MUST be a power of 2 */
     private static final int TABLE_SIZE = 512;
+
     /* ...and now you see why. The table size is used as a mask for generating hashes */
     private static final int TABLE_SIZE_MASK = TABLE_SIZE - 1;
 
     private Entry[] _table;
+
     private ClassCacheInspector _classInspector;
+
     private int _size = 0;
 
     public ClassCacheImpl()
@@ -42,14 +47,14 @@ public class ClassCacheImpl implements C
         _table = new Entry[TABLE_SIZE];
     }
 
-    public void setClassInspector(ClassCacheInspector inspector)
+    public void setClassInspector( ClassCacheInspector inspector )
     {
         _classInspector = inspector;
     }
 
     public void clear()
     {
-        for (int i=0; i < _table.length; i++)
+        for ( int i = 0; i < _table.length; i++ )
         {
             _table[i] = null;
         }
@@ -62,14 +67,14 @@ public class ClassCacheImpl implements C
         return _size;
     }
 
-    public final Object get(Class key)
+    public final Object get( Class key )
     {
         Object result = null;
         int i = key.hashCode() & TABLE_SIZE_MASK;
 
-        for (Entry entry = _table[i]; entry != null; entry = entry.next)
+        for ( Entry entry = _table[i]; entry != null; entry = entry.next )
         {
-            if (entry.key == key)
+            if ( entry.key == key )
             {
                 result = entry.value;
                 break;
@@ -79,41 +84,44 @@ public class ClassCacheImpl implements C
         return result;
     }
 
-    public final Object put(Class key, Object value)
+    public final Object put( Class key, Object value )
     {
-        if (_classInspector != null && !_classInspector.shouldCache(key))
+        if ( _classInspector != null && !_classInspector.shouldCache( key ) )
             return value;
 
         Object result = null;
         int i = key.hashCode() & TABLE_SIZE_MASK;
         Entry entry = _table[i];
 
-        if (entry == null)
+        if ( entry == null )
         {
-            _table[i] = new Entry(key, value);
+            _table[i] = new Entry( key, value );
             _size++;
-        } else
+        }
+        else
         {
-            if (entry.key == key)
+            if ( entry.key == key )
             {
                 result = entry.value;
                 entry.value = value;
-            } else
+            }
+            else
             {
-                while (true)
+                while ( true )
                 {
-                    if (entry.key == key)
+                    if ( entry.key == key )
                     {
                         /* replace value */
                         result = entry.value;
                         entry.value = value;
                         break;
-                    } else
+                    }
+                    else
                     {
-                        if (entry.next == null)
+                        if ( entry.next == null )
                         {
                             /* add value */
-                            entry.next = new Entry(key, value);
+                            entry.next = new Entry( key, value );
                             break;
                         }
                     }
@@ -127,13 +135,7 @@ public class ClassCacheImpl implements C
 
     public String toString()
     {
-        return "ClassCacheImpl[" +
-               "_table=" + (_table == null ? null : Arrays.asList(_table)) +
-               '\n' +
-               ", _classInspector=" + _classInspector +
-               '\n' +
-               ", _size=" + _size +
-               '\n' +
-               ']';
+        return "ClassCacheImpl[" + "_table=" + ( _table == null ? null : Arrays.asList( _table ) ) + '\n'
+            + ", _classInspector=" + _classInspector + '\n' + ", _size=" + _size + '\n' + ']';
     }
 }

Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/Entry.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/Entry.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/Entry.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/internal/Entry.java Sat May 14 13:18:29 2011
@@ -22,13 +22,16 @@ package org.apache.commons.ognl.internal
 /**
  * Used by {@link ClassCacheImpl} to store entries in the cache.
  */
-class Entry {
+class Entry
+{
 
     Entry next;
+
     Class key;
+
     Object value;
 
-    public Entry(Class key, Object value)
+    public Entry( Class key, Object value )
     {
         this.key = key;
         this.value = value;
@@ -36,13 +39,6 @@ class Entry {
 
     public String toString()
     {
-        return "Entry[" +
-               "next=" + next +
-               '\n' +
-               ", key=" + key +
-               '\n' +
-               ", value=" + value +
-               '\n' +
-               ']';
+        return "Entry[" + "next=" + next + '\n' + ", key=" + key + '\n' + ", value=" + value + '\n' + ']';
     }
 }

Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/package-info.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/package-info.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/package-info.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/package-info.java Sat May 14 13:18:29 2011
@@ -35,3 +35,4 @@
  * pronunciation of "orthogonal" or like "ogg-null".
  */
 package org.apache.commons.ognl;
+

Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/InExpressionTest.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/InExpressionTest.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/InExpressionTest.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/InExpressionTest.java Sat May 14 13:18:29 2011
@@ -24,16 +24,18 @@ import junit.framework.TestCase;
 /**
  * Test for OGNL-118.
  */
-public class InExpressionTest extends TestCase {
+public class InExpressionTest
+    extends TestCase
+{
 
     public void test_String_In()
-            throws Exception
+        throws Exception
     {
-        OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
-        Object node = Ognl.parseExpression("#name in {\"Greenland\", \"Austin\", \"Africa\", \"Rome\"}");
+        OgnlContext context = (OgnlContext) Ognl.createDefaultContext( null );
+        Object node = Ognl.parseExpression( "#name in {\"Greenland\", \"Austin\", \"Africa\", \"Rome\"}" );
         Object root = null;
 
-        context.put("name", "Austin");
-        assertEquals(Boolean.TRUE, Ognl.getValue(node, context, root));
+        context.put( "name", "Austin" );
+        assertEquals( Boolean.TRUE, Ognl.getValue( node, context, root ) );
     }
 }

Modified: incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/TestOgnlException.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/TestOgnlException.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/TestOgnlException.java (original)
+++ incubator/ognl/trunk/src/test/java/org/apache/commons/ognl/TestOgnlException.java Sat May 14 13:18:29 2011
@@ -24,24 +24,32 @@ import junit.framework.TestCase;
 /**
  * Tests {@link OgnlException}.
  */
-public class TestOgnlException extends TestCase {
+public class TestOgnlException
+    extends TestCase
+{
 
     public void test_Throwable_Reason()
     {
-        try {
+        try
+        {
             throwException();
-        } catch (OgnlException e) {
-            assertTrue(NumberFormatException.class.isInstance(e.getReason()));
+        }
+        catch ( OgnlException e )
+        {
+            assertTrue( NumberFormatException.class.isInstance( e.getReason() ) );
         }
     }
 
     void throwException()
-            throws OgnlException
+        throws OgnlException
     {
-        try {
-            Integer.parseInt("45ac");
-        } catch (NumberFormatException et) {
-            throw new OgnlException("Unable to parse input string.", et);
+        try
+        {
+            Integer.parseInt( "45ac" );
+        }
+        catch ( NumberFormatException et )
+        {
+            throw new OgnlException( "Unable to parse input string.", et );
         }
     }
 }



Mime
View raw message