KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > model > schema > Schema


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

20
21 package org.apache.directory.ldapstudio.browser.core.model.schema;
22
23
24 import java.io.InputStream JavaDoc;
25 import java.io.InputStreamReader JavaDoc;
26 import java.io.Reader JavaDoc;
27 import java.io.Serializable JavaDoc;
28 import java.io.StringReader JavaDoc;
29 import java.io.Writer JavaDoc;
30 import java.net.URL JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.Arrays JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.HashSet JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.Set JavaDoc;
39
40 import org.apache.directory.ldapstudio.browser.core.internal.model.AttributeDescription;
41 import org.apache.directory.ldapstudio.browser.core.model.DN;
42 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
43 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEnumeration;
44 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
45 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
46 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine;
47 import org.apache.directory.ldapstudio.browser.core.model.ldif.parser.LdifParser;
48 import org.apache.directory.ldapstudio.browser.core.model.schema.parser.SchemaLexer;
49 import org.apache.directory.ldapstudio.browser.core.model.schema.parser.SchemaParser;
50
51
52 public class Schema implements Serializable JavaDoc
53 {
54
55     private static final long serialVersionUID = 2439355717760227167L;
56
57     public static final String JavaDoc SCHEMA_FILTER = "(objectClass=subschema)";
58     
59     public static final String JavaDoc SCHEMA_ATTRIBUTE_OBJECTCLASSES = "objectClasses";
60
61     public static final String JavaDoc SCHEMA_ATTRIBUTE_ATTRIBUTETYPES = "attributeTypes";
62
63     public static final String JavaDoc SCHEMA_ATTRIBUTE_LDAPSYNTAXES = "ldapSyntaxes";
64
65     public static final String JavaDoc SCHEMA_ATTRIBUTE_MATCHINGRULES = "matchingRules";
66
67     public static final String JavaDoc SCHEMA_ATTRIBUTE_MATCHINGRULEUSE = "matchingRuleUse";
68
69     public static final Schema DEFAULT_SCHEMA;
70     static
71     {
72         Schema defaultSchema = null;
73
74         try
75         {
76             URL JavaDoc url = Schema.class.getClassLoader().getResource(
77                 "default_schema.ldif" );
78             InputStream JavaDoc is = url.openStream();
79             Reader JavaDoc reader = new InputStreamReader JavaDoc( is );
80
81             defaultSchema = new Schema();
82             defaultSchema.defaultSchema = true;
83             defaultSchema.loadFromLdif( reader );
84         }
85         catch ( Exception JavaDoc e )
86         {
87             e.printStackTrace();
88         }
89
90         DEFAULT_SCHEMA = defaultSchema;
91     }
92
93     private boolean defaultSchema = false;
94
95
96     public boolean isDefault()
97     {
98         return this.defaultSchema;
99     }
100
101     private LdifContentRecord schemaRecord;
102
103     private DN dn;
104
105     private String JavaDoc[] objectClasses;
106
107     private String JavaDoc createTimestamp;
108
109     private String JavaDoc modifyTimestamp;
110
111     private Map JavaDoc ocdMapByName;
112
113     private Map JavaDoc atdMapByName;
114
115     private Map JavaDoc lsdMapByNumericOID;
116
117     private Map JavaDoc mrdMapByName;
118
119     private Map JavaDoc mrdMapByNumericOID;
120
121     private Map JavaDoc mrudMapByName;
122
123     private Map JavaDoc mrudMapByNumericOID;
124
125
126     public Schema()
127     {
128         this.schemaRecord = null;
129         this.dn = null;
130         this.objectClasses = new String JavaDoc[0];
131         this.createTimestamp = null;
132         this.modifyTimestamp = null;
133         this.ocdMapByName = new HashMap JavaDoc();
134         this.atdMapByName = new HashMap JavaDoc();
135         this.lsdMapByNumericOID = new HashMap JavaDoc();
136         this.mrdMapByName = new HashMap JavaDoc();
137         this.mrdMapByNumericOID = new HashMap JavaDoc();
138         this.mrudMapByName = new HashMap JavaDoc();
139         this.mrudMapByNumericOID = new HashMap JavaDoc();
140     }
141
142
143     /**
144      * Loads all schema elements from the given reader. The input must be in
145      * LDIF format.
146      *
147      * @param reader
148      */

149     public void loadFromLdif( Reader JavaDoc reader )
150     {
151         try
152         {
153             LdifParser parser = new LdifParser();
154             LdifEnumeration enumeration = parser.parse( reader );
155             if ( enumeration.hasNext( null ) )
156             {
157                 LdifContainer container = enumeration.next( null );
158                 if ( container instanceof LdifContentRecord )
159                 {
160                     LdifContentRecord schemaRecord = ( LdifContentRecord ) container;
161                     this.parseSchemaRecord( schemaRecord );
162                 }
163             }
164         }
165         catch ( Exception JavaDoc e )
166         {
167             System.out.println( "Schema#loadFromLdif: " + e.toString() );
168         }
169     }
170
171
172     public void loadFromRecord( LdifContentRecord schemaRecord )
173     {
174         try
175         {
176             this.parseSchemaRecord( schemaRecord );
177         }
178         catch ( Exception JavaDoc e )
179         {
180             System.out.println( "Schema#loadFromRecord: " + e.toString() );
181         }
182     }
183
184
185     /**
186      * Saves the schema in LDIF format to the given writer.
187      *
188      * @param writer
189      */

190     public void saveToLdif( Writer JavaDoc writer )
191     {
192         try
193         {
194             writer.write( this.getSchemaRecord().toFormattedString() );
195         }
196         catch ( Exception JavaDoc e )
197         {
198             System.out.println( "Schema#saveToLdif: " + e.toString() );
199         }
200     }
201
202
203     private void parseSchemaRecord( LdifContentRecord schemaRecord ) throws Exception JavaDoc
204     {
205
206         this.setSchemaRecord( schemaRecord );
207         this.setDn( new DN( schemaRecord.getDnLine().getValueAsString() ) );
208
209         LdifAttrValLine[] lines = schemaRecord.getAttrVals();
210         for ( int i = 0; i < lines.length; i++ )
211         {
212             LdifAttrValLine line = lines[i];
213             String JavaDoc attributeName = line.getUnfoldedAttributeDescription();
214             String JavaDoc value = line.getValueAsString();
215
216             SchemaLexer lexer = new SchemaLexer( new StringReader JavaDoc( value ) );
217             SchemaParser parser = new SchemaParser( lexer );
218
219             try
220             {
221                 if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_OBJECTCLASSES ) )
222                 {
223                     ObjectClassDescription ocd = parser.objectClassDescription();
224                     ocd.setSchema( this );
225                     ocd.setLine( line );
226                     this.addObjectClassDescription( ocd );
227                 }
228                 else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_ATTRIBUTETYPES ) )
229                 {
230                     AttributeTypeDescription atd = parser.attributeTypeDescription();
231                     atd.setSchema( this );
232                     atd.setLine( line );
233                     this.addAttributeTypeDescription( atd );
234                 }
235                 else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_LDAPSYNTAXES ) )
236                 {
237                     LdapSyntaxDescription lsd = parser.syntaxDescription();
238                     lsd.setSchema( this );
239                     lsd.setLine( line );
240                     this.addLdapSyntaxDescription( lsd );
241                 }
242                 else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_MATCHINGRULES ) )
243                 {
244                     MatchingRuleDescription mrd = parser.matchingRuleDescription();
245                     mrd.setSchema( this );
246                     mrd.setLine( line );
247                     this.addMatchingRuleDescription( mrd );
248                 }
249                 else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_MATCHINGRULEUSE ) )
250                 {
251                     MatchingRuleUseDescription mrud = parser.matchingRuleUseDescription();
252                     mrud.setSchema( this );
253                     mrud.setLine( line );
254                     this.addMatchingRuleUseDescription( mrud );
255                 }
256                 else if ( attributeName.equalsIgnoreCase( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) )
257                 {
258                     this.setCreateTimestamp( value );
259                 }
260                 else if ( attributeName.equalsIgnoreCase( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) )
261                 {
262                     this.setModifyTimestamp( value );
263                 }
264             }
265             catch ( Exception JavaDoc e )
266             {
267                 System.out.println( e.getMessage() + ": " + attributeName + " - " + value );
268                 e.printStackTrace();
269             }
270         }
271
272         // set extensibleObject may attributes
273
ObjectClassDescription extensibleObjectOcd = this
274             .getObjectClassDescription( ObjectClassDescription.EXTENSIBLEOBJECT_OBJECTCLASSNAME );
275         AttributeTypeDescription[] userAtds = SchemaUtils.getUserAttributeDescriptions( this );
276         String JavaDoc[] attributeTypeDescriptionNames = SchemaUtils.getAttributeTypeDescriptionNames( userAtds );
277         extensibleObjectOcd.setMayAttributeTypeDescriptionNames( attributeTypeDescriptionNames );
278     }
279
280
281     /**
282      *
283      * @return the schema record when the schema was created using the
284      * loadFromLdif() method, null otherwise
285      */

