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   *    https://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.api.ldap.model.schema;
21  
22  
23  import java.util.List;
24  import java.util.Map;
25  
26  
27  /**
28   * Most schema objects have some common attributes. This class
29   * contains the minimum set of properties exposed by a SchemaObject.<br>
30   * We have 11 types of SchemaObjects :
31   * <ul>
32   *   <li> AttributeType </li>
33   *   <li> DitCOntentRule </li>
34   *   <li> DitStructureRule </li>
35   *   <li> LdapComparator (specific to ADS) </li>
36   *   <li> LdapSyntaxe </li>
37   *   <li> MatchingRule </li>
38   *   <li> MatchingRuleUse </li>
39   *   <li> NameForm </li>
40   *   <li> Normalizer (specific to ADS) </li>
41   *   <li> ObjectClass </li>
42   *   <li> SyntaxChecker (specific to ADS) </li>
43   * </ul>
44   * <br>
45   * <br>
46   * This class provides accessors and setters for the following attributes,
47   * which are common to all those SchemaObjects :
48   * <ul>
49   *   <li>oid : The numeric OID </li>
50   *   <li>description : The SchemaObject description </li>
51   *   <li>obsolete : Tells if the schema object is obsolete </li>
52   *   <li>extensions : The extensions, a key/Values map </li>
53   *   <li>schemaObjectType : The SchemaObject type (see upper) </li>
54   *   <li>schema : The schema the SchemaObject is associated with (it's an extension).
55   *   Can be null </li>
56   *   <li>isEnabled : The SchemaObject status (it's related to the schema status) </li>
57   *   <li>isReadOnly : Tells if the SchemaObject can be modified or not </li>
58   * </ul>
59   * <br><br>
60   * Some of those attributes are not used by some Schema elements, even if they should
61   * have been used. Here is the list :
62   * <ul>
63   *   <li><b>name</b> : LdapSyntax, Comparator, Normalizer, SyntaxChecker</li>
64   *   <li><b>numericOid</b> : DitStructureRule</li>
65   *   <li><b>obsolete</b> : LdapSyntax, Comparator, Normalizer, SyntaxChecker</li>
66   * </ul>
67   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
68   */
69  public interface SchemaObject
70  {
71      /**
72       * Gets usually what is the numeric object identifier assigned to this
73       * SchemaObject. All schema objects except for MatchingRuleUses have an OID
74       * assigned specifically to then. A MatchingRuleUse's OID really is the OID
75       * of it's MatchingRule and not specific to the MatchingRuleUse. This
76       * effects how MatchingRuleUse objects are maintained by the system.
77       * 
78       * @return an OID for this SchemaObject or its MatchingRule if this
79       *         SchemaObject is a MatchingRuleUse object
80       */
81      String getOid();
82  
83  
84      /**
85       * A special method used when renaming an SchemaObject: we may have to
86       * change it's OID
87       * @param oid The new OID
88       */
89      void setOid( String oid );
90  
91  
92      /**
93       * Gets short names for this SchemaObject if any exists for it, otherwise,
94       * returns an empty list.
95       * 
96       * @return the names for this SchemaObject
97       */
98      List<String> getNames();
99  
100 
101     /**
102      * Gets the first name in the set of short names for this SchemaObject if
103      * any exists for it.
104      * 
105      * @return the first of the names for this SchemaObject or the oid
106      * if one does not exist
107      */
108     String getName();
109 
110 
111     /**
112      * Add a new name to the list of names for this SchemaObject. The name
113      * is lower cased and trimmed.
114      * 
115      * @param names The names to add
116      */
117     void addName( String... names );
118 
119 
120     /**
121      * Sets the list of names for this SchemaObject. The names are
122      * lower cased and trimmed.
123      * 
124      * @param names The list of names. Can be empty
125      */
126     void setNames( List<String> names );
127 
128 
129     /**
130      * Gets a short description about this SchemaObject.
131      * 
132      * @return a short description about this SchemaObject
133      */
134     String getDescription();
135 
136 
137     /**
138      * Sets the SchemaObject's description
139      * 
140      * @param description The SchemaObject's description
141      */
142     void setDescription( String description );
143 
144 
145     /**
146      * Gets the SchemaObject specification.
147      * 
148      * @return the SchemaObject specification
149      */
150     String getSpecification();
151 
152 
153     /**
154      * Sets the SchemaObject's specification
155      * 
156      * @param specification The SchemaObject's specification
157      */
158     void setSpecification( String specification );
159 
160 
161     /**
162      * Tells if this SchemaObject is enabled.
163      * 
164      * @return true if the SchemaObject is enabled, or if it depends on
165      * an enabled schema
166      */
167     boolean isEnabled();
168 
169 
170     /**
171      * Tells if this SchemaObject is disabled.
172      * 
173      * @return true if the SchemaObject is disabled
174      */
175     boolean isDisabled();
176 
177 
178     /**
179      * Sets the SchemaObject state, either enabled or disabled.
180      * 
181      * @param enabled The current SchemaObject state
182      */
183     void setEnabled( boolean enabled );
184 
185 
186     /**
187      * Gets whether or not this SchemaObject has been inactivated. All
188      * SchemaObjects except Syntaxes allow for this parameter within their
189      * definition. For Syntaxes this property should always return false in
190      * which case it is never included in the description.
191      * 
192      * @return true if inactive, false if active
193      */
194     boolean isObsolete();
195 
196 
197     /**
198      * Sets the Obsolete flag.
199      * 
200      * @param obsolete The Obsolete flag state
201      */
202     void setObsolete( boolean obsolete );
203 
204 
205     /**
206      * @return The SchemaObject extensions, as a Map of [extension, values]
207      */
208     Map<String, List<String>> getExtensions();
209 
210 
211     /**
212      * Check if a given extension is part of the SchemaObject. Extensions are case insensitive.
213      * 
214      * @param extension The extension we are looking for.
215      * @return <code>true</code> if the extension is present.
216      */
217     boolean hasExtension( String extension );
218 
219 
220     /**
221      * Get back the values associated with a given extension.
222      * 
223      * @param extension The extension we are looking for.
224      * @return The list of values associated with the extension
225      */
226     List<String> getExtension( String extension );
227 
228 
229     /**
230      * Add an extension with its values
231      * @param key The extension key
232      * @param values The associated values
233      */
234     void addExtension( String key, String... values );
235 
236 
237     /**
238      * Add an extension with its values
239      * @param key The extension key
240      * @param values The associated values
241      */
242     void addExtension( String key, List<String> values );
243 
244 
245     /**
246      * Add an extensions with their values. (Actually do a copy)
247      * 
248      * @param extensions The extensions map
249      */
250     void setExtensions( Map<String, List<String>> extensions );
251 
252 
253     /**
254      * The SchemaObject type :
255      * <ul>
256      *   <li> AttributeType</li>
257      *   <li> DitCOntentRule</li>
258      *   <li> DitStructureRule</li>
259      *   <li> LdapComparator (specific to ADS)</li>
260      *   <li> LdapSyntaxe</li>
261      *   <li> MatchingRule</li>
262      *   <li> MatchingRuleUse</li>
263      *   <li> NameForm</li>
264      *   <li> Normalizer (specific to ADS)</li>
265      *   <li> ObjectClass</li>
266      *   <li> SyntaxChecker (specific to ADS)</li>
267      * </ul>
268      * 
269      * @return the SchemaObject type
270      */
271     SchemaObjectType getObjectType();
272 
273 
274     /**
275      * Gets the name of the schema this SchemaObject is associated with.
276      *
277      * @return the name of the schema associated with this schemaObject
278      */
279     String getSchemaName();
280 
281 
282     /**
283      * Sets the name of the schema this SchemaObject is associated with.
284      * 
285      * @param schemaName the new schema name
286      */
287     void setSchemaName( String schemaName );
288 
289 
290     /**
291      * {@inheritDoc}
292      */
293     @Override
294     int hashCode();
295 
296 
297     /**
298      * {@inheritDoc}
299      */
300     @Override
301     boolean equals( Object o1 );
302 
303 
304     /**
305      * Copy the current SchemaObject on place
306      *
307      * @return The copied SchemaObject
308      */
309     SchemaObject copy();
310 
311 
312     /**
313      * Copies the given schema object into this schema object.
314      *
315      * @param original the original SchemaObject
316      * @return this
317      */
318     SchemaObject copy( SchemaObject original );
319 
320 
321     /**
322      * Clear the current SchemaObject : remove all the references to other objects,
323      * and all the Maps.
324      */
325     void clear();
326 
327 
328     /**
329      * Transform the SchemaObject to an immutable object
330      * TODO locked.
331      *
332      */
333     void lock();
334 }