1
2
3
4
5
6
7
8 package org.codehaus.metaclass.tools.qdox;
9
10 import org.codehaus.metaclass.model.Attribute;
11 import com.thoughtworks.qdox.model.JavaClass;
12 import com.thoughtworks.qdox.model.JavaField;
13 import com.thoughtworks.qdox.model.JavaMethod;
14
15 /***
16 * Interceptor that only returns attributes if they have a namespace.
17 * Attributes with namespace have names of the form
18 * <namespace>.<name>.
19 *
20 * @author Peter Donald
21 * @version $Revision: 1.2 $ $Date: 2003/11/27 08:08:04 $
22 */
23 public class NonNamespaceAttributeRemovingInterceptor
24 extends DefaultQDoxAttributeInterceptor
25 {
26 /***
27 * Constant containing an instance of interceptor.
28 */
29 public static final NonNamespaceAttributeRemovingInterceptor INTERCEPTOR =
30 new NonNamespaceAttributeRemovingInterceptor();
31
32 /***
33 * @see DefaultQDoxAttributeInterceptor#processClassAttribute
34 */
35 public Attribute processClassAttribute( final JavaClass clazz,
36 final Attribute attribute )
37 {
38 return processAttribute( attribute );
39 }
40
41 /***
42 * @see DefaultQDoxAttributeInterceptor#processFieldAttribute
43 */
44 public Attribute processFieldAttribute( final JavaField field,
45 final Attribute attribute )
46 {
47 return processAttribute( attribute );
48 }
49
50 /***
51 * @see DefaultQDoxAttributeInterceptor#processMethodAttribute
52 */
53 public Attribute processMethodAttribute( final JavaMethod method,
54 final Attribute attribute )
55 {
56 return processAttribute( attribute );
57 }
58
59 /***
60 * Only return an attribute if it has a namespace.
61 *
62 * @param attribute the attribute
63 * @return the attribute or null
64 */
65 Attribute processAttribute( final Attribute attribute )
66 {
67 final String name = attribute.getName();
68 final int length = name.length();
69 final int index = name.indexOf( "." );
70 if( -1 == index || 0 == index || length - 1 == index )
71 {
72 return null;
73 }
74 else
75 {
76 return attribute;
77 }
78 }
79 }