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.DITStructureRule;
28  import org.apache.directory.shared.ldap.schema.MutableSchemaObject;
29  import org.apache.directory.shared.ldap.schema.NameForm;
30  
31  
32  /**
33   * A ditStructureRule bean implementation which dynamically looks up dependencies using 
34   * a resgistries object.
35   *
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   * @version $Rev$
38   */
39  public class DitStructureRuleImpl extends AbstractSchemaObject implements DITStructureRule, MutableSchemaObject
40  {
41      private static final long serialVersionUID = 1L;
42      private final Integer[] EMPTY_INT_ARRAY = new Integer[0];
43      private final DITStructureRule[] EMPTY_DSR_ARRAY = new DITStructureRule[0];
44  
45      private final Registries registries;
46      private String nameFormOid;
47      private Integer[] superClassRuleIds;
48      private DITStructureRule[] superClasses;
49      
50      
51      public DitStructureRuleImpl( String nameFormOid, Integer ruleId, Registries registries )
52      {
53          super( nameFormOid + "." + ruleId.toString() );
54          this.nameFormOid = nameFormOid;
55          this.registries = registries;
56      }
57  
58  
59      /* (non-Javadoc)
60       * @see org.apache.directory.shared.ldap.schema.DITStructureRule#getNameForm()
61       */
62      public NameForm getNameForm() throws NamingException
63      {
64          return registries.getNameFormRegistry().lookup( nameFormOid );
65      }
66  
67      
68      /* (non-Javadoc)
69       * @see org.apache.directory.shared.ldap.schema.DITStructureRule#getSuperClasses()
70       */
71      public DITStructureRule[] getSuperClasses() throws NamingException
72      {
73          if ( this.superClassRuleIds == null )
74          {
75              return EMPTY_DSR_ARRAY;
76          }
77          
78          for ( int ii = 0; ii < superClassRuleIds.length; ii++ )
79          {
80              superClasses[ii] = registries.getDitStructureRuleRegistry().lookup( superClassRuleIds[ii] );
81          }
82          
83          return superClasses;
84      }
85      
86      
87      public void setSuperClassRuleIds( Integer[] superClassRuleIds )
88      {
89          if ( superClassRuleIds == null )
90          {
91              this.superClassRuleIds = EMPTY_INT_ARRAY;
92              this.superClasses = EMPTY_DSR_ARRAY;
93          }
94          else
95          {
96              this.superClassRuleIds = superClassRuleIds;
97              this.superClasses = new DITStructureRule[superClassRuleIds.length];
98          }
99      }
100     
101     
102     public void setObsolete( boolean obsolete )
103     {
104         super.setObsolete( obsolete );
105     }
106     
107     
108     public void setNames( String[] names )
109     {
110         super.setNames( names );
111     }
112     
113     
114     public void setSchema( String schema )
115     {
116         super.setSchema( schema );
117     }
118     
119     
120     public void setDescription( String description )
121     {
122         super.setDescription( description );
123     }
124 
125 
126     public Integer getRuleId()
127     {
128         return null;
129     }
130 }