Commits

Anonymous committed d0e0c75

Removed unecessary getPropertyClass from PropertyAccessor interface.

Comments (0)

Files changed (7)

src/java/ognl/ArrayElementsAccessor.java

         return new Enumeration() {
             private int count = Array.getLength( target );
             private int index = 0;
-            public boolean hasMoreElements() {
+
+            public boolean hasMoreElements()
+            {
                 return index < count;
             }
-            public Object nextElement() {
+
+            public Object nextElement()
+            {
                 return Array.get( target, index++ );
             }
         };

src/java/ognl/ArrayPropertyAccessor.java

 /**
  * Implementation of PropertyAccessor that uses numbers and dynamic subscripts as properties to
  * index into Java arrays.
- * 
+ *
  * @author Luke Blanshard (blanshlu@netscape.net)
  * @author Drew Davidson (drew@ognl.org)
  */
 {
 
     public Object getProperty(Map context, Object target, Object name)
-        throws OgnlException
+            throws OgnlException
     {
         Object result = null;
-        
-        if (name instanceof String) {
-            if (name.equals("length")) {
+
+        if (name instanceof String)
+        {
+            if (name.equals("length"))
+            {
                 result = new Integer(Array.getLength(target));
-            } else {
+            } else
+            {
                 result = super.getProperty(context, target, name);
             }
-        } else {
+        } else
+        {
             Object index = name;
 
-            if (index instanceof DynamicSubscript) {
+            if (index instanceof DynamicSubscript)
+            {
                 int len = Array.getLength(target);
 
-                switch(((DynamicSubscript) index).getFlag()) {
-                case DynamicSubscript.ALL:
-                    result = Array.newInstance(target.getClass().getComponentType(), len);
-                    System.arraycopy(target, 0, result, 0, len);
-                    break;
-                case DynamicSubscript.FIRST:
-                    index = new Integer((len > 0) ? 0 : -1);
-                    break;
-                case DynamicSubscript.MID:
-                    index = new Integer((len > 0) ? (len / 2) : -1);
-                    break;
-                case DynamicSubscript.LAST:
-                    index = new Integer((len > 0) ? (len - 1) : -1);
-                    break;
+                switch(((DynamicSubscript) index).getFlag())
+                {
+                    case DynamicSubscript.ALL:
+                        result = Array.newInstance(target.getClass().getComponentType(), len);
+                        System.arraycopy(target, 0, result, 0, len);
+                        break;
+                    case DynamicSubscript.FIRST:
+                        index = new Integer((len > 0) ? 0 : -1);
+                        break;
+                    case DynamicSubscript.MID:
+                        index = new Integer((len > 0) ? (len / 2) : -1);
+                        break;
+                    case DynamicSubscript.LAST:
+                        index = new Integer((len > 0) ? (len - 1) : -1);
+                        break;
                 }
             }
-            if (result == null) {
-                if (index instanceof Number) {
+            if (result == null)
+            {
+                if (index instanceof Number)
+                {
                     int i = ((Number) index).intValue();
 
                     result = (i >= 0) ? Array.get(target, i) : null;
-                } else {
+                } else
+                {
                     throw new NoSuchPropertyException(target, index);
                 }
             }
     }
 
     public void setProperty(Map context, Object target, Object name, Object value)
-        throws OgnlException
+            throws OgnlException
     {
         Object index = name;
         boolean isNumber = (index instanceof Number);
 
-        if (isNumber || (index instanceof DynamicSubscript)) {
+        if (isNumber || (index instanceof DynamicSubscript))
+        {
             TypeConverter converter = ((OgnlContext) context).getTypeConverter();
             Object convertedValue;
-            
-            convertedValue = converter.convertValue(context, target, null, name.toString(), value, target.getClass()
-                    .getComponentType());
-            if (isNumber) {
+
+            convertedValue =
+                    converter.convertValue(context, target, null, name.toString(),
+                                           value, target.getClass().getComponentType());
+            if (isNumber)
+            {
                 int i = ((Number) index).intValue();
-                
-                if (i >= 0) {
+
+                if (i >= 0)
+                {
                     Array.set(target, i, convertedValue);
                 }
-            } else {
+            } else
+            {
                 int len = Array.getLength(target);
 
-                switch(((DynamicSubscript) index).getFlag()) {
-                case DynamicSubscript.ALL:
-                    System.arraycopy(target, 0, convertedValue, 0, len);
-                    return;
-                case DynamicSubscript.FIRST:
-                    index = new Integer((len > 0) ? 0 : -1);
-                    break;
-                case DynamicSubscript.MID:
-                    index = new Integer((len > 0) ? (len / 2) : -1);
-                    break;
-                case DynamicSubscript.LAST:
-                    index = new Integer((len > 0) ? (len - 1) : -1);
-                    break;
+                switch(((DynamicSubscript) index).getFlag())
+                {
+                    case DynamicSubscript.ALL:
+                        System.arraycopy(target, 0, convertedValue, 0, len);
+                        return;
+                    case DynamicSubscript.FIRST:
+                        index = new Integer((len > 0) ? 0 : -1);
+                        break;
+                    case DynamicSubscript.MID:
+                        index = new Integer((len > 0) ? (len / 2) : -1);
+                        break;
+                    case DynamicSubscript.LAST:
+                        index = new Integer((len > 0) ? (len - 1) : -1);
+                        break;
                 }
             }
         } else {
-            if (name instanceof String) {
+            if (name instanceof String)
+            {
                 super.setProperty(context, target, name, value);
-            } else {
+            } else
+            {
                 throw new NoSuchPropertyException(target, index);
             }
         }
     }
 
-    public Class getPropertyClass(OgnlContext context, Object target, Object index)
-    {
-        if (target.getClass().getComponentType().isPrimitive())
-            return target.getClass().getComponentType();
-        
-        if (String.class.isAssignableFrom(index.getClass())) {
-            String key = ((String) index).replaceAll("\"", "");
-            
-            if (key.equals("length")) {
-                return int.class;
-            } else {
-                return super.getPropertyClass(context, target, index);
-            }
-        }
-        
-        if (index instanceof Number) {
-            int i = ((Number) index).intValue();
-            
-            Object result = Array.get(target, i);
-            if (result != null) 
-                return result.getClass();
-        }
-
-        return null;
-    }
-
     public String getSourceAccessor(OgnlContext context, Object target, Object index)
     {
         String indexStr = index.toString();
-        
+
         // need to convert to primitive for list index access
 
         // System.out.println("index class " + index.getClass() + " current type " + context.getCurrentType() + " current object class " + context.getCurrentObject().getClass());
 
         if (context.getCurrentType() != null && !context.getCurrentType().isPrimitive()
-            && Number.class.isAssignableFrom(context.getCurrentType())) {
-
+            && Number.class.isAssignableFrom(context.getCurrentType()))
+        {
             indexStr += "." + OgnlRuntime.getNumericValueGetter(context.getCurrentType());
         } else if (context.getCurrentObject() != null && Number.class.isAssignableFrom(context.getCurrentObject().getClass())
-                    && !context.getCurrentType().isPrimitive()) {
-
+                   && !context.getCurrentType().isPrimitive())
+        {
             // means it needs to be cast first as well
 
             String toString = String.class.isInstance(index) && context.getCurrentType() != Object.class ? "" : ".toString()";
 
         context.setCurrentAccessor(target.getClass());
         context.setCurrentType(target.getClass().getComponentType());
-        
+
         return "[" + indexStr + "]";
     }
 
         // need to convert to primitive for list index access
 
         if (context.getCurrentType() != null && !context.getCurrentType().isPrimitive()
-            && Number.class.isAssignableFrom(context.getCurrentType())) {
-
+            && Number.class.isAssignableFrom(context.getCurrentType()))
+        {
             indexStr += "." + OgnlRuntime.getNumericValueGetter(context.getCurrentType());
         } else if (context.getCurrentObject() != null && Number.class.isAssignableFrom(context.getCurrentObject().getClass())
-                    && !context.getCurrentType().isPrimitive()) {
-
+                   && !context.getCurrentType().isPrimitive())
+        {
             // means it needs to be cast first as well
 
             String toString = String.class.isInstance(index) && context.getCurrentType() != Object.class ? "" : ".toString()";
         }
 
         Class type = target.getClass().isArray() ? target.getClass().getComponentType() : target.getClass();
-        
+
         context.setCurrentAccessor(target.getClass());
         context.setCurrentType(target.getClass().getComponentType());
-        
-        if (type.isPrimitive()) {
-            
+
+        if (type.isPrimitive())
+        {
             Class wrapClass = OgnlRuntime.getPrimitiveWrapperClass(type);
             
             return "[" + indexStr + "]=((" + wrapClass.getName() + ")ognl.OgnlOps.convertValue($3," + wrapClass.getName()
-                    + ".class, true))." + OgnlRuntime.getNumericValueGetter(wrapClass);
-        } else {
-
+                   + ".class, true))." + OgnlRuntime.getNumericValueGetter(wrapClass);
+        } else
+        {
             return "[" + indexStr + "]=ognl.OgnlOps.convertValue($3," + type.getName() + ".class)";
         }
     }

src/java/ognl/MapPropertyAccessor.java

         map.put(name, value);
     }
 
-    public Class getPropertyClass(OgnlContext context, Object target, Object index)
-    {
-        Node currentNode = ((OgnlContext) context).getCurrentNode().jjtGetParent();
-        boolean indexedAccess = false;
-
-        if (currentNode == null) { throw new RuntimeException("node is null for '" + index + "'"); }
-        if (!(currentNode instanceof ASTProperty)) {
-            currentNode = currentNode.jjtGetParent();
-        }
-        if (currentNode instanceof ASTProperty) {
-            indexedAccess = ((ASTProperty) currentNode).isIndexedAccess();
-        }
-
-        if (String.class.isAssignableFrom(index.getClass()) && !indexedAccess) {
-            String key = ((String)index).replaceAll("\"", "");
-
-            if (key.equals("size"))
-                return int.class;
-            else if (key.equals("keys") || key.equals("keySet"))
-                return Set.class;
-            else if (key.equals("values"))
-                return Collection.class;
-            else if (key.equals("isEmpty"))
-                return boolean.class;
-        }
-
-        return Object.class;
-    }
-
     public String getSourceAccessor(OgnlContext context, Object target, Object index)
     {
         Node currentNode = ((OgnlContext) context).getCurrentNode().jjtGetParent();

src/java/ognl/PropertyAccessor.java

      */
     void setProperty(Map context, Object target, Object name, Object value)
         throws OgnlException;
-    
-    /**
-     * Expected to return the actual class type that would be returned by this property
-     * accessor in a native java call. Ie sometimes it may be primitive.
-     * 
-     * @param context
-     *          The standard ognl context.
-     * @param target
-     *          The object whos property is being accessed.
-     * @param index
-     *          The index identifier for the property.
-     * @return
-     *          The class type that would result from a property access.
-     */
-    Class getPropertyClass(OgnlContext context, Object target, Object index);
-    
+
     /**
      * Returns a java string representing the textual method that should be called to access a
      * particular element. (ie "get")

src/java/ognl/enhance/ExpressionCompiler.java

 
         CtField nodeMember = null; // will only be set if uncompilable exception is thrown
 
-        // must evaluate expression value at least once if object isn't null
-
-        //if (root != null)
-            //Ognl.getValue(expression, context, root);
-
         CtClass nodeClass = getCtClass(Node.class);
         CtMethod setExpression = null;
 
 
             getBody = generateGetter(context, newClass, objClass, pool, valueGetter, expression, root);
 
-        } catch (UnsupportedCompilationException uc) {
-
+        } catch (UnsupportedCompilationException uc)
+        {
             //uc.printStackTrace();
 
             nodeMember = new CtField(nodeClass, "_node", newClass);
 
             setBody = generateSetter(context, newClass, objClass, pool,  valueSetter, expression, root);
 
-        } catch (UnsupportedCompilationException uc) {
+        } catch (UnsupportedCompilationException uc)
+        {
 
             //uc.printStackTrace();
 
 
             setBody = generateOgnlSetter(newClass, valueSetter, nodeMember);
 
-            if (setExpression == null) {
-
+            if (setExpression == null)
+            {
                 setExpression = CtNewMethod.setter("setExpression", nodeMember);
                 newClass.addMethod(setExpression);
             }

src/test/java/org/ognl/test/PropertyNotFoundTest.java

             return null;
         }
 
-        public Class getPropertyClass(OgnlContext context, Object target, Object index)
-        {
-            return null;
-        }
-
         public String getSourceAccessor(OgnlContext context, Object target, Object index)
         {
             return index.toString();

src/test/java/org/ognl/test/objects/BeanProviderAccessor.java

         return provider.getBean(beanName) != null;
     }
     
-    public Class getPropertyClass(OgnlContext context, Object target, Object name)
-    {
-        BeanProvider provider = (BeanProvider)target;
-        String beanName = ((String)name).replaceAll("\"", "");
-
-        if (provider.getBean(beanName) != null)
-            return provider.getBean(beanName).getClass();
-        else
-            return super.getPropertyClass(context, target, name);
-    }
-    
     public String getSourceAccessor(OgnlContext context, Object target, Object name)
     {
         BeanProvider provider = (BeanProvider)target;
         String beanName = ((String)name).replaceAll("\"", "");
         
-        if (provider.getBean(beanName) != null) {
-            
+        if (provider.getBean(beanName) != null)
+        {    
             context.setCurrentAccessor(BeanProvider.class);
             context.setCurrentType(provider.getBean(beanName).getClass());
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.