Author: rhauch
Date: 2009-02-13 11:35:07 -0500 (Fri, 13 Feb 2009)
New Revision: 724
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/PropertyTypeTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/FakeRepositorySource.java
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PropertyType.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
Log:
DNA-283 fileSystemPaths property value is ignored for FileSystemSources configured through
XML
Changed RepositoryService to do a better job at figuring out how to convert the property
values in the configuration repository into value(s) that are acceptable to the setter
method. This uses the value factories to do the conversion, so RepositoryService really
only works with RepositorySource implementations that have property setters that accept
any of our known/supported property types or primitives (or arrays of those property types
or primitives).
In order to do this, I added a new method added to PropertyType to discover the property
type given a Class parameter.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PropertyType.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PropertyType.java 2009-02-12
22:27:44 UTC (rev 723)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/PropertyType.java 2009-02-13
16:35:07 UTC (rev 724)
@@ -32,6 +32,7 @@
import java.util.List;
import java.util.UUID;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.GraphI18n;
/**
@@ -119,6 +120,50 @@
}
/**
+ * Discover the most appropriate {@link PropertyType} whose values can be assigned to
variables or parameters of the supplied
+ * type. This method does check whether the supplied {@link Class} is an array, in
which case it just evalutes the
+ * {@link Class#getComponentType() component type} of the array.
+ *
+ * @param clazz the class representing the type of a value or parameter; may not be
null
+ * @return the PropertyType that best represents the type whose values can be used as
a value in the supplied class, or null
+ * if no matching PropertyType could be found
+ */
+ public static PropertyType discoverType( Class<?> clazz ) {
+ CheckArg.isNotNull(clazz, "clazz");
+ // Is the supplied class an array (or an array of arrays)?
+ while (clazz.isArray()) {
+ // Then just call extract the component type that of which we have an array
...
+ clazz = clazz.getComponentType();
+ }
+ // Try each property type, and see if its value type is an exact match ...
+ for (PropertyType type : PropertyType.values()) {
+ if (type.valueClass.equals(clazz)) return type;
+ // If the property type is capable of handling a primitive ...
+ switch (type) {
+ case LONG:
+ if (Long.TYPE.equals(clazz) || Integer.TYPE.equals(clazz) ||
Short.TYPE.equals(clazz)) return type;
+ if (Integer.class.equals(clazz) || Short.class.equals(clazz)) return
type;
+ break;
+ case DOUBLE:
+ if (Double.TYPE.equals(clazz) || Float.TYPE.equals(clazz)) return
type;
+ if (Float.class.equals(clazz)) return type;
+ break;
+ case BOOLEAN:
+ if (Boolean.TYPE.equals(clazz)) return type;
+ break;
+ default:
+ break;
+ }
+ }
+ // No value class of the property type matched exactly, so now see if any
property type is assignable to 'clazz' ...
+ for (PropertyType type : PropertyType.values()) {
+ if (clazz.isAssignableFrom(type.valueClass)) return type;
+ }
+ // Nothing works, ...
+ return null;
+ }
+
+ /**
* Return an iterator over all the property type enumeration literals.
*
* @return an immutable iterator
Added: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/PropertyTypeTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/PropertyTypeTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/PropertyTypeTest.java 2009-02-13
16:35:07 UTC (rev 724)
@@ -0,0 +1,220 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * Unless otherwise indicated, all code in JBoss DNA is licensed
+ * to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.graph.property;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URI;
+import java.util.UUID;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class PropertyTypeTest {
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenPrimitiveClass() throws Exception {
+ assertThat(PropertyType.discoverType(Integer.TYPE), is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(Long.TYPE), is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(Short.TYPE), is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(Boolean.TYPE), is(PropertyType.BOOLEAN));
+ assertThat(PropertyType.discoverType(Double.TYPE), is(PropertyType.DOUBLE));
+ assertThat(PropertyType.discoverType(Float.TYPE), is(PropertyType.DOUBLE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenNumberClass() throws Exception {
+ assertThat(PropertyType.discoverType(Integer.class), is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(Long.class), is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(Short.class), is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(Boolean.class), is(PropertyType.BOOLEAN));
+ assertThat(PropertyType.discoverType(Double.class), is(PropertyType.DOUBLE));
+ assertThat(PropertyType.discoverType(Float.class), is(PropertyType.DOUBLE));
+ assertThat(PropertyType.discoverType(BigDecimal.class),
is(PropertyType.DECIMAL));
+ }
+
+ @Test
+ public void shouldNotDiscoverPropertyTypeOfByteClass() {
+ assertThat(PropertyType.discoverType(Byte.class), is(nullValue()));
+ }
+
+ @Test
+ public void shouldNotDiscoverPropertyTypeOfBigIntegerClass() {
+ assertThat(PropertyType.discoverType(BigInteger.class), is(nullValue()));
+ }
+
+ @Test
+ public void shouldNotDiscoverPropertyTypeOfVoidClass() {
+ assertThat(PropertyType.discoverType(Void.TYPE), is(nullValue()));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenPrimitiveArrayClass() throws Exception {
+ assertThat(PropertyType.discoverType(new int[] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new long[] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new short[] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new boolean[] {}.getClass()),
is(PropertyType.BOOLEAN));
+ assertThat(PropertyType.discoverType(new double[] {}.getClass()),
is(PropertyType.DOUBLE));
+ assertThat(PropertyType.discoverType(new float[] {}.getClass()),
is(PropertyType.DOUBLE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArrayOfPrimitiveArrayClass() throws
Exception {
+ assertThat(PropertyType.discoverType(new int[][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new long[][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new short[][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new boolean[][] {}.getClass()),
is(PropertyType.BOOLEAN));
+ assertThat(PropertyType.discoverType(new double[][] {}.getClass()),
is(PropertyType.DOUBLE));
+ assertThat(PropertyType.discoverType(new float[][] {}.getClass()),
is(PropertyType.DOUBLE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArrayOfArrayOfPrimitiveArrayClass() throws
Exception {
+ assertThat(PropertyType.discoverType(new int[][][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new long[][][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new short[][][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new boolean[][][] {}.getClass()),
is(PropertyType.BOOLEAN));
+ assertThat(PropertyType.discoverType(new double[][][] {}.getClass()),
is(PropertyType.DOUBLE));
+ assertThat(PropertyType.discoverType(new float[][][] {}.getClass()),
is(PropertyType.DOUBLE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenNumberArrayClass() throws Exception {
+ assertThat(PropertyType.discoverType(new Integer[] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new Long[] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new Short[] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new Boolean[] {}.getClass()),
is(PropertyType.BOOLEAN));
+ assertThat(PropertyType.discoverType(new Double[] {}.getClass()),
is(PropertyType.DOUBLE));
+ assertThat(PropertyType.discoverType(new Float[] {}.getClass()),
is(PropertyType.DOUBLE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArrayOfNumberArrayClass() throws Exception
{
+ assertThat(PropertyType.discoverType(new Integer[][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new Long[][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new Short[][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new Boolean[][] {}.getClass()),
is(PropertyType.BOOLEAN));
+ assertThat(PropertyType.discoverType(new Double[][] {}.getClass()),
is(PropertyType.DOUBLE));
+ assertThat(PropertyType.discoverType(new Float[][] {}.getClass()),
is(PropertyType.DOUBLE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArrayOfArrayOfNumberArrayClass() throws
Exception {
+ assertThat(PropertyType.discoverType(new Integer[][][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new Long[][][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new Short[][][] {}.getClass()),
is(PropertyType.LONG));
+ assertThat(PropertyType.discoverType(new Boolean[][][] {}.getClass()),
is(PropertyType.BOOLEAN));
+ assertThat(PropertyType.discoverType(new Double[][][] {}.getClass()),
is(PropertyType.DOUBLE));
+ assertThat(PropertyType.discoverType(new Float[][][] {}.getClass()),
is(PropertyType.DOUBLE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenStringClass() throws Exception {
+ assertThat(PropertyType.discoverType(String.class), is(PropertyType.STRING));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenPathClass() throws Exception {
+ assertThat(PropertyType.discoverType(Path.class), is(PropertyType.PATH));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenNameClass() throws Exception {
+ assertThat(PropertyType.discoverType(Name.class), is(PropertyType.NAME));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenReferenceClass() throws Exception {
+ assertThat(PropertyType.discoverType(Reference.class),
is(PropertyType.REFERENCE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenDateTimeClass() throws Exception {
+ assertThat(PropertyType.discoverType(DateTime.class), is(PropertyType.DATE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenUriClass() throws Exception {
+ assertThat(PropertyType.discoverType(URI.class), is(PropertyType.URI));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenUuidClass() throws Exception {
+ assertThat(PropertyType.discoverType(UUID.class), is(PropertyType.UUID));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArraysOfStringClass() throws Exception {
+ assertThat(PropertyType.discoverType(new String[] {}.getClass()),
is(PropertyType.STRING));
+ assertThat(PropertyType.discoverType(new String[][] {}.getClass()),
is(PropertyType.STRING));
+ assertThat(PropertyType.discoverType(new String[][][] {}.getClass()),
is(PropertyType.STRING));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArraysOfPathClass() throws Exception {
+ assertThat(PropertyType.discoverType(new Path[] {}.getClass()),
is(PropertyType.PATH));
+ assertThat(PropertyType.discoverType(new Path[][] {}.getClass()),
is(PropertyType.PATH));
+ assertThat(PropertyType.discoverType(new Path[][][] {}.getClass()),
is(PropertyType.PATH));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArraysOfNameClass() throws Exception {
+ assertThat(PropertyType.discoverType(new Name[] {}.getClass()),
is(PropertyType.NAME));
+ assertThat(PropertyType.discoverType(new Name[][] {}.getClass()),
is(PropertyType.NAME));
+ assertThat(PropertyType.discoverType(new Name[][][] {}.getClass()),
is(PropertyType.NAME));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArraysOfReferenceClass() throws Exception
{
+ assertThat(PropertyType.discoverType(new Reference[] {}.getClass()),
is(PropertyType.REFERENCE));
+ assertThat(PropertyType.discoverType(new Reference[][] {}.getClass()),
is(PropertyType.REFERENCE));
+ assertThat(PropertyType.discoverType(new Reference[][][] {}.getClass()),
is(PropertyType.REFERENCE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArraysOfDateTimeClass() throws Exception
{
+ assertThat(PropertyType.discoverType(new DateTime[] {}.getClass()),
is(PropertyType.DATE));
+ assertThat(PropertyType.discoverType(new DateTime[][] {}.getClass()),
is(PropertyType.DATE));
+ assertThat(PropertyType.discoverType(new DateTime[][][] {}.getClass()),
is(PropertyType.DATE));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArraysOfUriClass() throws Exception {
+ assertThat(PropertyType.discoverType(new URI[] {}.getClass()),
is(PropertyType.URI));
+ assertThat(PropertyType.discoverType(new URI[][] {}.getClass()),
is(PropertyType.URI));
+ assertThat(PropertyType.discoverType(new URI[][][] {}.getClass()),
is(PropertyType.URI));
+ }
+
+ @Test
+ public void shouldDiscoverPropertyTypeGivenArraysOfUuidClass() throws Exception {
+ assertThat(PropertyType.discoverType(new UUID[] {}.getClass()),
is(PropertyType.UUID));
+ assertThat(PropertyType.discoverType(new UUID[][] {}.getClass()),
is(PropertyType.UUID));
+ assertThat(PropertyType.discoverType(new UUID[][][] {}.getClass()),
is(PropertyType.UUID));
+ }
+
+}
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2009-02-12
22:27:44 UTC (rev 723)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2009-02-13
16:35:07 UTC (rev 724)
@@ -24,6 +24,7 @@
package org.jboss.dna.repository;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -31,6 +32,7 @@
import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.collection.SimpleProblems;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.common.util.Reflection;
import org.jboss.dna.connector.federation.FederationException;
import org.jboss.dna.graph.DnaLexicon;
@@ -44,6 +46,7 @@
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathNotFoundException;
import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.PropertyType;
import org.jboss.dna.graph.property.ValueFactories;
import org.jboss.dna.graph.property.ValueFactory;
import org.jboss.dna.repository.service.AbstractServiceAdministrator;
@@ -263,46 +266,123 @@
problems.addError(err, RepositoryI18n.unableToInstantiateClassUsingClasspath,
classname, classpath);
}
- // Try to set the name property to the local name of the node...
+ // We need to set the name using the local name of the node, so hack this by
putting another name property
+ // into the map of properties. Since only the local name is used, we don't
care what the namespace of the
+ // fake property name is, so create something bogus. However, it really won't
hurt if this happens to override an existing
+ // property.
+ String fakeUri = DnaLexicon.Namespace.URI + "/300939b9dg93kd9gb";
+ Name nameName = context.getValueFactories().getNameFactory().create(fakeUri,
"name");
+ Property nameProperty = context.getPropertyFactory().create(nameName,
path.getLastSegment().getName().getLocalName());
+ properties.put(nameName, nameProperty);
+
+ // Now set all the properties that we can, ignoring any property that doesn't
fit the pattern ...
Reflection reflection = new Reflection(source.getClass());
- try {
- reflection.invokeSetterMethodOnTarget("name", source,
path.getLastSegment().getName().getLocalName());
- } catch (SecurityException err) {
- // Do nothing ... assume not a JavaBean property
- } catch (NoSuchMethodException err) {
- // Do nothing ... assume not a JavaBean property
- } catch (IllegalArgumentException err) {
- // Do nothing ... assume not a JavaBean property
- } catch (IllegalAccessException err) {
- // Do nothing ... assume not a JavaBean property
- } catch (InvocationTargetException err) {
- // Do nothing ... assume not a JavaBean property
- }
-
- // Now set all the properties that we can, ignoring any property that doesn't
fit pattern ...
for (Map.Entry<Name, Property> entry : properties.entrySet()) {
Name propertyName = entry.getKey();
Property property = entry.getValue();
String javaPropertyName = propertyName.getLocalName();
if (property.isEmpty()) continue;
+
Object value = null;
- if (property.isSingle()) {
- value = property.getValues().next();
- } else if (property.isMultiple()) {
- value = property.getValuesAsArray();
- }
+ Method setter = null;
try {
- reflection.invokeSetterMethodOnTarget(javaPropertyName, source, value);
+ setter = reflection.findFirstMethod("set" + javaPropertyName,
false);
+ if (setter == null) continue;
+ // Determine the type of the one parameter ...
+ Class<?>[] parameterTypes = setter.getParameterTypes();
+ if (parameterTypes.length != 1) continue; // not a valid JavaBean
property
+ Class<?> paramType = parameterTypes[0];
+ PropertyType allowedType = PropertyType.discoverType(paramType);
+ if (allowedType == null) continue; // assume not a JavaBean property with
usable type
+ ValueFactory<?> factory =
context.getValueFactories().getValueFactory(allowedType);
+ if (paramType.isArray()) {
+ if (paramType.getComponentType().isArray()) continue; // array of
array, which we don't do
+ Object[] values = factory.create(property.getValuesAsArray());
+ // Convert to an array of primitives if that's what the signature
requires ...
+ Class<?> componentType = paramType.getComponentType();
+ if (Integer.TYPE.equals(componentType)) {
+ int[] primitiveValues = new int[values.length];
+ for (int i = 0; i != values.length; ++i) {
+ primitiveValues[i] = ((Long)values[i]).intValue();
+ }
+ value = primitiveValues;
+ } else if (Short.TYPE.equals(componentType)) {
+ short[] primitiveValues = new short[values.length];
+ for (int i = 0; i != values.length; ++i) {
+ primitiveValues[i] = ((Long)values[i]).shortValue();
+ }
+ value = primitiveValues;
+ } else if (Long.TYPE.equals(componentType)) {
+ long[] primitiveValues = new long[values.length];
+ for (int i = 0; i != values.length; ++i) {
+ primitiveValues[i] = ((Long)values[i]).longValue();
+ }
+ value = primitiveValues;
+ } else if (Double.TYPE.equals(componentType)) {
+ double[] primitiveValues = new double[values.length];
+ for (int i = 0; i != values.length; ++i) {
+ primitiveValues[i] = ((Double)values[i]).doubleValue();
+ }
+ value = primitiveValues;
+ } else if (Float.TYPE.equals(componentType)) {
+ float[] primitiveValues = new float[values.length];
+ for (int i = 0; i != values.length; ++i) {
+ primitiveValues[i] = ((Double)values[i]).floatValue();
+ }
+ value = primitiveValues;
+ } else if (Boolean.TYPE.equals(componentType)) {
+ boolean[] primitiveValues = new boolean[values.length];
+ for (int i = 0; i != values.length; ++i) {
+ primitiveValues[i] = ((Boolean)values[i]).booleanValue();
+ }
+ value = primitiveValues;
+ } else {
+ value = values;
+ }
+ } else {
+ value = factory.create(property.getFirstValue());
+ // Convert to the correct primitive, if needed ...
+ if (Integer.TYPE.equals(paramType)) {
+ value = new Integer(((Long)value).intValue());
+ } else if (Short.TYPE.equals(paramType)) {
+ value = new Short(((Long)value).shortValue());
+ } else if (Float.TYPE.equals(paramType)) {
+ value = new Float(((Double)value).floatValue());
+ }
+ }
+ // Invoke the method ...
+ String msg = "Setting property {0} to {1} on source at {2} in
configuration repository {3} in workspace {4}";
+ Logger.getLogger(getClass()).trace(msg,
+ javaPropertyName,
+ value,
+ path,
+ configurationSourceName,
+ configurationWorkspaceName);
+ setter.invoke(source, value);
} catch (SecurityException err) {
- // Do nothing ... assume not a JavaBean property
- } catch (NoSuchMethodException err) {
- // Do nothing ... assume not a JavaBean property
+ Logger.getLogger(getClass()).debug(err, "Error invoking
{0}.{1}", source.getClass(), setter);
} catch (IllegalArgumentException err) {
- // Do nothing ... assume not a JavaBean property
+ // Do nothing ... assume not a JavaBean property (but log)
+ String msg = "Invalid argument invoking {0} with parameter {1} on
source at {2} in configuration repository {3} in workspace {4}";
+ Logger.getLogger(getClass()).debug(err,
+ msg,
+ setter,
+ value,
+ path,
+ configurationSourceName,
+ configurationWorkspaceName);
} catch (IllegalAccessException err) {
- // Do nothing ... assume not a JavaBean property
+ Logger.getLogger(getClass()).debug(err, "Error invoking
{0}.{1}", source.getClass(), setter);
} catch (InvocationTargetException err) {
- // Do nothing ... assume not a JavaBean property
+ // Do nothing ... assume not a JavaBean property (but log)
+ String msg = "Error invoking {0} with parameter {1} on source at {2}
in configuration repository {3} in workspace {4}";
+ Logger.getLogger(getClass()).debug(err.getTargetException(),
+ msg,
+ setter,
+ value,
+ path,
+ configurationSourceName,
+ configurationWorkspaceName);
}
}
return source;
Added:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/FakeRepositorySource.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/FakeRepositorySource.java
(rev 0)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/FakeRepositorySource.java 2009-02-13
16:35:07 UTC (rev 724)
@@ -0,0 +1,204 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * Unless otherwise indicated, all code in JBoss DNA is licensed
+ * to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.repository;
+
+import javax.naming.Reference;
+import org.apache.jackrabbit.spi.RepositoryService;
+import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositoryContext;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.RepositorySourceCapabilities;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+
+/**
+ * A fake {@link RepositorySource} implementation that has a variety of parameters, used
for testing whether
+ * {@link RepositoryService} can properly configure different kinds of properties.
+ */
+public class FakeRepositorySource implements RepositorySource {
+
+ /**
+ */
+ private static final long serialVersionUID = 1L;
+
+ private String name;
+ private int retryLimit;
+ private int intParam;
+ private short shortParam;
+ private boolean booleanParam;
+ private String stringParam;
+ private int[] intArrayParam;
+ private boolean[] booleanArrayParam;
+ private Long[] longObjectArrayParam;
+ private Boolean[] booleanObjectArrayParam;
+ private String[] stringArrayParam;
+
+ /**
+ *
+ */
+ public FakeRepositorySource() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getCapabilities()
+ */
+ public RepositorySourceCapabilities getCapabilities() {
+ return new RepositorySourceCapabilities();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getConnection()
+ */
+ public RepositoryConnection getConnection() throws RepositorySourceException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name Sets name to the specified value.
+ */
+ public void setName( String name ) {
+ this.name = name;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getRetryLimit()
+ */
+ public int getRetryLimit() {
+ return retryLimit;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#setRetryLimit(int)
+ */
+ public void setRetryLimit( int limit ) {
+ this.retryLimit = limit;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.connector.RepositorySource#initialize(org.jboss.dna.graph.connector.RepositoryContext)
+ */
+ public void initialize( RepositoryContext context ) throws RepositorySourceException
{
+ // do nothing
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.naming.Referenceable#getReference()
+ */
+ public Reference getReference() {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getIntParam() {
+ return intParam;
+ }
+
+ public void setIntParam( int intParam ) {
+ this.intParam = intParam;
+ }
+
+ public short getShortParam() {
+ return shortParam;
+ }
+
+ public void setShortParam( short shortParam ) {
+ this.shortParam = shortParam;
+ }
+
+ public boolean isBooleanParam() {
+ return booleanParam;
+ }
+
+ public void setBooleanParam( boolean booleanParam ) {
+ this.booleanParam = booleanParam;
+ }
+
+ public String getStringParam() {
+ return stringParam;
+ }
+
+ public void setStringParam( String stringParam ) {
+ this.stringParam = stringParam;
+ }
+
+ public int[] getIntArrayParam() {
+ return intArrayParam;
+ }
+
+ public void setIntArrayParam( int[] intArrayParam ) {
+ this.intArrayParam = intArrayParam;
+ }
+
+ public boolean[] getBooleanArrayParam() {
+ return booleanArrayParam;
+ }
+
+ public void setBooleanArrayParam( boolean[] booleanArrayParam ) {
+ this.booleanArrayParam = booleanArrayParam;
+ }
+
+ public Long[] getLongObjectArrayParam() {
+ return longObjectArrayParam;
+ }
+
+ public void setLongObjectArrayParam( Long[] longObjectArrayParam ) {
+ this.longObjectArrayParam = longObjectArrayParam;
+ }
+
+ public Boolean[] getBooleanObjectArrayParam() {
+ return booleanObjectArrayParam;
+ }
+
+ public void setBooleanObjectArrayParam( Boolean[] booleanObjectArrayParam ) {
+ this.booleanObjectArrayParam = booleanObjectArrayParam;
+ }
+
+ public String[] getStringArrayParam() {
+ return stringArrayParam;
+ }
+
+ public void setStringArrayParam( String[] stringArrayParam ) {
+ this.stringArrayParam = stringArrayParam;
+ }
+
+}
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2009-02-12
22:27:44 UTC (rev 723)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2009-02-13
16:35:07 UTC (rev 724)
@@ -197,6 +197,7 @@
@Test
public void
shouldStartUpAndCreateRepositoryUsingConfigurationRepositoryThatContainsNoSources() {
// Set up the configuration repository ...
+ configRepository.useWorkspace("default");
configRepository.create("/dna:sources");
configRepository.create("/dna:sources/source A");
@@ -251,4 +252,49 @@
// }
}
+ @Test
+ public void
shouldConfigureRepositorySourceWithSetterThatTakesArrayButWithSingleValues() {
+ RepositoryLibrary sources = new RepositoryLibrary(context);
+ sources.addSource(configRepositorySource);
+ service = new RepositoryService(sources, configSourceName, configWorkspaceName,
context);
+
+ // Set up the configuration repository ...
+ configRepository.useWorkspace("default");
+ configRepository.create("/dna:system");
+ configRepository.create("/dna:system/dna:sources");
+ configRepository.create("/dna:system/dna:sources/source A");
+
+ final String className = FakeRepositorySource.class.getName();
+
configRepository.set(DnaLexicon.CLASSNAME).on("/dna:system/dna:sources/source
A").to(className);
+
configRepository.set(DnaLexicon.CLASSPATH).on("/dna:system/dna:sources/source
A").to("");
+
configRepository.set("retryLimit").on("/dna:system/dna:sources/source
A").to(3);
+
configRepository.set("intParam").on("/dna:system/dna:sources/source
A").to("3");
+
configRepository.set("shortParam").on("/dna:system/dna:sources/source
A").to("32");
+
configRepository.set("booleanParam").on("/dna:system/dna:sources/source
A").to("true");
+
configRepository.set("stringParam").on("/dna:system/dna:sources/source
A").to("string value");
+
configRepository.set("intArrayParam").on("/dna:system/dna:sources/source
A").to("3");
+
configRepository.set("booleanArrayParam").on("/dna:system/dna:sources/source
A").to("true");
+
configRepository.set("longObjectArrayParam").on("/dna:system/dna:sources/source
A").to("987654321");
+
configRepository.set("booleanObjectArrayParam").on("/dna:system/dna:sources/source
A").to("true");
+
configRepository.set("stringArrayParam").on("/dna:system/dna:sources/source
A").to("string value");
+
+ // Now, start up the service ...
+ service.getAdministrator().start();
+
+ // Get the source, which should be configured ...
+ RepositorySource repositorySourceA =
service.getRepositorySourceManager().getSource("source A");
+ assertThat(repositorySourceA, is(instanceOf(FakeRepositorySource.class)));
+ FakeRepositorySource sourceA = (FakeRepositorySource)repositorySourceA;
+
+ assertThat(sourceA.getIntParam(), is(3));
+ assertThat(sourceA.getShortParam(), is((short)32));
+ assertThat(sourceA.isBooleanParam(), is(true));
+ assertThat(sourceA.getStringParam(), is("string value"));
+ assertThat(sourceA.getIntArrayParam(), is(new int[] {3}));
+ assertThat(sourceA.getBooleanArrayParam(), is(new boolean[] {true}));
+ assertThat(sourceA.getLongObjectArrayParam(), is(new Long[] {987654321L}));
+ assertThat(sourceA.getBooleanObjectArrayParam(), is(new Boolean[]
{Boolean.TRUE}));
+ assertThat(sourceA.getStringArrayParam(), is(new String[] {"string
value"}));
+ }
+
}