1 8 package com.tc.backport175.proxy; 9 10 import com.tc.backport175.Annotation; 11 import com.tc.backport175.bytecode.AnnotationElement; 12 13 import java.lang.reflect.InvocationHandler ; 14 import java.lang.reflect.Proxy ; 15 16 22 public class ProxyFactory { 23 24 31 public static Annotation newAnnotationProxy(final AnnotationElement.Annotation annotation, 32 ClassLoader loader) { 33 ClassLoader backportLoader = Annotation.class.getClassLoader(); 34 if (loader != backportLoader) { 35 loader = backportLoader; 36 } 37 final Class interfaceClass; 38 try { 39 interfaceClass = Class.forName(annotation.getInterfaceName(), false, loader); 40 } catch (ClassNotFoundException e) { 41 throw new ResolveAnnotationException("annotation interface [" + annotation.getInterfaceName() + "] could not be found"); 42 } 43 final InvocationHandler handler = new JavaDocAnnotationInvocationHander(interfaceClass, annotation, loader); 44 final Object annotationProxy = Proxy.newProxyInstance( 45 loader, 46 new Class []{Annotation.class, interfaceClass}, 47 handler 48 ); 49 return (Annotation)annotationProxy; 50 } 51 } 52 | Popular Tags |