Package org.opends.server.util
Class SchemaUtils
- java.lang.Object
-
- org.opends.server.util.SchemaUtils
-
public class SchemaUtils extends Object
Utility methods related to schema.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSchemaUtils.PasswordTypeRepresents a password type, including a "not a password" value.static classSchemaUtils.SchemaFileFilterA file filter implementation that accepts only LDIF files.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringaddSchemaFileToElementDefinitionIfAbsent(String definition, String schemaFile)Adds the provided schema file to the provided schema element definition.static SchemaUtils.PasswordTypecheckPasswordType(AttributeType attrType)Checks if the provided attribute type contains a password.static ByteStringcreateBooleanValue(boolean b)Retrieves an attribute value containing a representation of the provided boolean value.static StringgetElementDefinitionWithFileName(SchemaElement element)Retrieves the definition string used to create the provided schema element and including the X-SCHEMA-FILE extension.static StringgetElementOrigin(SchemaElement element)Returns the origin of the provided schema element.static StringgetElementPropertyAsSingleValue(SchemaElement element, String property)Returns the single value of the provided extra property for the provided schema element.static StringgetElementSchemaFile(SchemaElement element)Returns the schema file of the provided schema element.static Collection<String>getNameOrOIDsForATs(Collection<AttributeType> attributeTypes)Returns a new collection with the result of callingAttributeType.getNameOrOID()on each element of the provided collection.static Collection<String>getNameOrOIDsForOCs(Collection<ObjectClass> objectClasses)Returns a new collection with the result of callingObjectClass.getNameOrOID()on each element of the provided collection.static AttributeTypegetNewAttributeTypeWithProperty(ServerContext serverContext, AttributeType attributeType, String property, String... values)Returns the new updated attribute type with the provided extra property and its values.static File[]getSchemaFiles(File schemaDirectory)Returns the list of schema files contained in the provided schema directory.static booleanis02ConfigLdif(String schemaFile)Indicates if the provided schema file corresponds to the configuration schema.static StringparseAttributeTypeOID(String definition)Returns the OID from the provided attribute type definition, assuming the definition is valid.static StringparseDITContentRuleOID(String definition)Returns the OID from the provided DIT content rule definition, assuming the definition is valid.static StringparseMatchingRuleUseOID(String definition)Returns the OID from the provided matching rule use definition, assuming the definition is valid.static StringparseNameFormOID(String definition)Returns the OID from the provided name form definition, assuming the definition is valid.static StringparseObjectClassOID(String definition)Returns the OID from the provided object class definition, assuming the definition is valid.static intparseRuleID(String definition)Returns the ruleID from the provided DIT structure rule definition, assuming the definition is valid.static StringparseSchemaFileFromElementDefinition(String definition)Parses the schema file (value of X-SCHEMA-FILE extension) from the provided schema element definition.static StringparseSyntaxOID(String definition)Returns the OID from the provided syntax definition, assuming the definition is valid.
-
-
-
Method Detail
-
checkPasswordType
public static SchemaUtils.PasswordType checkPasswordType(AttributeType attrType)
Checks if the provided attribute type contains a password.- Parameters:
attrType- The attribute type to check.- Returns:
- a PasswordTypeCheck result
-
createBooleanValue
public static ByteString createBooleanValue(boolean b)
Retrieves an attribute value containing a representation of the provided boolean value.- Parameters:
b- The boolean value for which to retrieve the attribute value.- Returns:
- The attribute value created from the provided boolean value.
-
getElementDefinitionWithFileName
public static String getElementDefinitionWithFileName(SchemaElement element)
Retrieves the definition string used to create the provided schema element and including the X-SCHEMA-FILE extension.- Parameters:
element- The schema element.- Returns:
- The definition string used to create the schema element including the X-SCHEMA-FILE extension.
-
getElementOrigin
public static String getElementOrigin(SchemaElement element)
Returns the origin of the provided schema element.- Parameters:
element- The schema element.- Returns:
- the origin of the schema element as defined in the extra properties.
-
getElementPropertyAsSingleValue
public static String getElementPropertyAsSingleValue(SchemaElement element, String property)
Returns the single value of the provided extra property for the provided schema element.- Parameters:
element- The schema element.property- The name of property to retrieve.- Returns:
- the single value of the extra property
-
getElementSchemaFile
public static String getElementSchemaFile(SchemaElement element)
Returns the schema file of the provided schema element.- Parameters:
element- The schema element.- Returns:
- the schema file of schema element.
-
getNameOrOIDsForOCs
public static Collection<String> getNameOrOIDsForOCs(Collection<ObjectClass> objectClasses)
Returns a new collection with the result of callingObjectClass.getNameOrOID()on each element of the provided collection.- Parameters:
objectClasses- the schema elements on which to act- Returns:
- a new collection comprised of the names or OIDs of each element
-
getNameOrOIDsForATs
public static Collection<String> getNameOrOIDsForATs(Collection<AttributeType> attributeTypes)
Returns a new collection with the result of callingAttributeType.getNameOrOID()on each element of the provided collection.- Parameters:
attributeTypes- the schema elements on which to act- Returns:
- a new collection comprised of the names or OIDs of each element
-
getNewAttributeTypeWithProperty
public static AttributeType getNewAttributeTypeWithProperty(ServerContext serverContext, AttributeType attributeType, String property, String... values)
Returns the new updated attribute type with the provided extra property and its values.- Parameters:
serverContext- the server contextattributeType- attribute type to updateproperty- the property to setvalues- the values to set- Returns:
- the new updated attribute type
-
getSchemaFiles
public static File[] getSchemaFiles(File schemaDirectory) throws InitializationException
Returns the list of schema files contained in the provided schema directory.- Parameters:
schemaDirectory- The directory containing schema files- Returns:
- the schema files
- Throws:
InitializationException- If the files can't be retrieved
-
addSchemaFileToElementDefinitionIfAbsent
public static String addSchemaFileToElementDefinitionIfAbsent(String definition, String schemaFile)
Adds the provided schema file to the provided schema element definition.- Parameters:
definition- The schema element definitionschemaFile- The name of the schema file to include in the definition- Returns:
- The definition string of the element including the X-SCHEMA-FILE extension.
-
parseSchemaFileFromElementDefinition
public static String parseSchemaFileFromElementDefinition(String definition) throws DirectoryException
Parses the schema file (value of X-SCHEMA-FILE extension) from the provided schema element definition.It expects a single value for the X-SCHEMA-FILE extension, e.g.: "X-SCHEMA-FILE '99-user.ldif'", as there is no sensible meaning for multiple values.
- Parameters:
definition- The definition of a schema element- Returns:
- the value of the schema file or
nullif the X-SCHEMA-FILE extension is not present in the definition - Throws:
DirectoryException- If an error occurs while parsing the schema element definition
-
parseAttributeTypeOID
public static String parseAttributeTypeOID(String definition) throws DirectoryException
Returns the OID from the provided attribute type definition, assuming the definition is valid.This method does not perform any check.
- Parameters:
definition- The definition of an attribute type, assumed to be valid- Returns:
- the OID, which is never
null - Throws:
DirectoryException- If a problem occurs while parsing the definition
-
parseObjectClassOID
public static String parseObjectClassOID(String definition) throws DirectoryException
Returns the OID from the provided object class definition, assuming the definition is valid.This method does not perform any check.
- Parameters:
definition- The definition of a object class, assumed to be valid- Returns:
- the OID, which is never
null - Throws:
DirectoryException- If a problem occurs while parsing the definition
-
parseNameFormOID
public static String parseNameFormOID(String definition) throws DirectoryException
Returns the OID from the provided name form definition, assuming the definition is valid.This method does not perform any check.
- Parameters:
definition- The definition of a name form, assumed to be valid- Returns:
- the OID, which is never
null - Throws:
DirectoryException- If a problem occurs while parsing the definition
-
parseDITContentRuleOID
public static String parseDITContentRuleOID(String definition) throws DirectoryException
Returns the OID from the provided DIT content rule definition, assuming the definition is valid.This method does not perform any check.
- Parameters:
definition- The definition of a DIT content rule, assumed to be valid- Returns:
- the OID, which is never
null - Throws:
DirectoryException- If a problem occurs while parsing the definition
-
parseRuleID
public static int parseRuleID(String definition) throws DirectoryException
Returns the ruleID from the provided DIT structure rule definition, assuming the definition is valid.This method does not perform any check.
- Parameters:
definition- The definition of a DIT structure rule, assumed to be valid- Returns:
- the OID, which is never
null - Throws:
DirectoryException- If a problem occurs while parsing the definition
-
parseMatchingRuleUseOID
public static String parseMatchingRuleUseOID(String definition) throws DirectoryException
Returns the OID from the provided matching rule use definition, assuming the definition is valid.This method does not perform any check.
- Parameters:
definition- The definition of a matching rule use, assumed to be valid- Returns:
- the OID, which is never
null - Throws:
DirectoryException- If a problem occurs while parsing the definition
-
parseSyntaxOID
public static String parseSyntaxOID(String definition) throws DirectoryException
Returns the OID from the provided syntax definition, assuming the definition is valid.This method does not perform any check.
- Parameters:
definition- The definition of a syntax, assumed to be valid- Returns:
- the OID, which is never
null - Throws:
DirectoryException- If a problem occurs while parsing the definition
-
is02ConfigLdif
public static boolean is02ConfigLdif(String schemaFile)
Indicates if the provided schema file corresponds to the configuration schema.The file containing the definitions of the schema elements used for configuration must not be imported nor propagated to other servers because these definitions may vary between versions of OpenDJ.
- Parameters:
schemaFile- The name of a file defining schema elements- Returns:
trueif the file defines configuration elements,falseotherwise
-
-