286     public LdifContentRecord getSchemaRecord()
287     {
288         return schemaRecord;
289     }
290
291
292     public void setSchemaRecord( LdifContentRecord schemaRecord )
293     {
294         this.schemaRecord = schemaRecord;
295     }
296
297
298     /**
299      *
300      * @return the dn of the schema record, may be null
301      */

302     public DN getDn()
303     {
304         return dn;
305     }
306
307
308     public void setDn( DN dn )
309     {
310         this.dn = dn;
311     }
312
313
314     /**
315      *
316      * @return the create timestamp of the schema record, may be null
317      */

318     public String JavaDoc getCreateTimestamp()
319     {
320         return createTimestamp;
321     }
322
323
324     public void setCreateTimestamp( String JavaDoc createTimestamp )
325     {
326         this.createTimestamp = createTimestamp;
327     }
328
329
330     /**
331      *
332      * @return the modify timestamp of the schema record, may be null
333      */

334     public String JavaDoc getModifyTimestamp()
335     {
336         return modifyTimestamp;
337     }
338
339
340     public void setModifyTimestamp( String JavaDoc modifyTimestamp )
341     {
342         this.modifyTimestamp = modifyTimestamp;
343     }
344
345
346     /**
347      *
348      * @return the object classes of the schema record, may be an empty
349      * array.
350      */

