1
2
3
4
5
6
7
8 package org.codehaus.metaclass.model;
9
10 import java.io.Serializable;
11
12 /***
13 * This is the Abstract class for all feature descriptors.
14 * Every descriptor has the capability of adding Attributes
15 * of some kind. These Attributes can then be interpreted by
16 * the container. The meaning of the specific Attributes will
17 * be defined by future specification documents.
18 *
19 * @author Peter Donald
20 * @author <a href="mailto:doug at stocksoftware.com.au">Doug Hagan</a>
21 * @version $Revision: 1.12 $ $Date: 2003/11/27 08:09:53 $
22 */
23 public abstract class FeatureDescriptor
24 implements Serializable
25 {
26 /***
27 * The arbitrary set of declared Attributes.
28 */
29 private final Attribute[] m_declaredAttributes;
30
31 /***
32 * The arbitrary set of Attributes.
33 */
34 private final Attribute[] m_attributes;
35
36 /***
37 * Create a FeatureDescriptor with specific set of attributes.
38 *
39 * @param attributes the attributes
40 * @param declaredAttributes the declared attributes
41 */
42 protected FeatureDescriptor( final Attribute[] declaredAttributes,
43 final Attribute[] attributes )
44 {
45 if( null == declaredAttributes )
46 {
47 throw new NullPointerException( "declaredAttributes" );
48 }
49 if( null == attributes )
50 {
51 throw new NullPointerException( "attributes" );
52 }
53 for( int i = 0; i < declaredAttributes.length; i++ )
54 {
55 if( null == declaredAttributes[ i ] )
56 {
57 throw new NullPointerException( "declaredAttributes[" + i + "]" );
58 }
59 }
60 for( int i = 0; i < attributes.length; i++ )
61 {
62 if( null == attributes[ i ] )
63 {
64 throw new NullPointerException( "attributes[" + i + "]" );
65 }
66 }
67 for( int i = 0; i < declaredAttributes.length; i++ )
68 {
69 final Attribute attribute = declaredAttributes[ i ];
70 boolean match = false;
71 for( int j = 0; j < attributes.length; j++ )
72 {
73 final Attribute other = attributes[ j ];
74 if( attribute.equals( other ) )
75 {
76 match = true;
77 break;
78 }
79 }
80 if( !match )
81 {
82 final String message =
83 "declaredAttribute[" + i + "] not an attribute";
84 throw new IllegalArgumentException( message );
85 }
86 }
87
88 m_declaredAttributes = declaredAttributes;
89 m_attributes = attributes;
90 }
91
92 /***
93 * Return the declared attributes associated with descriptor.
94 *
95 * @return the declared attributes associated with descriptor.
96 */
97 public Attribute[] getDeclaredAttributes()
98 {
99 return m_declaredAttributes;
100 }
101
102 /***
103 * Return the attributes associated with descriptor.
104 *
105 * @return the attributes associated with descriptor.
106 */
107 public Attribute[] getAttributes()
108 {
109 return m_attributes;
110 }
111 }