001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 * 
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 * 
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 * 
019 */
020package org.apache.directory.api.ldap.model.schema;
021
022
023import java.util.List;
024import java.util.Map;
025
026
027/**
028 * Most schema objects have some common attributes. This class
029 * contains the minimum set of properties exposed by a SchemaObject.<br>
030 * We have 11 types of SchemaObjects :
031 * <ul>
032 *   <li> AttributeType </li>
033 *   <li> DitCOntentRule </li>
034 *   <li> DitStructureRule </li>
035 *   <li> LdapComparator (specific to ADS) </li>
036 *   <li> LdapSyntaxe </li>
037 *   <li> MatchingRule </li>
038 *   <li> MatchingRuleUse </li>
039 *   <li> NameForm </li>
040 *   <li> Normalizer (specific to ADS) </li>
041 *   <li> ObjectClass </li>
042 *   <li> SyntaxChecker (specific to ADS) </li>
043 * </ul>
044 * <br>
045 * <br>
046 * This class provides accessors and setters for the following attributes,
047 * which are common to all those SchemaObjects :
048 * <ul>
049 *   <li>oid : The numeric OID </li>
050 *   <li>description : The SchemaObject description </li>
051 *   <li>obsolete : Tells if the schema object is obsolete </li>
052 *   <li>extensions : The extensions, a key/Values map </li>
053 *   <li>schemaObjectType : The SchemaObject type (see upper) </li>
054 *   <li>schema : The schema the SchemaObject is associated with (it's an extension).
055 *   Can be null </li>
056 *   <li>isEnabled : The SchemaObject status (it's related to the schema status) </li>
057 *   <li>isReadOnly : Tells if the SchemaObject can be modified or not </li>
058 * </ul>
059 * <br><br>
060 * Some of those attributes are not used by some Schema elements, even if they should
061 * have been used. Here is the list :
062 * <ul>
063 *   <li><b>name</b> : LdapSyntax, Comparator, Normalizer, SyntaxChecker</li>
064 *   <li><b>numericOid</b> : DitStructureRule</li>
065 *   <li><b>obsolete</b> : LdapSyntax, Comparator, Normalizer, SyntaxChecker</li>
066 * </ul>
067 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
068 */
069public interface SchemaObject
070{
071    /**
072     * Gets usually what is the numeric object identifier assigned to this
073     * SchemaObject. All schema objects except for MatchingRuleUses have an OID
074     * assigned specifically to then. A MatchingRuleUse's OID really is the OID
075     * of it's MatchingRule and not specific to the MatchingRuleUse. This
076     * effects how MatchingRuleUse objects are maintained by the system.
077     * 
078     * @return an OID for this SchemaObject or its MatchingRule if this
079     *         SchemaObject is a MatchingRuleUse object
080     */
081    String getOid();
082
083
084    /**
085     * A special method used when renaming an SchemaObject: we may have to
086     * change it's OID
087     * @param oid The new OID
088     */
089    void setOid( String oid );
090
091
092    /**
093     * Gets short names for this SchemaObject if any exists for it, otherwise,
094     * returns an empty list.
095     * 
096     * @return the names for this SchemaObject
097     */
098    List<String> getNames();
099
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     * Tells if this SchemaObject is ReadOnly.
188     * 
189     * @return true if the SchemaObject is not modifiable
190     */
191    boolean isReadOnly();
192
193
194    /**
195     * Sets the SchemaObject readOnly flag
196     * 
197     * @param isReadOnly The current SchemaObject ReadOnly status
198     */
199    void setReadOnly( boolean isReadOnly );
200
201
202    /**
203     * Gets whether or not this SchemaObject has been inactivated. All
204     * SchemaObjects except Syntaxes allow for this parameter within their
205     * definition. For Syntaxes this property should always return false in
206     * which case it is never included in the description.
207     * 
208     * @return true if inactive, false if active
209     */
210    boolean isObsolete();
211
212
213    /**
214     * Sets the Obsolete flag.
215     * 
216     * @param obsolete The Obsolete flag state
217     */
218    void setObsolete( boolean obsolete );
219
220
221    /**
222     * @return The SchemaObject extensions, as a Map of [extension, values]
223     */
224    Map<String, List<String>> getExtensions();
225
226
227    /**
228     * Check if a given extension is part of the SchemaObject. Extensions are case insensitive.
229     * 
230     * @param extension The extension we are looking for.
231     * @return <code>true</code> if the extension is present.
232     */
233    boolean hasExtension( String extension );
234
235
236    /**
237     * Get back the values associated with a given extension.
238     * 
239     * @param extension The extension we are looking for.
240     * @return The list of values associated with the extension
241     */
242    List<String> getExtension( String extension );
243
244
245    /**
246     * Add an extension with its values
247     * @param key The extension key
248     * @param values The associated values
249     */
250    void addExtension( String key, String... values );
251
252
253    /**
254     * Add an extension with its values
255     * @param key The extension key
256     * @param values The associated values
257     */
258    void addExtension( String key, List<String> values );
259
260
261    /**
262     * Add an extensions with their values. (Actually do a copy)
263     * 
264     * @param extensions The extensions map
265     */
266    void setExtensions( Map<String, List<String>> extensions );
267
268
269    /**
270     * The SchemaObject type :
271     * <ul>
272     *   <li> AttributeType</li>
273     *   <li> DitCOntentRule</li>
274     *   <li> DitStructureRule</li>
275     *   <li> LdapComparator (specific to ADS)</li>
276     *   <li> LdapSyntaxe</li>
277     *   <li> MatchingRule</li>
278     *   <li> MatchingRuleUse</li>
279     *   <li> NameForm</li>
280     *   <li> Normalizer (specific to ADS)</li>
281     *   <li> ObjectClass</li>
282     *   <li> SyntaxChecker (specific to ADS)</li>
283     * </ul>
284     * 
285     * @return the SchemaObject type
286     */
287    SchemaObjectType getObjectType();
288
289
290    /**
291     * Gets the name of the schema this SchemaObject is associated with.
292     *
293     * @return the name of the schema associated with this schemaObject
294     */
295    String getSchemaName();
296
297
298    /**
299     * Sets the name of the schema this SchemaObject is associated with.
300     * 
301     * @param schemaName the new schema name
302     */
303    void setSchemaName( String schemaName );
304
305
306    /**
307     * {@inheritDoc}
308     */
309    @Override
310    int hashCode();
311
312
313    /**
314     * {@inheritDoc}
315     */
316    @Override
317    boolean equals( Object o1 );
318
319
320    /**
321     * Copy the current SchemaObject on place
322     *
323     * @return The copied SchemaObject
324     */
325    SchemaObject copy();
326
327
328    /**
329     * Copies the given schema object into this schema object.
330     *
331     * @param original the original SchemaObject
332     * @return this
333     */
334    SchemaObject copy( SchemaObject original );
335
336
337    /**
338     * Clear the current SchemaObject : remove all the references to other objects,
339     * and all the Maps.
340     */
341    void clear();
342
343
344    /**
345     * Transform the SchemaObject to an immutable object
346     *
347     */
348    void lock();
349}