351     public String JavaDoc[] getObjectClasses()
352     {
353         return objectClasses;
354     }
355
356
357     public void setObjectClasses( String JavaDoc[] objectClasses )
358     {
359         this.objectClasses = objectClasses;
360     }
361
362
363     /**
364      *
365      * @return a Map of name to attribute type description
366      */

367     Map JavaDoc getAtdMapByName()
368     {
369         return atdMapByName;
370     }
371
372
373     void setAtdMapByName( Map JavaDoc atdMapByName )
374     {
375         this.atdMapByName = atdMapByName;
376     }
377
378
379     public void addAttributeTypeDescription( AttributeTypeDescription atd )
380     {
381         if ( atd.getNames() != null && atd.getNames().length > 0 )
382         {
383             for ( int i = 0; i < atd.getNames().length; i++ )
384             {
385                 this.atdMapByName.put( atd.getNames()[i].toLowerCase(), atd );
386             }
387         }
388         if ( atd.getNumericOID() != null )
389         {
390             this.atdMapByName.put( atd.getNumericOID().toLowerCase(), atd );
391         }
392     }
393
394
395     /**
396      *
397      * @return an array of all attribute type description names
398      */

399     public String JavaDoc[] getAttributeTypeDescriptionNames()
400     {
401         Set JavaDoc set = new HashSet JavaDoc();
402         for ( Iterator JavaDoc it = this.atdMapByName.values().iterator(); it.hasNext(); )
403         {
404             AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next();
405             for ( int i = 0; i < atd.getNames().length; i++ )
406             {
407                 set.add( atd.getNames()[i] );
408             }
409         }
410         return ( String JavaDoc[] ) set.toArray( new String JavaDoc[set.size()] );
411     }
412
413
414     public AttributeTypeDescription[] getAttributeTypeDescriptions()
415     {
416         Set JavaDoc set = new HashSet JavaDoc();
417         for ( Iterator JavaDoc it = this.atdMapByName.values().iterator(); it.hasNext(); )
418         {
419             AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next();
420             set.add( atd );
421         }
422         return ( AttributeTypeDescription[] ) set.toArray( new AttributeTypeDescription[set.size()] );
423     }
424
425
426     /**
427      *
428      * @return a Map of oid to syntax description
429      */

