Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   // --------------------------------------------------------------------------
   // Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
   // All rights reserved.
   //
   // Redistribution and use in source and binary forms, with or without
   // modification, are permitted provided that the following conditions are
   // met:
   //
   // Redistributions of source code must retain the above copyright notice,
  // this list of conditions and the following disclaimer.
  // Redistributions in binary form must reproduce the above copyright
  // notice, this list of conditions and the following disclaimer in the
  // documentation and/or other materials provided with the distribution.
  // Neither the name of the Drew Davidson nor the names of its contributors
  // may be used to endorse or promote products derived from this software
  // without specific prior written permission.
  //
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  // DAMAGE.
  // --------------------------------------------------------------------------
  package ognl;
  
  
  import java.beans.*;
  import java.util.*;

Utility class used by internal OGNL API to do various things like:

Author(s):
Luke Blanshard (blanshlu@netscape.net)
Drew Davidson (drew@ognl.org)
  
  public class OgnlRuntime {

    
Constant expression used to indicate that a given method / property couldn't be found during reflection operations.
  
      public static final Object NotFound = new Object();
      public static final List NotFoundList = new ArrayList();
      public static final Map NotFoundMap = new HashMap();
      public static final Object[] NoArguments = new Object[]{};
      public static final Class[] NoArgumentTypes = new Class[]{};

    
Token returned by TypeConverter for no conversion possible
  
      public static final Object NoConversionPossible = "ognl.NoConversionPossible";

    
Not an indexed property
  
      public static int INDEXED_PROPERTY_NONE = 0;
    
JavaBeans IndexedProperty
  
      public static int INDEXED_PROPERTY_INT = 1;
    
OGNL ObjectIndexedProperty
  
      public static int INDEXED_PROPERTY_OBJECT = 2;

    
Constant string representation of null string.
  
      public static final String NULL_STRING = "" + null;

    
Java beans standard set method prefix.
  
      private static final String SET_PREFIX = "set";
    
Java beans standard get method prefix.
  
     private static final String GET_PREFIX = "get";
    
Java beans standard is<Foo> boolean getter prefix.
 
     private static final String IS_PREFIX = "is";

    
Prefix padding for hexadecimal numbers to HEX_LENGTH.
 
     private static final Map HEX_PADDING = new HashMap();
 
     private static final int HEX_LENGTH = 8;

    
Returned by getUniqueDescriptor() when the object is null.
 
     private static final String NULL_OBJECT_STRING = "<null>";

    
Used to store the result of determining if current jvm is 1.5 language compatible.
 
     private static boolean _jdk15 = false;
     private static boolean _jdkChecked = false;
 
     static final ClassCache _methodAccessors = new ClassCacheImpl();
     static final ClassCache _propertyAccessors = new ClassCacheImpl();
     static final ClassCache _elementsAccessors = new ClassCacheImpl();
     static final ClassCache _nullHandlers = new ClassCacheImpl();
 
     static final ClassCache _propertyDescriptorCache = new ClassCacheImpl();
     static final ClassCache _constructorCache = new ClassCacheImpl();
     static final ClassCache _staticMethodCache = new ClassCacheImpl();
     static final ClassCache _instanceMethodCache = new ClassCacheImpl();
     static final ClassCache _invokePermissionCache = new ClassCacheImpl();
     static final ClassCache _fieldCache = new ClassCacheImpl();
     static final List _superclasses = new ArrayList(); /* Used by fieldCache lookup */
     static final ClassCache[] _declaredMethods = new ClassCache[]{new ClassCacheImpl(), new ClassCacheImpl()};
 
     static final Map _primitiveTypes = new HashMap(101);
     static final ClassCache _primitiveDefaults = new ClassCacheImpl();
     static final Map _methodParameterTypesCache = new HashMap(101);
     static final Map _genericMethodParameterTypesCache = new HashMap(101);
     static final Map _ctorParameterTypesCache = new HashMap(101);
     static SecurityManager _securityManager = System.getSecurityManager();
     static final EvaluationPool _evaluationPool = new EvaluationPool();
     static final ObjectArrayPool _objectArrayPool = new ObjectArrayPool();
 
     static final IntHashMap _methodAccessCache = new IntHashMap();
     static final IntHashMap _methodPermCache = new IntHashMap();
     
     static final Map cacheSetMethod = new HashMap();
     static final Map cacheGetMethod = new HashMap();
 
     static ClassCacheInspector _cacheInspector;

    
 
     private static OgnlExpressionCompiler _compiler;

    
Lazy loading of Javassist library
 
     static {
         try {
             Class.forName("javassist.ClassPool");
              = new ExpressionCompiler();
         } catch (ClassNotFoundException e) {
             throw new IllegalArgumentException("Javassist library is missing in classpath! Please add missed dependency!",e);
         }
     }
 
     private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
 
     private static IdentityHashMap PRIMITIVE_WRAPPER_CLASSES = new IdentityHashMap();

    
Used to provide primitive type equivalent conversions into and out of native / object types.
 
     static {
         .put(.Byte.class);
         .put(Byte.class.);
         .put(.Short.class);
         .put(Short.class.);
         .put(.Long.class);
         .put(Long.class.);
         .put(.Float.class);
         .put(Float.class.);
         .put(.Double.class);
         .put(Double.class.);
     }
 
     private static final Map NUMERIC_CASTS = new HashMap();

    
Constant strings for casting different primitive types.
 
     static {
         .put(Double.class"(double)");
         .put(Float.class"(float)");
         .put(Integer.class"(int)");
         .put(Long.class"(long)");
         .put(BigDecimal.class"(double)");
         .put(BigInteger.class"");
     }
 
     private static final Map NUMERIC_VALUES = new HashMap();

    
Constant strings for getting the primitive value of different native types on the generic Number object interface. (or the less generic BigDecimal/BigInteger types)
 
     static {
         .put(Double.class"doubleValue()");
         .put(Float.class"floatValue()");
         .put(Integer.class"intValue()");
         .put(Long.class"longValue()");
         .put(Short.class"shortValue()");
         .put(Byte.class"byteValue()");
         .put(BigDecimal.class"doubleValue()");
         .put(BigInteger.class"doubleValue()");
         .put(Boolean.class"booleanValue()");
     }
 
     private static final Map NUMERIC_LITERALS = new HashMap();

    
Numeric primitive literal string expressions.
 
     static {
         .put(Integer.class"");
         .put(."");
         .put(Long.class"l");
         .put(."l");
         .put(BigInteger.class"d");
         .put(Float.class"f");
         .put(."f");
         .put(Double.class"d");
         .put(."d");
         .put(BigInteger.class"d");
         .put(BigDecimal.class"d");
     }
 
     private static final Map NUMERIC_DEFAULTS = new HashMap();
 
     static {
         .put(Boolean.class.);
         .put(Byte.classnew Byte((byte) 0));
         .put(Short.classnew Short((short) 0));
         .put(Character.classnew Character((char) 0));
         .put(Integer.classnew Integer(0));
         .put(Long.classnew Long(0L));
         .put(Float.classnew Float(0.0f));
         .put(Double.classnew Double(0.0));
 
         .put(BigInteger.classnew BigInteger("0"));
         .put(BigDecimal.classnew BigDecimal(0.0));
     }
 
     static {
         PropertyAccessor p = new ArrayPropertyAccessor();
 
         setPropertyAccessor(Object.classnew ObjectPropertyAccessor());
         setPropertyAccessor(byte[].classp);
         setPropertyAccessor(short[].classp);
         setPropertyAccessor(char[].classp);
         setPropertyAccessor(int[].classp);
         setPropertyAccessor(long[].classp);
         setPropertyAccessor(float[].classp);
         setPropertyAccessor(double[].classp);
         setPropertyAccessor(Object[].classp);
         setPropertyAccessor(List.classnew ListPropertyAccessor());
         setPropertyAccessor(Map.classnew MapPropertyAccessor());
         setPropertyAccessor(Set.classnew SetPropertyAccessor());
         setPropertyAccessor(Iterator.classnew IteratorPropertyAccessor());
 
         ElementsAccessor e = new ArrayElementsAccessor();
 
         setElementsAccessor(Object.classnew ObjectElementsAccessor());
         setElementsAccessor(byte[].classe);
         setElementsAccessor(short[].classe);
         setElementsAccessor(char[].classe);
         setElementsAccessor(int[].classe);
         setElementsAccessor(long[].classe);
         setElementsAccessor(float[].classe);
         setElementsAccessor(double[].classe);
         setElementsAccessor(Object[].classe);
         setElementsAccessor(Map.classnew MapElementsAccessor());
         setElementsAccessor(Iterator.classnew IteratorElementsAccessor());
         setElementsAccessor(Number.classnew NumberElementsAccessor());
 
         NullHandler nh = new ObjectNullHandler();
 
         setNullHandler(Object.classnh);
         setNullHandler(byte[].classnh);
         setNullHandler(short[].classnh);
         setNullHandler(char[].classnh);
         setNullHandler(int[].classnh);
         setNullHandler(long[].classnh);
         setNullHandler(float[].classnh);
         setNullHandler(double[].classnh);
         setNullHandler(Object[].classnh);
 
         MethodAccessor ma = new ObjectMethodAccessor();
 
         setMethodAccessor(Object.classma);
         setMethodAccessor(byte[].classma);
         setMethodAccessor(short[].classma);
         setMethodAccessor(char[].classma);
         setMethodAccessor(int[].classma);
         setMethodAccessor(long[].classma);
         setMethodAccessor(float[].classma);
         setMethodAccessor(double[].classma);
         setMethodAccessor(Object[].classma);
 
         .put("boolean".);
         .put("byte".);
         .put("short".);
         .put("char".);
         .put("int".);
         .put("long".);
         .put("float".);
         .put("double".);
 
         .put(Boolean.class.);
         .put(.new Byte((byte) 0));
         .put(Byte.classnew Byte((byte) 0));
         .put(.new Short((short) 0));
         .put(Short.classnew Short((short) 0));
         .put(.new Character((char) 0));
         .put(.new Integer(0));
         .put(.new Long(0L));
         .put(.new Float(0.0f));
         .put(.new Double(0.0));
 
         .put(BigInteger.classnew BigInteger("0"));
         .put(BigDecimal.classnew BigDecimal(0.0));
     }

    
Clears all of the cached reflection information normally used to improve the speed of expressions that operate on the same classes or are executed multiple times.

Warning: Calling this too often can be a huge performance drain on your expressions - use with care.

 
     public static void clearCache()
     {
         .clear();
         .clear();
         .clear();
         .clear();
         .clear();
         .clear();
         .clear();
         .clear();
         [0].clear();
         [1].clear();
         .clear();
     }

    
Checks if the current jvm is java language >= 1.5 compatible.

Returns:
True if jdk15 features are present.
 
     public static boolean isJdk15()
     {
         if ()
             return ;
 
         try
         {
             Class.forName("java.lang.annotation.Annotation");
              = true;
         } catch (Exception e) { /* ignore */ }
 
          = true;
 
         return ;
     }
 
     public static String getNumericValueGetter(Class type)
     {
         return (String.get(type);
     }
 
     public static Class getPrimitiveWrapperClass(Class primitiveClass)
     {
         return (Class.get(primitiveClass);
     }
 
     public static String getNumericCast(Class type)
     {
         return (String.get(type);
     }
 
     public static String getNumericLiteral(Class type)
     {
         return (String.get(type);
     }
 
     public static void setCompiler(OgnlExpressionCompiler compiler)
     {
          = compiler;
     }
 
     public static OgnlExpressionCompiler getCompiler()
     {
         return ;
     }
 
     public static void compileExpression(OgnlContext contextNode expressionObject root)
             throws Exception
     {
         .compileExpression(contextexpressionroot);
     }

    
Gets the "target" class of an object for looking up accessors that are registered on the target. If the object is a Class object this will return the Class itself, else it will return object's getClass() result.
 
     public static Class getTargetClass(Object o)
     {
         return (o == null) ? null : ((o instanceof Class) ? (Classo : o.getClass());
     }

    
Returns the base name (the class name without the package name prepended) of the object given.
 
     public static String getBaseName(Object o)
     {
         return (o == null) ? null : getClassBaseName(o.getClass());
     }

    
Returns the base name (the class name without the package name prepended) of the class given.
 
     public static String getClassBaseName(Class c)
     {
         String s = c.getName();
 
         return s.substring(s.lastIndexOf('.') + 1);
     }
 
     public static String getClassName(Object oboolean fullyQualified)
     {
         if (!(o instanceof Class))
         {
             o = o.getClass();
         }
 
         return getClassName((ClassofullyQualified);
     }
 
     public static String getClassName(Class cboolean fullyQualified)
     {
         return fullyQualified ? c.getName() : getClassBaseName(c);
     }

    
Returns the package name of the object's class.
 
     public static String getPackageName(Object o)
     {
         return (o == null) ? null : getClassPackageName(o.getClass());
     }

    
Returns the package name of the class given.
 
     public static String getClassPackageName(Class c)
     {
         String s = c.getName();
         int i = s.lastIndexOf('.');
 
         return (i < 0) ? null : s.substring(0, i);
     }

    
Returns a "pointer" string in the usual format for these things - 0x<hex digits>.
 
     public static String getPointerString(int num)
     {
         StringBuffer result = new StringBuffer();
         String hex = Integer.toHexString(num), pad;
         Integer l = new Integer(hex.length());
 
         // result.append(HEX_PREFIX);
         if ((pad = (String.get(l)) == null) {
             StringBuffer pb = new StringBuffer();
 
             for (int i = hex.length(); i < i++) {
                 pb.append('0');
             }
             pad = new String(pb);
             .put(lpad);
         }
         result.append(pad);
         result.append(hex);
         return new String(result);
     }

    
Returns a "pointer" string in the usual format for these things - 0x<hex digits> for the object given. This will always return a unique value for each object.
 
     public static String getPointerString(Object o)
     {
         return getPointerString((o == null) ? 0 : System.identityHashCode(o));
     }

    
Returns a unique descriptor string that includes the object's class and a unique integer identifier. If fullyQualified is true then the class name will be fully qualified to include the package name, else it will be just the class' base name.
 
     public static String getUniqueDescriptor(Object objectboolean fullyQualified)
     {
         StringBuffer result = new StringBuffer();
 
         if (object != null) {
             if (object instanceof Proxy) {
                 Class interfaceClass = object.getClass().getInterfaces()[0];
 
                 result.append(getClassName(interfaceClassfullyQualified));
                 result.append('^');
                 object = Proxy.getInvocationHandler(object);
             }
             result.append(getClassName(objectfullyQualified));
             result.append('@');
             result.append(getPointerString(object));
         } else {
             result.append();
         }
         return new String(result);
     }

    
Returns a unique descriptor string that includes the object's class' base name and a unique integer identifier.
 
     public static String getUniqueDescriptor(Object object)
     {
         return getUniqueDescriptor(objectfalse);
     }

    
Utility to convert a List into an Object[] array. If the list is zero elements this will return a constant array; toArray() on List always returns a new object and this is wasteful for our purposes.
 
     public static Object[] toArray(List list)
     {
         Object[] result;
         int size = list.size();
 
         if (size == 0) {
             result = ;
         } else {
             result = getObjectArrayPool().create(list.size());
             for (int i = 0; i < sizei++) {
                 result[i] = list.get(i);
             }
         }
         return result;
     }

    
Returns the parameter types of the given method.
 
     public static Class[] getParameterTypes(Method m)
     {
         synchronized ()
         {
             Class[] result;
 
             if ((result = (Class[]) .get(m)) == null)
             {
                 .put(mresult = m.getParameterTypes());
             }
             return result;
         }
     }

    
Finds the appropriate parameter types for the given java.lang.reflect.Method and java.lang.Class instance of the type the method is associated with. Correctly finds generic types if running in >= 1.5 jre as well.

Parameters:
type The class type the method is being executed against.
m The method to find types for.
Returns:
Array of parameter types for the given method.
 
     public static Class[] findParameterTypes(Class typeMethod m)
     {
         Type[] genTypes = m.getGenericParameterTypes();
         Class[] types = new Class[genTypes.length];;
         boolean noGenericParameter = true;
         for (int i=0; i < genTypes.lengthi++)
         {
             if (Class.class.isInstance(genTypes[i]))
             {
                 types[i] = (ClassgenTypes[i];
                 continue;
             }
             noGenericParameter = false;
             break;
         }
         if (noGenericParameter)
         {
             return types;
         }
 
         if (type == null || !isJdk15())
         {
             return getParameterTypes(m);
         }
 
         final Type typeGenericSuperclass = type.getGenericSuperclass();
         if (typeGenericSuperclass == null
             || !ParameterizedType.class.isInstance(typeGenericSuperclass)
             || m.getDeclaringClass().getTypeParameters() == null)
         {
             return getParameterTypes(m);
         }
 
         if ((types = (Class[]) .get(m)) != null)
         {
             ParameterizedType genericSuperclass = (ParameterizedTypetypeGenericSuperclass;
             if (Arrays.equals(typesgenericSuperclass.getActualTypeArguments())) {
                 return types;
             }
         }
 
         ParameterizedType param = (ParameterizedType)typeGenericSuperclass;
         TypeVariable[] declaredTypes = m.getDeclaringClass().getTypeParameters();
 
         types = new Class[genTypes.length];
 
         for (int i=0; i < genTypes.lengthi++)
         {
             TypeVariable paramType = null;
 
             if (TypeVariable.class.isInstance(genTypes[i]))
             {
                 paramType = (TypeVariable)genTypes[i];
             } else if (GenericArrayType.class.isInstance(genTypes[i]))
             {
                 paramType = (TypeVariable) ((GenericArrayType)genTypes[i]).getGenericComponentType();
             }
             else if (ParameterizedType.class.isInstance(genTypes[i]))
             {
                  types[i] = (Class) ((ParameterizedTypegenTypes[i]).getRawType();
                  continue;
             } else if (Class.class.isInstance(genTypes[i]))
             {
                 types[i] = (ClassgenTypes[i];
                 continue;
             }
 
             Class resolved = resolveType(paramparamTypedeclaredTypes);
 
             if (resolved != null)
             {
                 if (GenericArrayType.class.isInstance(genTypes[i]))
                 {
                     resolved = Array.newInstance(resolved, 0).getClass();
                 }
 
                 types[i] = resolved;
                 continue;
             }
 
             types[i] = m.getParameterTypes()[i];
         }
 
         synchronized ()
         {
             .put(mtypes);
         }
 
         return types;
     }
 
     static Class resolveType(ParameterizedType paramTypeVariable varTypeVariable[] declaredTypes)
     {
         if (param.getActualTypeArguments().length < 1)
             return null;
 
         for (int i=0; i < declaredTypes.lengthi++)
         {
             if (!TypeVariable.class.isInstanceparam.getActualTypeArguments()[i])
                 && declaredTypes[i].getName().equals(var.getName()))
             {
                 return (Classparam.getActualTypeArguments()[i];
             }
         }
 
         /*
         for (int i=0; i < var.getBounds().length; i++)
         {
             Type t = var.getBounds()[i];
             Class resolvedType = null;
 
             if (ParameterizedType.class.isInstance(t))
             {
                 ParameterizedType pparam = (ParameterizedType)t;
                 for (int e=0; e < pparam.getActualTypeArguments().length; e++)
                 {
                     if (!TypeVariable.class.isInstance(pparam.getActualTypeArguments()[e]))
                         continue;
 
                     resolvedType = resolveType(pparam, (TypeVariable)pparam.getActualTypeArguments()[e], declaredTypes);
                 }
             } else
             {
                 resolvedType = findType(param.getActualTypeArguments(), (Class)t);
             }
 
             if (resolvedType != null)
                 return resolvedType;
         }
         */
 
         return null;
     }
 
     static Class findType(Type[] typesClass type)
     {
         for (int i = 0; i < types.lengthi++)
         {
             if (Class.class.isInstance(types[i]) && type.isAssignableFrom((Class)types[i]))
                 return (Class)types[i];
         }
 
         return null;
     }

    
Returns the parameter types of the given method.
 
     public static Class[] getParameterTypes(Constructor c)
     {
         Class[] result;
         if ((result = (Class[]) .get(c)) == null) {
             synchronized () {
                 if ((result = (Class[]) .get(c)) == null) {
                     .put(cresult = c.getParameterTypes());
                 }
             }
         }
         return result;
     }

    
Gets the SecurityManager that OGNL uses to determine permissions for invoking methods.

Returns:
SecurityManager for OGNL
 
     public static SecurityManager getSecurityManager()
     {
         return ;
     }

    
Sets the SecurityManager that OGNL uses to determine permissions for invoking methods.

Parameters:
value SecurityManager to set
 
     public static void setSecurityManager(SecurityManager value)
     {
          = value;
     }

    
Permission will be named "invoke.<declaring-class>.<method-name>".
 
     public static Permission getPermission(Method method)
     {
         Permission result;
         Class mc = method.getDeclaringClass();
 
         synchronized () {
             Map permissions = (Map.get(mc);
 
             if (permissions == null) {
                 .put(mcpermissions = new HashMap(101));
             }
             if ((result = (Permissionpermissions.get(method.getName())) == null) {
                 result = new OgnlInvokePermission("invoke." + mc.getName() + "." + method.getName());
                 permissions.put(method.getName(), result);
             }
         }
         return result;
     }
 
     public static Object invokeMethod(Object targetMethod methodObject[] argsArray)
             throws InvocationTargetExceptionIllegalAccessException
     {
         boolean syncInvoke = false;
         boolean checkPermission = false;
         int mHash = method.hashCode();
 
         // only synchronize method invocation if it actually requires it
 
         synchronized(method) {
             if (.get(mHash) == null
                 || .get(mHash) == .) {
                 syncInvoke = true;
             }
 
             if ( != null && .get(mHash) == null
                 || .get(mHash) == .) {
                 checkPermission = true;
             }
         }
 
         Object result;
         boolean wasAccessible = true;
 
         if (syncInvoke)
         {
             synchronized(method)
             {
                 if (checkPermission)
                 {
                     try
                     {
                         .checkPermission(getPermission(method));
                         .put(mHash.);
                     } catch (SecurityException ex) {
                         .put(mHash.);
                         throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
                     }
                 }
 
                 if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
                 {
                     if (!(wasAccessible = ((AccessibleObjectmethod).isAccessible()))
                     {
                         ((AccessibleObjectmethod).setAccessible(true);
                         .put(mHash.);
                     } else
                     {
                         .put(mHash.);
                     }
                 } else
                 {
                     .put(mHash.);
                 }
 
                 result = method.invoke(targetargsArray);
 
                 if (!wasAccessible)
                 {
                     ((AccessibleObjectmethod).setAccessible(false);
                 }
             }
         } else
         {
             if (checkPermission)
             {
                 try
                 {
                     .checkPermission(getPermission(method));
                     .put(mHash.);
                 } catch (SecurityException ex) {
                     .put(mHash.);
                     throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
                 }
             }
 
             result = method.invoke(targetargsArray);
         }
 
         return result;
     }

    
Gets the class for a method argument that is appropriate for looking up methods by reflection, by looking for the standard primitive wrapper classes and exchanging for them their underlying primitive class objects. Other classes are passed through unchanged.

Parameters:
arg an object that is being passed to a method
Returns:
the class to use to look up the method
 
     public static final Class getArgClass(Object arg)
     {
         if (arg == null)
             return null;
         Class c = arg.getClass();
         if (c == Boolean.class)
             return .;
         else if (c.getSuperclass() == Number.class) {
             if (c == Integer.class)
                 return .;
             if (c == Double.class)
                 return .;
             if (c == Byte.class)
                 return .;
             if (c == Long.class)
                 return .;
             if (c == Float.class)
                 return .;
             if (c == Short.class)
                 return .;
         } else if (c == Character.class)
             return .;
         return c;
     }

    
Tells whether the given object is compatible with the given class ---that is, whether the given object can be passed as an argument to a method or constructor whose parameter type is the given class. If object is null this will return true because null is compatible with any type.
 
     public static final boolean isTypeCompatible(Object objectClass c)
     {
         boolean result = true;
 
         if (object != null) {
             if (c.isPrimitive()) {
                 if (getArgClass(object) != c) {
                     result = false;
                 }
             } else if (!c.isInstance(object)) {
                 result = false;
             }
         }
         return result;
     }

    
Tells whether the given array of objects is compatible with the given array of classes---that is, whether the given array of objects can be passed as arguments to a method or constructor whose parameter types are the given array of classes.
 
     public static boolean areArgsCompatible(Object[] argsClass[] classes)
     {
         return areArgsCompatible(argsclassesnull);
     }
 
     public static boolean areArgsCompatible(Object[] argsClass[] classesMethod m)
     {
         boolean result = true;
         boolean varArgs = m != null && isJdk15() && m.isVarArgs();
 
         if (args.length != classes.length && !varArgs) {
             result = false;
         } else if (varArgs) {
             for (int index = 0, count = args.lengthresult && (index < count); ++index) {
                 if (index >= classes.length){
                     break;
                 }
 
                 result = isTypeCompatible(args[index], classes[index]);
 
                 if (!result && classes[index].isArray()) {
                     result = isTypeCompatible(args[index], classes[index].getComponentType());
                 }
             }
         } else {
             for (int index = 0, count = args.lengthresult && (index < count); ++index) {
                 result = isTypeCompatible(args[index], classes[index]);
             }
         }
         return result;
     }

    
Tells whether the first array of classes is more specific than the second. Assumes that the two arrays are of the same length.
 
     public static final boolean isMoreSpecific(Class[] classes1Class[] classes2)
     {
         for (int index = 0, count = classes1.lengthindex < count; ++index) {
             Class c1 = classes1[index], c2 = classes2[index];
             if (c1 == c2)
                 continue;
             else if (c1.isPrimitive())
                return true;
            else if (c1.isAssignableFrom(c2))
                return false;
            else if (c2.isAssignableFrom(c1))
                return true;
        }
        // They are the same! So the first is not more specific than the second.
        return false;
    }
    public static String getModifierString(int modifiers)
    {
        String result;
        if (Modifier.isPublic(modifiers))
            result = "public";
        else if (Modifier.isProtected(modifiers))
            result = "protected";
        else if (Modifier.isPrivate(modifiers))
            result = "private";
        else
            result = "";
        if (Modifier.isStatic(modifiers))
            result = "static " + result;
        if (Modifier.isFinal(modifiers))
            result = "final " + result;
        if (Modifier.isNative(modifiers))
            result = "native " + result;
        if (Modifier.isSynchronized(modifiers))
            result = "synchronized " + result;
        if (Modifier.isTransient(modifiers))
            result = "transient " + result;
        return result;
    }
    public static Class classForName(OgnlContext contextString className)
            throws ClassNotFoundException
    {
        Class result = (Class.get(className);
        if (result == null) {
            ClassResolver resolver;
            if ((context == null) || ((resolver = context.getClassResolver()) == null)) {
                resolver = .;
            }
            result = resolver.classForName(classNamecontext);
        }
        if (result == null)
            throw new ClassNotFoundException("Unable to resolve class: " + className);
        return result;
    }
    public static boolean isInstance(OgnlContext contextObject valueString className)
            throws OgnlException
    {
        try {
            Class c = classForName(contextclassName);
            return c.isInstance(value);
        } catch (ClassNotFoundException e) {
            throw new OgnlException("No such class: " + classNamee);
        }
    }
    public static Object getPrimitiveDefaultValue(Class forClass)
    {
        return .get(forClass);
    }
    public static Object getNumericDefaultValue(Class forClass)
    {
        return .get(forClass);
    }
    public static Object getConvertedType(OgnlContext contextObject targetMember memberString propertyName,
                                          Object valueClass type)
    {
        return context.getTypeConverter().convertValue(contexttargetmemberpropertyNamevaluetype);
    }
    public static boolean getConvertedTypes(OgnlContext contextObject targetMember memberString propertyName,
                                            Class[] parameterTypesObject[] argsObject[] newArgs)
    {
        boolean result = false;
        if (parameterTypes.length == args.length) {
            result = true;
            for (int i = 0, ilast = parameterTypes.length - 1; result && (i <= ilast); i++) {
                Object arg = args[i];
                Class type = parameterTypes[i];
                if (isTypeCompatible(argtype)) {
                    newArgs[i] = arg;
                } else {
                    Object v = getConvertedType(contexttargetmemberpropertyNameargtype);
                    if (v == .) {
                        result = false;
                    } else {
                        newArgs[i] = v;
                    }
                }
            }
        }
        return result;
    }
    public static Method getConvertedMethodAndArgs(OgnlContext contextObject targetString propertyName,
                                                   List methodsObject[] argsObject[] newArgs)
    {
        Method result = null;
        TypeConverter converter = context.getTypeConverter();
        if ((converter != null) && (methods != null))
        {
            for (int i = 0, icount = methods.size(); (result == null) && (i < icount); i++)
            {
                Method m = (Methodmethods.get(i);
                Class[] parameterTypes = findParameterTypes(target != null ? target.getClass() : nullm);//getParameterTypes(m);
                if (getConvertedTypes(contexttargetmpropertyNameparameterTypesargsnewArgs))
                {
                    result = m;
                }
            }
        }
        return result;
    }
    public static Constructor getConvertedConstructorAndArgs(OgnlContext contextObject targetList constructors,
                                                             Object[] argsObject[] newArgs)
    {
        Constructor result = null;
        TypeConverter converter = context.getTypeConverter();
        if ((converter != null) && (constructors != null)) {
            for (int i = 0, icount = constructors.size(); (result == null) && (i < icount); i++) {
                Constructor ctor = (Constructorconstructors.get(i);
                Class[] parameterTypes = getParameterTypes(ctor);
                if (getConvertedTypes(contexttargetctornullparameterTypesargsnewArgs)) {
                    result = ctor;
                }
            }
        }
        return result;
    }

    
Gets the appropriate method to be called for the given target, method name and arguments. If successful this method will return the Method within the target that can be called and the converted arguments in actualArgs. If unsuccessful this method will return null and the actualArgs will be empty.

Parameters:
context The current execution context.
source Target object to run against or method name.
target Instance of object to be run against.
propertyName Name of property to get method of.
methods List of current known methods.
args Arguments originally passed in.
actualArgs Converted arguments.
Returns:
Best method match or null if none could be found.
    public static Method getAppropriateMethod(OgnlContext contextObject sourceObject targetString propertyName,
                                              List methodsObject[] argsObject[] actualArgs)
    {
        Method result = null;
        Class[] resultParameterTypes = null;
        if (methods != null)
        {
            for (int i = 0, icount = methods.size(); i < icounti++)
            {
                Method m = (Methodmethods.get(i);
                Class typeClass = target != null ? target.getClass() : null;
                if (typeClass == null && source != null && Class.class.isInstance(source))
                {
                    typeClass = (Class)source;
                }
                Class[] mParameterTypes = findParameterTypes(typeClassm);
                if (areArgsCompatible(argsmParameterTypesm)
                    && ((result == null) || isMoreSpecific(mParameterTypesresultParameterTypes)))
                {
                    result = m;
                    resultParameterTypes = mParameterTypes;
                    System.arraycopy(args, 0, actualArgs, 0, args.length);
                    for (int j = 0; j < mParameterTypes.lengthj++)
                    {
                        Class type = mParameterTypes[j];
                        if (type.isPrimitive() && (actualArgs[j] == null))
                        {
                            actualArgs[j] = getConvertedType(contextsourceresultpropertyNamenull