1
2
3
4
5
6
7
8 package org.codehaus.metaclass.tools.qdox;
9
10 import com.thoughtworks.qdox.model.JavaClass;
11 import com.thoughtworks.qdox.model.JavaField;
12 import com.thoughtworks.qdox.model.JavaMethod;
13 import org.codehaus.metaclass.model.Attribute;
14
15 /***
16 * Thhis interceptor passes each attribute or set of attributes
17 * through a chain of interceptors. When processing a single
18 * attribute the chain will terminate when the first interceptor
19 * returns null.
20 *
21 * @author Peter Donald
22 * @version $Revision: 1.5 $ $Date: 2003/11/27 08:08:04 $
23 */
24 class MulticastInterceptor
25 implements QDoxAttributeInterceptor
26 {
27 /***
28 * The interceptor chain to delegate to.
29 */
30 private final QDoxAttributeInterceptor[] m_interceptors;
31
32 /***
33 * Create a interceptor that delegates to specified interceptors.
34 *
35 * @param interceptors the interceptors
36 */
37 public MulticastInterceptor( final QDoxAttributeInterceptor[] interceptors )
38 {
39 if( null == interceptors )
40 {
41 throw new NullPointerException( "interceptors" );
42 }
43 for( int i = 0; i < interceptors.length; i++ )
44 {
45 if( null == interceptors[ i ] )
46 {
47 throw new NullPointerException( "interceptors[" + i + "]" );
48 }
49 }
50 m_interceptors = interceptors;
51 }
52
53 /***
54 * Process a single attribute at the Class level.
55 * The implementation may return a new attribute
56 * instance, the old attribute instance or null to
57 * ignore attribute.
58 *
59 * @param clazz the corresponding JavaClass instance
60 * @param attribute the attribute
61 * @return the resulting attribute or null
62 */
63 public Attribute processClassAttribute( final JavaClass clazz,
64 final Attribute attribute )
65 {
66 Attribute result = attribute;
67 for( int i = 0; i < m_interceptors.length; i++ )
68 {
69 result = m_interceptors[ i ].processClassAttribute( clazz, result );
70 if( null == result )
71 {
72 return null;
73 }
74 }
75 return result;
76 }
77
78 /***
79 * Process a single attribute at the Field level.
80 * The implementation may return a new attribute
81 * instance, the old attribute instance or null to
82 * ignore attribute.
83 *
84 * @param field the corresponding JavaField instance
85 * @param attribute the attribute
86 * @return the resulting attribute or null
87 */
88 public Attribute processFieldAttribute( final JavaField field,
89 final Attribute attribute )
90 {
91 Attribute result = attribute;
92 for( int i = 0; i < m_interceptors.length; i++ )
93 {
94 result = m_interceptors[ i ].processFieldAttribute( field, result );
95 if( null == result )
96 {
97 return null;
98 }
99 }
100 return result;
101 }
102
103 /***
104 * Process a single attribute at the Method level.
105 * The implementation may return a new attribute
106 * instance, the old attribute instance or null to
107 * ignore attribute.
108 *
109 * @param method the corresponding JavaMethod instance
110 * @param attribute the attribute
111 * @return the resulting attribute or null
112 */
113 public Attribute processMethodAttribute( final JavaMethod method,
114 final Attribute attribute )
115 {
116 Attribute result = attribute;
117 for( int i = 0; i < m_interceptors.length; i++ )
118 {
119 result = m_interceptors[ i ].processMethodAttribute( method, result );
120 if( null == result )
121 {
122 return null;
123 }
124 }
125 return result;
126 }
127
128 /***
129 * Process the set of attributes for a specific Class.
130 * The implementation must return an array of attributes
131 * with no null entrys.
132 *
133 * @param clazz the corresponding JavaClass instance
134 * @param attributes the attributes
135 * @return the resulting attribute array
136 */
137 public Attribute[] processClassAttributes( final JavaClass clazz,
138 final Attribute[] attributes )
139 {
140 Attribute[] results = attributes;
141 for( int i = 0; i < m_interceptors.length; i++ )
142 {
143 results = m_interceptors[ i ].processClassAttributes( clazz, results );
144 }
145 return results;
146 }
147
148 /***
149 * Process the set of attributes for a specific Field.
150 * The implementation must return an array of attributes
151 * with no null entrys.
152 *
153 * @param field the corresponding JavaField instance
154 * @param attributes the attributes
155 * @return the resulting attribute array
156 */
157 public Attribute[] processFieldAttributes( final JavaField field,
158 final Attribute[] attributes )
159 {
160 Attribute[] results = attributes;
161 for( int i = 0; i < m_interceptors.length; i++ )
162 {
163 results = m_interceptors[ i ].processFieldAttributes( field, results );
164 }
165 return results;
166 }
167
168 /***
169 * Process the set of attributes for a specific Method.
170 * The implementation must return an array of attributes
171 * with no null entrys.
172 *
173 * @param method the corresponding JavaMethod instance
174 * @param attributes the attributes
175 * @return the resulting attribute array
176 */
177 public Attribute[] processMethodAttributes( final JavaMethod method,
178 final Attribute[] attributes )
179 {
180 Attribute[] results = attributes;
181 for( int i = 0; i < m_interceptors.length; i++ )
182 {
183 results = m_interceptors[ i ].processMethodAttributes( method, results );
184 }
185 return results;
186 }
187 }