Some of the common usages of the reflection package is showcased here
|
Refer to the java doc of org.sape.carbon.core.util.relection.BeanUtil getObjectAttribute and setObjectAttribute
|
|
GenericProxy reflection handler provides a cleaner way to implement dynamic
proxy invocation handlers. The generic proxy extends from the
InvocationHandler interface and provides implementations for common methods
defined in java.lang.Object such as hashCode(), equals(), toString()
public class MyInvocationHandler extends GenericProxy {
protected Object handleInvoke(Object proxy, Method m, Object[] args) throws Throwable {
Object result = null;
//my specific invocation handler stuff comes here
....
....
....
....
return result;
}
}
A thing to note is that the overridden equals() invocation does a instance
comparison of the underlying proxy objects and not a object equality check
|
|
ClassFinder can be used to search for classes over the classpath implementing a certain interface. The list of classes which are retrieved can also be filtered by specifying the package name under which the classes should lie
The following code snippets show examples where
all classes all implementing a certain interface are retrieved class is retrieved
public Set findAllClasses(Class classNode) throws Exception {
ClassFinder cf = new ClassFinder(classNode);
return cf.getClasses();
}
all classes all implementing a certain interface and lying under a certain package is retrieved
public Set findClassInPackage(Class classNode, String packageName) {
ClassFinder cf = new ClassFinder(classNode, packageName);
return cf.getClasses();
}
|
|