Brooklyn

brooklyn.util.javalang
[Java] Class Reflections

java.lang.Object
  brooklyn.util.javalang.Reflections

public class Reflections

Reflection utilities ("borrowed" from cloudsoft monterey).

Authors:
aled


Nested Class Summary
static class Reflections.ReflectionAccessException

static class Reflections.ReflectionNotFoundException

 
Field Summary
protected static Logger LOG

 
Method Summary
java.lang.Object Reflections(java.lang.ClassLoader classLoader)

static void copyFields(java.lang.Object source, java.lang.Object target)

copies all fields from the source to target; very little compile-time safety checking, so use with care

static java.lang.reflect.Constructor findCallabaleConstructor(java.lang.Class clazz, java.lang.Object[] args)

Returns a constructor that accepts the given arguments, or null if no such constructor is accessible.

static java.lang.reflect.Method findMethod(java.lang.Class clazz, java.lang.String name, java.lang.Class... parameterTypes)

static java.lang.Class findSuperType(java.lang.Object impl, java.lang.String typeName)

static java.lang.StackTraceElement getCaller()

java.lang.ClassLoader getClassLoader()

java.net.URL getResource(java.lang.String r)

finds the resource in the classloader, if it exists; inserts or replaces leading slash as necessary (i believe it should _not_ have one, but there is some inconsistency)

java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object... argValues)

@throws ReflectionAccessException If invocation failed due to illegal access or the invoked method failed

java.lang.Object invokeStaticMethod(java.lang.reflect.Method method, java.lang.Object... argValues)

java.lang.Class loadClass(java.lang.String classname)

instantiates the given class from its binary name

java.lang.Class loadClassFromCanonicalName(java.lang.String canonicalName)

Loads class given its canonical name format (e.g. com.acme.Foo.Inner), using iterative strategy (trying com.acme.Foo$Inner, then com.acme$Foo$Inner, etc).

java.lang.reflect.Constructor loadConstructor(java.lang.Class clazz, java.lang.Class[] argTypes)

java.lang.Class loadInnerClassNotInheritted(java.lang.String outerClassname, java.lang.String innerClassname)

does not look through ancestors of outer class

java.lang.Class loadInnerClassNotInheritted(java.lang.Class outerClazz, java.lang.String innerClassname)

does not look through ancestors of outer class

static java.lang.Class loadInnerClassPossiblyInheritted(java.lang.Class clazz, java.lang.String nestedPart)

given a nested part, e.g.

java.lang.Object loadInstance(java.lang.String classname, java.lang.Class[] argTypes, java.lang.Object[] argValues)

java.lang.Object loadInstance(java.lang.String classname)

java.lang.Object loadInstance(java.lang.reflect.Constructor constructor, java.lang.Object[] argValues)

java.lang.reflect.Method loadMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] argTypes)

java.lang.reflect.Method loadMethod(java.lang.Class clazz, java.lang.String methodName)

returns the first method matching the given name

java.lang.reflect.Constructor loadSingleConstructor(java.lang.Class clazz)

returns a single constructor in a given class, or throws an exception

java.lang.Object loadStaticField(java.lang.Class clazz, java.lang.String fieldname)

java.lang.Object[] loadStaticFields(java.lang.Class clazz, java.lang.String[] fieldnamesArray, java.lang.Object[] defaults)

java.lang.Object updateFromNewClassLoader(java.lang.Object data)

Serialize the given object, then reload using the current class loader; this removes linkages to instances with classes loaded by an older class loader.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

LOG

protected static final Logger LOG


 
Method Detail

Reflections

public java.lang.Object Reflections(java.lang.ClassLoader classLoader)


copyFields

public static void copyFields(java.lang.Object source, java.lang.Object target)
copies all fields from the source to target; very little compile-time safety checking, so use with care
throws:
IllegalAccessException
throws:
IllegalArgumentException


findCallabaleConstructor

