View Javadoc

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  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.NameForm;
30  import org.apache.directory.shared.ldap.schema.ObjectClass;
31  
32  
33  /**
34   * A nameForm bean implementation that uses a set of registries to dynamically
35   * resolve it's dependencies.
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   * @version $Rev$
39   */
40  public class NameFormImpl extends AbstractSchemaObject implements NameForm, MutableSchemaObject
41  {
42      private static final long serialVersionUID = 1L;
43      private static final String[] EMPTY_STR_ARRAY = new String[0];
44      private static final AttributeType[] EMPTY_ATTR_ARRAY = new AttributeType[0];
45  
46      
47      private final Registries registries;
48      
49      private String objectClassOid;
50  
51      private String[] mayUseOids = EMPTY_STR_ARRAY;
52      private AttributeType[] mayUse = EMPTY_ATTR_ARRAY;
53      
54      private String[] mustUseOids = EMPTY_STR_ARRAY;
55      private AttributeType[] mustUse = EMPTY_ATTR_ARRAY;
56      
57  
58      /**
59       * @param oid
60       */
61      public NameFormImpl( String oid, Registries registries )
62      {
63          super( oid );
64          this.registries = registries;
65      }
66  
67      
68      public void setMayUseOids( String[] mayUseOids )
69      {
70          if ( mayUseOids == null )
71          {
72              this.mayUse = EMPTY_ATTR_ARRAY;
73              this.mayUseOids = EMPTY_STR_ARRAY;
74          }
75          else
76          {
77              this.mayUse = new AttributeType[mayUseOids.length];
78              this.mayUseOids = mayUseOids;
79          }
80      }
81      
82      
83      /* (non-Javadoc)
84       * @see org.apache.directory.shared.ldap.schema.NameForm#getMaytUse()
85       */
86      public AttributeType[] getMayUse() throws NamingException
87      {
88          if ( mayUseOids == null || mayUseOids.length == 0 )
89          {
90              return EMPTY_ATTR_ARRAY;
91          }
92          
93          for ( int ii = 0; ii < mayUseOids.length; ii++ )
94          {
95              mayUse[ii] = registries.getAttributeTypeRegistry().lookup( mayUseOids[ii] );
96          }
97          
98          return mayUse;
99      }
100 
101 
102     public void setMustUseOids( String[] mustUseOids )
103     {
104         if ( mustUseOids == null )
105         {
106             this.mustUse = EMPTY_ATTR_ARRAY;
107             this.mustUseOids = EMPTY_STR_ARRAY;
108         }
109         else
110         {
111             this.mustUse = new AttributeType[mustUseOids.length];
112             this.mustUseOids = mustUseOids;
113         }
114     }
115     
116     
117     /* (non-Javadoc)
118      * @see org.apache.directory.shared.ldap.schema.NameForm#getMustUse()
119      */
120     public AttributeType[] getMustUse() throws NamingException
121     {
122         if ( mustUseOids == null || mustUseOids.length == 0 )
123         {
124             return EMPTY_ATTR_ARRAY;
125         }
126         
127         for ( int ii = 0; ii < mustUseOids.length; ii++ )
128         {
129             mustUse[ii] = registries.getAttributeTypeRegistry().lookup( mustUseOids[ii] );
130         }
131         
132         return mustUse;
133     }
134     
135     
136     public void setObjectClassOid( String objectClassOid )
137     {
138         this.objectClassOid = objectClassOid;
139     }
140 
141 
142     /* (non-Javadoc)
143      * @see org.apache.directory.shared.ldap.schema.NameForm#getObjectClass()
144      */
145     public ObjectClass getObjectClass() throws NamingException
146     {
147         return registries.getObjectClassRegistry().lookup( objectClassOid );
148     }
149 
150     
151     public void setDescription( String description )
152     {
153         super.setDescription( description );
154     }
155     
156     
157     public void setObsolete( boolean obsolete )
158     {
159         super.setObsolete( obsolete );
160     }
161     
162     
163     public void setNames( String[] names )
164     {
165         super.setNames( names );
166     }
167     
168     
169     public void setSchema( String schema )
170     {
171         super.setSchema( schema );
172     }
173 }