KickJava   Java API By Example, From Geeks To Geeks.

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


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  * 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 field access or field update.
33  *
34  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
35  * @version $Revision: 44253 $
36  */

37 public abstract class FieldInvocation extends InvocationBase
38 {
39    private static final long serialVersionUID = -6040602776393748583L;
40    
41    protected transient Field JavaDoc field = null;
42    protected int index;
43
44    public FieldInvocation(Field JavaDoc field, int fieldIndex, Interceptor[] interceptors)
45    {
46       super(interceptors);
47       this.field = field;
48       this.index = fieldIndex;
49    }
50
51    protected FieldInvocation(Interceptor[] interceptors)
52    {
53       super(interceptors);
54    }
55
56    protected FieldInvocation(FieldInfo info, Interceptor[] interceptors)
57    {
58       this(info.getAdvisedField(), info.getIndex(), interceptors);
59       this.advisor = info.getAdvisor();
60    }
61    
62    /**
63     * This method resolves an annotation based on the context of the invocation.
64     *
65     */

66    public Object JavaDoc resolveAnnotation(Class JavaDoc annotation)
67    {
68       Object JavaDoc val = super.resolveAnnotation(annotation);
69       if (val != null) return val;
70
71       if (getAdvisor() != null)
72       {
73          val = getAdvisor().resolveAnnotation(field, annotation);
74          if (val != null) return val;
75       }
76
77       return null;
78    }
79    /**
80     * This method resolves metadata based on the context of the invocation.
81     * It iterates through its list of MetaDataResolvers to find out the
82     * value of the metadata desired.
83     *
84     * This list usually is ThreadMetaData, InstanceAdvisor.getMetaData
85     * ClassAdvisor.getMethodMetaData (or field, or constructor)
86     * ClassAdvisor.getDefaultMetaData
87     */

88    public Object JavaDoc getMetaData(Object JavaDoc group, Object JavaDoc attr)
89    {
90       Object JavaDoc val = super.getMetaData(group, attr);
91       if (val != null) return val;
92
93       if (getAdvisor() != null)
94       {
95          val = getAdvisor().getFieldMetaData().resolve(this, group, attr);
96          if (val != null) return val;
97       }
98
99       if (getAdvisor() != null)
100       {
101          val = getAdvisor().getDefaultMetaData().resolve(this, group, attr);
102          if (val != null) return val;
103       }
104
105       return null;
106    }
107
108     /**
109      * This is the field the invocation is accessing
110      *
111      * @return
112      */

113     public Field JavaDoc getField()
114     {
115         return field;
116     }
117
118    /**
119     * This is an index into the Field[] array accessed through the ClassAdvisor
120     *
121     * @return
122     */

123    public int getIndex()
124    {
125       return index;
126    }
127
128 }
129
Popular Tags