1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.schema;
21
22
23 import javax.naming.NamingException;
24
25 import org.apache.directory.server.schema.registries.Registries;
26 import org.apache.directory.shared.ldap.schema.AbstractSchemaObject;
27 import org.apache.directory.shared.ldap.schema.AttributeType;
28 import org.apache.directory.shared.ldap.schema.MutableSchemaObject;
29 import org.apache.directory.shared.ldap.schema.ObjectClass;
30 import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
31
32
33
34
35
36
37
38
39 class ObjectClassImpl extends AbstractSchemaObject implements MutableSchemaObject, ObjectClass
40 {
41 private static final long serialVersionUID = 1L;
42 private final ObjectClass[] EMPTY_OC_ARRAY = new ObjectClass[0];
43 private final String[] EMPTY_STR_ARRAY = new String[0];
44 private final AttributeType[] EMPTY_AT_ARRAY = new AttributeType[0];
45
46 private final Registries registries;
47
48 private ObjectClassTypeEnum objectClassType;
49 private ObjectClass[] superClasses;
50
51 private String[] mayListOids;
52 private AttributeType[] mayList = EMPTY_AT_ARRAY;
53 private boolean mayListReloaded;
54
55 private String[] mustListOids;
56 private AttributeType[] mustList = EMPTY_AT_ARRAY;
57 private boolean mustListReloaded;
58
59 private String[] superClassOids;
60
61
62 protected ObjectClassImpl( String oid, Registries registries )
63 {
64 super( oid );
65 this.registries = registries;
66 }
67
68
69 public void setDescription( String description )
70 {
71 super.setDescription( description );
72 }
73
74
75 public void setNames( String[] names )
76 {
77 super.setNames( names );
78 }
79
80
81 public void setObsolete( boolean obsolete )
82 {
83 super.setObsolete( obsolete );
84 }
85
86
87 public void setSchema( String schema )
88 {
89 super.setSchema( schema );
90 }
91
92
93 public AttributeType[] getMayList() throws NamingException
94 {
95 if ( this.mayListOids == null )
96 {
97 return EMPTY_AT_ARRAY;
98 }
99
100 if ( mayListReloaded )
101 {
102 for ( int ii = 0; ii < mayListOids.length; ii++ )
103 {
104 mayList[ii] = registries.getAttributeTypeRegistry().lookup( mayListOids[ii] );
105 }
106
107 mayListReloaded = false;
108 }
109
110 return mayList;
111 }
112
113
114 public void setMayListOids( String[] mayListOids ) throws NamingException
115 {
116 if ( mayListOids == null )
117 {
118 this.mayListOids = EMPTY_STR_ARRAY;
119 mayList = EMPTY_AT_ARRAY;
120 }
121 else
122 {
123 this.mayListOids = mayListOids;
124 mayList = new AttributeType[mayListOids.length];
125 }
126
127 mayListReloaded = true;
128 }
129
130
131 public AttributeType[] getMustList() throws NamingException
132 {
133 if ( mustListOids == null )
134 {
135 return EMPTY_AT_ARRAY;
136 }
137
138 if ( mustListReloaded )
139 {
140 for ( int ii = 0; ii < mustListOids.length; ii++ )
141 {
142 mustList[ii] = registries.getAttributeTypeRegistry().lookup( mustListOids[ii] );
143 }
144
145 mustListReloaded = false;
146 }
147
148 return mustList;
149 }
150
151
152 public void setMustListOids( String[] mustListOids ) throws NamingException
153 {
154 if ( mustListOids == null )
155 {
156 this.mustListOids = EMPTY_STR_ARRAY;
157 mustList = EMPTY_AT_ARRAY;
158 }
159 else
160 {
161 this.mustListOids = mustListOids;
162 mustList = new AttributeType[mustListOids.length];
163 }
164
165 mustListReloaded = true;
166 }
167
168
169 public ObjectClass[] getSuperClasses() throws NamingException
170 {
171 if ( superClassOids == null )
172 {
173 return EMPTY_OC_ARRAY;
174 }
175
176 for ( int ii = 0; ii < superClassOids.length; ii++ )
177 {
178 superClasses[ii] = registries.getObjectClassRegistry().lookup( superClassOids[ii] );
179 }
180
181 return superClasses;
182 }
183
184
185 void setSuperClassOids( String[] superClassOids )
186 {
187 if ( superClassOids == null || superClassOids.length == 0 )
188 {
189 this.superClassOids = EMPTY_STR_ARRAY;
190 this.superClasses = EMPTY_OC_ARRAY;
191 }
192 else
193 {
194 this.superClassOids = superClassOids;
195 this.superClasses = new ObjectClass[superClassOids.length];
196 }
197 }
198
199
200 public ObjectClassTypeEnum getType()
201 {
202 return objectClassType;
203 }
204
205
206 public boolean isStructural()
207 {
208 return objectClassType == ObjectClassTypeEnum.STRUCTURAL;
209 }
210
211
212 public boolean isAbstract()
213 {
214 return objectClassType == ObjectClassTypeEnum.ABSTRACT;
215 }
216
217
218 public boolean isAuxiliary()
219 {
220 return objectClassType == ObjectClassTypeEnum.AUXILIARY;
221 }
222
223
224 void setType( ObjectClassTypeEnum objectClassType )
225 {
226 this.objectClassType = objectClassType;
227 }
228 }