CommonSchemaElements.java revision 94e9037522922b67e8af412b4cfe476f5e991118
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2009 Sun Microsystems, Inc.
* Portions Copyright 2013-2015 ForgeRock AS
*/
/**
* An abstract base class for LDAP schema definitions which contain an
* OID, optional names, description, an obsolete flag, and an optional
* set of extra properties.
* <p>
* This class defines common properties and behaviour of the various
* types of schema definitions (e.g. object class definitions, and
* attribute type definitions).
* <p>
* Any methods which accesses the set of names associated with this
* definition, will retrieve the primary name as the first name,
* regardless of whether or not it was contained in the original set
* of <code>names</code> passed to the constructor.
* <p>
* Where ordered sets of names, or extra properties are provided, the
* ordering will be preserved when the associated fields are accessed
* via their getters or via the {@link #toString()} methods.
* <p>
* Note that these schema elements are not completely immutable, as
* the set of extra properties for the schema element may be altered
* after the element is created. Among other things, this allows the
* associated schema file to be edited so that an element created over
* protocol may be associated with a particular schema file.
*/
mayInstantiate=false,
mayExtend=false,
mayInvoke=true)
public abstract class CommonSchemaElements implements SchemaFileElement {
// Indicates whether this definition is declared "obsolete".
private final boolean isObsolete;
// The hash code for this definition.
private final int hashCode;
// The set of additional name-value pairs associated with this
// definition.
// The set of names for this definition, in a mapping between
// the all-lowercase form and the user-defined form.
// The description for this definition.
private final String description;
// The OID that may be used to reference this definition.
// The primary name to use for this definition.
private final String primaryName;
// The lower case name for this definition.
/**
* Creates a new definition with the provided information.
* <p>
* If no <code>primaryName</code> is specified, but a set of
* <code>names</code> is specified, then the first name retrieved
* from the set of <code>names</code> will be used as the primary
* name.
*
* @param primaryName
* The primary name for this definition, or
* <code>null</code> if there is no primary name.
* @param names
* The full set of names for this definition, or
* <code>null</code> if there are no names.
* @param oid
* The OID for this definition (must not be
* <code>null</code>).
* @param description
* The description for the definition, or <code>null</code>
* if there is no description.
* @param isObsolete
* Indicates whether this definition is declared
* "obsolete".
* @param extraProperties
* A set of extra properties for this definition, or
* <code>null</code> if there are no extra properties.
* @throws NullPointerException
* If the provided OID was <code>null</code>.
*/
throws NullPointerException {
// Make sure mandatory parameters are specified.
throw new NullPointerException(
"No oid specified in constructor");
}
this.description = description;
this.isObsolete = isObsolete;
// Make sure we have a primary name if possible.
if (primaryName == null) {
} else {
this.primaryName = null;
}
} else {
this.primaryName = primaryName;
}
// OPENDJ-1645: oid changes during server bootstrap, so prefer using name if available
// Construct the normalized attribute name mapping.
// Make sure the primary name is first (never null).
// Add the remaining names in the order specified.
}
} else if (this.primaryName != null) {
this.primaryName);
} else {
}
// FIXME: should really be a deep-copy.
if (extraProperties != null) {
} else {
}
}
/**
* Check if the extra schema properties contain safe filenames.
*
* @param extraProperties
* The schema properties to check.
*
* @throws DirectoryException
* If a provided value was unsafe.
*/
throws DirectoryException
{
// Check that X-SCHEMA-FILE doesn't contain unsafe characters
{
message);
}
}
}
/**
* Retrieves the primary name for this schema definition.
*
* @return The primary name for this schema definition, or
* <code>null</code> if there is no primary name.
*/
public final String getPrimaryName() {
return primaryName;
}
/**
* Retrieve the normalized primary name for this schema definition.
*
* @return Returns the normalized primary name for this attribute
* type, or <code>null</code> if there is no primary name.
*/
public final String getNormalizedPrimaryName() {
return lowerName;
}
/**
* Retrieves an iterable over the set of normalized names that may
* be used to reference this schema definition. The normalized form
* of an attribute name is defined as the user-defined name
* converted to lower-case.
*
* @return Returns an iterable over the set of normalized names that
* may be used to reference this schema definition.
*/
}
/**
* Retrieves an iterable over the set of user-defined names that may
* be used to reference this schema definition.
*
* @return Returns an iterable over the set of user-defined names
* that may be used to reference this schema definition.
*/
}
/**
* Indicates whether this schema definition has the specified name.
*
* @param lowerName
* The lowercase name for which to make the determination.
* @return <code>true</code> if the specified name is assigned to
* this schema definition, or <code>false</code> if not.
*/
}
/**
* Retrieves the OID for this schema definition.
*
* @return The OID for this schema definition.
*/
return oid;
}
/**
* Retrieves the name or OID for this schema definition. If it has
* one or more names, then the primary name will be returned. If it
* does not have any names, then the OID will be returned.
*
* @return The name or OID for this schema definition.
*/
public final String getNameOrOID() {
if (primaryName != null) {
return primaryName;
} else {
// Guaranteed not to be null.
return oid;
}
}
/**
* Retrieves the normalized primary name or OID for this schema
* definition. If it does not have any names, then the OID will be
* returned.
*
* @return The name or OID for this schema definition.
*/
public final String getNormalizedPrimaryNameOrOID() {
return lowerName;
} else {
// Guaranteed not to be null.
return oid;
}
}
/**
* Indicates whether this schema definition has the specified name
* or OID.
*
* @param lowerValue
* The lowercase value for which to make the determination.
* @return <code>true</code> if the provided value matches the OID
* or one of the names assigned to this schema definition,
* or <code>false</code> if not.
*/
}
/**
* Retrieves the name of the schema file that contains the
* definition for this schema definition.
*
* @param elem The element where to get the schema file from
* @return The name of the schema file that contains the definition
* for this schema definition, or <code>null</code> if it
* is not known or if it is not stored in any schema file.
*/
{
}
/**
* Retrieves the name of a single value property for this schema element.
*
* @param elem The element where to get the single value property from
* @param propertyName The name of the property to get
* @return The single value for this property, or <code>null</code> if it
* is this property is not set.
*/
{
}
return null;
}
/**
* Specifies the name of the schema file that contains the
* definition for this schema element. If a schema file is already
* defined in the set of extra properties, then it will be
* overwritten. If the provided schema file value is {@code null},
* then any existing schema file definition will be removed.
*
* @param elem The element where to set the schema file
* @param schemaFile The name of the schema file that contains the
* definition for this schema element.
*/
{
}
/**
* Retrieves the description for this schema definition.
*
* @return The description for this schema definition, or
* <code>null</code> if there is no description.
*/
public final String getDescription() {
return description;
}
/**
* Indicates whether this schema definition is declared "obsolete".
*
* @return <code>true</code> if this schema definition is declared
* "obsolete", or <code>false</code> if not.
*/
public final boolean isObsolete() {
return isObsolete;
}
/** {@inheritDoc} */
{
return extraProperties;
}
/**
* Sets the value for an "extra" property for this schema element.
* If a property already exists with the specified name, then it
* will be overwritten. If the value is {@code null}, then any
* existing property with the given name will be removed.
*
* @param elem The element where to set the extra property
* @param name The name for the "extra" property. It must not be
* {@code null}.
* @param value The value for the "extra" property. If it is
* {@code null}, then any existing definition will be
* removed.
*/
{
{
}
else
{
}
}
/**
* Sets the values for an "extra" property for this schema element.
* If a property already exists with the specified name, then it
* will be overwritten. If the set of values is {@code null} or
* empty, then any existing property with the given name will be
* removed.
*
* @param name The name for the "extra" property. It must not
* be {@code null}.
* @param values The set of values for the "extra" property. If
* it is {@code null} or empty, then any existing
* definition will be removed.
*/
{
}
else
{
}
}
/**
* Indicates whether the provided object is equal to this attribute
* type. The object will be considered equal if it is an attribute
* type with the same OID as the current type.
*
* @param o
* The object for which to make the determination.
* @return <code>true</code> if the provided object is equal to
* this schema definition, or <code>false</code> if not.
*/
if (this == o) {
return true;
}
if (o instanceof CommonSchemaElements) {
}
return false;
}
/**
* Retrieves the hash code for this schema definition. It will be
* based on the sum of the bytes of the OID.
*
* @return The hash code for this schema definition.
*/
public final int hashCode() {
return hashCode;
}
/**
* Retrieves the definition string used to create this attribute
* type and including the X-SCHEMA-FILE extension.
*
* @param elem The element where to get definition from
* @return The definition string used to create this attribute
* type including the X-SCHEMA-FILE extension.
*/
{
if (schemaFile != null)
{
}
return definition;
}
}