430     public Map JavaDoc getLsdMapByNumericOID()
431     {
432         return lsdMapByNumericOID;
433     }
434
435
436     public void setLsdMapByNumericOID( Map JavaDoc lsdMapByNumericOID )
437     {
438         this.lsdMapByNumericOID = lsdMapByNumericOID;
439     }
440
441
442     public void addLdapSyntaxDescription( LdapSyntaxDescription lsd )
443     {
444         if ( lsd.getNumericOID() != null )
445         {
446             this.lsdMapByNumericOID.put( lsd.getNumericOID().toLowerCase(), lsd );
447         }
448     }
449
450
451     /**
452      *
453      * @return an array of all syntax description oids
454      */

455     public String JavaDoc[] getLdapSyntaxDescriptionOids()
456     {
457         Set JavaDoc set = new HashSet JavaDoc();
458         for ( Iterator JavaDoc it = this.lsdMapByNumericOID.values().iterator(); it.hasNext(); )
459         {
460             LdapSyntaxDescription lsd = ( LdapSyntaxDescription ) it.next();
461             set.add( lsd.getNumericOID() );
462         }
463         return ( String JavaDoc[] ) set.toArray( new String JavaDoc[set.size()] );
464     }
465
466
467     public LdapSyntaxDescription[] getLdapSyntaxDescriptions()
468     {
469         Set JavaDoc set = new HashSet JavaDoc();
470         for ( Iterator JavaDoc it = this.lsdMapByNumericOID.values().iterator(); it.hasNext(); )
471         {
472             LdapSyntaxDescription lsd = ( LdapSyntaxDescription ) it.next();
473             set.add( lsd );
474         }
475         return ( LdapSyntaxDescription[] ) set.toArray( new LdapSyntaxDescription[set.size()] );
476     }
477
478
479     /**
480      *
481      * @return a Map of name to matching rule description
482      */

483     public Map JavaDoc getMrdMapByName()
484     {
485         return mrdMapByName;
486     }
487
488
489     public void setMrdMapByName( Map JavaDoc mrdMapByName )
490     {
491         this.mrdMapByName = mrdMapByName;
492     }
493
494
495     public void addMatchingRuleDescription( MatchingRuleDescription mrd )
496     {
497         if ( mrd.getNames() != null && mrd.getNames().length > 0 )
498         {
499             for ( int i = 0; i < mrd.getNames().length; i++ )
500             {
501                 this.mrdMapByName.put( mrd.getNames()[i].toLowerCase(), mrd );
502             }
503         }
504         if ( mrd.getNumericOID() != null )
505         {
506             this.mrdMapByNumericOID.put( mrd.getNumericOID().toLowerCase(), mrd );
507         }
508     }
509
510
511     /**
512      *
513      * @return a Map of oid to matching rule description
514      */

