From e114a899bbc0df59f5135f195d24797bf6c1b778 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Thu, 02 Jan 2014 09:33:43 +0000
Subject: [PATCH] Checkpoint commit for OPENDJ-1235 : Migrate configuration framework

---
 opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagementContext.java |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagementContext.java b/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagementContext.java
index 29e4164..010371b 100644
--- a/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagementContext.java
+++ b/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagementContext.java
@@ -59,6 +59,7 @@
 import org.opends.server.admin.ManagedObjectPath;
 import org.opends.server.admin.PropertyDefinition;
 import org.opends.server.admin.PropertyDefinitionVisitor;
+import org.opends.server.admin.PropertyDefinitionsOptions;
 import org.opends.server.admin.PropertyException;
 import org.opends.server.admin.PropertyIsMandatoryException;
 import org.opends.server.admin.PropertyIsSingleValuedException;
@@ -146,7 +147,7 @@
 
             for (String stringValue : stringValues) {
                 try {
-                    values.add(nextProperty.decodeValue(stringValue));
+                    values.add(nextProperty.decodeValue(stringValue, propertyDefOptions));
                 } catch (IllegalPropertyValueStringException e) {
                     exception = new DefaultBehaviorException(nextProperty, e);
                     break;
@@ -237,7 +238,7 @@
                 if (attributeValues.size() > 0) {
                     Collection<T> pvalues = new ArrayList<T>();
                     for (String value : attributeValues) {
-                        pvalues.add(ValueDecoder.decode(propDef1, value));
+                        pvalues.add(ValueDecoder.decode(propDef1, value, propertyDefOptions));
                     }
                     return pvalues;
                 } else {
@@ -245,7 +246,7 @@
                     Collection<T> tmp = find(target, propDef2);
                     Collection<T> pvalues = new ArrayList<T>(tmp.size());
                     for (T value : tmp) {
-                        propDef1.validateValue(value);
+                        propDef1.validateValue(value, propertyDefOptions);
                         pvalues.add(value);
                     }
                     return pvalues;
@@ -300,6 +301,8 @@
      */
     private static final class ValueDecoder extends PropertyDefinitionVisitor<Object, String> {
 
+        private final PropertyDefinitionsOptions options;
+
         /**
          * Decodes the provided property LDAP value.
          *
@@ -309,18 +312,21 @@
          *            The property definition.
          * @param value
          *            The LDAP string representation.
+         * @param options
+         *            Options to decode property definitions values.
          * @return Returns the decoded LDAP value.
          * @throws IllegalPropertyValueStringException
          *             If the property value could not be decoded because it was
          *             invalid.
          */
-        public static <P> P decode(PropertyDefinition<P> propertyDef, String value) {
-            return propertyDef.castValue(propertyDef.accept(new ValueDecoder(), value));
+        public static <P> P decode(PropertyDefinition<P> propertyDef, String value,
+            PropertyDefinitionsOptions options) {
+            return propertyDef.castValue(propertyDef.accept(new ValueDecoder(options), value));
         }
 
         // Prevent instantiation.
-        private ValueDecoder() {
-            // No implementation required.
+        private ValueDecoder(PropertyDefinitionsOptions options) {
+            this.options = options;
         }
 
         /**
@@ -345,7 +351,7 @@
         @Override
         public <T> Object visitUnknown(PropertyDefinition<T> d, String p) {
             // By default the property definition's decoder will do.
-            return d.decodeValue(p);
+            return d.decodeValue(p, options);
         }
     }
 
@@ -360,13 +366,23 @@
     private final ConfigurationRepository configRepository;
 
     /**
+     * Options to use when decoding and validating values of property
+     * definitions.
+     */
+    private final PropertyDefinitionsOptions propertyDefOptions;
+
+    /**
      * Creates a context from the provided configuration repository.
      *
      * @param repository
      *          The repository of configuration entries.
+     * @param propertyDefOptions
+     *          Options to use when decoding and validating values
+     *          of property definitions.
      */
-    ServerManagementContext(ConfigurationRepository repository) {
+    ServerManagementContext(ConfigurationRepository repository, PropertyDefinitionsOptions propertyDefOptions) {
         configRepository = repository;
+        this.propertyDefOptions = propertyDefOptions;
     }
 
     /**
@@ -530,8 +546,8 @@
      * @return the root configuration server managed object
      */
     public ServerManagedObject<RootCfg> getRootConfigurationManagedObject() {
-        // Use lazy initialisation because it needs a reference to this server
-        // context.
+        // Use lazy initialisation
+        // because it needs a reference to this server context.
         ServerManagedObject<RootCfg> rootObject = root;
         if (rootObject == null) {
             synchronized (this) {
@@ -711,7 +727,7 @@
             // The property has values defined for it.
             for (String value : attributeValues) {
                 try {
-                    pvalues.add(ValueDecoder.decode(propertyDef, value));
+                    pvalues.add(ValueDecoder.decode(propertyDef, value, propertyDefOptions));
                 } catch (IllegalPropertyValueStringException e) {
                     exception = e;
                 }

--
Gitblit v1.10.0