org.atmosphere.util
Class IntrospectionUtils

java.lang.Object
  extended by org.atmosphere.util.IntrospectionUtils

public final class IntrospectionUtils
extends Object

Utils for introspection and reflection


Nested Class Summary
static interface IntrospectionUtils.AttributeHolder
           
static interface IntrospectionUtils.PropertySource
           
 
Constructor Summary
IntrospectionUtils()
           
 
Method Summary
static void addJarsFromClassPath(Vector<URL> jars, String cp)
          Add elements from the classpath cp to a Vector jars as file URLs (We use Vector for JDK 1.1 compat).
static boolean addProperty(Object o, String name, String value)
           
static void addToClassPath(Vector<URL> cpV, String dir)
          Add all the jar files in a dir to the classpath, represented as a Vector of URLs.
static void addToolsJar(Vector<URL> v)
           
static void callMain(Class<?> c, String[] args)
           
static Object callMethod0(Object target, String methodN)
           
static Object callMethod1(Object target, String methodN, Object param1, String typeParam1, ClassLoader cl)
           
static Object callMethodN(Object target, String methodN, Object[] params, Class<?>[] typeParams)
           
static String capitalize(String name)
          Reverse of Introspector.decapitalize
static void clear()
           
static Object convert(String object, Class<?> paramType)
           
static void execute(Object proxy, String method)
          Call execute() - any ant-like task should work
static String[] findBooleanSetters(Class<?> c)
           
static Method findMethod(Class<?> c, String name, Class<?>[] params)
           
static Method[] findMethods(Class<?> c)
           
static String[] findVoidSetters(Class<?> c)
           
static Object getAttribute(Object proxy, String name)
          Call void getAttribute( String )
static URL[] getClassPath(String dir, String cpath, String cpathProp, boolean addTools)
          Construct a URL classpath from files in a directory, a cpath property, and tools.jar.
static URL[] getClassPath(Vector<URL> v)
          Return a URL[] that can be used to construct a class loader
static String[] getFilesByExt(String ld, String ext)
          Return all files with a given extension in a dir
static Object getProperty(Object object, String name)
           
static URL getURL(String base, String file)
          Construct a file url from a file, using a base dir
static ClassLoader getURLClassLoader(URL[] urls, ClassLoader parent)
          Construct a URLClassLoader.
static boolean hasHook(Object obj, String methodN)
          Test if the object implements a particular method
static boolean invokeProperty(Object object, String setter, String name, String value)
           
static boolean processArgs(Object proxy, String[] args)
           
static boolean processArgs(Object proxy, String[] args, String[] args0, String[] args1, Hashtable<String,String> aliases)
           
static String replaceProperties(String value, Hashtable<String,String> staticProp, IntrospectionUtils.PropertySource[] dynamicProp)
          Replace ${NAME} with the property value
static void setAttribute(Object proxy, String name, Object value)
          Call void setAttribute( String ,Object )
static void setProperty(Object object, String name)
           
static boolean setProperty(Object o, String name, String value)
          Find a method with the right name If found, call the method ( if param is int or boolean we'll convert value to the right type before) - that means you can have setDebug(1).
static String unCapitalize(String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntrospectionUtils

public IntrospectionUtils()
Method Detail

execute

public static void execute(Object proxy,
                           String method)
                    throws Exception
Call execute() - any ant-like task should work

Throws:
Exception

setAttribute

public static void setAttribute(Object proxy,
                                String name,
                                Object value)
                         throws Exception
Call void setAttribute( String ,Object )

Throws:
Exception

getAttribute

public static Object getAttribute(Object proxy,
                                  String name)
                           throws Exception
Call void getAttribute( String )

Throws:
Exception

getURLClassLoader

public static ClassLoader getURLClassLoader(URL[] urls,
                                            ClassLoader parent)
Construct a URLClassLoader. Will compile and work in JDK1.1 too.


setProperty

public static final boolean setProperty(Object o,
                                        String name,
                                        String value)
Find a method with the right name If found, call the method ( if param is int or boolean we'll convert value to the right type before) - that means you can have setDebug(1).


addProperty

public static final boolean addProperty(Object o,
                                        String name,
                                        String value)

invokeProperty

public static final boolean invokeProperty(Object object,
                                           String setter,
                                           String name,
                                           String value)

getProperty

public static Object getProperty(Object object,
                                 String name)

setProperty

public static void setProperty(Object object,
                               String name)

replaceProperties

public static String replaceProperties(String value,
                                       Hashtable<String,String> staticProp,
                                       IntrospectionUtils.PropertySource[] dynamicProp)
Replace ${NAME} with the property value


capitalize

public static String capitalize(String name)
Reverse of Introspector.decapitalize


unCapitalize

public static String unCapitalize(String name)

addToClassPath

public static void addToClassPath(Vector<URL> cpV,
                                  String dir)
Add all the jar files in a dir to the classpath, represented as a Vector of URLs.


addToolsJar

public static void addToolsJar(Vector<URL> v)

getFilesByExt

public static String[] getFilesByExt(String ld,
                                     String ext)
Return all files with a given extension in a dir


getURL

public static URL getURL(String base,
                         String file)
Construct a file url from a file, using a base dir


addJarsFromClassPath

public static void addJarsFromClassPath(Vector<URL> jars,
                                        String cp)
                                 throws IOException,
                                        MalformedURLException
Add elements from the classpath cp to a Vector jars as file URLs (We use Vector for JDK 1.1 compat).

Parameters:
jars - The jar list
cp - a String classpath of directory or jar file elements separated by path.separator delimiters.
Throws:
IOException - If an I/O error occurs
MalformedURLException - Doh ;)

getClassPath

public static URL[] getClassPath(Vector<URL> v)
Return a URL[] that can be used to construct a class loader


getClassPath

public static URL[] getClassPath(String dir,
                                 String cpath,
                                 String cpathProp,
                                 boolean addTools)
                          throws IOException,
                                 MalformedURLException
Construct a URL classpath from files in a directory, a cpath property, and tools.jar.

Throws:
IOException
MalformedURLException

processArgs

public static boolean processArgs(Object proxy,
                                  String[] args)
                           throws Exception
Throws:
Exception

processArgs

public static boolean processArgs(Object proxy,
                                  String[] args,
                                  String[] args0,
                                  String[] args1,
                                  Hashtable<String,String> aliases)
                           throws Exception
Throws:
Exception

clear

public static void clear()

findVoidSetters

public static String[] findVoidSetters(Class<?> c)

findBooleanSetters

public static String[] findBooleanSetters(Class<?> c)

findMethods

public static Method[] findMethods(Class<?> c)

findMethod

public static Method findMethod(Class<?> c,
                                String name,
                                Class<?>[] params)

hasHook

public static boolean hasHook(Object obj,
                              String methodN)
Test if the object implements a particular method


callMain

public static void callMain(Class<?> c,
                            String[] args)
                     throws Exception
Throws:
Exception

callMethod1

public static Object callMethod1(Object target,
                                 String methodN,
                                 Object param1,
                                 String typeParam1,
                                 ClassLoader cl)
                          throws Exception
Throws:
Exception

callMethod0

public static Object callMethod0(Object target,
                                 String methodN)
                          throws Exception
Throws:
Exception

callMethodN

public static Object callMethodN(Object target,
                                 String methodN,
                                 Object[] params,
                                 Class<?>[] typeParams)
                          throws Exception
Throws:
Exception

convert

public static Object convert(String object,
                             Class<?> paramType)


Copyright © 2012. All Rights Reserved.