515     public Map JavaDoc getMrdMapByNumericOID()
516     {
517         return mrdMapByNumericOID;
518     }
519
520
521     public void setMrdMapByNumericOID( Map JavaDoc mrdMapByNumericOID )
522     {
523         this.mrdMapByNumericOID = mrdMapByNumericOID;
524     }
525
526
527     /**
528      *
529      * @return a Map of name to matching rule use description
530      */

531     public Map JavaDoc getMrudMapByName()
532     {
533         return mrudMapByName;
534     }
535
536
537     public void setMrudMapByName( Map JavaDoc mrudMapByName )
538     {
539         this.mrudMapByName = mrudMapByName;
540     }
541
542
543     public void addMatchingRuleUseDescription( MatchingRuleUseDescription mrud )
544     {
545         if ( mrud.getNames() != null && mrud.getNames().length > 0 )
546         {
547             for ( int i = 0; i < mrud.getNames().length; i++ )
548             {
549                 this.mrudMapByName.put( mrud.getNames()[i].toLowerCase(), mrud );
550             }
551         }
552         if ( mrud.getNumericOID() != null )
553         {
554             this.mrudMapByNumericOID.put( mrud.getNumericOID().toLowerCase(), mrud );
555         }
556     }
557
558
559     /**
560      *
561      * @return a Map of oid to matching rule use description
562      */

563     public Map JavaDoc getMrudMapByNumericOID()
564     {
565         return mrudMapByNumericOID;
566     }
567
568
569     public void setMrduMapByNumericOID( Map JavaDoc mrudMapByNumericOID )
570     {
571         this.mrudMapByNumericOID = mrudMapByNumericOID;
572     }
573
574
575     /**
576      *
577      * @return a Map of name to object class description
578      */

579     Map JavaDoc getOcdMapByName()
580     {
581         return ocdMapByName;
582     }
583
584
585     void setOcdMapByName( Map JavaDoc ocdMapByName )
586     {
587         this.ocdMapByName = ocdMapByName;
588     }
589
590
591     public void addObjectClassDescription( ObjectClassDescription ocd )
592     {
593         if ( ocd.getNames() != null && ocd.getNames().length > 0 )
594         {
595             for ( int i = 0; i < ocd.getNames().length; i++ )
596             {
597                 this.ocdMapByName.put( ocd.getNames()[i].toLowerCase(), ocd );
598             }
599         }
600         if ( ocd.getNumericOID() != null )
601         {
602             this.ocdMapByName.put( ocd.getNumericOID().toLowerCase(), ocd );
603         }
604     }
605
606
607     /**
608      *
609      * @return an array of all object class names
610      */

611     public String JavaDoc[] getObjectClassDescriptionNames()
612     {
613         Set JavaDoc set = new HashSet JavaDoc();
614         for ( Iterator JavaDoc it = this.ocdMapByName.values().iterator(); it.hasNext(); )
615         {
616             ObjectClassDescription ocd = ( ObjectClassDescription ) it.next();
617             for ( int i = 0; i < ocd.getNames().length; i++ )
618             {
619                 set.add( ocd.getNames()[i] );
620             }
621         }
622         return ( String JavaDoc[] ) set.toArray( new String JavaDoc[set.size()] );
623     }
624
625
626     public ObjectClassDescription[] getObjectClassDescriptions()
627     {
628         Set JavaDoc set = new HashSet JavaDoc();
629         for ( Iterator JavaDoc it = this.ocdMapByName.values().iterator(); it.hasNext(); )
630         {
631             ObjectClassDescription ocd = ( ObjectClassDescription ) it.next();
632             set.add( ocd );
633         }
634         return ( ObjectClassDescription[] ) set.toArray( new ObjectClassDescription[set.size()] );
635     }
636
637
638     /**
639      *
640      * @param name
641      * @return true if a object class description with the given name
642      * exists.
643      */

