From 8e1f955e67af8e580b63fa5466861c057c25c36e Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Mon, 30 May 2016 10:43:13 +0000
Subject: [PATCH] OPENDJ-2987 Refactor ServerSchemaElement, SomeSchemaElement and CommonsSchemaElements classes This is a step toward future removal of SomeSchemaElement and CommonSchemaElements classes - Add more responsabilities in ServerSchemaElement class - SomeSchemaElement class delegates several methods to ServerSchemaElement class - Update javadoc of SomeSchemaElement and CommonSchemaElements classes
---
opendj-server-legacy/src/main/java/org/opends/server/schema/ServerSchemaElement.java | 67 +++++++++++++++++++--
opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java | 32 ++--------
opendj-server-legacy/src/main/java/org/opends/server/schema/SomeSchemaElement.java | 39 ++++--------
3 files changed, 81 insertions(+), 57 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/schema/ServerSchemaElement.java b/opendj-server-legacy/src/main/java/org/opends/server/schema/ServerSchemaElement.java
index f9ea629..326b892 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/schema/ServerSchemaElement.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/schema/ServerSchemaElement.java
@@ -15,7 +15,10 @@
*/
package org.opends.server.schema;
+import static org.opends.server.util.ServerConstants.SCHEMA_PROPERTY_FILENAME;
+
import java.util.List;
+import java.util.Map;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.Schema;
@@ -30,6 +33,7 @@
public class ServerSchemaElement
{
+ /** The underlying schema element. */
private final SchemaElement element;
/**
@@ -44,13 +48,56 @@
}
/**
- * Returns the schema file of the provided schema element.
+ * Retrieves the definition string used to create this schema element
+ * and including the X-SCHEMA-FILE extension.
*
- * @return the schema file of the provided schema element.
+ * @return The definition string used to create this attribute
+ * type including the X-SCHEMA-FILE extension.
*/
- public String getSchemaFile()
+ public String getDefinitionWithFileName()
{
- return getExtraPropertySingleValue(ServerConstants.SCHEMA_PROPERTY_FILENAME);
+ final String schemaFile = getSchemaFile();
+ final String definition = element.toString();
+ if (schemaFile != null)
+ {
+ int pos = definition.lastIndexOf(')');
+ return definition.substring(0, pos).trim() + " "
+ + SCHEMA_PROPERTY_FILENAME + " '" + schemaFile + "' )";
+ }
+ return definition;
+ }
+
+ /**
+ * Returns the description of this schema element.
+ *
+ * @return The description of this schema element, or the empty string if it does not have a description.
+ */
+ public String getDescription()
+ {
+ return element.getDescription();
+ }
+
+ /**
+ * Returns a map of extra properties of this schema element.
+ *
+ * @return An unmodifiable map containing all of the extra properties associated with this schema element.
+ */
+ public Map<String, List<String>> getExtraProperties()
+ {
+ return element.getExtraProperties();
+ }
+
+ /**
+ * Returns the single value of the provided extra property.
+ *
+ * @param property
+ * The name of property to retrieve.
+ * @return the single value of the property
+ */
+ public String getExtraPropertyAsSingleValue(String property)
+ {
+ List<String> values = element.getExtraProperties().get(property);
+ return values != null && !values.isEmpty() ? values.get(0) : null;
}
/**
@@ -60,13 +107,17 @@
*/
public String getOrigin()
{
- return getExtraPropertySingleValue(ServerConstants.SCHEMA_PROPERTY_ORIGIN);
+ return getExtraPropertyAsSingleValue(ServerConstants.SCHEMA_PROPERTY_ORIGIN);
}
- private String getExtraPropertySingleValue(String property)
+ /**
+ * Returns the schema file of the provided schema element.
+ *
+ * @return the schema file of the provided schema element.
+ */
+ public String getSchemaFile()
{
- List<String> values = element.getExtraProperties().get(property);
- return values != null && !values.isEmpty() ? values.get(0) : null;
+ return getExtraPropertyAsSingleValue(ServerConstants.SCHEMA_PROPERTY_FILENAME);
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/schema/SomeSchemaElement.java b/opendj-server-legacy/src/main/java/org/opends/server/schema/SomeSchemaElement.java
index 72e98ee..51936d9 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/schema/SomeSchemaElement.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/schema/SomeSchemaElement.java
@@ -28,23 +28,20 @@
import org.forgerock.opendj.ldap.schema.SchemaElement;
import org.opends.server.config.ConfigConstants;
import org.opends.server.core.ServerContext;
-import org.opends.server.types.CommonSchemaElements;
import org.opends.server.util.RemoveOnceSDKSchemaIsUsed;
-import org.opends.server.util.ServerConstants;
/**
- * Represents a schema element which is either a SDK attribute type or an objectclass from the server.
+ * Represents a schema element which is either an attribute type or an object class.
* <p>
- * In absence of a common interface, this class allows to process all elements in the same way,
- * and to provide useful server-oriented methods like {@code getSchemaFile()} or
- * {@code getOrigin()}.
+ * Allows to share the methods getOID(), getNameOrOID(), getNames() and a setter on extra properties.
*/
-@RemoveOnceSDKSchemaIsUsed("This class is a temporary mechanism"
- + " to manage in the same way SDK and server schema element classes")
+@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.
@@ -100,9 +97,13 @@
return attributeType != null;
}
- private SchemaElement asSchemaElement()
+ private ServerSchemaElement asSchemaElement()
{
- return attributeType != null ? attributeType : objectClass;
+ if (element == null)
+ {
+ element = attributeType != null ? new ServerSchemaElement(attributeType) : new ServerSchemaElement(objectClass);
+ }
+ return element;
}
/**
@@ -162,14 +163,7 @@
*/
public String getDefinitionWithFileName()
{
- final String schemaFile = getSchemaFile();
- final String definition = toString();
- if (schemaFile != null)
- {
- int pos = definition.lastIndexOf(')');
- return definition.substring(0, pos).trim() + " " + SCHEMA_PROPERTY_FILENAME + " '" + schemaFile + "' )";
- }
- return definition;
+ return asSchemaElement().getDefinitionWithFileName();
}
/**
@@ -179,7 +173,7 @@
*/
public String getSchemaFile()
{
- return getExtraPropertySingleValue(ServerConstants.SCHEMA_PROPERTY_FILENAME);
+ return asSchemaElement().getSchemaFile();
}
/**
@@ -201,12 +195,7 @@
*/
public String getOrigin()
{
- return getExtraPropertySingleValue(ServerConstants.SCHEMA_PROPERTY_ORIGIN);
- }
-
- private String getExtraPropertySingleValue(String schemaPropertyOrigin)
- {
- return CommonSchemaElements.getSingleValueProperty(asSchemaElement(), schemaPropertyOrigin);
+ return asSchemaElement().getOrigin();
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java b/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
index 4c1eee7..7fe718f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
@@ -30,30 +30,15 @@
import org.opends.server.util.RemoveOnceSDKSchemaIsUsed;
/**
- * 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.
+ * Utility class to retrieve information from a SchemaElement and to set extra property
+ * for a SchemaElement.
* <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 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.
+ * Note that {@code setSchemaFile()} method works ONLY for non-SDK classes, because SDK schema
+ * elements are immutable, so modifying the map fo extra properties has no effect on the actual
+ * element.
*/
-@RemoveOnceSDKSchemaIsUsed
+@RemoveOnceSDKSchemaIsUsed("All read methods can be provided by ServerSchemaElement class. Write method" +
+ " has to rebuild fully the schema element within the schema, which means specific code for each element")
public final class CommonSchemaElements
{
private CommonSchemaElements()
@@ -147,8 +132,7 @@
* @param value The value for the "extra" property. If it is
* {@code null}, then any existing definition will be removed.
*/
- public static void setExtraProperty(SchemaElement elem,
- String name, String value)
+ private static void setExtraProperty(SchemaElement elem, String name, String value)
{
ifNull(name);
--
Gitblit v1.10.0