1
2
3
4
5
6
7
8 package org.codehaus.metaclass.model;
9
10 import java.io.Serializable;
11
12 /***
13 * This class contains the meta information about a Class. It contains
14 * the name of the class, access modifiers, attributes, the classes fields and
15 * the classes methods.
16 *
17 * @author Peter Donald
18 * @version $Revision: 1.11 $ $Date: 2003/11/27 08:09:53 $
19 */
20 public final class ClassDescriptor
21 extends FeatureDescriptor
22 implements Serializable
23 {
24 /***
25 * The name of class.
26 */
27 private final String m_name;
28
29 /***
30 * The fields of the class.
31 */
32 private final FieldDescriptor[] m_fields;
33
34 /***
35 * The methods in the class.
36 */
37 private final MethodDescriptor[] m_methods;
38
39 /***
40 * Create a ClassDescriptor with metadata about a class.
41 * The descriptor usually represents a corrresponding
42 * java class but this is not always the case.
43 *
44 * @param name the name of class
45 * @param declaredAttributes the declared attributes
46 * @param attributes the top level attribute metadata
47 * @param fields the field descriptors for class
48 * @param methods the method descriptors for class
49 */
50 public ClassDescriptor( final String name,
51 final Attribute[] declaredAttributes,
52 final Attribute[] attributes,
53 final FieldDescriptor[] fields,
54 final MethodDescriptor[] methods )
55 {
56 super( declaredAttributes, attributes );
57 if( null == name )
58 {
59 throw new NullPointerException( "name" );
60 }
61 if( null == fields )
62 {
63 throw new NullPointerException( "fields" );
64 }
65 for( int i = 0; i < fields.length; i++ )
66 {
67 if( null == fields[ i ] )
68 {
69 throw new NullPointerException( "fields[" + i + "]" );
70 }
71 }
72 if( null == methods )
73 {
74 throw new NullPointerException( "methods" );
75 }
76 for( int i = 0; i < methods.length; i++ )
77 {
78 if( null == methods[ i ] )
79 {
80 throw new NullPointerException( "methods[" + i + "]" );
81 }
82 }
83 m_name = name;
84 m_fields = fields;
85 m_methods = methods;
86 }
87
88 /***
89 * Return the name of the class.
90 *
91 * @return the name of the class.
92 */
93 public String getName()
94 {
95 return m_name;
96 }
97
98 /***
99 * Return the FieldDescriptors for class.
100 * Note that it is not necessary that all fields in the
101 * class have corresponding FieldDescriptors.
102 *
103 * @return the FieldDescriptors for class.
104 */
105 public FieldDescriptor[] getFields()
106 {
107 return m_fields;
108 }
109
110 /***
111 * Return the MethodDescriptors for class.
112 * Note that it is not necessary that all methods in the
113 * class have corresponding MethodDescriptors.
114 *
115 * @return the MethodDescriptors for class.
116 */
117 public MethodDescriptor[] getMethods()
118 {
119 return m_methods;
120 }
121 }