KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > advice > AspectFactoryDelegator


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

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 JavaDoc;
29
30 /**
31  * Lazy loading of AspectFactory
32  *
33  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
34  * @version $Revision: 40271 $
35  */

36 public class AspectFactoryDelegator extends AspectFactoryWithClassLoaderSupport
37 {
38    private AspectFactory factory;
39    private String JavaDoc factoryClass;
40    private Element JavaDoc element;
41
42    public AspectFactoryDelegator(String JavaDoc factory, Element JavaDoc element)
43    {
44       this.factoryClass = factory;
45       this.element = element;
46    }
47
48    public String JavaDoc getName()
49    {
50       return factoryClass;
51    }
52
53    public Element JavaDoc getElement()
54    {
55       return element;
56    }
57
58    public void setElement(Element JavaDoc element)
59    {
60       this.element = element;
61    }
62
63    public synchronized AspectFactory getFactory()
64    {
65       if (factory == null)
66       {
67          try
68          {
69             Class JavaDoc 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 JavaDoc e)
84          {
85             throw new RuntimeException JavaDoc(e);
86          }
87          catch (InstantiationException JavaDoc e)
88          {
89             throw new RuntimeException JavaDoc(e);
90          }
91          catch (IllegalAccessException JavaDoc e)
92          {
93             throw new RuntimeException JavaDoc(e);
94          }
95       }
96       return factory;
97    }
98
99    public Object JavaDoc createPerVM()
100    {
101       Object JavaDoc aspect = getFactory().createPerVM();
102       return aspect;
103    }
104
105    public Object JavaDoc createPerClass(Advisor advisor)
106    {
107       Object JavaDoc aspect = getFactory().createPerClass(advisor);
108       return aspect;
109    }
110
111    public Object JavaDoc createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor)
112    {
113       Object JavaDoc aspect = getFactory().createPerInstance(advisor, instanceAdvisor);
114       return aspect;
115    }
116
117    public Object JavaDoc createPerJoinpoint(Advisor advisor, Joinpoint jp)
118    {
119       Object JavaDoc aspect = getFactory().createPerJoinpoint(advisor, jp);
120       return aspect;
121    }
122
123    public Object JavaDoc createPerJoinpoint(Advisor advisor, InstanceAdvisor instanceAdvisor, Joinpoint jp)
124    {
125       Object JavaDoc aspect = getFactory().createPerJoinpoint(advisor, instanceAdvisor, jp);
126       return aspect;
127    }
128
129 }
130
Popular Tags