001/*
002 * Copyright 2020-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2020-2024 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2020-2024 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.schema;
037
038
039
040import com.unboundid.util.NotNull;
041import com.unboundid.util.Nullable;
042import com.unboundid.util.StaticUtils;
043import com.unboundid.util.ThreadSafety;
044import com.unboundid.util.ThreadSafetyLevel;
045
046
047
048/**
049 * This enum defines the types of elements that can make up an LDAP schema.
050 */
051@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
052public enum SchemaElementType
053{
054  /**
055   * The schema element type used to indicate the type of data that an attribute
056   * of a given type can hold.
057   */
058  ATTRIBUTE_SYNTAX("attribute-syntax", Schema.ATTR_ATTRIBUTE_SYNTAX),
059
060
061
062  /**
063   * The schema element type used to indicate how to perform matching operations
064   * against values for attributes of a given type.
065   */
066  MATCHING_RULE("matching-rule", Schema.ATTR_MATCHING_RULE),
067
068
069
070  /**
071   * The schema element type used to hold provide information about an
072   * attribute.
073   */
074  ATTRIBUTE_TYPE("attribute-type", Schema.ATTR_ATTRIBUTE_TYPE),
075
076
077
078  /**
079   * The schema element type used to define the sets of attributes that may be
080   * present in different types of entries.
081   */
082  OBJECT_CLASS("object-class", Schema.ATTR_OBJECT_CLASS),
083
084
085
086  /**
087   * The schema element type used to define the types of attributes that must
088   * and may be present in the RDN of an entry with a given structural object
089   * class.
090   */
091  NAME_FORM("name-form", Schema.ATTR_NAME_FORM),
092
093
094
095  /**
096   * The schema element type used to define additional constraints about
097   * attributes with a given structural object class, including allowed
098   * auxiliary object classes and required, optional, and prohibited attribute
099   * types.
100   */
101  DIT_CONTENT_RULE("dit-content-rule", Schema.ATTR_DIT_CONTENT_RULE),
102
103
104
105  /**
106   * The schema element type used to define allowed hierarchical relationships
107   * between entries with different types of structural object classes.
108   */
109  DIT_STRUCTURE_RULE("dit-structure-rule", Schema.ATTR_DIT_STRUCTURE_RULE),
110
111
112
113  /**
114   * The schema element type that may be used to restrict the set of attribute
115   * types with which a matching rule may be used.
116   */
117  MATCHING_RULE_USE("matching-rule-use", Schema.ATTR_MATCHING_RULE_USE);
118
119
120
121  // A name for this schema element type.
122  @NotNull private final String name;
123
124  // The name used to hold definitions for elements of this type in a subschema
125  // subentry.
126  @NotNull private final String subschemaAttributeTypeName;
127
128
129
130  /**
131   * Creates a new schema element type with the provided information.
132   *
133   * @param  name                        A name for this schema element type.
134   * @param  subschemaAttributeTypeName  The name used to hold definitions for
135   *                                     elements of this type in a subschema
136   *                                     subentry.
137   */
138  SchemaElementType(@NotNull final String name,
139                    @NotNull final String subschemaAttributeTypeName)
140  {
141    this.name = name;
142    this.subschemaAttributeTypeName = subschemaAttributeTypeName;
143  }
144
145
146
147  /**
148   * Retrieves the name for this schema element type.
149   *
150   * @return  The name for this schema element type.
151   */
152  @NotNull()
153  public String getName()
154  {
155    return name;
156  }
157
158
159
160  /**
161   * Retrieves the name used to hold definitions for elements of this type in a
162   * subschema subentry.
163   *
164   * @return  The name used to hold definitions for elements of this type in a
165   *          subschema subentry.
166   */
167  @NotNull()
168  public String getSubschemaAttributeTypeName()
169  {
170    return subschemaAttributeTypeName;
171  }
172
173
174
175  /**
176   * Retrieves the schema element type with the given name.
177   *
178   * @param  name  The name for the schema element type to retrieve.  It must
179   *               not be {@code null}.
180   *
181   * @return  The schema element type with the given name, or {@code null} if
182   *          there is no schema element type with that name.
183   */
184  @Nullable()
185  public static SchemaElementType forName(@NotNull final String name)
186  {
187    final String lowerName = StaticUtils.toLowerCase(name.replace('_', '-'));
188    switch (lowerName)
189    {
190      case "as":
191      case "syntax":
192      case "syntaxes":
193      case "attributesyntax":
194      case "attribute-syntax":
195      case "attributesyntaxes":
196      case "attribute-syntaxes":
197      case "attributetypesyntax":
198      case "attribute-type-syntax":
199      case "attributetypesyntaxes":
200      case "attribute-type-syntaxes":
201      case "attrsyntax":
202      case "attr-syntax":
203      case "attrsyntaxes":
204      case "attr-syntaxes":
205      case "attrtypesyntax":
206      case "attr-type-syntax":
207      case "attrtypesyntaxes":
208      case "attr-type-syntaxes":
209      case "ldapsyntax":
210      case "ldap-syntax":
211      case "ldapsyntaxes":
212      case "ldap-syntaxes":
213        return ATTRIBUTE_SYNTAX;
214
215      case "mr":
216      case "matchingrule":
217      case "matching-rule":
218      case "matchingrules":
219      case "matching-rules":
220        return MATCHING_RULE;
221
222      case "at":
223      case "type":
224      case "types":
225      case "attributetype":
226      case "attribute-type":
227      case "attributetypes":
228      case "attribute-types":
229      case "attrtype":
230      case "attr-type":
231      case "attrtypes":
232      case "attr-types":
233        return ATTRIBUTE_TYPE;
234
235      case "oc":
236      case "class":
237      case "classes":
238      case "objectclass":
239      case "object-class":
240      case "objectclasses":
241      case "object-classes":
242        return OBJECT_CLASS;
243
244      case "nf":
245      case "form":
246      case "forms":
247      case "nameform":
248      case "name-form":
249      case "nameforms":
250      case "name-forms":
251        return NAME_FORM;
252
253      case "dcr":
254      case "contentrule":
255      case "content-rule":
256      case "contentrules":
257      case "content-rules":
258      case "ditcontentrule":
259      case "dit-content-rule":
260      case "ditcontentrules":
261      case "dit-content-rules":
262        return DIT_CONTENT_RULE;
263
264      case "dsr":
265      case "structurerule":
266      case "structure-rule":
267      case "structurerules":
268      case "structure-rules":
269      case "ditstructurerule":
270      case "dit-structure-rule":
271      case "ditstructurerules":
272      case "dit-structure-rules":
273        return DIT_STRUCTURE_RULE;
274
275      case "mru":
276      case "use":
277      case "uses":
278      case "matchingruleuse":
279      case "matching-rule-use":
280      case "matchingruleuses":
281      case "matching-rule-uses":
282        return MATCHING_RULE_USE;
283
284      default:
285        return null;
286    }
287  }
288
289
290
291  /**
292   * Retrieves a string representation of this schema element type.
293   *
294   * @return  A string representation of this schema element type.
295   */
296  @Override()
297  @NotNull()
298  public String toString()
299  {
300    return name;
301  }
302}