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 +++++++++++++++++++++++++++++----
 1 files changed, 59 insertions(+), 8 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);
   }
 
   /**

--
Gitblit v1.10.0