[jboss-cvs] JBossAS SVN: r88661 - in projects/bootstrap/trunk: impl-base/src/test/java/org/jboss/bootstrap/impl/base/config/unit and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 11 14:14:47 EDT 2009
Author: ALRubinger
Date: 2009-05-11 14:14:47 -0400 (Mon, 11 May 2009)
New Revision: 88661
Modified:
projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/AbstractBasicServerConfig.java
projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/config/unit/BasicConfigurationTestCase.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java
Log:
[JBBOOT-71] Allow setting of N properties at once, expose method to get a single property
Modified: projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/AbstractBasicServerConfig.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/AbstractBasicServerConfig.java 2009-05-11 17:58:55 UTC (rev 88660)
+++ projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/config/AbstractBasicServerConfig.java 2009-05-11 18:14:47 UTC (rev 88661)
@@ -198,6 +198,24 @@
}
/* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.config.ServerConfig#getProperty(java.lang.String)
+ */
+ public String getProperty(final String key) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (key == null)
+ {
+ throw new IllegalArgumentException("key must be specified");
+ }
+
+ // Obtain
+ final String value = this.properties.get(key);
+
+ // Return
+ return value;
+ }
+
+ /* (non-Javadoc)
* @see org.jboss.bootstrap.spi.config.ServerConfig#setBootstrapHome(java.net.URL)
*/
public synchronized T bootstrapHome(final URL bootstrapHome) throws IllegalArgumentException
@@ -259,8 +277,12 @@
*/
public T property(final String key, final String value) throws IllegalArgumentException
{
- // Precondition check
+ // Precondition checks
this.checkMutable();
+ if (key == null)
+ {
+ throw new IllegalArgumentException("Key may not be null");
+ }
// Set property
this.setPropertyForString(key, value);
@@ -270,6 +292,77 @@
}
/* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.config.ServerConfig#properties(java.util.Map)
+ */
+ public T properties(final Map<String, String> properties) throws IllegalArgumentException, IllegalStateException
+ {
+ // Precondition checks
+ this.checkMutable();
+ if (properties == null)
+ {
+ throw new IllegalArgumentException("properties may not be null");
+ }
+
+ // Set properties
+ for (final String propName : properties.keySet())
+ {
+ final String propValue = properties.get(propName);
+ this.setPropertyForString(propName, propValue);
+ }
+
+ // Return
+ return this.covarientReturn();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.config.ServerConfig#properties(java.util.Properties)
+ */
+ public T properties(final Properties properties) throws IllegalArgumentException, IllegalStateException
+ {
+ // Precondition check
+ this.checkMutable();
+ if (properties == null)
+ {
+ throw new IllegalArgumentException("properties may not be null");
+ }
+
+ // Set properties
+ for (final Object propName : properties.keySet())
+ {
+ // Get the key and cast
+ String propNameString = null;
+ try
+ {
+ propNameString = (String) propName;
+ }
+ catch (final ClassCastException cce)
+ {
+ throw new IllegalArgumentException("Properties supported must be in String/String pairs, but found: "
+ + propName + " of type: " + propName.getClass().getName(), cce);
+ }
+
+ // Get the value and cast
+ final Object propValue = properties.get(propNameString);
+ String propValueString = null;
+ try
+ {
+ propValueString = (String) propValue;
+ }
+ catch (final ClassCastException cce)
+ {
+ throw new IllegalArgumentException("Properties supported must be in String/String pairs, but found: "
+ + propName + " with value: " + propValue + "of type: " + propValue.getClass().getName(), cce);
+ }
+
+ // Set
+ this.setPropertyForString(propNameString, propValueString);
+ }
+
+ // Return
+ return this.covarientReturn();
+ }
+
+ /* (non-Javadoc)
* @see org.jboss.bootstrap.spi.config.ServerConfig#freeze()
*/
public void freeze() throws IllegalStateException
@@ -362,7 +455,6 @@
this.setPropertyForString(propertyName, stringValue);
}
-
/**
* Throws IllegalStateException if this configuration is frozen
*
Modified: projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/config/unit/BasicConfigurationTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/config/unit/BasicConfigurationTestCase.java 2009-05-11 17:58:55 UTC (rev 88660)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/config/unit/BasicConfigurationTestCase.java 2009-05-11 18:14:47 UTC (rev 88661)
@@ -23,6 +23,8 @@
package org.jboss.bootstrap.impl.base.config.unit;
import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
import junit.framework.TestCase;
@@ -84,6 +86,35 @@
.endsWith(TRAILING_SLASH));
}
+ @Test
+ public void testPropertiesSet() throws Throwable
+ {
+ // Log
+ log.info("testPropertiesSet");
+
+ // Make a config
+ final TestServerConfig configuration = new TestServerConfig();
+
+ // Set a bunch of properties at once
+ final String key1 = "key1";
+ final String key2 = "key2";
+ final String value1 = "value1";
+ final String value2 = "value2";
+ final Map<String, String> properties = new HashMap<String, String>();
+ properties.put(key1, value1);
+ properties.put(key2, value2);
+ configuration.properties(properties);
+
+ // Get out the props
+ final String actualValue1 = configuration.getProperty(key1);
+ final String actualValue2 = configuration.getProperty(key2);
+
+ // Test
+ final String failMessage = "Obtained wrong property from that expected";
+ TestCase.assertEquals(failMessage, value1, actualValue1);
+ TestCase.assertEquals(failMessage, value2, actualValue2);
+ }
+
//-------------------------------------------------------------------------------------||
// Internal Helper Methods ------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java 2009-05-11 17:58:55 UTC (rev 88660)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java 2009-05-11 18:14:47 UTC (rev 88661)
@@ -25,6 +25,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
+import java.util.Properties;
/**
* ServerConfig
@@ -149,6 +150,16 @@
Map<String, String> getProperties();
/**
+ * Returns the configuration property for the specified key,
+ * or null if not present
+ *
+ * @return
+ * @param key The key
+ * @throws IllegalArgumentException If the key was not specified
+ */
+ String getProperty(String key) throws IllegalArgumentException;
+
+ /**
* Sets the property with the specified key to the specified value
*
* @param key
@@ -160,6 +171,29 @@
T property(String key, String value) throws IllegalArgumentException, IllegalStateException;
/**
+ * Sets the specified properties upon the configuration
+ *
+ * @param properties
+ * @return
+ * @throws IllegalArgumentException If the properties are null
+ * @throws IllegalStateException If the configuration has been frozen
+ */
+ T properties(Map<String, String> properties) throws IllegalArgumentException, IllegalStateException;
+
+ /**
+ * Sets the specified properties upon the configuration. For true type safety,
+ * it is recommended to use {@link ServerConfig#properties(Map)} instead. This
+ * is provided for compatibility with {@link System#getProperties()}.
+ *
+ * @param properties
+ * @return
+ * @throws IllegalArgumentException If the properties are null, or if any of the
+ * properties are not String/String pairs.
+ * @throws IllegalStateException If the configuration has been frozen
+ */
+ T properties(Properties properties) throws IllegalArgumentException, IllegalStateException;
+
+ /**
* Freezes the configuration, marking it as immutable. Will typically
* be invoked by a server during the start lifecycle.
*
More information about the jboss-cvs-commits
mailing list