From efa949b25f472d7e4c39733678d8f0e5229f8201 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Thu, 26 Dec 2013 15:31:32 +0000
Subject: [PATCH] Checkpoint commit for OPENDJ-1235 : Migrate configuration framework
---
opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/DefaultManagedObject.java | 245 +++++++++++++++++++++---------------------------
1 files changed, 109 insertions(+), 136 deletions(-)
diff --git a/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/DefaultManagedObject.java b/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/DefaultManagedObject.java
index 09a16eb..3cb97c0 100644
--- a/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/DefaultManagedObject.java
+++ b/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/DefaultManagedObject.java
@@ -25,8 +25,6 @@
*/
package org.opends.server.admin;
-
-
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -34,166 +32,141 @@
import java.util.SortedSet;
import java.util.TreeSet;
-
-
/**
- * A default managed object which should be created when a parent
- * managed object is created. Default managed objects are associated
- * with a {@link RelationDefinition}.
+ * A default managed object which should be created when a parent managed object
+ * is created. Default managed objects are associated with a
+ * {@link RelationDefinition}.
*
* @param <C>
- * The type of client default managed object configuration.
+ * The type of client default managed object configuration.
* @param <S>
- * The type of server default managed object configuration.
+ * The type of server default managed object configuration.
*/
-public final class DefaultManagedObject
- <C extends ConfigurationClient, S extends Configuration>
- implements PropertyProvider {
+public final class DefaultManagedObject<C extends ConfigurationClient, S extends Configuration> implements
+ PropertyProvider {
- /**
- * An interface for incrementally constructing default managed
- * objects.
- *
- * @param <C>
- * The type of client default managed object configuration.
- * @param <S>
- * The type of server default managed object configuration.
- */
- public static final class Builder
- <C extends ConfigurationClient, S extends Configuration> {
+ /**
+ * An interface for incrementally constructing default managed objects.
+ *
+ * @param <C>
+ * The type of client default managed object configuration.
+ * @param <S>
+ * The type of server default managed object configuration.
+ */
+ public static final class Builder<C extends ConfigurationClient, S extends Configuration> {
+
+ // The default managed object's definition.
+ private final ManagedObjectDefinition<C, S> definition;
+
+ // The string encoded default managed object's properties.
+ private final Map<String, List<String>> propertyStringValues = new HashMap<String, List<String>>();
+
+ /**
+ * Creates a new default managed object builder.
+ *
+ * @param definition
+ * The default managed object's definition.
+ */
+ public Builder(ManagedObjectDefinition<C, S> definition) {
+ this.definition = definition;
+ }
+
+ /**
+ * Construct a default managed object based on the properties of this
+ * builder.
+ *
+ * @return Returns the new default managed object.
+ */
+ public DefaultManagedObject<C, S> getInstance() {
+ return new DefaultManagedObject<C, S>(definition, propertyStringValues);
+ }
+
+ /**
+ * Defines a property's values for the default managed object.
+ *
+ * @param name
+ * The name of the property.
+ * @param values
+ * One or more property values in the string representation.
+ */
+ public void setPropertyValues(String name, String... values) {
+ if (values == null || values.length == 0) {
+ throw new IllegalArgumentException("null or empty values specified for property " + name);
+ }
+
+ propertyStringValues.put(name, Arrays.asList(values));
+ }
+ }
// The default managed object's definition.
private final ManagedObjectDefinition<C, S> definition;
// The string encoded default managed object's properties.
- private final Map<String, List<String>> propertyStringValues =
- new HashMap<String, List<String>>();
+ private final Map<String, List<String>> propertyStringValues;
-
+ // Private constructor.
+ private DefaultManagedObject(ManagedObjectDefinition<C, S> definition,
+ Map<String, List<String>> propertyStringValues) {
+ this.definition = definition;
+ this.propertyStringValues = propertyStringValues;
+ }
/**
- * Creates a new default managed object builder.
+ * Gets the managed object definition associated with this default managed
+ * object.
*
- * @param definition
- * The default managed object's definition.
+ * @return Returns the managed object definition associated with this
+ * default managed object.
*/
- public Builder(ManagedObjectDefinition<C, S> definition) {
- this.definition = definition;
+ public ManagedObjectDefinition<C, S> getManagedObjectDefinition() {
+ return definition;
}
-
-
/**
- * Construct a default managed object based on the properties of
- * this builder.
+ * Gets a mutable copy of the set of property values for the specified
+ * property.
*
- * @return Returns the new default managed object.
+ * @param <T>
+ * The type of the property to be retrieved.
+ * @param pd
+ * The property to be retrieved.
+ * @return Returns a newly allocated set containing a copy of the property's
+ * values. An empty set indicates that the property has no values
+ * defined and any default behavior is applicable.
+ * @throws IllegalArgumentException
+ * If the property definition is not associated with this
+ * managed object's definition.
*/
- public DefaultManagedObject<C, S> getInstance() {
- return new DefaultManagedObject<C, S>(definition, propertyStringValues);
+ public <T> SortedSet<T> getPropertyValues(PropertyDefinition<T> pd) {
+ // Validate the property definition.
+ definition.getPropertyDefinition(pd.getName());
+
+ // Do a defensive copy.
+ SortedSet<T> values = new TreeSet<T>(pd);
+ List<String> stringValues = propertyStringValues.get(pd.getName());
+ if (stringValues != null) {
+ for (String stringValue : stringValues) {
+ values.add(pd.decodeValue(stringValue));
+ }
+ }
+ return values;
}
-
-
/**
- * Defines a property's values for the default managed object.
+ * Performs run-time initialization of properties.
*
- * @param name
- * The name of the property.
- * @param values
- * One or more property values in the string
- * representation.
+ * @throws Exception
+ * If this default managed object could not be initialized.
*/
- public void setPropertyValues(String name, String... values) {
- if (values == null || values.length == 0) {
- throw new IllegalArgumentException(
- "null or empty values specified for property " + name);
- }
+ void initialize() throws Exception {
+ // FIXME: it would be nice if we could decode all property values
+ // at this point. However this is not possible on the server side
+ // since some properties will be determined to be invalid since
+ // the schema is not loaded.
- propertyStringValues.put(name, Arrays.asList(values));
+ // Validate provided property names.
+ for (String name : propertyStringValues.keySet()) {
+ definition.getPropertyDefinition(name);
+ }
}
- }
-
- // The default managed object's definition.
- private final ManagedObjectDefinition<C, S> definition;
-
- // The string encoded default managed object's properties.
- private final Map<String, List<String>> propertyStringValues;
-
-
-
- // Private constructor.
- private DefaultManagedObject(ManagedObjectDefinition<C, S> definition,
- Map<String, List<String>> propertyStringValues) {
- this.definition = definition;
- this.propertyStringValues = propertyStringValues;
- }
-
-
-
- /**
- * Gets the managed object definition associated with this default
- * managed object.
- *
- * @return Returns the managed object definition associated with
- * this default managed object.
- */
- public ManagedObjectDefinition<C, S> getManagedObjectDefinition() {
- return definition;
- }
-
-
-
- /**
- * Gets a mutable copy of the set of property values for the
- * specified property.
- *
- * @param <T>
- * The type of the property to be retrieved.
- * @param pd
- * The property to be retrieved.
- * @return Returns a newly allocated set containing a copy of the
- * property's values. An empty set indicates that the
- * property has no values defined and any default behavior
- * is applicable.
- * @throws IllegalArgumentException
- * If the property definition is not associated with this
- * managed object's definition.
- */
- public <T> SortedSet<T> getPropertyValues(PropertyDefinition<T> pd)
- throws IllegalArgumentException {
- // Validate the property definition.
- definition.getPropertyDefinition(pd.getName());
-
- // Do a defensive copy.
- SortedSet<T> values = new TreeSet<T>(pd);
- List<String> stringValues = propertyStringValues.get(pd.getName());
- if (stringValues != null) {
- for (String stringValue : stringValues) {
- values.add(pd.decodeValue(stringValue));
- }
- }
- return values;
- }
-
-
-
- /**
- * Performs run-time initialization of properties.
- *
- * @throws Exception
- * If this default managed object could not be
- * initialized.
- */
- void initialize() throws Exception {
- // FIXME: it would be nice if we could decode all property values
- // at this point. However this is not possible on the server side
- // since some properties will be determined to be invalid since
- // the schema is not loaded.
-
- // Validate provided property names.
- for (String name : propertyStringValues.keySet()) {
- definition.getPropertyDefinition(name);
- }
- }
}
--
Gitblit v1.10.0