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.MatchingRule;
29  import org.apache.directory.shared.ldap.schema.MatchingRuleUse;
30  import org.apache.directory.shared.ldap.schema.MutableSchemaObject;
31  
32  
33  /**
34   * A machingRuleUse implementation which dynamically pull applicable attributeTypes 
35   * and it's matchingRule from the registries associated with it.
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   * @version $Rev$
39   */
40  public class MatchingRuleUseImpl extends AbstractSchemaObject implements MatchingRuleUse, MutableSchemaObject
41  {
42      private static final long serialVersionUID = 1L;
43  
44      private static final AttributeType[] EMPTY_ATTRIBUTES = new AttributeType[0];
45      private static final String[] EMPTY_STRINGS = new String[0];
46  
47      private final Registries registries;
48      private AttributeType[] applicableAttributes = EMPTY_ATTRIBUTES;
49      private String[] applicableAttributesOids;
50      
51  
52      /**
53       * Creates a new matchingRuleUse.
54       * 
55       * @param oid the numeric oid of the matchingRule associated with this matchingRuleUse
56       * @param registries the registries used to resolve the matchingRule and the applicable attributes
57       */
58      protected MatchingRuleUseImpl( String oid, Registries registries )
59      {
60          super( oid );
61          this.registries = registries;
62      }
63  
64  
65      /* (non-Javadoc)
66       * @see org.apache.directory.shared.ldap.schema.MatchingRuleUse#getMatchingRule()
67       */
68      public MatchingRule getMatchingRule() throws NamingException
69      {
70          return registries.getMatchingRuleRegistry().lookup( getOid() );
71      }
72  
73  
74      /* (non-Javadoc)
75       * @see org.apache.directory.shared.ldap.schema.MatchingRuleUse#getApplicableAttributes()
76       */
77      public AttributeType[] getApplicableAttributes() throws NamingException
78      {
79          if ( applicableAttributesOids == null || applicableAttributesOids == EMPTY_STRINGS )
80          {
81              return EMPTY_ATTRIBUTES;
82          }
83          
84          for ( int ii = 0; ii < applicableAttributesOids.length; ii++ )
85          {
86              applicableAttributes[ii] = registries.getAttributeTypeRegistry().lookup( applicableAttributesOids[ii] );
87          }
88          
89          return applicableAttributes;
90      }
91      
92      
93      /**
94       * Sets the oids used to look up the applicable AttributeTypes.
95       * 
96       * @param applicableAttributesOids the String[] of attributeType oids
97       */
98      public void setApplicableAttributesOids( final String[] applicableAttributesOids )
99      {
100         this.applicableAttributesOids = applicableAttributesOids;
101         if ( applicableAttributesOids == null )
102         {
103             this.applicableAttributesOids = EMPTY_STRINGS;
104             this.applicableAttributes = EMPTY_ATTRIBUTES;
105         }
106         else
107         {
108             this.applicableAttributesOids = applicableAttributesOids;
109             this.applicableAttributes = new AttributeType[applicableAttributesOids.length];
110         }
111     }
112     
113     
114     /**
115      * Sets the names associated with this matchingRuleUse.
116      */
117     public void setNames( String[] names )
118     {
119         super.setNames( names );
120     }
121     
122     
123     /**
124      * Sets the description associated with this matchingRuleUse.
125      */
126     public void setDescription( String description )
127     {
128         super.setDescription( description );
129     }
130     
131     
132     /**
133      * Sets whether or not this matchingRuleUse is obsolete.
134      */
135     public void setObsolete( boolean obsolete )
136     {
137         super.setObsolete( obsolete );
138     }
139     
140     
141     /**
142      * Sets the schema this matchingRuleUse is defined under.
143      */
144     public void setSchema( String schemaName )
145     {
146         super.setSchema( schemaName );
147     }
148 }