You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2012/12/09 22:20:14 UTC
svn commit: r1419165 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/
main/java/org/apache/commons/configuration/builder/fluent/
test/java/org/apache/commons/configuration/builder/ test/java/org/apache/c...
Author: oheger
Date: Sun Dec 9 21:20:13 2012
New Revision: 1419165
URL: http://svn.apache.org/viewvc?rev=1419165&view=rev
Log:
Added parameters for JNDI configuration.
Added:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImpl.java (with props)
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImplBeanInfo.java (with props)
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderProperties.java (with props)
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/JndiBuilderParameters.java (with props)
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestJndiBuilderParametersImpl.java (with props)
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/Parameters.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/fluent/TestParameters.java
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImpl.java?rev=1419165&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImpl.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImpl.java Sun Dec 9 21:20:13 2012
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.naming.Context;
+
+/**
+ * <p>
+ * A specialized parameters object for JNDI configurations.
+ * </p>
+ * <p>
+ * In addition to the basic properties common to all configuration
+ * implementations, a JNDI configuration has some special properties defining
+ * the subset of the JNDI tree to be managed. This class provides fluent methods
+ * for setting these. The {@code getParameters()} method puts all properties
+ * defined by the user in a map from where they can be accessed by a builder for
+ * JNDI configurations.
+ * </p>
+ * <p>
+ * This class is not thread-safe. It is intended that an instance is constructed
+ * and initialized by a single thread during configuration of a
+ * {@code ConfigurationBuilder}.
+ * </p>
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+public class JndiBuilderParametersImpl extends BasicBuilderParameters implements
+ JndiBuilderProperties<JndiBuilderParametersImpl>
+{
+ /** Constant for the name of the context property. */
+ private static final String PROP_CONTEXT = "context";
+
+ /** Constant for the name of the prefix property. */
+ private static final String PROP_PREFIX = "prefix";
+
+ /** A map for storing the properties. */
+ private final Map<String, Object> properties;
+
+ /**
+ * Creates a new instance of {@code JndiBuilderParametersImpl}.
+ */
+ public JndiBuilderParametersImpl()
+ {
+ properties = new HashMap<String, Object>();
+ }
+
+ public JndiBuilderParametersImpl setContext(Context ctx)
+ {
+ properties.put(PROP_CONTEXT, ctx);
+ return this;
+ }
+
+ public JndiBuilderParametersImpl setPrefix(String p)
+ {
+ properties.put(PROP_PREFIX, p);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc} This implementation adds this object's own properties to
+ * the map returned by the base class.
+ */
+ @Override
+ public Map<String, Object> getParameters()
+ {
+ Map<String, Object> result = super.getParameters();
+ result.putAll(properties);
+ return result;
+ }
+}
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImplBeanInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImplBeanInfo.java?rev=1419165&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImplBeanInfo.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImplBeanInfo.java Sun Dec 9 21:20:13 2012
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder;
+
+/**
+ * An additional {@code BeanInfo} class for {@link JndiBuilderParametersImpl}.
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+public class JndiBuilderParametersImplBeanInfo extends
+ BuilderParametersBeanInfo
+{
+ /**
+ * Creates a new instance of {@code JndiBuilderParametersImplBeanInfo}.
+ */
+ public JndiBuilderParametersImplBeanInfo()
+ {
+ super(JndiBuilderParametersImpl.class);
+ }
+}
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImplBeanInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImplBeanInfo.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderParametersImplBeanInfo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderProperties.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderProperties.java?rev=1419165&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderProperties.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderProperties.java Sun Dec 9 21:20:13 2012
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder;
+
+import javax.naming.Context;
+
+/**
+ * <p>
+ * Definition of a properties interface for parameters of a JNDI configuration.
+ * </p>
+ * <p>
+ * This interface defines properties related to the JNDI tree to be represented
+ * by a {@code JNDIConfiguration}.
+ * </p>
+ *
+ * @version $Id$
+ * @since 2.0
+ * @param <T> the type of the result of all set methods for method chaining
+ */
+public interface JndiBuilderProperties<T>
+{
+ /**
+ * Sets the JNDI context to be used by the JNDI configuration.
+ *
+ * @param ctx the JNDI {@code Context}
+ * @return a reference to this object for method chaining
+ */
+ T setContext(Context ctx);
+
+ /**
+ * Sets the prefix in the JNDI tree. When creating the root JNDI context
+ * this prefix is taken into account.
+ *
+ * @param p the prefix
+ * @return a reference to this object for method chaining
+ */
+ T setPrefix(String p);
+}
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderProperties.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderProperties.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/JndiBuilderProperties.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/JndiBuilderParameters.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/JndiBuilderParameters.java?rev=1419165&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/JndiBuilderParameters.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/JndiBuilderParameters.java Sun Dec 9 21:20:13 2012
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder.fluent;
+
+import org.apache.commons.configuration.builder.BasicBuilderProperties;
+import org.apache.commons.configuration.builder.BuilderParameters;
+import org.apache.commons.configuration.builder.JndiBuilderProperties;
+
+/**
+ * <p>
+ * Definition of a parameters interface providing a fluent API for setting all
+ * properties for a JNDI configuration.
+ * </p>
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+public interface JndiBuilderParameters extends
+ BasicBuilderProperties<JndiBuilderParameters>,
+ JndiBuilderProperties<JndiBuilderParameters>, BuilderParameters
+{
+}
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/JndiBuilderParameters.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/JndiBuilderParameters.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/JndiBuilderParameters.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/Parameters.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/Parameters.java?rev=1419165&r1=1419164&r2=1419165&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/Parameters.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/fluent/Parameters.java Sun Dec 9 21:20:13 2012
@@ -23,6 +23,7 @@ import java.lang.reflect.Proxy;
import org.apache.commons.configuration.builder.BasicBuilderParameters;
import org.apache.commons.configuration.builder.BuilderParameters;
import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl;
+import org.apache.commons.configuration.builder.JndiBuilderParametersImpl;
import org.apache.commons.configuration.builder.combined.CombinedBuilderParametersImpl;
/**
@@ -104,6 +105,17 @@ public final class Parameters
}
/**
+ * Creates a new instance of a parameters object for JNDI configurations.
+ *
+ * @return the new parameters object
+ */
+ public static JndiBuilderParameters jndi()
+ {
+ return createParametersProxy(JndiBuilderParameters.class,
+ new JndiBuilderParametersImpl());
+ }
+
+ /**
* Creates a proxy object for a given parameters interface based on the
* given implementation object.
*
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestJndiBuilderParametersImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestJndiBuilderParametersImpl.java?rev=1419165&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestJndiBuilderParametersImpl.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestJndiBuilderParametersImpl.java Sun Dec 9 21:20:13 2012
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.util.Map;
+
+import javax.naming.Context;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test class for {@code JndiBuilderParametersImpl}.
+ *
+ * @version $Id$
+ */
+public class TestJndiBuilderParametersImpl
+{
+ /** The parameters object to be tested. */
+ private JndiBuilderParametersImpl params;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ params = new JndiBuilderParametersImpl();
+ }
+
+ /**
+ * Tests whether a JNDI context can be set.
+ */
+ @Test
+ public void testSetContext()
+ {
+ Context ctx = EasyMock.createMock(Context.class);
+ EasyMock.replay(ctx);
+ assertSame("Wrong result", params, params.setContext(ctx));
+ Map<String, Object> paramsMap = params.getParameters();
+ assertSame("Context not in map", ctx, paramsMap.get("context"));
+ }
+
+ /**
+ * Tests whether a prefix can be set.
+ */
+ @Test
+ public void testSetPrefix()
+ {
+ String prefix = "testJndiPrefix";
+ assertSame("Wrong result", params, params.setPrefix(prefix));
+ Map<String, Object> paramsMap = params.getParameters();
+ assertEquals("Prefix not in map", prefix, paramsMap.get("prefix"));
+ }
+
+ /**
+ * Tests whether the parameters map contains inherited properties, too.
+ */
+ @Test
+ public void testGetParametersBaseProperties()
+ {
+ params.setPrefix("somePrefix");
+ params.setListDelimiter('?');
+ Map<String, Object> paramsMap = params.getParameters();
+ assertEquals("Wrong delimiter parsing flag", Boolean.TRUE,
+ paramsMap.get("delimiterParsingDisabled"));
+ assertEquals("Wrong list delimiter", Character.valueOf('?'),
+ paramsMap.get("listDelimiter"));
+ }
+
+ /**
+ * Tests whether properties can be set through BeanUtils.
+ */
+ @Test
+ public void testSetBeanProperties() throws Exception
+ {
+ Context ctx = EasyMock.createMock(Context.class);
+ EasyMock.replay(ctx);
+ String prefix = "testJndiPrefix";
+ PropertyUtils.setProperty(params, "context", ctx);
+ PropertyUtils.setProperty(params, "prefix", prefix);
+ Map<String, Object> paramsMap = params.getParameters();
+ assertSame("Context not in map", ctx, paramsMap.get("context"));
+ assertEquals("Prefix not in map", prefix, paramsMap.get("prefix"));
+ }
+}
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestJndiBuilderParametersImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestJndiBuilderParametersImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestJndiBuilderParametersImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/fluent/TestParameters.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/fluent/TestParameters.java?rev=1419165&r1=1419164&r2=1419165&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/fluent/TestParameters.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/fluent/TestParameters.java Sun Dec 9 21:20:13 2012
@@ -45,6 +45,22 @@ public class TestParameters
}
/**
+ * Checks whether the given parameters map contains the standard values for
+ * basic properties.
+ *
+ * @param map the map to be tested
+ */
+ private static void checkBasicProperties(Map<String, Object> map)
+ {
+ assertEquals("Delimiter flag not set", Boolean.TRUE,
+ map.get("delimiterParsingDisabled"));
+ assertEquals("Wrong delimiter", Character.valueOf('#'),
+ map.get("listDelimiter"));
+ assertEquals("Wrong exception flag value", Boolean.TRUE,
+ map.get("throwExceptionOnMissing"));
+ }
+
+ /**
* Tests whether a file-based parameters object can be created.
*/
@Test
@@ -60,12 +76,7 @@ public class TestParameters
.getFileName());
assertEquals("Wrong encoding", "UTF-8", fbparams.getFileHandler()
.getEncoding());
- assertEquals("Delimiter flag not set", Boolean.TRUE,
- map.get("delimiterParsingDisabled"));
- assertEquals("Wrong delimiter", Character.valueOf('#'),
- map.get("listDelimiter"));
- assertEquals("Wrong exception flag value", Boolean.TRUE,
- map.get("throwExceptionOnMissing"));
+ checkBasicProperties(map);
}
/**
@@ -91,16 +102,25 @@ public class TestParameters
{
Map<String, Object> map =
Parameters.combined().setThrowExceptionOnMissing(true)
- .setBasePath("test").setListDelimiter('~')
+ .setBasePath("test").setListDelimiter('#')
.getParameters();
CombinedBuilderParametersImpl cparams =
CombinedBuilderParametersImpl.fromParameters(map);
assertEquals("Wrong base path", "test", cparams.getBasePath());
- assertEquals("Delimiter flag not set", Boolean.TRUE,
- map.get("delimiterParsingDisabled"));
- assertEquals("Wrong delimiter", Character.valueOf('~'),
- map.get("listDelimiter"));
- assertEquals("Wrong exception flag value", Boolean.TRUE,
- map.get("throwExceptionOnMissing"));
+ checkBasicProperties(map);
+ }
+
+ /**
+ * Tests whether a JNDI parameters object can be created.
+ */
+ @Test
+ public void testJndi()
+ {
+ Map<String, Object> map =
+ Parameters.jndi().setThrowExceptionOnMissing(true)
+ .setPrefix("test").setListDelimiter('#')
+ .getParameters();
+ assertEquals("Wrong prefix", "test", map.get("prefix"));
+ checkBasicProperties(map);
}
}