KickJava   Java API By Example, From Geeks To Geeks.

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


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

38 public class FieldWriteInvocation extends FieldInvocation
39 {
40    static final long serialVersionUID = 6795964118579848645L;
41
42    protected Object JavaDoc value;
43
44    public FieldWriteInvocation(Field JavaDoc field, int index, Object JavaDoc value, Interceptor[] interceptors)
45    {
46       super(field, index, interceptors);
47       this.value = value;
48    }
49
50    protected FieldWriteInvocation(Interceptor[] interceptors)
51    {
52       super(interceptors);
53    }
54
55    protected FieldWriteInvocation(FieldInfo info, Interceptor[] interceptors)
56    {
57       super(info, interceptors);
58    }
59
60    protected FieldWriteInvocation(FieldInfo info, Object JavaDoc value, Interceptor[] interceptors)
61    {
62       super(info, interceptors);
63       this.value = value;
64    }
65
66    /**
67     * Invoke on the next interceptor in the chain. If this is already
68     * the end of the chain, reflection will call the constructor, field, or
69     * method you are invoking on.
70     */

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

93    public Object JavaDoc invokeTarget() throws Throwable JavaDoc
94    {
95       field.set(getTargetObject(), getValue());
96       return null;
97    }
98
99    /**
100     * Get a wrapper invocation object that can insert a new chain of interceptors
101     * at runtime to the invocation flow. CFlow makes use of this.
102     * When the wrapper object finishes its invocation chain it delegates back to
103     * the wrapped invocation.
104     * @param newchain
105     * @return
106     */

107    public Invocation getWrapper(Interceptor[] newchain)
108    {
109       FieldWriteInvocationWrapper wrapper = new FieldWriteInvocationWrapper(this, newchain);
110       return wrapper;
111    }
112
113    /**
114     * Copies complete state of Invocation object.
115     * @return
116     */

117    public Invocation copy()
118    {
119       FieldWriteInvocation wrapper = new FieldWriteInvocation(field, index, value, interceptors);
120       wrapper.setAdvisor(this.getAdvisor());
121       wrapper.setTargetObject(this.getTargetObject());
122       wrapper.currentInterceptor = this.currentInterceptor;
123       wrapper.instanceResolver = this.instanceResolver;
124       wrapper.metadata = this.metadata;
125       return wrapper;
126    }
127
128    public Object JavaDoc getValue()
129    {
130       return value;
131    }
132
133    public void setValue(Object JavaDoc value)
134    {
135       this.value = value;
136    }
137 }
138
Popular Tags