1 22 package org.jboss.aop.advice; 23 24 import org.jboss.aop.Advisor; 25 import org.jboss.aop.InstanceAdvisor; 26 import org.jboss.aop.joinpoint.Joinpoint; 27 import org.jboss.util.xml.XmlLoadable; 28 import org.w3c.dom.Element ; 29 30 36 public class AspectFactoryDelegator extends AspectFactoryWithClassLoaderSupport 37 { 38 private AspectFactory factory; 39 private String factoryClass; 40 private Element element; 41 42 public AspectFactoryDelegator(String factory, Element element) 43 { 44 this.factoryClass = factory; 45 this.element = element; 46 } 47 48 public String getName() 49 { 50 return factoryClass; 51 } 52 53 public Element getElement() 54 { 55 return element; 56 } 57 58 public void setElement(Element element) 59 { 60 this.element = element; 61 } 62 63 public synchronized AspectFactory getFactory() 64 { 65 if (factory == null) 66 { 67 try 68 { 69 Class clazz = super.loadClass(factoryClass); 70 factory = (AspectFactory) clazz.newInstance(); 71 if (XmlLoadable.class.isAssignableFrom(factory.getClass())) 72 { 73 ((XmlLoadable) factory).importXml(element); 74 } 75 if (AspectFactoryWithClassLoader.class.isAssignableFrom(factory.getClass())) 76 { 77 if (super.getLoader() != null) 78 { 79 ((AspectFactoryWithClassLoader)factory).setClassLoader(super.getLoader()); 80 } 81 } 82 } 83 catch (ClassNotFoundException e) 84 { 85 throw new RuntimeException (e); 86 } 87 catch (InstantiationException e) 88 { 89 throw new RuntimeException (e); 90 } 91 catch (IllegalAccessException e) 92 { 93 throw new RuntimeException (e); 94 } 95 } 96 return factory; 97 } 98 99 public Object createPerVM() 100 { 101 Object aspect = getFactory().createPerVM(); 102 return aspect; 103 } 104 105 public Object createPerClass(Advisor advisor) 106 { 107 Object aspect = getFactory().createPerClass(advisor); 108 return aspect; 109 } 110 111 public Object createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor) 112 { 113 Object aspect = getFactory().createPerInstance(advisor, instanceAdvisor); 114 return aspect; 115 } 116 117 public Object createPerJoinpoint(Advisor advisor, Joinpoint jp) 118 { 119 Object aspect = getFactory().createPerJoinpoint(advisor, jp); 120 return aspect; 121 } 122 123 public Object createPerJoinpoint(Advisor advisor, InstanceAdvisor instanceAdvisor, Joinpoint jp) 124 { 125 Object aspect = getFactory().createPerJoinpoint(advisor, instanceAdvisor, jp); 126 return aspect; 127 } 128 129 } 130 | Popular Tags |