KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > proxy > container > InstanceProxyContainer


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.proxy.container;
23
24 import org.jboss.aop.Advisor;
25 import org.jboss.aop.ClassAdvisor;
26 import org.jboss.aop.Domain;
27 import org.jboss.aop.InstanceAdvisor;
28 import org.jboss.aop.InstanceAdvisorDelegate;
29 import org.jboss.aop.MethodInfo;
30 import org.jboss.aop.advice.AspectDefinition;
31 import org.jboss.aop.advice.Interceptor;
32 import org.jboss.aop.introduction.InterfaceIntroduction;
33 import org.jboss.aop.joinpoint.Joinpoint;
34 import org.jboss.aop.metadata.SimpleMetaData;
35 //import org.jboss.repository.spi.MetaDataContext;
36

37 /**
38  * The InstanceAdvisor returned by ClassProxyContainer
39  *
40  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
41  * @version $Revision: 57019 $
42  */

43 public class InstanceProxyContainer extends ClassProxyContainer implements InstanceAdvisor
44 {
45    Advisor classAdvisor;
46    InstanceAdvisorDelegate delegate;
47    
48    public InstanceProxyContainer(String JavaDoc name, ProxyAdvisorDomain instanceDomain, Advisor classAdvisor, /*MetaDataContext*/ Object JavaDoc metaDataContext)
49    {
50       super(name, instanceDomain);
51       this.classAdvisor = classAdvisor;
52       instanceDomain.setAdvisor(this);
53       setMetadataContext(metaDataContext);
54       delegate = new InstanceAdvisorDelegate(classAdvisor, this);
55       delegate.initialize();
56       initialise(classAdvisor.getClazz());
57    }
58
59    public static InstanceProxyContainer createInstanceProxyContainer(Advisor classAdvisor, InterfaceIntroduction introduction, /*MetaDataContext*/ Object JavaDoc metaDataContext)
60    {
61       ProxyAdvisorDomain domain = new ProxyAdvisorDomain(classAdvisor.getManager(), classAdvisor.getClazz(), false, true);
62       if (introduction != null)
63       {
64          domain.addInterfaceIntroduction(introduction);
65       }
66
67       InstanceProxyContainer ia = new InstanceProxyContainer(classAdvisor.getName(), domain, classAdvisor, metaDataContext);
68       
69       return ia;
70    }
71
72    public Advisor getClassAdvisor()
73    {
74       return classAdvisor;
75    }
76    
77    public Object JavaDoc getPerInstanceAspect(String JavaDoc aspectName)
78    {
79       return delegate.getPerInstanceAspect(aspectName);
80    }
81
82    public Object JavaDoc getPerInstanceAspect(AspectDefinition def)
83    {
84       return delegate.getPerInstanceAspect(def);
85    }
86
87    public Object JavaDoc getPerInstanceJoinpointAspect(Joinpoint joinpoint, AspectDefinition def)
88    {
89       return delegate.getPerInstanceJoinpointAspect(joinpoint, def);
90    }
91
92    public SimpleMetaData getMetaData()
93    {
94       return delegate.getMetaData();
95    }
96
97    public Domain getDomain()
98    {
99       return (Domain)super.getManager();
100    }
101
102    /**
103     * Not implemented InstanceAdvisor method, we should be using the domain
104     */

105    public boolean hasInterceptors()
106    {
107       throw new RuntimeException JavaDoc("Not implemented");
108    }
109
110    /**
111     * Not implemented InstanceAdvisor method, we should be using the domain
112     */

113    public Interceptor[] getInterceptors()
114    {
115       throw new RuntimeException JavaDoc("Not implemented");
116    }
117
118    /**
119     * Not implemented InstanceAdvisor method, we should be using the domain
120     */

121    public Interceptor[] getInterceptors(Interceptor[] baseChain)
122    {
123       throw new RuntimeException JavaDoc("Not implemented");
124    }
125
126    /**
127     * Not implemented InstanceAdvisor method, we should be using the domain
128     */

129    public void insertInterceptor(Interceptor interceptor)
130    {
131       throw new RuntimeException JavaDoc("Not implemented");
132    }
133
134    /**
135     * Not implemented InstanceAdvisor method, we should be using the domain
136     */

137    public void removeInterceptor(String JavaDoc name)
138    {
139       throw new RuntimeException JavaDoc("Not implemented");
140    }
141
142    /**
143     * Not implemented InstanceAdvisor method, we should be using the domain
144     */

145    public void appendInterceptor(Interceptor interceptor)
146    {
147       throw new RuntimeException JavaDoc("Not implemented");
148    }
149
150    /**
151     * Not implemented InstanceAdvisor method, we should be using the domain
152     */

153    public void insertInterceptorStack(String JavaDoc stackName)
154    {
155       throw new RuntimeException JavaDoc("Not implemented");
156    }
157
158    /**
159     * Not implemented InstanceAdvisor method, we should be using the domain
160     */

161    public void removeInterceptorStack(String JavaDoc name)
162    {
163       throw new RuntimeException JavaDoc("Not implemented");
164    }
165
166    /**
167     * Not implemented InstanceAdvisor method, we should be using the domain
168     */

169    public void appendInterceptorStack(String JavaDoc stackName)
170    {
171       throw new RuntimeException JavaDoc("Not implemented");
172    }
173
174    /**
175     * Not implemented InstanceAdvisor method, we should be using the domain
176     */

177    public void insertInterceptor(int index, Interceptor interceptor)
178    {
179       throw new RuntimeException JavaDoc("Not implemented");
180    }
181
182    /**
183     * Not implemented InstanceAdvisor method, we should be using the domain
184     */

185    public void appendInterceptor(int index, Interceptor interceptor)
186    {
187       throw new RuntimeException JavaDoc("Not implemented");
188    }
189
190    public void removeFromDomain()
191    {
192       ProxyAdvisorDomain domain = (ProxyAdvisorDomain)super.manager;
193       domain.removeAdvisor(this);
194    }
195
196    /**
197     * If the target instance is advised, make sure that we set the unadvised method to the one stored by the class advisor
198     * so that we don't get double invocations.
199     */

200    public MethodInfo getMethodInfo(long hash)
201    {
202       MethodInfo info = super.getMethodInfo(hash);
203       if (classAdvisor instanceof ClassAdvisor && info.getAdvisedMethod().equals(info.getUnadvisedMethod()))
204       {
205          MethodInfo superInfo = classAdvisor.getMethodInfo(hash);
206          if (superInfo != null)
207          {
208             info.setUnadvisedMethod(superInfo.getUnadvisedMethod());
209          }
210       }
211       
212       return info;
213    }
214
215    protected Advisor getParentAdvisor()
216    {
217       return classAdvisor;
218    }
219 }
220
Popular Tags