1 22 package org.jboss.aop.advice; 23 24 import org.jboss.aop.Advisor; 25 import org.jboss.aop.joinpoint.Joinpoint; 26 import org.jboss.util.xml.XmlLoadable; 27 import org.w3c.dom.Element ; 28 29 public class GenericInterceptorFactory implements InterceptorFactory 30 { 31 private Class clazz = null; 32 private String classname; 33 private Element element; 34 private boolean deployed = true; 35 private String name; 36 37 private static volatile int counter = 0; 38 39 public GenericInterceptorFactory(String classname, Element element) 40 { 41 this.name = classname + (counter++); 42 this.classname = classname; 43 this.element = element; 44 } 45 46 public GenericInterceptorFactory(Class clazz) 47 { 48 this.clazz = clazz; 49 this.classname = clazz.getName(); 50 } 51 52 public String getName() 53 { 54 return name; 55 } 56 57 public AspectDefinition getAspect() 58 { 59 return null; 60 } 61 62 public String getAdvice() 63 { 64 return "invoke"; 65 } 66 public void undeploy() { deployed = false; } 67 68 public boolean isDeployed() 69 { 70 return deployed; 71 } 72 73 public String getClassName() { return classname; } 74 75 public Interceptor create(Advisor advisor, Joinpoint joinpoint) 76 { 77 try 78 { 79 synchronized (this) 80 { 81 if (clazz == null) 82 { 83 clazz = Thread.currentThread().getContextClassLoader().loadClass(classname); 84 } 85 } 86 Interceptor interceptor = (Interceptor)clazz.newInstance(); 87 if (interceptor instanceof XmlLoadable && element != null) 88 { 89 ((XmlLoadable)interceptor).importXml(element); 90 } 91 return interceptor; 92 } 93 catch (Exception re) 94 { 95 if (re instanceof RuntimeException ) throw (RuntimeException )re; 96 throw new RuntimeException (re); 97 } 98 } 99 100 public boolean equals(Object obj) 101 { 102 if (this == obj) return true; 103 if (!(obj instanceof GenericInterceptorFactory)) return false; 104 if (!this.classname.equals(((GenericInterceptorFactory)obj).classname)) return false; 105 106 return true; 107 } 108 } 109 110 | Popular Tags |