|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
MulticastInterceptor.java | 100% | 100% | 100% | 100% |
|
1 |
/*
|
|
2 |
* Copyright (C) The MetaClass Group. All rights reserved.
|
|
3 |
*
|
|
4 |
* This software is published under the terms of the Spice
|
|
5 |
* Software License version 1.1, a copy of which has been included
|
|
6 |
* with this distribution in the LICENSE.txt file.
|
|
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 | 50 |
public MulticastInterceptor( final QDoxAttributeInterceptor[] interceptors )
|
38 |
{ |
|
39 | 50 |
if( null == interceptors ) |
40 |
{ |
|
41 | 2 |
throw new NullPointerException( "interceptors" ); |
42 |
} |
|
43 | 48 |
for( int i = 0; i < interceptors.length; i++ ) |
44 |
{ |
|
45 | 34 |
if( null == interceptors[ i ] ) |
46 |
{ |
|
47 | 2 |
throw new NullPointerException( "interceptors[" + i + "]" ); |
48 |
} |
|
49 |
} |
|
50 | 46 |
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 | 32 |
public Attribute processClassAttribute( final JavaClass clazz,
|
64 |
final Attribute attribute ) |
|
65 |
{ |
|
66 | 32 |
Attribute result = attribute; |
67 | 32 |
for( int i = 0; i < m_interceptors.length; i++ ) |
68 |
{ |
|
69 | 20 |
result = m_interceptors[ i ].processClassAttribute( clazz, result ); |
70 | 18 |
if( null == result ) |
71 |
{ |
|
72 | 4 |
return null; |
73 |
} |
|
74 |
} |
|
75 | 26 |
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 | 4 |
public Attribute processFieldAttribute( final JavaField field,
|
89 |
final Attribute attribute ) |
|
90 |
{ |
|
91 | 4 |
Attribute result = attribute; |
92 | 4 |
for( int i = 0; i < m_interceptors.length; i++ ) |
93 |
{ |
|
94 | 4 |
result = m_interceptors[ i ].processFieldAttribute( field, result ); |
95 | 4 |
if( null == result ) |
96 |
{ |
|
97 | 2 |
return null; |
98 |
} |
|
99 |
} |
|
100 | 2 |
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 | 4 |
public Attribute processMethodAttribute( final JavaMethod method,
|
114 |
final Attribute attribute ) |
|
115 |
{ |
|
116 | 4 |
Attribute result = attribute; |
117 | 4 |
for( int i = 0; i < m_interceptors.length; i++ ) |
118 |
{ |
|
119 | 4 |
result = m_interceptors[ i ].processMethodAttribute( method, result ); |
120 | 4 |
if( null == result ) |
121 |
{ |
|
122 | 2 |
return null; |
123 |
} |
|
124 |
} |
|
125 | 2 |
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 | 28 |
public Attribute[] processClassAttributes( final JavaClass clazz,
|
138 |
final Attribute[] attributes ) |
|
139 |
{ |
|
140 | 28 |
Attribute[] results = attributes; |
141 | 28 |
for( int i = 0; i < m_interceptors.length; i++ ) |
142 |
{ |
|
143 | 14 |
results = m_interceptors[ i ].processClassAttributes( clazz, results ); |
144 |
} |
|
145 | 28 |
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 | 2 |
public Attribute[] processFieldAttributes( final JavaField field,
|
158 |
final Attribute[] attributes ) |
|
159 |
{ |
|
160 | 2 |
Attribute[] results = attributes; |
161 | 2 |
for( int i = 0; i < m_interceptors.length; i++ ) |
162 |
{ |
|
163 | 2 |
results = m_interceptors[ i ].processFieldAttributes( field, results ); |
164 |
} |
|
165 | 2 |
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 | 2 |
public Attribute[] processMethodAttributes( final JavaMethod method,
|
178 |
final Attribute[] attributes ) |
|
179 |
{ |
|
180 | 2 |
Attribute[] results = attributes; |
181 | 2 |
for( int i = 0; i < m_interceptors.length; i++ ) |
182 |
{ |
|
183 | 2 |
results = m_interceptors[ i ].processMethodAttributes( method, results ); |
184 |
} |
|
185 | 2 |
return results;
|
186 |
} |
|
187 |
} |
|
188 |
|
|