644     public boolean hasObjectClassDescription( String JavaDoc name )
645     {
646         return this.ocdMapByName.containsKey( name.toLowerCase() );
647     }
648
649
650     /**
651      * Returns the object class description of the given name. If no such
652      * object exists the default or a dummy object class description is
653      * returned.
654      *
655      * @param name
656      * the object class name
657      * @return the object class description, the default or a dummy
658      */

659     public ObjectClassDescription getObjectClassDescription( String JavaDoc name )
660     {
661         if ( this.ocdMapByName.containsKey( name.toLowerCase() ) )
662         {
663             return ( ObjectClassDescription ) this.ocdMapByName.get( name.toLowerCase() );
664         }
665         else if ( !this.isDefault() )
666         {
667             return DEFAULT_SCHEMA.getObjectClassDescription( name );
668         }
669         else
670         {
671             // DUMMY
672
ObjectClassDescription ocd = new ObjectClassDescription();
673             ocd.setSchema( this );
674             ocd.setNumericOID( name );
675             ocd.setNames( new String JavaDoc[]
676                 { name } );
677             return ocd;
678         }
679     }
680
681
682     /**
683      *
684      * @param name
685      * @return true if a attribute type description with the given name
686      * exists.
687      */

688     public boolean hasAttributeTypeDescription( String JavaDoc name )
689     {
690         return this.atdMapByName.containsKey( name.toLowerCase() );
691     }
692
693
694     /**
695      * Returns the attribute type description of the given name. If no such
696      * object exists the default or a dummy attribute type description is
697      * returned.
698      *
699      * @param description
700      * the attribute description
701      * @return the attribute type description, or the default or a dummy
702      */

703     public AttributeTypeDescription getAttributeTypeDescription( String JavaDoc description )
704     {
705
706         AttributeDescription ad = new AttributeDescription( description );
707         String JavaDoc attributeType = ad.getParsedAttributeType();
708
709         if ( this.atdMapByName.containsKey( attributeType.toLowerCase() ) )
710         {
711             return ( AttributeTypeDescription ) this.atdMapByName.get( attributeType.toLowerCase() );
712         }
713         else if ( !this.isDefault() )
714         {
715             return DEFAULT_SCHEMA.getAttributeTypeDescription( attributeType );
716         }
717         else
718         {
719             // DUMMY
720
AttributeTypeDescription atd = new AttributeTypeDescription();
721             atd.setSchema( this );
722             atd.setNumericOID( attributeType );
723             atd.setNames( new String JavaDoc[]
724                 { attributeType } );
725             atd.setNoUserModification( true );
726             atd.setUsage( "" );
727             return atd;
728         }
729     }
730
731
732     /**
733      *
734      * @param name
735      * @return true if a syntax description with the given name exists.
736      */

737     public boolean hasLdapSyntaxDescription( String JavaDoc numericOID )
738     {
739         return this.lsdMapByNumericOID.containsKey( numericOID.toLowerCase() );
740     }
741
742
743     /**
744      * Returns the syntax description of the given name. If no such object
745      * exists the default or a dummy syntax description is returned.
746      *
747      * @param name
748      * the attribute name
749      * @return the attribute type description, or the default or a dummy
750      */

751     public LdapSyntaxDescription getLdapSyntaxDescription( String JavaDoc numericOID )
752     {
753         if ( this.lsdMapByNumericOID.containsKey( numericOID.toLowerCase() ) )
754         {
755             return ( LdapSyntaxDescription ) this.lsdMapByNumericOID.get( numericOID.toLowerCase() );
756         }
757         else if ( !this.isDefault() )
758         {
759             return DEFAULT_SCHEMA.getLdapSyntaxDescription( numericOID );
760         }
761         else
762         {
763             // DUMMY
764
LdapSyntaxDescription lsd = new LdapSyntaxDescription();
765             lsd.setSchema( this );
766             lsd.setNumericOID( numericOID );
767             return lsd;
768         }
769     }
770
771
772     /**
773      *
774      * @param name
775      * @return true if a matching rule description with the given name or
776      * oid exists.
777      */

