/* * The contents of this file are subject to the terms of the Common Development and * Distribution License (the License). You may not use this file except in compliance with the * License. * * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the * specific language governing permission and limitations under the License. * * When distributing Covered Software, include this CDDL Header Notice in each file and include * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions Copyright [year] [name of copyright owner]". * * Copyright 2015-2016 ForgeRock AS. */ package org.opends.server.schema; import static org.opends.server.util.ServerConstants.*; import java.util.Arrays; import java.util.List; import java.util.Map; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.ObjectClass; import org.forgerock.opendj.ldap.schema.Schema; import org.forgerock.opendj.ldap.schema.SchemaBuilder; import org.forgerock.opendj.ldap.schema.SchemaElement; import org.opends.server.config.ConfigConstants; import org.opends.server.core.ServerContext; import org.opends.server.util.RemoveOnceSDKSchemaIsUsed; /** * Represents a schema element which is either an attribute type or an object class. *
* Allows to share the methods getOID(), getNameOrOID(), getNames() and a setter on extra properties.
*/
@RemoveOnceSDKSchemaIsUsed("Some retrieval methods can be provided by ServerSchemaElement class. Others are only" +
"necessary for the control panel code, including the setter methods: specific control panel class could handle it.")
public class SomeSchemaElement implements SchemaElement
{
private ObjectClass objectClass;
private AttributeType attributeType;
private ServerSchemaElement element;
/**
* Builds SomeSchemaElement.
*
* @param objectClass
* the common schema element to wrap
*/
public SomeSchemaElement(ObjectClass objectClass)
{
this.objectClass = objectClass;
this.attributeType = null;
}
/**
* Builds SomeSchemaElement.
*
* @param attributeType
* the attribute type element to wrap
*/
public SomeSchemaElement(AttributeType attributeType)
{
this.objectClass = null;
this.attributeType = attributeType;
}
/**
* Returns the wrapped schema element as an object class.
*
* @return the wrapped object class
*/
public ObjectClass getObjectClass()
{
return objectClass;
}
/**
* Returns the wrapped schema element as an attribute type.
*
* @return the wrapped attribute type
*/
public AttributeType getAttributeType()
{
return attributeType;
}
/**
* Returns whether the wrapped element is an attribute type.
*
* @return {@code true} when the wrapped element is an attribute type, {@code false} otherwise
*/
public boolean isAttributeType()
{
return attributeType != null;
}
private ServerSchemaElement asSchemaElement()
{
if (element == null)
{
element = attributeType != null ? new ServerSchemaElement(attributeType) : new ServerSchemaElement(objectClass);
}
return element;
}
/**
* Returns the OID of the wrapped element.
*
* @return the OID of the wrapped element.
*/
public String getOID()
{
return attributeType != null ? attributeType.getOID() : objectClass.getOID();
}
/**
* Returns the name or OID of the wrapped element.
*
* @return the name or OID of the wrapped element.
*/
public String getNameOrOID()
{
return attributeType != null ? attributeType.getNameOrOID() : objectClass.getNameOrOID();
}
/**
* Returns the names of the wrapped element.
*
* @return the names of the wrapped element.
*/
public Iterable