KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > joinpoint > ConstructionInvocation


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.joinpoint;
23
24 import java.lang.reflect.Constructor JavaDoc;
25
26 import org.jboss.aop.ConstructionInfo;
27 import org.jboss.aop.advice.Interceptor;
28
29 /**
30  * This is a helper wrapper class for an Invocation object.
31  * It is used to add or get values or metadata that pertains to
32  * an AOP Constructor interception.
33  *
34  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
35  * @version $Revision: 46058 $
36  */

37 public class ConstructionInvocation extends InvocationBase
38 {
39    /** The serialVersionUID */
40    private static final long serialVersionUID = -6040602776303875808L;
41
42    protected Object JavaDoc[] arguments = null; // MARSHALLED
43
protected transient Constructor JavaDoc constructor = null;
44
45    public ConstructionInvocation(Interceptor[] interceptors, Constructor JavaDoc con, Object JavaDoc[] args)
46    {
47       super(interceptors);
48       this.constructor = con;
49       this.arguments = args;
50    }
51
52
53    public ConstructionInvocation(Interceptor[] interceptors, Constructor JavaDoc con)
54    {
55       super(interceptors);
56       this.constructor = con;
57    }
58
59    public ConstructionInvocation(ConstructionInfo info, Interceptor[] interceptors)
60    {
61       super(interceptors);
62       this.constructor = info.getConstructor();
63       super.advisor = info.getAdvisor();
64    }
65
66
67    /**
68     * Invoke on the next interceptor in the chain. If this is already
69     * the end of the chain, reflection will call the constructor, field, or
70     * method you are invoking on.
71     */

72    public Object JavaDoc invokeNext() throws Throwable JavaDoc
73    {
74       if (interceptors != null && currentInterceptor < interceptors.length)
75       {
76          try
77          {
78             return interceptors[currentInterceptor++].invoke(this);
79          }
80          finally
81          {
82             // so that interceptors like clustering can reinvoke down the chain
83
currentInterceptor--;
84          }
85       }
86
87       return invokeTarget();
88    }
89    
90
91    /**
92     * Invokes the target joinpoint for this invocation skipping any subsequent
93     * interceptors in the chain.
94     */

95    public Object JavaDoc invokeTarget() throws Throwable JavaDoc
96    {
97       return null;
98    }
99
100
101    /**
102     * This method resolves an annotation based on the context of the invocation.
103     *
104     */

105    public Object JavaDoc resolveAnnotation(Class JavaDoc annotation)
106    {
107       Object JavaDoc val = super.resolveAnnotation(annotation);
108       if (val != null) return val;
109
110       if (getAdvisor() != null)
111       {
112          val = getAdvisor().resolveAnnotation(constructor, annotation);
113          if (val != null) return val;
114       }
115
116       return null;
117    }
118
119    /**
120     * This method resolves metadata based on the context of the invocation.
121     * It iterates through its list of MetaDataResolvers to find out the
122     * value of the metadata desired.
123     *
124     * This list usually is ThreadMetaData, InstanceAdvisor.getMetaData
125     * ClassAdvisor.getMethodMetaData (or field, or constructor)
126     * ClassAdvisor.getDefaultMetaData
127     */

128    public Object JavaDoc getMetaData(Object JavaDoc group, Object JavaDoc attr)
129    {
130       Object JavaDoc val = super.getMetaData(group, attr);
131       if (val != null) return val;
132
133       if (getAdvisor() != null)
134       {
135          val = getAdvisor().getConstructorMetaData().resolve(this, group, attr);
136          if (val != null) return val;
137       }
138
139       if (getAdvisor() != null)
140       {
141          val = getAdvisor().getDefaultMetaData().resolve(this, group, attr);
142          if (val != null) return val;
143       }
144
145       return null;
146    }
147
148    /**
149     * Get a wrapper invocation object that can insert a new chain of interceptors
150     * at runtime to the invocation flow. CFlow makes use of this.
151     * When the wrapper object finishes its invocation chain it delegates back to
152     * the wrapped invocation.
153     * @param newchain
154     * @return
155     */

156    public Invocation getWrapper(Interceptor[] newchain)
157    {
158       ConstructionInvocationWrapper wrapper = new ConstructionInvocationWrapper(this, newchain);
159       return wrapper;
160    }
161
162    /**
163     * Copies complete state of Invocation object.
164     * @return
165     */

166    public Invocation copy()
167    {
168       ConstructionInvocation wrapper = new ConstructionInvocation(interceptors, constructor, arguments);
169       wrapper.setAdvisor(this.getAdvisor());
170       wrapper.currentInterceptor = this.currentInterceptor;
171       wrapper.metadata = this.metadata;
172       return wrapper;
173    }
174
175    public Object JavaDoc[] getArguments()
176    {
177       return arguments;
178    }
179
180    public void setArguments(Object JavaDoc[] arguments)
181    {
182       this.arguments = arguments;
183    }
184
185    public Constructor JavaDoc getConstructor()
186    {
187       return constructor;
188    }
189
190    public void setConstructor(Constructor JavaDoc constructor)
191    {
192       this.constructor = constructor;
193    }
194 }
195
Popular Tags