778     public boolean hasMatchingRuleDescription( String JavaDoc nameOrOID )
779     {
780         return this.mrdMapByName.containsKey( nameOrOID.toLowerCase() )
781             || this.mrdMapByNumericOID.containsKey( nameOrOID.toLowerCase() );
782     }
783
784
785     /**
786      * Returns the matching rule description of the given name or oid. If no
787      * such object exists the default or a dummy matching rule description
788      * is returned.
789      *
790      * @param name
791      * the matching rule
792      * @return the matching rule description, or the default or a dummy
793      */

794     public MatchingRuleDescription getMatchingRuleDescription( String JavaDoc nameOrOID )
795     {
796         if ( this.mrdMapByName.containsKey( nameOrOID.toLowerCase() ) )
797         {
798             return ( MatchingRuleDescription ) this.mrdMapByName.get( nameOrOID.toLowerCase() );
799         }
800         else if ( this.mrdMapByNumericOID.containsKey( nameOrOID.toLowerCase() ) )
801         {
802             return ( MatchingRuleDescription ) this.mrdMapByNumericOID.get( nameOrOID.toLowerCase() );
803         }
804         else if ( !this.isDefault() )
805         {
806             return DEFAULT_SCHEMA.getMatchingRuleDescription( nameOrOID );
807         }
808         else
809         {
810             // DUMMY
811
MatchingRuleDescription mrd = new MatchingRuleDescription();
812             mrd.setSchema( this );
813             mrd.setNumericOID( nameOrOID );
814             return mrd;
815         }
816     }
817
818
819     /**
820      *
821      * @param name
822      * @return true if a matching rule use description with the given name
823      * or oid exists.
824      */

825     public boolean hasMatchingRuleUseDescription( String JavaDoc nameOrOID )
826     {
827         return this.mrudMapByName.containsKey( nameOrOID.toLowerCase() )
828             || this.mrudMapByNumericOID.containsKey( nameOrOID.toLowerCase() );
829     }
830
831
832     /**
833      * Returns the matching rule description of the given name or oid. If no
834      * such object exists the default or a dummy matching rule description
835      * is returned.
836      *
837      * @param name
838      * the matching rule
839      * @return the matching rule description, or the default or a dummy
840      */

841     public MatchingRuleUseDescription getMatchingRuleUseDescription( String JavaDoc nameOrOID )
842     {
843         if ( this.mrudMapByName.containsKey( nameOrOID.toLowerCase() ) )
844         {
845             return ( MatchingRuleUseDescription ) this.mrudMapByName.get( nameOrOID.toLowerCase() );
846         }
847         else if ( this.mrudMapByNumericOID.containsKey( nameOrOID.toLowerCase() ) )
848         {
849             return ( MatchingRuleUseDescription ) this.mrudMapByNumericOID.get( nameOrOID.toLowerCase() );
850         }
851         else if ( !this.isDefault() )
852         {
853             return DEFAULT_SCHEMA.getMatchingRuleUseDescription( nameOrOID );
854         }
855         else
856         {
857             // DUMMY
858
MatchingRuleUseDescription mrud = new MatchingRuleUseDescription();
859             mrud.setSchema( this );
860             mrud.setNumericOID( nameOrOID );
861             return mrud;
862         }
863     }
864
865
866     static String JavaDoc[] addValue( String JavaDoc[] array, String JavaDoc value )
867     {
868         List JavaDoc list = new ArrayList JavaDoc( Arrays.asList( array ) );
869         list.add( value );
870         return ( String JavaDoc[] ) list.toArray( new String JavaDoc[list.size()] );
871     }
872
873 }
874
Popular Tags