@SuppressWarnings("unchecked")
public static java.lang.reflect.Constructor findCallabaleConstructor(java.lang.Class clazz, java.lang.Object[] args)
Returns a constructor that accepts the given arguments, or null if no such constructor is accessible.


findMethod

public static java.lang.reflect.Method findMethod(java.lang.Class clazz, java.lang.String name, java.lang.Class... parameterTypes)


findSuperType

ssWarnings("unchecked")
	public
public static java.lang.Class findSuperType(java.lang.Object impl, java.lang.String typeName)


getCaller

public static java.lang.StackTraceElement getCaller()


getClassLoader

public java.lang.ClassLoader getClassLoader()


getResource

le
	public
public java.net.URL getResource(java.lang.String r)
finds the resource in the classloader, if it exists; inserts or replaces leading slash as necessary (i believe it should _not_ have one, but there is some inconsistency) Will return null if no resource is found.


invokeMethod

public java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object... argValues)
throws:
ReflectionAccessException If invocation failed due to illegal access or the invoked method failed
throws:
IllegalArgumentException If the arguments were invalid


invokeStaticMethod

public java.lang.Object invokeStaticMethod(java.lang.reflect.Method method, java.lang.Object... argValues)


loadClass

public java.lang.Class loadClass(java.lang.String classname)
instantiates the given class from its binary name


loadClassFromCanonicalName

public java.lang.Class loadClassFromCanonicalName(java.lang.String canonicalName)
Loads class given its canonical name format (e.g. com.acme.Foo.Inner), using iterative strategy (trying com.acme.Foo$Inner, then com.acme$Foo$Inner, etc).
throws:
ReflectionNotFoundException


loadConstructor

public java.lang.reflect.Constructor loadConstructor(java.lang.Class clazz, java.lang.Class[] argTypes)


loadInnerClassNotInheritted

public java.lang.Class loadInnerClassNotInheritted(java.lang.String outerClassname, java.lang.String innerClassname)
does not look through ancestors of outer class


loadInnerClassNotInheritted

public java.lang.Class loadInnerClassNotInheritted(java.lang.Class outerClazz, java.lang.String innerClassname)
does not look through ancestors of outer class

uses the classloader set in this class, not in the clazz supplied


loadInnerClassPossiblyInheritted

public static java.lang.Class loadInnerClassPossiblyInheritted(java.lang.Class clazz, java.lang.String nestedPart)
given a nested part, e.g. Inner$VeryInner, this will recurse through clazz.Inner, looking for VeryInner, then looking in each supertype (interface) of clazz for Inner.VeryInner;

so it will find Clazz.Inner.VeryInner wherever in the hierarchy it is defined

(as opposed to ClassLoader which requires Inner.VeryInner to be _declared_ in clazz, not in any supertype

returns null if not found


loadInstance

public java.lang.Object loadInstance(java.lang.String classname, java.lang.Class[] argTypes, java.lang.Object[] argValues)


loadInstance

public java.lang.Object loadInstance(java.lang.String classname)


loadInstance

public java.lang.Object loadInstance(java.lang.reflect.Constructor constructor, java.lang.Object[] argValues)


loadMethod

public java.lang.reflect.Method loadMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] argTypes)


loadMethod

public java.lang.reflect.Method loadMethod(java.lang.Class clazz, java.lang.String methodName)
returns the first method matching the given name


loadSingleConstructor

public java.lang.reflect.Constructor loadSingleConstructor(java.lang.Class clazz)
returns a single constructor in a given class, or throws an exception


loadStaticField

public java.lang.Object loadStaticField(java.lang.Class clazz, java.lang.String fieldname)


loadStaticFields

public java.lang.Object[] loadStaticFields(java.lang.Class clazz, java.lang.String[] fieldnamesArray, java.lang.Object[] defaults)


updateFromNewClassLoader

public final java.lang.Object updateFromNewClassLoader(java.lang.Object data)
Serialize the given object, then reload using the current class loader; this removes linkages to instances with classes loaded by an older class loader.

(like a poor man's clone)

aka "reconstitute(Object)"


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.