KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > schema > bootstrap > AbstractBootstrapProducer


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.ldap.server.schema.bootstrap;
18
19
20 import org.apache.ldap.common.schema.*;
21 import org.apache.ldap.server.schema.*;
22
23 import javax.naming.NamingException JavaDoc;
24 import java.util.Comparator JavaDoc;
25
26
27 /**
28  * An abstract producer implementation.
29  *
30  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
31  * @version $Rev: 169198 $
32  */

33 public abstract class AbstractBootstrapProducer implements BootstrapProducer
34 {
35     /** a reused empty String array */
36     protected static final String JavaDoc[] EMPTY = new String JavaDoc[0];
37     /** the producer type */
38     private final ProducerTypeEnum type;
39
40
41     /**
42      * Creates a producer of a specific type.
43      *
44      * @param type the producer type
45      */

46     protected AbstractBootstrapProducer( ProducerTypeEnum type )
47     {
48         this.type = type;
49     }
50
51
52     /**
53      * @see BootstrapProducer#getType()
54      */

55     public ProducerTypeEnum getType()
56     {
57         return type;
58     }
59
60
61     protected static BootstrapSyntax
62         newSyntax( String JavaDoc oid, BootstrapRegistries registries )
63     {
64         return new BootstrapSyntax( oid, registries.getSyntaxCheckerRegistry() );
65     }
66
67
68
69     protected static BootstrapAttributeType
70         newAttributeType( String JavaDoc oid, BootstrapRegistries registries )
71     {
72         return new BootstrapAttributeType( oid, registries );
73     }
74
75
76
77     protected static BootstrapObjectClass
78         newObjectClass( String JavaDoc oid, BootstrapRegistries registries )
79     {
80         return new BootstrapObjectClass( oid, registries );
81     }
82
83
84
85     /**
86      * A mutable Syntax for the bootstrap phase that uses the
87      * syntaxCheckerRegistry to dynamically resolve syntax checkers.
88      */

89     public static class BootstrapSyntax extends AbstractSyntax
90     {
91         final SyntaxCheckerRegistry registry;
92
93
94         protected BootstrapSyntax( String JavaDoc oid, SyntaxCheckerRegistry registry )
95         {
96             super( oid );
97             this.registry = registry;
98         }
99
100
101         public void setDescription( String JavaDoc description )
102         {
103             super.setDescription( description );
104         }
105
106
107         public void setHumanReadible( boolean isHumanReadible )
108         {
109             super.setHumanReadible( isHumanReadible );
110         }
111
112
113         public void setNames( String JavaDoc[] names )
114         {
115             super.setNames( names );
116         }
117
118
119         public SyntaxChecker getSyntaxChecker( ) throws NamingException JavaDoc
120         {
121             return registry.lookup( getOid() );
122         }
123
124
125         public boolean isObsolete()
126         {
127             return false;
128         }
129     }
130
131
132     public static class BootstrapMatchingRule extends AbstractMatchingRule
133     {
134         final SyntaxRegistry syntaxRegistry;
135         final NormalizerRegistry normalizerRegistry;
136         final ComparatorRegistry comparatorRegistry;
137         String JavaDoc syntaxOid;
138
139
140         protected BootstrapMatchingRule( String JavaDoc oid, BootstrapRegistries registries )
141         {
142             super( oid );
143             this.syntaxRegistry = registries.getSyntaxRegistry();
144             this.normalizerRegistry = registries.getNormalizerRegistry();
145             this.comparatorRegistry = registries.getComparatorRegistry();
146         }
147
148
149         public void setNames( String JavaDoc[] names )
150         {
151             super.setNames( names );
152         }
153
154         public void setSyntaxOid( String JavaDoc syntaxOid )
155         {
156             this.syntaxOid = syntaxOid;
157         }
158
159         public void setDescription( String JavaDoc description )
160         {
161             super.setDescription( description );
162         }
163
164         public void setObsolete( boolean isObsolete )
165         {
166             super.setObsolete( isObsolete );
167         }
168
169
170         // accessors
171

172
173         public Syntax getSyntax() throws NamingException JavaDoc
174         {
175             return syntaxRegistry.lookup( syntaxOid );
176         }
177
178         public Comparator JavaDoc getComparator() throws NamingException JavaDoc
179         {
180             return comparatorRegistry.lookup( getOid() );
181         }
182
183         public Normalizer getNormalizer() throws NamingException JavaDoc
184         {
185             return normalizerRegistry.lookup( getOid() );
186         }
187     }
188
189
190     /**
191      * A concrete mutable attributeType implementation for bootstrapping which
192      * uses registries for dynamically resolving dependent objects.
193      */

194     public static class BootstrapAttributeType extends AbstractAttributeType
195     {
196         private static final long serialVersionUID = 4050205236738471984L;
197
198         private final SyntaxRegistry syntaxRegistry;
199         private final MatchingRuleRegistry matchingRuleRegistry;
200         private final AttributeTypeRegistry attributeTypeRegistry;
201         private String JavaDoc superiorId;
202         private String JavaDoc equalityId;
203         private String JavaDoc substrId;
204         private String JavaDoc orderingId;
205         private String JavaDoc syntaxId;
206
207
208         protected BootstrapAttributeType( String JavaDoc oid, BootstrapRegistries registries )
209         {
210             super( oid );
211
212             syntaxRegistry = registries.getSyntaxRegistry();
213             matchingRuleRegistry = registries.getMatchingRuleRegistry();
214             attributeTypeRegistry = registries.getAttributeTypeRegistry();
215         }
216
217         public void setSuperiorId( String JavaDoc superiorId )
218         {
219             this.superiorId = superiorId;
220         }
221
222         public AttributeType getSuperior() throws NamingException JavaDoc
223         {
224             if ( superiorId == null )
225             {
226                 return null;
227             }
228
229             return this.attributeTypeRegistry.lookup( superiorId );
230         }
231
232         public void setNames( String JavaDoc[] names )
233         {
234             super.setNames( names );
235         }
236
237         public MatchingRule getEquality() throws NamingException JavaDoc
238         {
239             if ( equalityId != null )
240             {
241                 return this.matchingRuleRegistry.lookup( equalityId );
242             }
243
244             if ( superiorId != null )
245             {
246                 return getSuperior().getEquality();
247             }
248
249             return null;
250         }
251
252         public void setEqualityId( String JavaDoc equalityId )
253         {
254             this.equalityId = equalityId;
255         }
256
257         public MatchingRule getSubstr() throws NamingException JavaDoc
258         {
259             if ( substrId != null )
260             {
261                 return this.matchingRuleRegistry.lookup( substrId );
262             }
263
264             if ( superiorId != null )
265             {
266                 return getSuperior().getSubstr();
267             }
268
269             return null;
270         }
271
272         public void setSubstrId( String JavaDoc substrId )
273         {
274             this.substrId = substrId;
275         }
276
277         public MatchingRule getOrdering() throws NamingException JavaDoc
278         {
279             if ( orderingId != null )
280             {
281                 return this.matchingRuleRegistry.lookup( orderingId );
282             }
283
284             if ( superiorId != null )
285             {
286                 return getSuperior().getOrdering();
287             }
288
289             return null;
290         }
291
292         public void setOrderingId( String JavaDoc orderingId )
293         {
294             this.orderingId = orderingId;
295         }
296
297         public void setSyntaxId( String JavaDoc syntaxId )
298         {
299             this.syntaxId = syntaxId;
300         }
301
302         public Syntax getSyntax() throws NamingException JavaDoc
303         {
304             if ( syntaxId != null )
305             {
306                 return this.syntaxRegistry.lookup( syntaxId );
307             }
308
309             if ( superiorId != null )
310             {
311                 return getSuperior().getSyntax();
312             }
313
314             return null;
315         }
316
317         public void setSingleValue( boolean singleValue )
318         {
319             super.setSingleValue( singleValue );
320         }
321
322         public void setCollective( boolean collective )
323         {
324             super.setCollective( collective );
325         }
326
327         public void setCanUserModify( boolean canUserModify )
328         {
329             super.setCanUserModify( canUserModify );
330         }
331
332         public void setObsolete( boolean obsolete )
333         {
334             super.setObsolete( obsolete );
335         }
336
337         public void setDescription( String JavaDoc description )
338         {
339             super.setDescription( description );
340         }
341
342         public void setUsage( UsageEnum usage )
343         {
344             super.setUsage( usage );
345         }
346
347         public void setLength( int length )
348         {
349             super.setLength( length );
350         }
351     }
352
353
354     /**
355      * A concrete mutable objectClass implementation for bootstrapping which
356      * uses registries for dynamically resolving dependent objects.
357      */

358     public static class BootstrapObjectClass extends AbstractSchemaObject
359         implements ObjectClass
360     {
361         private final ObjectClassRegistry objectClassRegistry;
362         private final AttributeTypeRegistry attributeTypeRegistry;
363
364         private String JavaDoc[] superClassIds = EMPTY;
365         private ObjectClass[] superClasses;
366         private ObjectClassTypeEnum type = ObjectClassTypeEnum.STRUCTURAL;
367
368         private String JavaDoc[] mayListIds = EMPTY;
369         private AttributeType[] mayList;
370
371         private String JavaDoc[] mustListIds = EMPTY;
372         private AttributeType[] mustList;
373
374
375         /**
376          * Creates a mutable ObjectClass for the bootstrap process.
377          *
378          * @param oid the OID of the new objectClass
379          * @param registries the bootstrap registries to use for resolving dependent objects
380          */

381         protected BootstrapObjectClass( String JavaDoc oid, BootstrapRegistries registries )
382         {
383             super( oid );
384
385             objectClassRegistry = registries.getObjectClassRegistry();
386             attributeTypeRegistry = registries.getAttributeTypeRegistry();
387         }
388
389
390         // --------------------------------------------------------------------
391
// ObjectClass Accessors
392
// --------------------------------------------------------------------
393

394
395         public ObjectClass[] getSuperClasses() throws NamingException JavaDoc
396         {
397             if ( superClasses == null )
398             {
399                 superClasses = new ObjectClass[superClassIds.length];
400             }
401
402             for( int ii = 0; ii < superClassIds.length; ii++ )
403             {
404                 superClasses[ii] = objectClassRegistry.lookup( superClassIds[ii] );
405             }
406
407             return superClasses;
408         }
409
410
411         public void setSuperClassIds( String JavaDoc[] superClassIds )
412         {
413             this.superClassIds = superClassIds;
414         }
415
416
417         public ObjectClassTypeEnum getType()
418         {
419             return type;
420         }
421
422
423         public void setType( ObjectClassTypeEnum type )
424         {
425             this.type = type;
426         }
427
428
429         public AttributeType[] getMustList() throws NamingException JavaDoc
430         {
431             if ( mustList == null )
432             {
433                 mustList = new AttributeType[mustListIds.length];
434             }
435
436             for( int ii = 0; ii < mustListIds.length; ii++ )
437             {
438                 mustList[ii] = attributeTypeRegistry.lookup( mustListIds[ii] );
439             }
440
441             return mustList;
442         }
443
444
445         public void setMustListIds( String JavaDoc[] mustListIds )
446         {
447             this.mustListIds = mustListIds;
448         }
449
450
451         public AttributeType[] getMayList() throws NamingException JavaDoc
452         {
453             if ( mayList == null )
454             {
455                 mayList = new AttributeType[mayListIds.length];
456             }
457
458             for( int ii = 0; ii < mayListIds.length; ii++ )
459             {
460                 mayList[ii] = attributeTypeRegistry.lookup( mayListIds[ii] );
461             }
462
463             return mayList;
464         }
465
466
467         public void setMayListIds( String JavaDoc[] mayListIds )
468         {
469             this.mayListIds = mayListIds;
470         }
471
472
473         // --------------------------------------------------------------------
474
// SchemaObject Mutators
475
// --------------------------------------------------------------------
476

477
478         public void setObsolete( boolean obsolete )
479         {
480             super.setObsolete( obsolete );
481         }
482
483         public void setNames( String JavaDoc[] names )
484         {
485             super.setNames( names );
486         }
487
488         public void setDescription( String JavaDoc description )
489         {
490             super.setDescription( description );
491         }
492
493
494     }
495 }
496
Popular Tags