DNA SVN: r755 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-04 16:58:43 -0500 (Wed, 04 Mar 2009)
New Revision: 755
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java
Log:
DNA-293 JcrSession creates Property instances that use the PropertyType.UNDEFINED, which is not allowed
Changed JcrSession.populateNode(...) to never use PropertyType.UNDEFINED for the actual property type on a property. This means that even though UNDEFINED is allows on PropertyDefinition, it is not allowed on an actual Property instance. Therefore, I added the actual property type as an int field to JcrAbstractProperty, and modified the subclasses and the code where the constructors are called (mostly JcrSession and unit tests).
The current choice is to use PropertyType.STRING, since all property values can be converted to a String. See the issue for more details and a discussion of this logic.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2009-03-04 19:40:01 UTC (rev 754)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2009-03-04 21:58:43 UTC (rev 755)
@@ -47,10 +47,12 @@
private final ExecutionContext executionContext;
private final org.jboss.dna.graph.property.Property dnaProperty;
private final PropertyDefinition jcrPropertyDefinition;
+ private final int propertyType;
AbstractJcrProperty( Node node,
ExecutionContext executionContext,
PropertyDefinition definition,
+ int propertyType,
org.jboss.dna.graph.property.Property dnaProperty ) {
assert node != null;
assert executionContext != null;
@@ -60,6 +62,7 @@
this.executionContext = executionContext;
this.dnaProperty = dnaProperty;
this.jcrPropertyDefinition = definition;
+ this.propertyType = propertyType;
}
/**
@@ -91,7 +94,7 @@
* @see javax.jcr.Property#getType()
*/
public final int getType() {
- return jcrPropertyDefinition.getRequiredType();
+ return propertyType;
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2009-03-04 19:40:01 UTC (rev 754)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2009-03-04 21:58:43 UTC (rev 755)
@@ -44,8 +44,9 @@
JcrMultiValueProperty( Node node,
ExecutionContext executionContext,
PropertyDefinition definition,
+ int propertyType,
Property dnaProperty ) {
- super(node, executionContext, definition, dnaProperty);
+ super(node, executionContext, definition, propertyType, dnaProperty);
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-04 19:40:01 UTC (rev 754)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-04 21:58:43 UTC (rev 755)
@@ -633,7 +633,7 @@
case DATE:
return PropertyType.DATE;
case DECIMAL:
- return PropertyType.UNDEFINED;
+ return PropertyType.STRING; // better than losing information
case DOUBLE:
return PropertyType.DOUBLE;
case BINARY:
@@ -745,7 +745,8 @@
if (referenceable) {
if (uuidProperty == null) uuidProperty = executionContext.getPropertyFactory().create(JcrLexicon.UUID, uuid);
PropertyDefinition propertyDefinition = propertyDefinitionsByPropertyName.get(JcrLexicon.UUID);
- properties.add(new JcrSingleValueProperty(node, executionContext, propertyDefinition, uuidProperty));
+ properties.add(new JcrSingleValueProperty(node, executionContext, propertyDefinition, PropertyType.STRING,
+ uuidProperty));
}
// Now create the JCR property object wrappers around the other properties ...
@@ -805,11 +806,26 @@
continue;
}
+ // Figure out the property type ...
+ int propertyType = propertyDefinition.getRequiredType();
+ if (propertyType == PropertyType.UNDEFINED) {
+ // See DNA-293 for discussion. Best option is to use PropertyType.STRING, since values can always
+ // be converted to Strings (and because clients might use Property.getType() to decide how to
+ // manipulate or set values).
+ propertyType = PropertyType.STRING;
+
+ // // Or, we can choose the property type for the first value (or the default value, if there is one) ...
+ // Object value = dnaProp.getFirstValue();
+ // org.jboss.dna.graph.property.PropertyType dnaType =
+ // org.jboss.dna.graph.property.PropertyType.discoverType(value);
+ // propertyType = jcrPropertyTypeFor(dnaType);
+ }
+
// Create the appropriate JCR property wrapper ...
if (isMultiple) {
- properties.add(new JcrMultiValueProperty(node, executionContext, propertyDefinition, dnaProp));
+ properties.add(new JcrMultiValueProperty(node, executionContext, propertyDefinition, propertyType, dnaProp));
} else {
- properties.add(new JcrSingleValueProperty(node, executionContext, propertyDefinition, dnaProp));
+ properties.add(new JcrSingleValueProperty(node, executionContext, propertyDefinition, propertyType, dnaProp));
}
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java 2009-03-04 19:40:01 UTC (rev 754)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java 2009-03-04 21:58:43 UTC (rev 755)
@@ -43,10 +43,11 @@
final class JcrSingleValueProperty extends AbstractJcrProperty {
JcrSingleValueProperty( Node node,
- ExecutionContext executionContext,
- PropertyDefinition definition,
- Property dnaProperty ) {
- super(node, executionContext, definition, dnaProperty);
+ ExecutionContext executionContext,
+ PropertyDefinition definition,
+ int propertyType,
+ Property dnaProperty ) {
+ super(node, executionContext, definition, propertyType, dnaProperty);
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2009-03-04 19:40:01 UTC (rev 754)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2009-03-04 21:58:43 UTC (rev 755)
@@ -49,8 +49,7 @@
assert valueFactories != null;
assert type == PropertyType.BINARY || type == PropertyType.BOOLEAN || type == PropertyType.DATE
|| type == PropertyType.DOUBLE || type == PropertyType.LONG || type == PropertyType.NAME
- || type == PropertyType.PATH || type == PropertyType.REFERENCE || type == PropertyType.STRING
- || type == PropertyType.UNDEFINED;
+ || type == PropertyType.PATH || type == PropertyType.REFERENCE || type == PropertyType.STRING;
assert value != null;
this.valueFactories = valueFactories;
this.type = type;
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2009-03-04 19:40:01 UTC (rev 754)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2009-03-04 21:58:43 UTC (rev 755)
@@ -234,7 +234,7 @@
ExecutionContext executionContext,
PropertyDefinition propertyDefinition,
org.jboss.dna.graph.property.Property dnaProperty ) {
- super(node, executionContext, propertyDefinition, dnaProperty);
+ super(node, executionContext, propertyDefinition, propertyDefinition.getRequiredType(), dnaProperty);
}
/**
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java 2009-03-04 19:40:01 UTC (rev 754)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java 2009-03-04 21:58:43 UTC (rev 755)
@@ -85,7 +85,7 @@
addTestSuite(org.apache.jackrabbit.test.api.PathPropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.ReferencePropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.StringPropertyTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.UndefinedPropertyTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.UndefinedPropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NamespaceRegistryReadMethodsTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NamespaceRemappingTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NodeIteratorTest.class);
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java 2009-03-04 19:40:01 UTC (rev 754)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java 2009-03-04 21:58:43 UTC (rev 755)
@@ -59,7 +59,7 @@
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, true);
stub(definition.getRequiredType()).toReturn(PropertyType.BOOLEAN);
stub(definition.isMultiple()).toReturn(true);
- prop = new JcrMultiValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrMultiValueProperty(node, executionContext, definition, definition.getRequiredType(), dnaProperty);
}
@Test
@@ -138,7 +138,7 @@
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, value);
stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
stub(definition.isMultiple()).toReturn(true);
- prop = new JcrMultiValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrMultiValueProperty(node, executionContext, definition, definition.getRequiredType(), dnaProperty);
lengths = prop.getLengths();
assertThat(lengths, notNullValue());
assertThat(lengths.length, is(1));
@@ -149,7 +149,7 @@
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, value);
stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
stub(definition.isMultiple()).toReturn(true);
- prop = new JcrMultiValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrMultiValueProperty(node, executionContext, definition, definition.getRequiredType(), dnaProperty);
lengths = prop.getLengths();
assertThat(lengths, notNullValue());
assertThat(lengths.length, is(1));
@@ -159,7 +159,7 @@
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, (Object[])values);
stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
stub(definition.isMultiple()).toReturn(true);
- prop = new JcrMultiValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrMultiValueProperty(node, executionContext, definition, definition.getRequiredType(), dnaProperty);
lengths = prop.getLengths();
assertThat(lengths, notNullValue());
assertThat(lengths.length, is(values.length));
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java 2009-03-04 19:40:01 UTC (rev 754)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java 2009-03-04 21:58:43 UTC (rev 755)
@@ -65,16 +65,14 @@
MockitoAnnotations.initMocks(this);
executionContext = new ExecutionContext();
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "text/plain");
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
stub(definition.isMultiple()).toReturn(false);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.STRING, dnaProperty);
}
@Test
public void shouldProvideBoolean() throws Exception {
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "true");
- stub(definition.getRequiredType()).toReturn(PropertyType.BOOLEAN);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.BOOLEAN, dnaProperty);
assertThat(prop.getBoolean(), is(true));
assertThat(prop.getType(), is(PropertyType.BOOLEAN));
}
@@ -90,8 +88,7 @@
public void shouldProvideDate() throws Exception {
DateTime dnaDate = executionContext.getValueFactories().getDateFactory().create();
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, dnaDate);
- stub(definition.getRequiredType()).toReturn(PropertyType.DATE);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.DATE, dnaProperty);
assertThat(prop.getDate(), is(dnaDate.toCalendar()));
assertThat(prop.getLong(), is(dnaDate.getMilliseconds()));
assertThat(prop.getType(), is(PropertyType.DATE));
@@ -102,12 +99,11 @@
public void shouldProvideNode() throws Exception {
UUID referencedUuid = UUID.randomUUID();
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, referencedUuid);
- stub(definition.getRequiredType()).toReturn(PropertyType.REFERENCE);
Node referencedNode = mock(Node.class);
JcrSession session = mock(JcrSession.class);
stub(node.getSession()).toReturn(session);
stub(session.getNode(referencedUuid)).toReturn(referencedNode);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.REFERENCE, dnaProperty);
assertThat(prop.getNode(), is(referencedNode));
assertThat(prop.getType(), is(PropertyType.REFERENCE));
assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
@@ -116,13 +112,12 @@
@Test
public void shouldProvideDouble() throws Exception {
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1.0);
- stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.DOUBLE, dnaProperty);
assertThat(prop.getDouble(), is(1.0));
assertThat(prop.getType(), is(PropertyType.DOUBLE));
assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1.0F);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.DOUBLE, dnaProperty);
assertThat(prop.getDouble(), is(1.0));
assertThat(prop.getType(), is(PropertyType.DOUBLE));
assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
@@ -131,15 +126,13 @@
@Test
public void shouldProvideLong() throws Exception {
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1);
- stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.DOUBLE, dnaProperty);
assertThat(prop.getLong(), is(1L));
assertThat(prop.getType(), is(PropertyType.DOUBLE));
assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1L);
- stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.DOUBLE, dnaProperty);
assertThat(prop.getLong(), is(1L));
assertThat(prop.getString(), is("1"));
assertThat(prop.getType(), is(PropertyType.DOUBLE));
@@ -149,8 +142,7 @@
@Test
public void shouldProvideStream() throws Exception {
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, new Object());
- stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.BINARY, dnaProperty);
assertThat(prop.getType(), is(PropertyType.BINARY));
assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
InputStream stream = prop.getStream();
@@ -166,8 +158,7 @@
@Test
public void shouldProvideString() throws Exception {
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "value");
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.STRING, dnaProperty);
assertThat(prop.getString(), is("value"));
assertThat(prop.getType(), is(PropertyType.STRING));
assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
@@ -177,8 +168,7 @@
public void shouldAllowReferenceValue() throws Exception {
UUID uuid = UUID.randomUUID();
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, uuid);
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.STRING, dnaProperty);
assertThat(prop.getString(), is(uuid.toString()));
assertThat(prop.getType(), is(PropertyType.STRING));
assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
@@ -189,8 +179,7 @@
executionContext.getNamespaceRegistry().register("acme", "http://example.com");
Name path = executionContext.getValueFactories().getNameFactory().create("acme:something");
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, path);
- stub(definition.getRequiredType()).toReturn(PropertyType.NAME);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.NAME, dnaProperty);
assertThat(prop.getString(), is("acme:something"));
assertThat(prop.getType(), is(PropertyType.NAME));
assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
@@ -204,8 +193,7 @@
executionContext.getNamespaceRegistry().register("acme", "http://example.com");
Path path = executionContext.getValueFactories().getPathFactory().create("/a/b/acme:c");
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, (Object)path);
- stub(definition.getRequiredType()).toReturn(PropertyType.PATH);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.PATH, dnaProperty);
assertThat(prop.getString(), is("/a/b/acme:c"));
assertThat(prop.getType(), is(PropertyType.PATH));
assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
@@ -232,15 +220,13 @@
dnaValue = "some other value";
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, dnaValue);
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.STRING, dnaProperty);
assertThat(prop.getLength(), is((long)dnaValue.length()));
Object obj = new Object();
long binaryLength = executionContext.getValueFactories().getBinaryFactory().create(obj).getSize();
dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, obj);
- stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
- prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, PropertyType.BINARY, dnaProperty);
assertThat(prop.getLength(), is(binaryLength));
}
15 years, 2 months
DNA SVN: r754 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-04 14:40:01 -0500 (Wed, 04 Mar 2009)
New Revision: 754
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
Log:
DNA-291 JCR property objects do not have PropertyDefinition
Changed the JcrSession.populateNode(...) method to look for "*" property definitions in the primary type or mixins' NodeType, and to use that for properties for which there is no explicit property defintion.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-04 19:11:34 UTC (rev 753)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-04 19:40:01 UTC (rev 754)
@@ -31,6 +31,9 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@@ -79,6 +82,12 @@
@NotThreadSafe
class JcrSession implements Session {
+ /**
+ * Hidden flag that controls whether properties that appear on DNA nodes but not allowed by the node type or mixins should be
+ * included anyway. This is currently {@value} .
+ */
+ private static final boolean INCLUDE_PROPERTIES_NOT_ALLOWED_BY_NODE_TYPE_OR_MIXINS = true;
+
private static final String[] NO_ATTRIBUTES_NAMES = new String[] {};
/**
@@ -659,14 +668,21 @@
ValueFactories factories = executionContext.getValueFactories();
NameFactory nameFactory = factories.getNameFactory();
NodeTypeManager nodeTypeManager = getWorkspace().getNodeTypeManager();
+ List<PropertyDefinition> anyPropertyDefinitions = new LinkedList<PropertyDefinition>();
org.jboss.dna.graph.property.Property primaryTypeProperty = graphNode.getProperty(JcrLexicon.PRIMARY_TYPE);
if (primaryTypeProperty != null && !primaryTypeProperty.isEmpty()) {
Name primaryTypeName = nameFactory.create(primaryTypeProperty.getFirstValue());
String primaryTypeNameString = primaryTypeName.getString(registry);
NodeType primaryType = nodeTypeManager.getNodeType(primaryTypeNameString);
for (PropertyDefinition propertyDefn : primaryType.getPropertyDefinitions()) {
- Name name = nameFactory.create(propertyDefn.getName());
- propertyDefinitionsByPropertyName.put(name, propertyDefn);
+ String nameString = propertyDefn.getName();
+ if ("*".equals(nameString)) {
+ anyPropertyDefinitions.add(propertyDefn);
+ continue;
+ }
+ Name name = nameFactory.create(nameString);
+ PropertyDefinition prev = propertyDefinitionsByPropertyName.put(name, propertyDefn);
+ if (prev != null) propertyDefinitionsByPropertyName.put(name, prev); // put the first one back ...
}
}
org.jboss.dna.graph.property.Property mixinTypesProperty = graphNode.getProperty(JcrLexicon.MIXIN_TYPES);
@@ -677,8 +693,14 @@
String mixinTypeNameString = mixinTypeName.getString(registry);
NodeType primaryType = nodeTypeManager.getNodeType(mixinTypeNameString);
for (PropertyDefinition propertyDefn : primaryType.getPropertyDefinitions()) {
- Name name = nameFactory.create(propertyDefn.getName());
- propertyDefinitionsByPropertyName.put(name, propertyDefn);
+ String nameString = propertyDefn.getName();
+ if ("*".equals(nameString)) {
+ anyPropertyDefinitions.add(propertyDefn);
+ continue;
+ }
+ Name name = nameFactory.create(nameString);
+ PropertyDefinition prev = propertyDefinitionsByPropertyName.put(name, propertyDefn);
+ if (prev != null) propertyDefinitionsByPropertyName.put(name, prev); // put the first one back ...
}
}
}
@@ -736,21 +758,45 @@
// Figure out the JCR property type for this property ...
PropertyDefinition propertyDefinition = propertyDefinitionsByPropertyName.get(name);
- // If no property type was specified, then use "nt:unstructured" property definitions for any property
+ // If no property type was found for this property, see if there is a wildcard property ...
+ if (propertyDefinition == null && !anyPropertyDefinitions.isEmpty()) {
+ Iterator<PropertyDefinition> iter = anyPropertyDefinitions.iterator();
+ propertyDefinition = iter.next(); // use the first one by default ...
+ if (iter.hasNext()) {
+ // Look for a better one if not multiple but the property has multiple values ...
+ if (!propertyDefinition.isMultiple() && dnaProp.isMultiple()) {
+ while (iter.hasNext()) {
+ PropertyDefinition next = iter.next();
+ if (next.isMultiple()) {
+ propertyDefinition = next;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ // If there still is no property type defined ...
if (propertyDefinition == null) {
- if (anyMultiplePropertyDefinition == null) {
- String unstructuredName = JcrNtLexicon.UNSTRUCTURED.getString(registry);
- NodeType unstructured = nodeTypeManager.getNodeType(unstructuredName);
- for (PropertyDefinition definition : unstructured.getDeclaredPropertyDefinitions()) {
- if (definition.isMultiple()) {
- anyMultiplePropertyDefinition = definition;
+ assert anyPropertyDefinitions.isEmpty();
+ if (INCLUDE_PROPERTIES_NOT_ALLOWED_BY_NODE_TYPE_OR_MIXINS) {
+ // We can use the "nt:unstructured" property definitions for any property ...
+ if (anyMultiplePropertyDefinition == null) {
+ String unstructuredName = JcrNtLexicon.UNSTRUCTURED.getString(registry);
+ NodeType unstructured = nodeTypeManager.getNodeType(unstructuredName);
+ for (PropertyDefinition definition : unstructured.getDeclaredPropertyDefinitions()) {
+ if (definition.isMultiple()) {
+ anyMultiplePropertyDefinition = definition;
+ }
}
}
+ propertyDefinition = anyMultiplePropertyDefinition;
}
- assert anyMultiplePropertyDefinition != null;
- propertyDefinition = anyMultiplePropertyDefinition;
}
- assert propertyDefinition != null;
+ if (propertyDefinition == null) {
+ // We're supposed to skip this property (since we don't have a definition for it) ...
+ continue;
+ }
// Figure out if this is a multi-valued property ...
boolean isMultiple = propertyDefinition.isMultiple();
15 years, 2 months
DNA SVN: r753 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-04 14:11:34 -0500 (Wed, 04 Mar 2009)
New Revision: 753
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java
Removed:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
Log:
DNA-291 JCR property objects do not have PropertyDefinition
Renamed JcrProperty to JcrSingleValueProperty to more closely match the existing JcrMultiValueProperty and reduce confusion.
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2009-03-04 19:08:45 UTC (rev 752)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2009-03-04 19:11:34 UTC (rev 753)
@@ -1,244 +0,0 @@
-/*
- * 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.
- *
- * JBoss DNA is free software. 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.jcr;
-
-import java.io.InputStream;
-import java.util.Calendar;
-import java.util.UUID;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
-import javax.jcr.nodetype.PropertyDefinition;
-import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.Binary;
-import org.jboss.dna.graph.property.Property;
-import org.jboss.dna.graph.property.Reference;
-import org.jboss.dna.graph.property.ValueFactories;
-
-/**
- * @author jverhaeg
- */
-final class JcrProperty extends AbstractJcrProperty {
-
- JcrProperty( Node node,
- ExecutionContext executionContext,
- PropertyDefinition definition,
- Property dnaProperty ) {
- super(node, executionContext, definition, dnaProperty);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getBoolean()
- */
- public boolean getBoolean() throws RepositoryException {
- try {
- return getExecutionContext().getValueFactories().getBooleanFactory().create(getDnaProperty().getFirstValue());
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getDate()
- */
- public Calendar getDate() throws RepositoryException {
- try {
- return getExecutionContext().getValueFactories()
- .getDateFactory()
- .create(getDnaProperty().getFirstValue())
- .toCalendar();
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getDouble()
- */
- public double getDouble() throws RepositoryException {
- try {
- return getExecutionContext().getValueFactories().getDoubleFactory().create(getDnaProperty().getFirstValue());
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getLength()
- */
- public long getLength() throws RepositoryException {
- return createValue(getDnaProperty().getFirstValue()).getLength();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws ValueFormatException always
- * @see javax.jcr.Property#getLengths()
- */
- public long[] getLengths() throws ValueFormatException {
- throw new ValueFormatException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getLong()
- */
- public long getLong() throws RepositoryException {
- try {
- return getExecutionContext().getValueFactories().getLongFactory().create(getDnaProperty().getFirstValue());
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getNode()
- */
- public final Node getNode() throws RepositoryException {
- try {
- ValueFactories factories = getExecutionContext().getValueFactories();
- Reference dnaReference = factories.getReferenceFactory().create(getDnaProperty().getFirstValue());
- UUID uuid = factories.getUuidFactory().create(dnaReference);
- return ((JcrSession)getSession()).getNode(uuid);
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getStream()
- */
- public InputStream getStream() throws RepositoryException {
- try {
- Binary binary = getExecutionContext().getValueFactories().getBinaryFactory().create(getDnaProperty().getFirstValue());
- return new SelfClosingInputStream(binary);
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getString()
- */
- public String getString() throws RepositoryException {
- try {
- return getExecutionContext().getValueFactories().getStringFactory().create(getDnaProperty().getFirstValue());
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getValue()
- */
- public Value getValue() {
- return createValue(getDnaProperty().getFirstValue());
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws ValueFormatException always
- * @see javax.jcr.Property#getValues()
- */
- public Value[] getValues() throws ValueFormatException {
- throw new ValueFormatException();
- }
-
- /*
- * {@inheritDoc}
- *
- * @throws IllegalArgumentException if <code>value</code> is <code>null</code>.
- * @see javax.jcr.Property#setValue(javax.jcr.Value)
- *
- @SuppressWarnings( "fallthrough" )
- public void setValue( Value value ) throws RepositoryException {
- CheckArg.isNotNull(value, "value");
- // TODOx: Check node type constraint
- try {
- jcrValue = JcrValue.class.cast(value);
- } catch (ClassCastException error) {
- // TODOx: not sure if this is even possible
- ValueFactories valueFactories = getExecutionContext().getValueFactories();
- int type = value.getType();
- switch (type) {
- case PropertyType.BINARY: {
- jcrValue = new JcrValue<InputStream>(valueFactories, type, value.getStream());
- break;
- }
- case PropertyType.BOOLEAN: {
- jcrValue = new JcrValue<Boolean>(valueFactories, type, value.getBoolean());
- break;
- }
- case PropertyType.DATE: {
- jcrValue = new JcrValue<Calendar>(valueFactories, type, value.getDate());
- break;
- }
- case PropertyType.DOUBLE: {
- jcrValue = new JcrValue<Double>(valueFactories, type, value.getDouble());
- break;
- }
- case PropertyType.LONG: {
- jcrValue = new JcrValue<Long>(valueFactories, type, value.getLong());
- break;
- }
- case PropertyType.REFERENCE: {
- try {
- jcrValue = new JcrValue<UUID>(valueFactories, type, UUID.fromString(value.getString()));
- } catch (IllegalArgumentException fallsThroughToString) {
- }
- }
- case PropertyType.NAME:
- case PropertyType.PATH:
- case PropertyType.STRING: {
- jcrValue = new JcrValue<String>(valueFactories, type, value.getString());
- break;
- }
- default: {
- throw new AssertionError("Unsupported PropertyType: " + value.getType());
- }
- }
- }
- }
- */
-}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-04 19:08:45 UTC (rev 752)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-04 19:11:34 UTC (rev 753)
@@ -723,7 +723,7 @@
if (referenceable) {
if (uuidProperty == null) uuidProperty = executionContext.getPropertyFactory().create(JcrLexicon.UUID, uuid);
PropertyDefinition propertyDefinition = propertyDefinitionsByPropertyName.get(JcrLexicon.UUID);
- properties.add(new JcrProperty(node, executionContext, propertyDefinition, uuidProperty));
+ properties.add(new JcrSingleValueProperty(node, executionContext, propertyDefinition, uuidProperty));
}
// Now create the JCR property object wrappers around the other properties ...
@@ -763,7 +763,7 @@
if (isMultiple) {
properties.add(new JcrMultiValueProperty(node, executionContext, propertyDefinition, dnaProp));
} else {
- properties.add(new JcrProperty(node, executionContext, propertyDefinition, dnaProp));
+ properties.add(new JcrSingleValueProperty(node, executionContext, propertyDefinition, dnaProp));
}
}
Copied: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java (from rev 752, trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java)
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java 2009-03-04 19:11:34 UTC (rev 753)
@@ -0,0 +1,244 @@
+/*
+ * 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.
+ *
+ * JBoss DNA is free software. 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.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.UUID;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.property.Binary;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.Reference;
+import org.jboss.dna.graph.property.ValueFactories;
+
+/**
+ * @author jverhaeg
+ */
+final class JcrSingleValueProperty extends AbstractJcrProperty {
+
+ JcrSingleValueProperty( Node node,
+ ExecutionContext executionContext,
+ PropertyDefinition definition,
+ Property dnaProperty ) {
+ super(node, executionContext, definition, dnaProperty);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getBoolean()
+ */
+ public boolean getBoolean() throws RepositoryException {
+ try {
+ return getExecutionContext().getValueFactories().getBooleanFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDate()
+ */
+ public Calendar getDate() throws RepositoryException {
+ try {
+ return getExecutionContext().getValueFactories()
+ .getDateFactory()
+ .create(getDnaProperty().getFirstValue())
+ .toCalendar();
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDouble()
+ */
+ public double getDouble() throws RepositoryException {
+ try {
+ return getExecutionContext().getValueFactories().getDoubleFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLength()
+ */
+ public long getLength() throws RepositoryException {
+ return createValue(getDnaProperty().getFirstValue()).getLength();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws ValueFormatException always
+ * @see javax.jcr.Property#getLengths()
+ */
+ public long[] getLengths() throws ValueFormatException {
+ throw new ValueFormatException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLong()
+ */
+ public long getLong() throws RepositoryException {
+ try {
+ return getExecutionContext().getValueFactories().getLongFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getNode()
+ */
+ public final Node getNode() throws RepositoryException {
+ try {
+ ValueFactories factories = getExecutionContext().getValueFactories();
+ Reference dnaReference = factories.getReferenceFactory().create(getDnaProperty().getFirstValue());
+ UUID uuid = factories.getUuidFactory().create(dnaReference);
+ return ((JcrSession)getSession()).getNode(uuid);
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getStream()
+ */
+ public InputStream getStream() throws RepositoryException {
+ try {
+ Binary binary = getExecutionContext().getValueFactories().getBinaryFactory().create(getDnaProperty().getFirstValue());
+ return new SelfClosingInputStream(binary);
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getString()
+ */
+ public String getString() throws RepositoryException {
+ try {
+ return getExecutionContext().getValueFactories().getStringFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getValue()
+ */
+ public Value getValue() {
+ return createValue(getDnaProperty().getFirstValue());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws ValueFormatException always
+ * @see javax.jcr.Property#getValues()
+ */
+ public Value[] getValues() throws ValueFormatException {
+ throw new ValueFormatException();
+ }
+
+ /*
+ * {@inheritDoc}
+ *
+ * @throws IllegalArgumentException if <code>value</code> is <code>null</code>.
+ * @see javax.jcr.Property#setValue(javax.jcr.Value)
+ *
+ @SuppressWarnings( "fallthrough" )
+ public void setValue( Value value ) throws RepositoryException {
+ CheckArg.isNotNull(value, "value");
+ // TODOx: Check node type constraint
+ try {
+ jcrValue = JcrValue.class.cast(value);
+ } catch (ClassCastException error) {
+ // TODOx: not sure if this is even possible
+ ValueFactories valueFactories = getExecutionContext().getValueFactories();
+ int type = value.getType();
+ switch (type) {
+ case PropertyType.BINARY: {
+ jcrValue = new JcrValue<InputStream>(valueFactories, type, value.getStream());
+ break;
+ }
+ case PropertyType.BOOLEAN: {
+ jcrValue = new JcrValue<Boolean>(valueFactories, type, value.getBoolean());
+ break;
+ }
+ case PropertyType.DATE: {
+ jcrValue = new JcrValue<Calendar>(valueFactories, type, value.getDate());
+ break;
+ }
+ case PropertyType.DOUBLE: {
+ jcrValue = new JcrValue<Double>(valueFactories, type, value.getDouble());
+ break;
+ }
+ case PropertyType.LONG: {
+ jcrValue = new JcrValue<Long>(valueFactories, type, value.getLong());
+ break;
+ }
+ case PropertyType.REFERENCE: {
+ try {
+ jcrValue = new JcrValue<UUID>(valueFactories, type, UUID.fromString(value.getString()));
+ } catch (IllegalArgumentException fallsThroughToString) {
+ }
+ }
+ case PropertyType.NAME:
+ case PropertyType.PATH:
+ case PropertyType.STRING: {
+ jcrValue = new JcrValue<String>(valueFactories, type, value.getString());
+ break;
+ }
+ default: {
+ throw new AssertionError("Unsupported PropertyType: " + value.getType());
+ }
+ }
+ }
+ }
+ */
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2009-03-04 19:08:45 UTC (rev 752)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2009-03-04 19:11:34 UTC (rev 753)
@@ -1,257 +0,0 @@
-/*
- * 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.
- *
- * JBoss DNA is free software. 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.jcr;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.stub;
-import java.io.InputStream;
-import java.util.UUID;
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyType;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
-import javax.jcr.nodetype.PropertyDefinition;
-import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.DateTime;
-import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.Path;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.MockitoAnnotations;
-import org.mockito.MockitoAnnotations.Mock;
-
-/**
- * @author jverhaeg
- */
-public class JcrPropertyTest {
-
- private Property prop;
- @Mock
- private Node node;
- private ExecutionContext executionContext;
- @Mock
- Name name;
- @Mock
- private PropertyDefinition definition;
- private org.jboss.dna.graph.property.Property dnaProperty;
-
- @Before
- public void before() {
- MockitoAnnotations.initMocks(this);
- executionContext = new ExecutionContext();
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "text/plain");
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- stub(definition.isMultiple()).toReturn(false);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- }
-
- @Test
- public void shouldProvideBoolean() throws Exception {
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "true");
- stub(definition.getRequiredType()).toReturn(PropertyType.BOOLEAN);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getBoolean(), is(true));
- assertThat(prop.getType(), is(PropertyType.BOOLEAN));
- }
-
- @Test
- public void shouldIndicateHasSingleValue() throws Exception {
- PropertyDefinition def = prop.getDefinition();
- assertThat(def, notNullValue());
- assertThat(def.isMultiple(), is(false));
- }
-
- @Test
- public void shouldProvideDate() throws Exception {
- DateTime dnaDate = executionContext.getValueFactories().getDateFactory().create();
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, dnaDate);
- stub(definition.getRequiredType()).toReturn(PropertyType.DATE);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getDate(), is(dnaDate.toCalendar()));
- assertThat(prop.getLong(), is(dnaDate.getMilliseconds()));
- assertThat(prop.getType(), is(PropertyType.DATE));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldProvideNode() throws Exception {
- UUID referencedUuid = UUID.randomUUID();
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, referencedUuid);
- stub(definition.getRequiredType()).toReturn(PropertyType.REFERENCE);
- Node referencedNode = mock(Node.class);
- JcrSession session = mock(JcrSession.class);
- stub(node.getSession()).toReturn(session);
- stub(session.getNode(referencedUuid)).toReturn(referencedNode);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getNode(), is(referencedNode));
- assertThat(prop.getType(), is(PropertyType.REFERENCE));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldProvideDouble() throws Exception {
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1.0);
- stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getDouble(), is(1.0));
- assertThat(prop.getType(), is(PropertyType.DOUBLE));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1.0F);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getDouble(), is(1.0));
- assertThat(prop.getType(), is(PropertyType.DOUBLE));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldProvideLong() throws Exception {
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1);
- stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getLong(), is(1L));
- assertThat(prop.getType(), is(PropertyType.DOUBLE));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
-
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1L);
- stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getLong(), is(1L));
- assertThat(prop.getString(), is("1"));
- assertThat(prop.getType(), is(PropertyType.DOUBLE));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldProvideStream() throws Exception {
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, new Object());
- stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getType(), is(PropertyType.BINARY));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- InputStream stream = prop.getStream();
- try {
- assertThat(stream, notNullValue());
- } finally {
- if (stream != null) {
- stream.close();
- }
- }
- }
-
- @Test
- public void shouldProvideString() throws Exception {
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "value");
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getString(), is("value"));
- assertThat(prop.getType(), is(PropertyType.STRING));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldAllowReferenceValue() throws Exception {
- UUID uuid = UUID.randomUUID();
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, uuid);
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getString(), is(uuid.toString()));
- assertThat(prop.getType(), is(PropertyType.STRING));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldAllowNameValue() throws Exception {
- executionContext.getNamespaceRegistry().register("acme", "http://example.com");
- Name path = executionContext.getValueFactories().getNameFactory().create("acme:something");
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, path);
- stub(definition.getRequiredType()).toReturn(PropertyType.NAME);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getString(), is("acme:something"));
- assertThat(prop.getType(), is(PropertyType.NAME));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- // Change the namespace registry ...
- executionContext.getNamespaceRegistry().register("acme2", "http://example.com");
- assertThat(prop.getString(), is("acme2:something"));
- }
-
- @Test
- public void shouldAllowPathValue() throws Exception {
- executionContext.getNamespaceRegistry().register("acme", "http://example.com");
- Path path = executionContext.getValueFactories().getPathFactory().create("/a/b/acme:c");
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, (Object)path);
- stub(definition.getRequiredType()).toReturn(PropertyType.PATH);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getString(), is("/a/b/acme:c"));
- assertThat(prop.getType(), is(PropertyType.PATH));
- assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- // Change the namespace registry ...
- executionContext.getNamespaceRegistry().register("acme2", "http://example.com");
- assertThat(prop.getString(), is("/a/b/acme2:c"));
- }
-
- @Test
- public void shouldProvideValue() throws Exception {
- Value val = prop.getValue();
- assertThat(val, notNullValue());
- }
-
- @Test( expected = ValueFormatException.class )
- public void shouldNotProvideValues() throws Exception {
- prop.getValues();
- }
-
- @Test
- public void shouldProvideLength() throws Exception {
- String dnaValue = executionContext.getValueFactories().getStringFactory().create(dnaProperty.getFirstValue());
- assertThat(prop.getLength(), is((long)dnaValue.length()));
-
- dnaValue = "some other value";
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, dnaValue);
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getLength(), is((long)dnaValue.length()));
-
- Object obj = new Object();
- long binaryLength = executionContext.getValueFactories().getBinaryFactory().create(obj).getSize();
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, obj);
- stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getLength(), is(binaryLength));
- }
-
- @Test( expected = ValueFormatException.class )
- public void shouldNotProvideLengths() throws Exception {
- prop.getLengths();
- }
-
- @Test
- public void shouldProvidePropertyDefinition() throws Exception {
- assertThat(prop.getDefinition(), notNullValue());
- }
-
-}
Copied: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java (from rev 752, trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java)
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java 2009-03-04 19:11:34 UTC (rev 753)
@@ -0,0 +1,257 @@
+/*
+ * 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.
+ *
+ * JBoss DNA is free software. 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.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.io.InputStream;
+import java.util.UUID;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.property.DateTime;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.Path;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrSingleValuePropertyTest {
+
+ private Property prop;
+ @Mock
+ private Node node;
+ private ExecutionContext executionContext;
+ @Mock
+ Name name;
+ @Mock
+ private PropertyDefinition definition;
+ private org.jboss.dna.graph.property.Property dnaProperty;
+
+ @Before
+ public void before() {
+ MockitoAnnotations.initMocks(this);
+ executionContext = new ExecutionContext();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "text/plain");
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ stub(definition.isMultiple()).toReturn(false);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ }
+
+ @Test
+ public void shouldProvideBoolean() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "true");
+ stub(definition.getRequiredType()).toReturn(PropertyType.BOOLEAN);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getBoolean(), is(true));
+ assertThat(prop.getType(), is(PropertyType.BOOLEAN));
+ }
+
+ @Test
+ public void shouldIndicateHasSingleValue() throws Exception {
+ PropertyDefinition def = prop.getDefinition();
+ assertThat(def, notNullValue());
+ assertThat(def.isMultiple(), is(false));
+ }
+
+ @Test
+ public void shouldProvideDate() throws Exception {
+ DateTime dnaDate = executionContext.getValueFactories().getDateFactory().create();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, dnaDate);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DATE);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getDate(), is(dnaDate.toCalendar()));
+ assertThat(prop.getLong(), is(dnaDate.getMilliseconds()));
+ assertThat(prop.getType(), is(PropertyType.DATE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldProvideNode() throws Exception {
+ UUID referencedUuid = UUID.randomUUID();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, referencedUuid);
+ stub(definition.getRequiredType()).toReturn(PropertyType.REFERENCE);
+ Node referencedNode = mock(Node.class);
+ JcrSession session = mock(JcrSession.class);
+ stub(node.getSession()).toReturn(session);
+ stub(session.getNode(referencedUuid)).toReturn(referencedNode);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getNode(), is(referencedNode));
+ assertThat(prop.getType(), is(PropertyType.REFERENCE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldProvideDouble() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1.0);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getDouble(), is(1.0));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1.0F);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getDouble(), is(1.0));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldProvideLong() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getLong(), is(1L));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1L);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getLong(), is(1L));
+ assertThat(prop.getString(), is("1"));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldProvideStream() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, new Object());
+ stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getType(), is(PropertyType.BINARY));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ InputStream stream = prop.getStream();
+ try {
+ assertThat(stream, notNullValue());
+ } finally {
+ if (stream != null) {
+ stream.close();
+ }
+ }
+ }
+
+ @Test
+ public void shouldProvideString() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "value");
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getString(), is("value"));
+ assertThat(prop.getType(), is(PropertyType.STRING));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldAllowReferenceValue() throws Exception {
+ UUID uuid = UUID.randomUUID();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, uuid);
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getString(), is(uuid.toString()));
+ assertThat(prop.getType(), is(PropertyType.STRING));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldAllowNameValue() throws Exception {
+ executionContext.getNamespaceRegistry().register("acme", "http://example.com");
+ Name path = executionContext.getValueFactories().getNameFactory().create("acme:something");
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, path);
+ stub(definition.getRequiredType()).toReturn(PropertyType.NAME);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getString(), is("acme:something"));
+ assertThat(prop.getType(), is(PropertyType.NAME));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ // Change the namespace registry ...
+ executionContext.getNamespaceRegistry().register("acme2", "http://example.com");
+ assertThat(prop.getString(), is("acme2:something"));
+ }
+
+ @Test
+ public void shouldAllowPathValue() throws Exception {
+ executionContext.getNamespaceRegistry().register("acme", "http://example.com");
+ Path path = executionContext.getValueFactories().getPathFactory().create("/a/b/acme:c");
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, (Object)path);
+ stub(definition.getRequiredType()).toReturn(PropertyType.PATH);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getString(), is("/a/b/acme:c"));
+ assertThat(prop.getType(), is(PropertyType.PATH));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ // Change the namespace registry ...
+ executionContext.getNamespaceRegistry().register("acme2", "http://example.com");
+ assertThat(prop.getString(), is("/a/b/acme2:c"));
+ }
+
+ @Test
+ public void shouldProvideValue() throws Exception {
+ Value val = prop.getValue();
+ assertThat(val, notNullValue());
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideValues() throws Exception {
+ prop.getValues();
+ }
+
+ @Test
+ public void shouldProvideLength() throws Exception {
+ String dnaValue = executionContext.getValueFactories().getStringFactory().create(dnaProperty.getFirstValue());
+ assertThat(prop.getLength(), is((long)dnaValue.length()));
+
+ dnaValue = "some other value";
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, dnaValue);
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getLength(), is((long)dnaValue.length()));
+
+ Object obj = new Object();
+ long binaryLength = executionContext.getValueFactories().getBinaryFactory().create(obj).getSize();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, obj);
+ stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
+ prop = new JcrSingleValueProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getLength(), is(binaryLength));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideLengths() throws Exception {
+ prop.getLengths();
+ }
+
+ @Test
+ public void shouldProvidePropertyDefinition() throws Exception {
+ assertThat(prop.getDefinition(), notNullValue());
+ }
+
+}
Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 2 months
DNA SVN: r752 - in trunk: dna-jcr/src/main/java/org/jboss/dna/jcr and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-04 14:08:45 -0500 (Wed, 04 Mar 2009)
New Revision: 752
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SelfClosingInputStream.java
Removed:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractValueFactory.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java
Log:
DNA-291 JCR property objects do not have PropertyDefinition
Restructured how our Property implementations create Value objects, since the Value objects cannot be cached in the Property. Section 6.2.7 of JSR-170 says that Value objects can become unusable after Value.getStream() is called, and the proper procedure in this case is for the client to get a new Value object. Therefore Property objects have to be able to re-create new Value objects.
This change led me to look more into how JcrAbstractProperty, JcrProperty, and JcrMultiValueProperty are implemented. I was able to simplify them quite a bit by having them hold onto the DNA Property instance, and to pass in the PropertyDefinition into the constructor. Several other errors were found in the current code, including "Property.getNode()" does not return the parent node that owns the property (that's "Property.getParent()"), but should instead return the node pointed to by the reference property value.
The JcrSession.populateNode(...) method was also refactored to validate the DNA graph node using the primary node type and mixin types, and to find and associate the appropriate PropertyDefinition with each of the node's properties.
All of these changes had a fairly large impact on the unit tests for these classes, so these were fixed. Note that any test methods that check for AssertionException is not a valid test (as the tests should be able be run without assertions enabled to verify the behavior is still correct).
Also enabled several JCR TCK tests, since we're now passing all of their test methods. Not too many remain for JCR Level 1 compliance!
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractValueFactory.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractValueFactory.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/AbstractValueFactory.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -112,6 +112,7 @@
if (value instanceof Float) return create(((Float)value).floatValue());
if (value instanceof Boolean) return create(((Boolean)value).booleanValue());
if (value instanceof BigDecimal) return create((BigDecimal)value);
+ if (value instanceof DateTime) return create((DateTime)value);
if (value instanceof Calendar) return create((Calendar)value);
if (value instanceof Date) return create((Date)value);
if (value instanceof Name) return create((Name)value);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -24,24 +24,18 @@
package org.jboss.dna.jcr;
import java.io.InputStream;
-import java.io.Reader;
import java.util.Calendar;
-import java.util.Date;
-import java.util.UUID;
import javax.jcr.Item;
import javax.jcr.ItemVisitor;
import javax.jcr.Node;
import javax.jcr.Property;
-import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
+import javax.jcr.nodetype.PropertyDefinition;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.ValueFactories;
/**
* @author jverhaeg
@@ -51,17 +45,21 @@
private final Node node;
private final ExecutionContext executionContext;
- private final Name name;
+ private final org.jboss.dna.graph.property.Property dnaProperty;
+ private final PropertyDefinition jcrPropertyDefinition;
AbstractJcrProperty( Node node,
ExecutionContext executionContext,
- Name name ) {
+ PropertyDefinition definition,
+ org.jboss.dna.graph.property.Property dnaProperty ) {
assert node != null;
assert executionContext != null;
- assert name != null;
+ assert dnaProperty != null;
+ assert definition != null;
this.node = node;
this.executionContext = executionContext;
- this.name = name;
+ this.dnaProperty = dnaProperty;
+ this.jcrPropertyDefinition = definition;
}
/**
@@ -75,39 +73,47 @@
visitor.visit(this);
}
- JcrValue<?> createValue( ValueFactories valueFactories,
- ValueInfo valueInfo,
- Object value ) {
- return createValue(valueFactories, valueInfo.valueClass, valueInfo.propertyType, value);
+ JcrValue createValue( Object value ) {
+ return new JcrValue(executionContext.getValueFactories(), getType(), value);
}
- private <T> JcrValue<T> createValue( ValueFactories valueFactories,
- Class<T> valueClass,
- int propertyType,
- Object value ) {
- return new JcrValue<T>(valueFactories, propertyType, valueClass.cast(value));
- }
-
final ExecutionContext getExecutionContext() {
return executionContext;
}
+ final org.jboss.dna.graph.property.Property getDnaProperty() {
+ return dnaProperty;
+ }
+
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getNode()
+ * @see javax.jcr.Property#getType()
*/
- public final Node getNode() {
- return node;
+ public final int getType() {
+ return jcrPropertyDefinition.getRequiredType();
}
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Property#getDefinition()
+ */
+ public final PropertyDefinition getDefinition() {
+ return jcrPropertyDefinition;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * This method returns the string form of the {@link org.jboss.dna.graph.property.Property#getName()}, computed dynamically
+ * each time this method is called to ensure that the property namespace prefix is used.
+ * </p>
+ *
* @see javax.jcr.Item#getName()
*/
public final String getName() {
- return name.getString(executionContext.getNamespaceRegistry());
+ return dnaProperty.getName().getString(executionContext.getNamespaceRegistry());
}
/**
@@ -154,9 +160,12 @@
*/
@Override
public final boolean isSame( Item otherItem ) throws RepositoryException {
- if (super.isSame(otherItem) && otherItem instanceof Property) {
- Property otherProp = (Property)otherItem;
- return (getName().equals(otherProp.getName()) && getNode().isSame(otherProp.getNode()));
+ if (otherItem instanceof Property) {
+ Property otherProperty = (Property)otherItem;
+ // The nodes that own the properties must be the same ...
+ if (!getParent().isSame(otherProperty.getParent())) return false;
+ // The properties must have the same name ...
+ return getName().equals(otherProperty.getName());
}
return false;
}
@@ -260,56 +269,4 @@
public final void setValue( Node value ) {
throw new UnsupportedOperationException();
}
-
- final class ValueInfo {
-
- final Class<?> valueClass;
- final int propertyType;
-
- ValueInfo( Object value ) {
- if (value instanceof Boolean) {
- valueClass = Boolean.class;
- propertyType = PropertyType.BOOLEAN;
- } else if (value instanceof Date) {
- valueClass = Date.class;
- propertyType = PropertyType.DATE;
- } else if (value instanceof Calendar) {
- valueClass = Calendar.class;
- propertyType = PropertyType.DATE;
- } else if (value instanceof Double) {
- valueClass = Double.class;
- propertyType = PropertyType.DOUBLE;
- } else if (value instanceof Float) {
- valueClass = Float.class;
- propertyType = PropertyType.DOUBLE;
- } else if (value instanceof Integer) {
- valueClass = Integer.class;
- propertyType = PropertyType.LONG;
- } else if (value instanceof Long) {
- valueClass = Long.class;
- propertyType = PropertyType.LONG;
- } else if (value instanceof UUID) {
- valueClass = UUID.class;
- propertyType = PropertyType.REFERENCE;
- } else if (value instanceof String) {
- valueClass = String.class;
- propertyType = PropertyType.STRING;
- } else if (value instanceof Name) {
- valueClass = Name.class;
- propertyType = PropertyType.NAME;
- } else if (value instanceof Path) {
- valueClass = Path.class;
- propertyType = PropertyType.PATH;
- } else if (value instanceof InputStream) {
- valueClass = InputStream.class;
- propertyType = PropertyType.BINARY;
- } else if (value instanceof Reader) {
- valueClass = Reader.class;
- propertyType = PropertyType.BINARY;
- } else {
- valueClass = Object.class;
- propertyType = PropertyType.BINARY;
- }
- }
- }
}
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -1,124 +0,0 @@
-/*
- * 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.
- *
- * JBoss DNA is free software. 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.jcr;
-
-import javax.jcr.Value;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.nodetype.PropertyDefinition;
-
-/**
- * @author jverhaeg
- */
-abstract class AbstractJcrPropertyDefinition implements PropertyDefinition {
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see javax.jcr.nodetype.PropertyDefinition#getDefaultValues()
- */
- public final Value[] getDefaultValues() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see javax.jcr.nodetype.PropertyDefinition#getRequiredType()
- */
- public final int getRequiredType() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see javax.jcr.nodetype.PropertyDefinition#getValueConstraints()
- */
- public final String[] getValueConstraints() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see javax.jcr.nodetype.ItemDefinition#getDeclaringNodeType()
- */
- public final NodeType getDeclaringNodeType() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see javax.jcr.nodetype.ItemDefinition#getName()
- */
- public final String getName() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see javax.jcr.nodetype.ItemDefinition#getOnParentVersion()
- */
- public final int getOnParentVersion() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see javax.jcr.nodetype.ItemDefinition#isAutoCreated()
- */
- public final boolean isAutoCreated() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see javax.jcr.nodetype.ItemDefinition#isMandatory()
- */
- public final boolean isMandatory() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see javax.jcr.nodetype.ItemDefinition#isProtected()
- */
- public final boolean isProtected() {
- throw new UnsupportedOperationException();
- }
-}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrBuiltinNodeTypeSource.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -69,10 +69,8 @@
JcrBuiltinNodeTypeSource( JcrSession session ) {
primaryNodeTypes = new ArrayList<JcrNodeType>();
- Value trueValue = new JcrValue<Boolean>(session.getExecutionContext().getValueFactories(), PropertyType.BOOLEAN,
- Boolean.TRUE);
- Value ntBaseValue = new JcrValue<Name>(session.getExecutionContext().getValueFactories(), PropertyType.NAME,
- JcrNtLexicon.BASE);
+ Value trueValue = new JcrValue(session.getExecutionContext().getValueFactories(), PropertyType.BOOLEAN, Boolean.TRUE);
+ Value ntBaseValue = new JcrValue(session.getExecutionContext().getValueFactories(), PropertyType.NAME, JcrNtLexicon.BASE);
// Stubbing in child node and property definitions for now
JcrNodeType base = new JcrNodeType(session, JcrNtLexicon.BASE, NO_SUPERTYPES, NO_PRIMARY_ITEM_NAME, NO_CHILD_NODES,
@@ -429,7 +427,7 @@
OnParentVersionBehavior.IGNORE.getJcrValue(), false,
true, false, NO_DEFAULT_VALUES, PropertyType.DATE,
NO_CONSTRAINTS, false),
- new JcrPropertyDefinition(session, null, JcrLexicon.MIME_TYPE,
+ new JcrPropertyDefinition(session, null, JcrLexicon.MIMETYPE,
OnParentVersionBehavior.COPY.getJcrValue(), false,
true, false, NO_DEFAULT_VALUES, PropertyType.STRING,
NO_CONSTRAINTS, false),}), NOT_MIXIN,
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -61,6 +61,8 @@
public static I18n invalidRelativePath;
public static I18n invalidPathParameter;
public static I18n invalidNamePattern;
+ public static I18n itemNotFoundWithUuid;
+ public static I18n errorWhileFindingNodeWithUuid;
public static I18n typeNotFound;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -53,7 +53,6 @@
public static final Name LOCK_OWNER = new BasicName(Namespace.URI, "lockOwner");
public static final Name MANDATORY = new BasicName(Namespace.URI, "mandatory");
public static final Name MERGE_FAILED = new BasicName(Namespace.URI, "mergeFailed");
- public static final Name MIME_TYPE = new BasicName(Namespace.URI, "mimeType");
public static final Name MULTIPLE = new BasicName(Namespace.URI, "multiple");
public static final Name NAME = new BasicName(Namespace.URI, "name");
public static final Name NODE_TYPE_NAME = new BasicName(Namespace.URI, "nodeTypeName");
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -24,10 +24,8 @@
package org.jboss.dna.jcr;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
-import java.util.List;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
@@ -35,8 +33,7 @@
import javax.jcr.nodetype.PropertyDefinition;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.ValueFactories;
+import org.jboss.dna.graph.property.Property;
/**
* @author jverhaeg
@@ -44,22 +41,11 @@
@NotThreadSafe
final class JcrMultiValueProperty extends AbstractJcrProperty {
- private List<JcrValue<?>> jcrValues = new ArrayList<JcrValue<?>>();
-
JcrMultiValueProperty( Node node,
ExecutionContext executionContext,
- Name name,
- Iterable<?> values ) {
- super(node, executionContext, name);
- assert values != null;
- ValueFactories valueFactories = executionContext.getValueFactories();
- ValueInfo valueInfo = null;
- for (Object value : values) {
- if (valueInfo == null) {
- valueInfo = new ValueInfo(value);
- }
- jcrValues.add(createValue(valueFactories, valueInfo, value));
- }
+ PropertyDefinition definition,
+ Property dnaProperty ) {
+ super(node, executionContext, definition, dnaProperty);
}
/**
@@ -85,24 +71,19 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getDefinition()
+ * @throws ValueFormatException always
+ * @see javax.jcr.Property#getDouble()
*/
- public PropertyDefinition getDefinition() {
- return new AbstractJcrPropertyDefinition() {
-
- public boolean isMultiple() {
- return true;
- }
- };
+ public double getDouble() throws ValueFormatException {
+ throw new ValueFormatException();
}
/**
* {@inheritDoc}
*
- * @throws ValueFormatException always
- * @see javax.jcr.Property#getDouble()
+ * @see javax.jcr.Property#getNode()
*/
- public double getDouble() throws ValueFormatException {
+ public Node getNode() throws ValueFormatException, RepositoryException {
throw new ValueFormatException();
}
@@ -122,10 +103,11 @@
* @see javax.jcr.Property#getLengths()
*/
public long[] getLengths() throws RepositoryException {
- long[] lengths = new long[jcrValues.size()];
- Iterator<JcrValue<?>> iter = jcrValues.iterator();
+ Property dnaProperty = getDnaProperty();
+ long[] lengths = new long[dnaProperty.size()];
+ Iterator<?> iter = dnaProperty.iterator();
for (int ndx = 0; iter.hasNext(); ndx++) {
- lengths[ndx] = iter.next().getLength();
+ lengths[ndx] = createValue(iter.next()).getLength();
}
return lengths;
}
@@ -163,15 +145,6 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getType()
- */
- public int getType() {
- return jcrValues.get(0).getType();
- }
-
- /**
- * {@inheritDoc}
- *
* @throws ValueFormatException always
* @see javax.jcr.Property#getValue()
*/
@@ -181,10 +154,21 @@
/**
* {@inheritDoc}
+ * <p>
+ * Per the JCR specification, these values need to be created each time this method is called, since the Value cannot be used
+ * after {@link Value#getStream()} is called/processed. The spec says that the client simply needs to obtain a new Value (or
+ * {@link #getValues()} for {@link JcrMultiValueProperty multi-valued properites}).
+ * </p>
*
* @see javax.jcr.Property#getValues()
*/
public Value[] getValues() {
- return jcrValues.toArray(new Value[jcrValues.size()]);
+ Property dnaProperty = getDnaProperty();
+ Value[] values = new JcrValue[dnaProperty.size()];
+ Iterator<?> iter = dnaProperty.iterator();
+ for (int ndx = 0; iter.hasNext(); ndx++) {
+ values[ndx] = createValue(iter.next());
+ }
+ return values;
}
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -25,13 +25,16 @@
import java.io.InputStream;
import java.util.Calendar;
+import java.util.UUID;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.PropertyDefinition;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.Binary;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.Reference;
import org.jboss.dna.graph.property.ValueFactories;
/**
@@ -39,16 +42,11 @@
*/
final class JcrProperty extends AbstractJcrProperty {
- private JcrValue<?> jcrValue;
-
JcrProperty( Node node,
ExecutionContext executionContext,
- Name name,
- Object value ) {
- super(node, executionContext, name);
- assert value != null;
- ValueFactories valueFactories = executionContext.getValueFactories();
- jcrValue = createValue(valueFactories, new ValueInfo(value), value);
+ PropertyDefinition definition,
+ Property dnaProperty ) {
+ super(node, executionContext, definition, dnaProperty);
}
/**
@@ -57,7 +55,11 @@
* @see javax.jcr.Property#getBoolean()
*/
public boolean getBoolean() throws RepositoryException {
- return jcrValue.getBoolean();
+ try {
+ return getExecutionContext().getValueFactories().getBooleanFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
}
/**
@@ -66,30 +68,27 @@
* @see javax.jcr.Property#getDate()
*/
public Calendar getDate() throws RepositoryException {
- return jcrValue.getDate();
+ try {
+ return getExecutionContext().getValueFactories()
+ .getDateFactory()
+ .create(getDnaProperty().getFirstValue())
+ .toCalendar();
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getDefinition()
- */
- public PropertyDefinition getDefinition() {
- return new AbstractJcrPropertyDefinition() {
-
- public boolean isMultiple() {
- return false;
- }
- };
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Property#getDouble()
*/
public double getDouble() throws RepositoryException {
- return jcrValue.getDouble();
+ try {
+ return getExecutionContext().getValueFactories().getDoubleFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
}
/**
@@ -98,7 +97,7 @@
* @see javax.jcr.Property#getLength()
*/
public long getLength() throws RepositoryException {
- return jcrValue.getLength();
+ return createValue(getDnaProperty().getFirstValue()).getLength();
}
/**
@@ -117,34 +116,54 @@
* @see javax.jcr.Property#getLong()
*/
public long getLong() throws RepositoryException {
- return jcrValue.getLong();
+ try {
+ return getExecutionContext().getValueFactories().getLongFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getStream()
+ * @see javax.jcr.Property#getNode()
*/
- public InputStream getStream() throws RepositoryException {
- return jcrValue.getStream();
+ public final Node getNode() throws RepositoryException {
+ try {
+ ValueFactories factories = getExecutionContext().getValueFactories();
+ Reference dnaReference = factories.getReferenceFactory().create(getDnaProperty().getFirstValue());
+ UUID uuid = factories.getUuidFactory().create(dnaReference);
+ return ((JcrSession)getSession()).getNode(uuid);
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getString()
+ * @see javax.jcr.Property#getStream()
*/
- public String getString() throws RepositoryException {
- return jcrValue.getString();
+ public InputStream getStream() throws RepositoryException {
+ try {
+ Binary binary = getExecutionContext().getValueFactories().getBinaryFactory().create(getDnaProperty().getFirstValue());
+ return new SelfClosingInputStream(binary);
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getType()
+ * @see javax.jcr.Property#getString()
*/
- public int getType() {
- return jcrValue.getType();
+ public String getString() throws RepositoryException {
+ try {
+ return getExecutionContext().getValueFactories().getStringFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
}
/**
@@ -153,7 +172,7 @@
* @see javax.jcr.Property#getValue()
*/
public Value getValue() {
- return jcrValue;
+ return createValue(getDnaProperty().getFirstValue());
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -29,12 +29,14 @@
import java.security.Principal;
import java.util.Calendar;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.jcr.Credentials;
import javax.jcr.Item;
+import javax.jcr.ItemNotFoundException;
import javax.jcr.NamespaceException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
@@ -47,6 +49,9 @@
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import javax.jcr.Workspace;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.PropertyDefinition;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
@@ -56,10 +61,11 @@
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NameFactory;
import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.UuidFactory;
import org.jboss.dna.graph.property.ValueFactories;
+import org.jboss.dna.graph.property.ValueFormatException;
import org.jboss.dna.graph.property.basic.LocalNamespaceRegistry;
import org.jboss.dna.jcr.JcrNamespaceRegistry.Behavior;
import org.xml.sax.ContentHandler;
@@ -110,6 +116,7 @@
private final ReferenceMap<String, Node> nodesByJcrUuid;
private boolean isLive;
private JcrRootNode rootNode;
+ private PropertyDefinition anyMultiplePropertyDefinition;
JcrSession( JcrRepository repository,
JcrWorkspace workspace,
@@ -401,12 +408,21 @@
/**
* {@inheritDoc}
*
- * @throws UnsupportedOperationException always
* @see javax.jcr.Session#getNodeByUUID(java.lang.String)
*/
- public Node getNodeByUUID( String uuid ) {
- // TODO: Need DNA command to get node by UUID before implementing
- throw new UnsupportedOperationException();
+ public Node getNodeByUUID( String uuid ) throws ItemNotFoundException, RepositoryException {
+ Node result = null;
+ try {
+ result = nodesByUuid.get(UUID.fromString(uuid));
+ } catch (IllegalArgumentException e) {
+ throw new ItemNotFoundException(JcrI18n.itemNotFoundWithUuid.text(uuid, workspace.getName()));
+ } catch (Throwable e) {
+ throw new RepositoryException(JcrI18n.errorWhileFindingNodeWithUuid.text(uuid, workspace.getName()));
+ }
+ if (result == null) {
+ throw new ItemNotFoundException(JcrI18n.itemNotFoundWithUuid.text(uuid, workspace.getName()));
+ }
+ return result;
}
/**
@@ -414,7 +430,7 @@
*
* @see javax.jcr.Session#getRootNode()
*/
- public Node getRootNode() {
+ public Node getRootNode() throws RepositoryException {
// Return cached root node if available
if (rootNode != null) {
return rootNode;
@@ -423,14 +439,16 @@
assert executionContext.getValueFactories() != null;
assert executionContext.getValueFactories().getPathFactory() != null;
rootNode = new JcrRootNode(this);
+
// Get root node from source
- populateNode(rootNode, graph.getNodeAt(executionContext.getValueFactories().getPathFactory().createRootPath()));
-
- // Root nodes need to have a type in JCR land
- JcrProperty primaryType = new JcrProperty(rootNode, executionContext, JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.BASE);
- // TODO: Not liking the hard-code
- rootNode.properties.add(primaryType);
-
+ Path rootPath = executionContext.getValueFactories().getPathFactory().createRootPath();
+ org.jboss.dna.graph.Node dnaRootNode = graph.getNodeAt(rootPath);
+ if (dnaRootNode.getProperty(JcrLexicon.PRIMARY_TYPE) == null) {
+ // Add the primary type and update the source ...
+ graph.set(JcrLexicon.PRIMARY_TYPE).to(JcrNtLexicon.BASE).on(rootPath);
+ dnaRootNode = graph.getNodeAt(rootPath);
+ }
+ populateNode(rootNode, dnaRootNode);
return rootNode;
}
@@ -458,35 +476,35 @@
public Value createValue( String value,
int propertyType ) {
- return new JcrValue<String>(valueFactories, propertyType, value);
+ return new JcrValue(valueFactories, propertyType, value);
}
public Value createValue( Node value ) throws RepositoryException {
- return new JcrValue<UUID>(valueFactories, PropertyType.REFERENCE, UUID.fromString(value.getUUID()));
+ return new JcrValue(valueFactories, PropertyType.REFERENCE, UUID.fromString(value.getUUID()));
}
public Value createValue( InputStream value ) {
- return new JcrValue<InputStream>(valueFactories, PropertyType.BINARY, value);
+ return new JcrValue(valueFactories, PropertyType.BINARY, value);
}
public Value createValue( Calendar value ) {
- return new JcrValue<Calendar>(valueFactories, PropertyType.DATE, value);
+ return new JcrValue(valueFactories, PropertyType.DATE, value);
}
public Value createValue( boolean value ) {
- return new JcrValue<Boolean>(valueFactories, PropertyType.BOOLEAN, value);
+ return new JcrValue(valueFactories, PropertyType.BOOLEAN, value);
}
public Value createValue( double value ) {
- return new JcrValue<Double>(valueFactories, PropertyType.DOUBLE, value);
+ return new JcrValue(valueFactories, PropertyType.DOUBLE, value);
}
public Value createValue( long value ) {
- return new JcrValue<Long>(valueFactories, PropertyType.LONG, value);
+ return new JcrValue(valueFactories, PropertyType.LONG, value);
}
public Value createValue( String value ) {
- return new JcrValue<String>(valueFactories, PropertyType.STRING, value);
+ return new JcrValue(valueFactories, PropertyType.STRING, value);
}
};
}
@@ -580,47 +598,184 @@
throw new UnsupportedOperationException();
}
+ /**
+ * Compute the JCR {@link PropertyType} for the given DNA {@link org.jboss.dna.graph.property.PropertyType}.
+ *
+ * @param dnaPropertyType the DNA property type; never null
+ * @return the JCR property type
+ */
+ static final int jcrPropertyTypeFor( org.jboss.dna.graph.property.PropertyType dnaPropertyType ) {
+ // Get the DNA property type for this ...
+ switch (dnaPropertyType) {
+ case STRING:
+ return PropertyType.STRING;
+ case NAME:
+ return PropertyType.NAME;
+ case LONG:
+ return PropertyType.LONG;
+ case UUID:
+ return PropertyType.STRING; // JCR treats UUID properties as strings
+ case URI:
+ return PropertyType.STRING;
+ case PATH:
+ return PropertyType.PATH;
+ case BOOLEAN:
+ return PropertyType.BOOLEAN;
+ case DATE:
+ return PropertyType.DATE;
+ case DECIMAL:
+ return PropertyType.UNDEFINED;
+ case DOUBLE:
+ return PropertyType.DOUBLE;
+ case BINARY:
+ return PropertyType.BINARY;
+ case OBJECT:
+ return PropertyType.UNDEFINED;
+ case REFERENCE:
+ return PropertyType.REFERENCE;
+ }
+ assert false;
+ return PropertyType.UNDEFINED;
+ }
+
private void populateNode( AbstractJcrNode node,
- org.jboss.dna.graph.Node graphNode ) {
- // TODO: What do we do to validate node against its primary type?
+ org.jboss.dna.graph.Node graphNode ) throws RepositoryException {
assert node != null;
assert graphNode != null;
+
+ // --------------------------------------------------
// Create JCR children for corresponding DNA children
+ // --------------------------------------------------
node.setChildren(graphNode.getChildrenSegments());
+
+ // ------------------------------------------------------
// Create JCR properties for corresponding DNA properties
+ // ------------------------------------------------------
+ // First get the property type for each property, based upon the primary type and mixins ...
+ Map<Name, PropertyDefinition> propertyDefinitionsByPropertyName = new HashMap<Name, PropertyDefinition>();
+ boolean referenceable = false;
+
+ NamespaceRegistry registry = executionContext.getNamespaceRegistry();
+ ValueFactories factories = executionContext.getValueFactories();
+ NameFactory nameFactory = factories.getNameFactory();
+ NodeTypeManager nodeTypeManager = getWorkspace().getNodeTypeManager();
+ org.jboss.dna.graph.property.Property primaryTypeProperty = graphNode.getProperty(JcrLexicon.PRIMARY_TYPE);
+ if (primaryTypeProperty != null && !primaryTypeProperty.isEmpty()) {
+ Name primaryTypeName = nameFactory.create(primaryTypeProperty.getFirstValue());
+ String primaryTypeNameString = primaryTypeName.getString(registry);
+ NodeType primaryType = nodeTypeManager.getNodeType(primaryTypeNameString);
+ for (PropertyDefinition propertyDefn : primaryType.getPropertyDefinitions()) {
+ Name name = nameFactory.create(propertyDefn.getName());
+ propertyDefinitionsByPropertyName.put(name, propertyDefn);
+ }
+ }
+ org.jboss.dna.graph.property.Property mixinTypesProperty = graphNode.getProperty(JcrLexicon.MIXIN_TYPES);
+ if (mixinTypesProperty != null && !mixinTypesProperty.isEmpty()) {
+ for (Object mixinTypeValue : mixinTypesProperty) {
+ Name mixinTypeName = nameFactory.create(mixinTypeValue);
+ if (!referenceable && JcrMixLexicon.REFERENCEABLE.equals(mixinTypeName)) referenceable = true;
+ String mixinTypeNameString = mixinTypeName.getString(registry);
+ NodeType primaryType = nodeTypeManager.getNodeType(mixinTypeNameString);
+ for (PropertyDefinition propertyDefn : primaryType.getPropertyDefinitions()) {
+ Name name = nameFactory.create(propertyDefn.getName());
+ propertyDefinitionsByPropertyName.put(name, propertyDefn);
+ }
+ }
+ }
+
+ // Look for the UUID property ...
+ UUID uuid = null;
+ org.jboss.dna.graph.property.Property uuidProperty = graphNode.getProperty(JcrLexicon.UUID);
+ Name jcrUuidPropertyName = null;
+ Name dnaUuidPropertyName = null;
+ if (uuidProperty != null) {
+ jcrUuidPropertyName = uuidProperty.getName();
+ // Grab the first 'good' UUID value ...
+ for (Object uuidValue : uuidProperty) {
+ try {
+ uuid = factories.getUuidFactory().create(uuidValue);
+ break;
+ } catch (ValueFormatException e) {
+ // Ignore; just continue with the next property value
+ }
+ }
+ }
+ if (uuid == null) {
+ // Look for the DNA UUID property ...
+ org.jboss.dna.graph.property.Property dnaUuidProperty = graphNode.getProperty(DnaLexicon.UUID);
+ if (dnaUuidProperty != null) {
+ dnaUuidPropertyName = dnaUuidProperty.getName();
+ // Grab the first 'good' UUID value ...
+ for (Object uuidValue : dnaUuidProperty) {
+ try {
+ uuid = factories.getUuidFactory().create(uuidValue);
+ break;
+ } catch (ValueFormatException e) {
+ // Ignore; just continue with the next property value
+ }
+ }
+ }
+ }
+
+ // Now create the JCR property object wrapper around the "jcr:uuid" property ...
Set<Property> properties = new HashSet<Property>();
- UUID uuid = null;
- Name jcrUuidName = executionContext.getValueFactories().getNameFactory().create("jcr:uuid");
- Name jcrMixinTypesName = executionContext.getValueFactories().getNameFactory().create("jcr:mixinTypes");
- UuidFactory uuidFactory = executionContext.getValueFactories().getUuidFactory();
- org.jboss.dna.graph.property.Property dnaUuidProp = null;
- boolean referenceable = false;
+ if (uuid == null) uuid = UUID.randomUUID();
+ if (referenceable) {
+ if (uuidProperty == null) uuidProperty = executionContext.getPropertyFactory().create(JcrLexicon.UUID, uuid);
+ PropertyDefinition propertyDefinition = propertyDefinitionsByPropertyName.get(JcrLexicon.UUID);
+ properties.add(new JcrProperty(node, executionContext, propertyDefinition, uuidProperty));
+ }
+
+ // Now create the JCR property object wrappers around the other properties ...
for (org.jboss.dna.graph.property.Property dnaProp : graphNode.getProperties()) {
Name name = dnaProp.getName();
- if (dnaProp.isMultiple()) properties.add(new JcrMultiValueProperty(node, executionContext, name, dnaProp));
- else {
- if (uuid == null && DnaLexicon.UUID.equals(name)) uuid = uuidFactory.create(dnaProp.getValues()).next();
- else if (jcrUuidName.equals(name)) dnaUuidProp = dnaProp;
- else if (jcrMixinTypesName.equals(name)) {
- org.jboss.dna.graph.property.ValueFactory<String> stringFactory = executionContext.getValueFactories()
- .getStringFactory();
- for (String mixin : stringFactory.create(dnaProp)) {
- if ("mix:referenceable".equals(mixin)) referenceable = true;
+
+ // Skip the JCR and DNA UUID properties (using the EXACT Name instances on the Property) ...
+ if (name == jcrUuidPropertyName || name == dnaUuidPropertyName) continue;
+
+ // Figure out the JCR property type for this property ...
+ PropertyDefinition propertyDefinition = propertyDefinitionsByPropertyName.get(name);
+
+ // If no property type was specified, then use "nt:unstructured" property definitions for any property
+ if (propertyDefinition == null) {
+ if (anyMultiplePropertyDefinition == null) {
+ String unstructuredName = JcrNtLexicon.UNSTRUCTURED.getString(registry);
+ NodeType unstructured = nodeTypeManager.getNodeType(unstructuredName);
+ for (PropertyDefinition definition : unstructured.getDeclaredPropertyDefinitions()) {
+ if (definition.isMultiple()) {
+ anyMultiplePropertyDefinition = definition;
+ }
}
}
- properties.add(new JcrProperty(node, executionContext, name, dnaProp.getValues().next()));
+ assert anyMultiplePropertyDefinition != null;
+ propertyDefinition = anyMultiplePropertyDefinition;
}
+ assert propertyDefinition != null;
+ // Figure out if this is a multi-valued property ...
+ boolean isMultiple = propertyDefinition.isMultiple();
+ if (!isMultiple && dnaProp.isEmpty()) {
+ // Only multi-valued properties can have no values; so if not multi-valued, then skip ...
+ continue;
+ }
+
+ // Create the appropriate JCR property wrapper ...
+ if (isMultiple) {
+ properties.add(new JcrMultiValueProperty(node, executionContext, propertyDefinition, dnaProp));
+ } else {
+ properties.add(new JcrProperty(node, executionContext, propertyDefinition, dnaProp));
+ }
}
+
+ if (referenceable) {
+ assert uuidProperty != null;
+ }
+
+ // Now set the properties on the node ...
node.setProperties(properties);
+
// Set node's UUID, creating one if necessary
- if (uuid == null) {
- if (dnaUuidProp == null || !referenceable) uuid = UUID.randomUUID();
- else {
- uuid = uuidFactory.create(dnaUuidProp.getValues()).next();
- nodesByJcrUuid.put(uuid.toString(), node);
- }
- }
+ nodesByJcrUuid.put(uuid.toString(), node);
node.setInternalUuid(uuid);
// Setup node to be retrieved by DNA UUID
nodesByUuid.put(uuid, node);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -30,26 +30,27 @@
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.graph.property.Binary;
import org.jboss.dna.graph.property.ValueFactories;
/**
- * @param <T> the type of value to create.
* @author jverhaeg
*/
@NotThreadSafe
-final class JcrValue<T> implements Value {
+final class JcrValue implements Value {
private final ValueFactories valueFactories;
private final int type;
- private final T value;
+ private final Object value;
JcrValue( ValueFactories valueFactories,
int type,
- T value ) {
+ Object value ) {
assert valueFactories != null;
assert type == PropertyType.BINARY || type == PropertyType.BOOLEAN || type == PropertyType.DATE
|| type == PropertyType.DOUBLE || type == PropertyType.LONG || type == PropertyType.NAME
- || type == PropertyType.PATH || type == PropertyType.REFERENCE || type == PropertyType.STRING;
+ || type == PropertyType.PATH || type == PropertyType.REFERENCE || type == PropertyType.STRING
+ || type == PropertyType.UNDEFINED;
assert value != null;
this.valueFactories = valueFactories;
this.type = type;
@@ -143,7 +144,8 @@
throw new IllegalStateException(JcrI18n.nonInputStreamConsumed.text());
}
try {
- InputStream convertedValue = valueFactories.getBinaryFactory().create(value).getStream();
+ Binary binary = valueFactories.getBinaryFactory().create(value);
+ InputStream convertedValue = new SelfClosingInputStream(binary);
state = State.INPUT_STREAM_CONSUMED;
return convertedValue;
} catch (RuntimeException error) {
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SelfClosingInputStream.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SelfClosingInputStream.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SelfClosingInputStream.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -0,0 +1,245 @@
+/*
+ * 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.jcr;
+
+import java.io.IOException;
+import java.io.InputStream;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.graph.property.Binary;
+
+/**
+ * An {@link InputStream} implementation that can be used to access the content of a supplied {@link Binary} value. An instance of
+ * this class immediately {@link Binary#acquire() acquires} the binary's lock, and allows the InputStream to be processed and used
+ * normally. This class, however, guarantees that the binary lock is {@link Binary#release() released} whenever this class throws
+ * an exception or when the instance is {@link #close() closed}.
+ * <p>
+ * The draft version of the JSR-283 specification outlines a new mechanism for obtaining a lock on a binary value, and in fact
+ * this mechanism was used as the baseline for the design of DNA's Binary value. Therefore, when DNA's JCR implementation supports
+ * JCR-283, this class will probably no longer be needed.
+ * </p>
+ */
+@NotThreadSafe
+public class SelfClosingInputStream extends InputStream {
+
+ private final Binary binary;
+ private final InputStream stream;
+
+ /**
+ * Create a self-closing {@link InputStream} to access the content of the supplied {@link Binary} value. This construct
+ * immediately {@link Binary#acquire() acquires} the binary's lock, which is {@link Binary#release() released} whenever this
+ * class throws an exception or when the instance is {@link #close() closed}.
+ *
+ * @param binary the {@link Binary} object that this stream accesses; may not be null
+ */
+ public SelfClosingInputStream( Binary binary ) {
+ assert binary != null;
+ this.binary = binary;
+ this.binary.acquire();
+ this.stream = binary.getStream();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.io.InputStream#available()
+ */
+ @Override
+ public int available() throws IOException {
+ try {
+ return stream.available();
+ } catch (IOException e) {
+ this.binary.release();
+ throw e;
+ } catch (RuntimeException e) {
+ this.binary.release();
+ throw e;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.io.InputStream#close()
+ */
+ @Override
+ public void close() throws IOException {
+ try {
+ stream.close();
+ } finally {
+ this.binary.release();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ return stream.equals(obj);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return stream.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.io.InputStream#mark(int)
+ */
+ @Override
+ public void mark( int readlimit ) {
+ try {
+ stream.mark(readlimit);
+ } catch (RuntimeException e) {
+ this.binary.release();
+ throw e;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.io.InputStream#markSupported()
+ */
+ @Override
+ public boolean markSupported() {
+ return stream.markSupported();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.io.InputStream#read(byte[], int, int)
+ */
+ @Override
+ public int read( byte[] b,
+ int off,
+ int len ) throws IOException {
+ try {
+ return stream.read(b, off, len);
+ } catch (IOException e) {
+ this.binary.release();
+ throw e;
+ } catch (RuntimeException e) {
+ this.binary.release();
+ throw e;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.io.InputStream#read(byte[])
+ */
+ @Override
+ public int read( byte[] b ) throws IOException {
+ try {
+ return stream.read(b);
+ } catch (IOException e) {
+ this.binary.release();
+ throw e;
+ } catch (RuntimeException e) {
+ this.binary.release();
+ throw e;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.io.InputStream#read()
+ */
+ @Override
+ public int read() throws IOException {
+ try {
+ return stream.read();
+ } catch (IOException e) {
+ this.binary.release();
+ throw e;
+ } catch (RuntimeException e) {
+ this.binary.release();
+ throw e;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.io.InputStream#reset()
+ */
+ @Override
+ public void reset() throws IOException {
+ try {
+ stream.reset();
+ } catch (IOException e) {
+ this.binary.release();
+ throw e;
+ } catch (RuntimeException e) {
+ this.binary.release();
+ throw e;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.io.InputStream#skip(long)
+ */
+ @Override
+ public long skip( long n ) throws IOException {
+ try {
+ return stream.skip(n);
+ } catch (IOException e) {
+ this.binary.release();
+ throw e;
+ } catch (RuntimeException e) {
+ this.binary.release();
+ throw e;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ try {
+ return stream.toString();
+ } catch (RuntimeException e) {
+ this.binary.release();
+ throw e;
+ }
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SelfClosingInputStream.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-04 19:08:45 UTC (rev 752)
@@ -51,6 +51,8 @@
invalidRelativePath = "{0}" is not a valid relative path
invalidPathParameter = The "{1}" parameter value "{0}" was not a valid path
invalidNamePattern = The "{1}" name pattern contained the '{0}' character, which is not allowed in a name pattern
+itemNotFoundWithUuid = An item with UUID "{0}" could not be found in workspace "{1}"
+errorWhileFindingNodeWithUuid = Error while finding the item with UUID "{0}" in workspace "{1}"
REP_NAME_DESC = DNA Repository
REP_VENDOR_DESC = JBoss - A division of Red Hat Middleware LLC
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -33,6 +33,7 @@
import javax.jcr.ItemVisitor;
import javax.jcr.Node;
import javax.jcr.Property;
+import javax.jcr.PropertyType;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.Value;
@@ -40,8 +41,6 @@
import javax.jcr.nodetype.PropertyDefinition;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.NamespaceRegistry;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -63,20 +62,20 @@
@Mock
private Node node;
@Mock
- private NamespaceRegistry namespaceRegistry;
- @Mock
+ private PropertyDefinition propertyDefinition;
private ExecutionContext executionContext;
- @Mock
- private Name name;
+ private org.jboss.dna.graph.property.Property dnaProperty;
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
+ executionContext = new ExecutionContext();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "text/plain");
+ stub(propertyDefinition.getRequiredType()).toReturn(PropertyType.STRING);
stub(session.getWorkspace()).toReturn(workspace);
stub(session.getRepository()).toReturn(repository);
stub(node.getSession()).toReturn(session);
- stub(executionContext.getNamespaceRegistry()).toReturn(namespaceRegistry);
- prop = new MockAbstractJcrProperty(node, executionContext, name);
+ prop = new MockAbstractJcrProperty(node, executionContext, propertyDefinition, dnaProperty);
}
@Test
@@ -91,21 +90,6 @@
prop.accept(null);
}
- @Test( expected = AssertionError.class )
- public void shouldNotAllowNoSession() throws Exception {
- new MockAbstractJcrProperty(null, executionContext, name);
- }
-
- @Test( expected = AssertionError.class )
- public void shouldNotAllowNoExecutionContext() throws Exception {
- new MockAbstractJcrProperty(node, null, name);
- }
-
- @Test( expected = AssertionError.class )
- public void shouldNotAllowNoName() throws Exception {
- new MockAbstractJcrProperty(node, executionContext, null);
- }
-
@Test( expected = ItemNotFoundException.class )
public void shouldNotAllowNegativeAncestorDepth() throws Exception {
stub(node.getAncestor(-2)).toThrow(new IllegalArgumentException());
@@ -136,14 +120,8 @@
}
@Test
- public void shouldProvideNode() throws Exception {
- assertThat(prop.getNode(), is(node));
- }
-
- @Test
public void shouldProvideName() throws Exception {
- stub(name.getString(namespaceRegistry)).toReturn("name");
- assertThat(prop.getName(), is("name"));
+ assertThat(prop.getName(), is("jcr:mimeType"));
}
@Test
@@ -154,8 +132,7 @@
@Test
public void shouldProvidePath() throws Exception {
stub(node.getPath()).toReturn("/nodeName");
- stub(name.getString(namespaceRegistry)).toReturn("propertyName");
- assertThat(prop.getPath(), is("/nodeName/propertyName"));
+ assertThat(prop.getPath(), is("/nodeName/jcr:mimeType"));
}
@Test
@@ -171,38 +148,33 @@
}
@Test
- public void shouldIndicateSameAsNodeWithSameParentAndName() throws Exception {
- stub(name.getString(namespaceRegistry)).toReturn("propertyName");
+ public void shouldIndicateSameAsNodeWithSameParentAndSamePropertyName() throws Exception {
+ org.jboss.dna.graph.property.Property otherDnaProperty = executionContext.getPropertyFactory()
+ .create(dnaProperty.getName());
Node otherNode = Mockito.mock(Node.class);
stub(otherNode.getSession()).toReturn(session);
- Name otherName = Mockito.mock(Name.class);
- stub(otherName.getString(namespaceRegistry)).toReturn("propertyName");
stub(node.isSame(otherNode)).toReturn(true);
- Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, otherName);
+ Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, propertyDefinition, otherDnaProperty);
assertThat(prop.isSame(otherProp), is(true));
}
@Test
public void shouldIndicateDifferentThanNodeWithDifferentParent() throws Exception {
- stub(name.getString(namespaceRegistry)).toReturn("propertyName");
+ org.jboss.dna.graph.property.Property otherDnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.NAME);
Node otherNode = Mockito.mock(Node.class);
stub(otherNode.getSession()).toReturn(session);
- Name otherName = Mockito.mock(Name.class);
- stub(otherName.getString(namespaceRegistry)).toReturn("propertyName");
stub(node.isSame(otherNode)).toReturn(false);
- Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, otherName);
+ Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, propertyDefinition, otherDnaProperty);
assertThat(prop.isSame(otherProp), is(false));
}
@Test
- public void shouldIndicateDifferentThanNodeWithDifferentName() throws Exception {
- stub(name.getString(namespaceRegistry)).toReturn("propertyName");
+ public void shouldIndicateDifferentThanPropertyWithSameNodeWithDifferentPropertyName() throws Exception {
+ org.jboss.dna.graph.property.Property otherDnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.NAME);
Node otherNode = Mockito.mock(Node.class);
stub(otherNode.getSession()).toReturn(session);
- Name otherName = Mockito.mock(Name.class);
- stub(otherName.getString(namespaceRegistry)).toReturn("propertyName2");
stub(node.isSame(otherNode)).toReturn(true);
- Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, otherName);
+ Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, propertyDefinition, otherDnaProperty);
assertThat(prop.isSame(otherProp), is(false));
}
@@ -260,34 +232,35 @@
MockAbstractJcrProperty( Node node,
ExecutionContext executionContext,
- Name name ) {
- super(node, executionContext, name);
+ PropertyDefinition propertyDefinition,
+ org.jboss.dna.graph.property.Property dnaProperty ) {
+ super(node, executionContext, propertyDefinition, dnaProperty);
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getBoolean()
+ * @see javax.jcr.Property#getNode()
*/
- public boolean getBoolean() {
- return false;
+ public Node getNode() {
+ throw new UnsupportedOperationException(); // shouldn't be called
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getDate()
+ * @see javax.jcr.Property#getBoolean()
*/
- public Calendar getDate() {
- return null;
+ public boolean getBoolean() {
+ return false;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getDefinition()
+ * @see javax.jcr.Property#getDate()
*/
- public PropertyDefinition getDefinition() {
+ public Calendar getDate() {
return null;
}
@@ -348,15 +321,6 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getType()
- */
- public int getType() {
- return 0;
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Property#getValue()
*/
public Value getValue() {
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -74,24 +74,24 @@
addTestSuite(org.apache.jackrabbit.test.api.RootNodeTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NodeReadMethodsTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.PropertyTypeTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.PropertyTypeTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NodeDiscoveringNodeTypesTest.class);
addTestSuite(org.apache.jackrabbit.test.api.BinaryPropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.BooleanPropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.DatePropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.DoublePropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.LongPropertyTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.NamePropertyTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.NamePropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.PathPropertyTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.ReferencePropertyTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.StringPropertyTest.class);
- addTestSuite(org.apache.jackrabbit.test.api.UndefinedPropertyTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.ReferencePropertyTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.StringPropertyTest.class);
+ // addTestSuite(org.apache.jackrabbit.test.api.UndefinedPropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NamespaceRegistryReadMethodsTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NamespaceRemappingTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NodeIteratorTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.PropertyReadMethodsTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.PropertyReadMethodsTest.class);
addTestSuite(org.apache.jackrabbit.test.api.RepositoryDescriptorTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.SessionReadMethodsTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.SessionReadMethodsTest.class);
// addTestSuite(org.apache.jackrabbit.test.api.WorkspaceReadMethodsTest.class);
addTestSuite(org.apache.jackrabbit.test.api.ReferenceableRootNodesTest.class);
// addTestSuite(org.apache.jackrabbit.test.api.ExportSysViewTest.class);
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -26,11 +26,7 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.UUID;
+import static org.mockito.Mockito.stub;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyType;
@@ -38,11 +34,8 @@
import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.PropertyDefinition;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.Path;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -54,120 +47,31 @@
private Property prop;
@Mock
private Node node;
- private ExecutionContext executionContext = new ExecutionContext();
+ private ExecutionContext executionContext;
@Mock
- Name name;
+ private PropertyDefinition definition;
+ private org.jboss.dna.graph.property.Property dnaProperty;
@Before
public void before() {
MockitoAnnotations.initMocks(this);
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true));
+ executionContext = new ExecutionContext();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, true);
+ stub(definition.getRequiredType()).toReturn(PropertyType.BOOLEAN);
+ stub(definition.isMultiple()).toReturn(true);
+ prop = new JcrMultiValueProperty(node, executionContext, definition, dnaProperty);
}
- @Test( expected = AssertionError.class )
- public void shouldNotAllowNoValue() {
- new JcrMultiValueProperty(node, executionContext, name, null);
- }
-
@Test
public void shouldProvideAppropriateType() throws Exception {
- assertThat(prop.getType(), is(PropertyType.BOOLEAN));
- Calendar cal = Calendar.getInstance();
- Property prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(cal));
- assertThat(prop.getType(), is(PropertyType.DATE));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(cal.getTime()));
- assertThat(prop.getType(), is(PropertyType.DATE));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(1.0));
- assertThat(prop.getType(), is(PropertyType.DOUBLE));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(1.0F));
- assertThat(prop.getType(), is(PropertyType.DOUBLE));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(1));
- assertThat(prop.getType(), is(PropertyType.LONG));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(1L));
- assertThat(prop.getType(), is(PropertyType.LONG));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(new Object()));
- assertThat(prop.getType(), is(PropertyType.BINARY));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList("value"));
- assertThat(prop.getType(), is(PropertyType.STRING));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(UUID.randomUUID()));
- assertThat(prop.getType(), is(PropertyType.REFERENCE));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(Mockito.mock(Reader.class)));
- assertThat(prop.getType(), is(PropertyType.BINARY));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(Mockito.mock(InputStream.class)));
- assertThat(prop.getType(), is(PropertyType.BINARY));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(new Object()));
- assertThat(prop.getType(), is(PropertyType.BINARY));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(name));
- assertThat(prop.getType(), is(PropertyType.NAME));
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(Mockito.mock(Path.class)));
- assertThat(prop.getType(), is(PropertyType.PATH));
+ assertThat(prop.getType(), is(definition.getRequiredType()));
}
- @Test( expected = ValueFormatException.class )
- public void shouldNotProvideBoolean() throws Exception {
- prop.getBoolean();
- }
-
- @Test( expected = ValueFormatException.class )
- public void shouldNotProvideDateForCalendar() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(Calendar.getInstance())).getDate();
- }
-
- @Test( expected = ValueFormatException.class )
- public void shouldNotProvideDateForDate() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(Calendar.getInstance().getTime())).getDate();
- }
-
@Test
public void shouldProvidePropertyDefinition() throws Exception {
assertThat(prop.getDefinition(), notNullValue());
}
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionDeclaringNodeType() throws Exception {
- prop.getDefinition().getDeclaringNodeType();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionDefaultValues() throws Exception {
- prop.getDefinition().getDefaultValues();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionName() throws Exception {
- prop.getDefinition().getName();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionGetOnParentVersion() throws Exception {
- prop.getDefinition().getOnParentVersion();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionGetRequiredType() throws Exception {
- prop.getDefinition().getRequiredType();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionGetValueConstraints() throws Exception {
- prop.getDefinition().getValueConstraints();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionIsAutoCreated() throws Exception {
- prop.getDefinition().isAutoCreated();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionIsMandatory() throws Exception {
- prop.getDefinition().isMandatory();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionIsProtected() throws Exception {
- prop.getDefinition().isProtected();
- }
-
@Test
public void shouldIndicateHasMultipleValues() throws Exception {
PropertyDefinition def = prop.getDefinition();
@@ -176,33 +80,33 @@
}
@Test( expected = ValueFormatException.class )
- public void shouldNotProvideDoubleForDouble() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(1.0)).getDouble();
+ public void shouldNotProvideBooleanForMultiValuedProperty() throws Exception {
+ prop.getBoolean();
}
@Test( expected = ValueFormatException.class )
- public void shouldNotProvideDoubleForFloat() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(1.0F)).getDouble();
+ public void shouldNotProvideDateForMultiValuedProperty() throws Exception {
+ prop.getDate();
}
@Test( expected = ValueFormatException.class )
- public void shouldNotProvideLongForInteger() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(1)).getLong();
+ public void shouldNotProvideDoubleForMultiValuedProperty() throws Exception {
+ prop.getDouble();
}
@Test( expected = ValueFormatException.class )
- public void shouldNotProvideLongForLong() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(1L)).getLong();
+ public void shouldNotProvideLongForMultiValuedProperty() throws Exception {
+ prop.getLong();
}
@Test( expected = ValueFormatException.class )
- public void shouldNotProvideStream() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(new Object())).getStream();
+ public void shouldNotProvideStreamForMultiValuedProperty() throws Exception {
+ prop.getStream();
}
@Test( expected = ValueFormatException.class )
- public void shouldNotProvideString() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList("value")).getString();
+ public void shouldNotProvideStringForMultiValuedProperty() throws Exception {
+ prop.getString();
}
@Test( expected = ValueFormatException.class )
@@ -229,14 +133,38 @@
assertThat(lengths, notNullValue());
assertThat(lengths.length, is(1));
assertThat(lengths[0], is(4L));
- lengths = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList("value")).getLengths();
+
+ Object value = "value";
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, value);
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ stub(definition.isMultiple()).toReturn(true);
+ prop = new JcrMultiValueProperty(node, executionContext, definition, dnaProperty);
+ lengths = prop.getLengths();
assertThat(lengths, notNullValue());
assertThat(lengths.length, is(1));
assertThat(lengths[0], is(5L));
- Object obj = new Object();
- lengths = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(obj)).getLengths();
+
+ value = new Object();
+ long expectedLength = executionContext.getValueFactories().getBinaryFactory().create(value).getSize();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, value);
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ stub(definition.isMultiple()).toReturn(true);
+ prop = new JcrMultiValueProperty(node, executionContext, definition, dnaProperty);
+ lengths = prop.getLengths();
assertThat(lengths, notNullValue());
assertThat(lengths.length, is(1));
- assertThat(lengths[0], is((long)obj.toString().length()));
+ assertThat(lengths[0], is(expectedLength));
+
+ String[] values = new String[] {"value1", "value2", "value 3 is longer"};
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, (Object[])values);
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ stub(definition.isMultiple()).toReturn(true);
+ prop = new JcrMultiValueProperty(node, executionContext, definition, dnaProperty);
+ lengths = prop.getLengths();
+ assertThat(lengths, notNullValue());
+ assertThat(lengths.length, is(values.length));
+ assertThat(lengths[0], is((long)values[0].length()));
+ assertThat(lengths[1], is((long)values[1].length()));
+ assertThat(lengths[2], is((long)values[2].length()));
}
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -26,9 +26,9 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
import java.io.InputStream;
-import java.io.Reader;
-import java.util.Calendar;
import java.util.UUID;
import javax.jcr.Node;
import javax.jcr.Property;
@@ -37,11 +37,11 @@
import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.PropertyDefinition;
import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.property.DateTime;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -53,122 +53,109 @@
private Property prop;
@Mock
private Node node;
- private ExecutionContext executionContext = new ExecutionContext();
+ private ExecutionContext executionContext;
@Mock
Name name;
+ @Mock
+ private PropertyDefinition definition;
+ private org.jboss.dna.graph.property.Property dnaProperty;
@Before
public void before() {
MockitoAnnotations.initMocks(this);
- prop = new JcrProperty(node, executionContext, name, true);
+ executionContext = new ExecutionContext();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "text/plain");
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ stub(definition.isMultiple()).toReturn(false);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
}
- @Test( expected = AssertionError.class )
- public void shouldNotAllowNoValue() {
- new JcrProperty(node, executionContext, name, null);
- }
-
@Test
public void shouldProvideBoolean() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "true");
+ stub(definition.getRequiredType()).toReturn(PropertyType.BOOLEAN);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
assertThat(prop.getBoolean(), is(true));
assertThat(prop.getType(), is(PropertyType.BOOLEAN));
}
@Test
- public void shouldProvideDate() throws Exception {
- Calendar cal = Calendar.getInstance();
- Property prop = new JcrProperty(node, executionContext, name, cal);
- assertThat(prop.getDate(), is(cal));
- assertThat(prop.getType(), is(PropertyType.DATE));
- prop = new JcrProperty(node, executionContext, name, cal.getTime());
- assertThat(prop.getDate(), is(cal));
- assertThat(prop.getType(), is(PropertyType.DATE));
+ public void shouldIndicateHasSingleValue() throws Exception {
+ PropertyDefinition def = prop.getDefinition();
+ assertThat(def, notNullValue());
+ assertThat(def.isMultiple(), is(false));
}
@Test
- public void shouldProvidePropertyDefinition() throws Exception {
- assertThat(prop.getDefinition(), notNullValue());
+ public void shouldProvideDate() throws Exception {
+ DateTime dnaDate = executionContext.getValueFactories().getDateFactory().create();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, dnaDate);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DATE);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getDate(), is(dnaDate.toCalendar()));
+ assertThat(prop.getLong(), is(dnaDate.getMilliseconds()));
+ assertThat(prop.getType(), is(PropertyType.DATE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
}
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionDeclaringNodeType() throws Exception {
- prop.getDefinition().getDeclaringNodeType();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionDefaultValues() throws Exception {
- prop.getDefinition().getDefaultValues();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionName() throws Exception {
- prop.getDefinition().getName();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionGetOnParentVersion() throws Exception {
- prop.getDefinition().getOnParentVersion();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionGetRequiredType() throws Exception {
- prop.getDefinition().getRequiredType();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionGetValueConstraints() throws Exception {
- prop.getDefinition().getValueConstraints();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionIsAutoCreated() throws Exception {
- prop.getDefinition().isAutoCreated();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionIsMandatory() throws Exception {
- prop.getDefinition().isMandatory();
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldNotAllowPropertyDefinitionIsProtected() throws Exception {
- prop.getDefinition().isProtected();
- }
-
@Test
- public void shouldIndicateHasSingleValue() throws Exception {
- PropertyDefinition def = prop.getDefinition();
- assertThat(def, notNullValue());
- assertThat(def.isMultiple(), is(false));
+ public void shouldProvideNode() throws Exception {
+ UUID referencedUuid = UUID.randomUUID();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, referencedUuid);
+ stub(definition.getRequiredType()).toReturn(PropertyType.REFERENCE);
+ Node referencedNode = mock(Node.class);
+ JcrSession session = mock(JcrSession.class);
+ stub(node.getSession()).toReturn(session);
+ stub(session.getNode(referencedUuid)).toReturn(referencedNode);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getNode(), is(referencedNode));
+ assertThat(prop.getType(), is(PropertyType.REFERENCE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
}
@Test
public void shouldProvideDouble() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name, 1.0);
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1.0);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
assertThat(prop.getDouble(), is(1.0));
assertThat(prop.getType(), is(PropertyType.DOUBLE));
- prop = new JcrProperty(node, executionContext, name, 1.0F);
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1.0F);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
assertThat(prop.getDouble(), is(1.0));
assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
}
@Test
public void shouldProvideLong() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name, 1);
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
assertThat(prop.getLong(), is(1L));
- assertThat(prop.getType(), is(PropertyType.LONG));
- prop = new JcrProperty(node, executionContext, name, 1L);
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, 1L);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
assertThat(prop.getLong(), is(1L));
- assertThat(prop.getType(), is(PropertyType.LONG));
+ assertThat(prop.getString(), is("1"));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
}
@Test
public void shouldProvideStream() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name, new Object());
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, new Object());
+ stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getType(), is(PropertyType.BINARY));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
InputStream stream = prop.getStream();
try {
assertThat(stream, notNullValue());
- assertThat(prop.getType(), is(PropertyType.BINARY));
} finally {
if (stream != null) {
stream.close();
@@ -178,46 +165,59 @@
@Test
public void shouldProvideString() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name, "value");
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, "value");
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
assertThat(prop.getString(), is("value"));
assertThat(prop.getType(), is(PropertyType.STRING));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
}
@Test
public void shouldAllowReferenceValue() throws Exception {
UUID uuid = UUID.randomUUID();
- Property prop = new JcrProperty(node, executionContext, name, uuid);
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, uuid);
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
assertThat(prop.getString(), is(uuid.toString()));
- assertThat(prop.getType(), is(PropertyType.REFERENCE));
+ assertThat(prop.getType(), is(PropertyType.STRING));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
}
@Test
- public void shouldAllowBinaryValue() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name, Mockito.mock(Reader.class));
- assertThat(prop.getType(), is(PropertyType.BINARY));
- prop = new JcrProperty(node, executionContext, name, Mockito.mock(InputStream.class));
- assertThat(prop.getType(), is(PropertyType.BINARY));
- prop = new JcrProperty(node, executionContext, name, new Object());
- assertThat(prop.getType(), is(PropertyType.BINARY));
- }
-
- @Test
public void shouldAllowNameValue() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name, name);
+ executionContext.getNamespaceRegistry().register("acme", "http://example.com");
+ Name path = executionContext.getValueFactories().getNameFactory().create("acme:something");
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, path);
+ stub(definition.getRequiredType()).toReturn(PropertyType.NAME);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getString(), is("acme:something"));
assertThat(prop.getType(), is(PropertyType.NAME));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ // Change the namespace registry ...
+ executionContext.getNamespaceRegistry().register("acme2", "http://example.com");
+ assertThat(prop.getString(), is("acme2:something"));
}
@Test
public void shouldAllowPathValue() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name, Mockito.mock(Path.class));
+ executionContext.getNamespaceRegistry().register("acme", "http://example.com");
+ Path path = executionContext.getValueFactories().getPathFactory().create("/a/b/acme:c");
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, (Object)path);
+ stub(definition.getRequiredType()).toReturn(PropertyType.PATH);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getString(), is("/a/b/acme:c"));
assertThat(prop.getType(), is(PropertyType.PATH));
+ assertThat(prop.getName(), is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ // Change the namespace registry ...
+ executionContext.getNamespaceRegistry().register("acme2", "http://example.com");
+ assertThat(prop.getString(), is("/a/b/acme2:c"));
}
@Test
public void shouldProvideValue() throws Exception {
Value val = prop.getValue();
assertThat(val, notNullValue());
- assertThat(val.getBoolean(), is(true));
}
@Test( expected = ValueFormatException.class )
@@ -227,14 +227,31 @@
@Test
public void shouldProvideLength() throws Exception {
- assertThat(prop.getLength(), is(4L));
- assertThat(new JcrProperty(node, executionContext, name, "value").getLength(), is(5L));
+ String dnaValue = executionContext.getValueFactories().getStringFactory().create(dnaProperty.getFirstValue());
+ assertThat(prop.getLength(), is((long)dnaValue.length()));
+
+ dnaValue = "some other value";
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, dnaValue);
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getLength(), is((long)dnaValue.length()));
+
Object obj = new Object();
- assertThat(new JcrProperty(node, executionContext, name, obj).getLength(), is((long)obj.toString().length()));
+ long binaryLength = executionContext.getValueFactories().getBinaryFactory().create(obj).getSize();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE, obj);
+ stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
+ prop = new JcrProperty(node, executionContext, definition, dnaProperty);
+ assertThat(prop.getLength(), is(binaryLength));
}
@Test( expected = ValueFormatException.class )
public void shouldNotProvideLengths() throws Exception {
prop.getLengths();
}
+
+ @Test
+ public void shouldProvidePropertyDefinition() throws Exception {
+ assertThat(prop.getDefinition(), notNullValue());
+ }
+
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java 2009-03-04 00:54:32 UTC (rev 751)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java 2009-03-04 19:08:45 UTC (rev 752)
@@ -45,29 +45,14 @@
public class JcrValueTest {
private ValueFactories factories;
- private JcrValue<Boolean> value;
+ private JcrValue value;
@Before
public void before() {
factories = new StandardValueFactories(Mockito.mock(NamespaceRegistry.class));
- value = new JcrValue<Boolean>(factories, PropertyType.BOOLEAN, true);
+ value = new JcrValue(factories, PropertyType.BOOLEAN, true);
}
- @Test( expected = AssertionError.class )
- public void shouldNotAllowNoValueFactories() throws Exception {
- new JcrValue<Object>(null, PropertyType.BINARY, true);
- }
-
- @Test( expected = AssertionError.class )
- public void shouldNotAllowInvalidType() throws Exception {
- new JcrValue<Object>(factories, 0, true);
- }
-
- @Test( expected = AssertionError.class )
- public void shouldNotAllowNoValue() throws Exception {
- new JcrValue<Object>(factories, PropertyType.BINARY, null);
- }
-
@Test
public void shouldProvideType() throws Exception {
assertThat(value.getType(), is(PropertyType.BOOLEAN));
@@ -117,30 +102,30 @@
@Test( expected = ValueFormatException.class )
public void shouldNotProvideBooleanForDate() throws Exception {
- new JcrValue<Date>(factories, PropertyType.DATE, new Date()).getBoolean();
+ new JcrValue(factories, PropertyType.DATE, new Date()).getBoolean();
}
@Test
public void shouldProvideDateForDate() throws Exception {
Date date = new Date();
- assertThat(new JcrValue<Date>(factories, PropertyType.DATE, date).getDate().getTime(), is(date));
+ assertThat(new JcrValue(factories, PropertyType.DATE, date).getDate().getTime(), is(date));
}
@Test
public void shouldProvideDoubleForDate() throws Exception {
Date date = new Date();
- assertThat(new JcrValue<Date>(factories, PropertyType.DATE, date).getDouble(), is((double)date.getTime()));
+ assertThat(new JcrValue(factories, PropertyType.DATE, date).getDouble(), is((double)date.getTime()));
}
@Test
public void shouldProvideLongForDate() throws Exception {
Date date = new Date();
- assertThat(new JcrValue<Date>(factories, PropertyType.DATE, date).getLong(), is(date.getTime()));
+ assertThat(new JcrValue(factories, PropertyType.DATE, date).getLong(), is(date.getTime()));
}
@Test
public void shouldProvideStreamForDate() throws Exception {
- testProvidesStream(new JcrValue<Date>(factories, PropertyType.DATE, new Date()));
+ testProvidesStream(new JcrValue(factories, PropertyType.DATE, new Date()));
}
@Test
@@ -149,163 +134,161 @@
date.set(2008, 7, 18, 12, 0, 0);
date.set(Calendar.MILLISECOND, 0);
String expectedValue = "2008-08-18T12:00:00.000";
- assertThat(new JcrValue<Calendar>(factories, PropertyType.DATE, date).getString().substring(0, expectedValue.length()),
+ assertThat(new JcrValue(factories, PropertyType.DATE, date).getString().substring(0, expectedValue.length()),
is(expectedValue));
- assertThat(new JcrValue<Date>(factories, PropertyType.DATE, date.getTime()).getString().substring(0,
- expectedValue.length()),
+ assertThat(new JcrValue(factories, PropertyType.DATE, date.getTime()).getString().substring(0, expectedValue.length()),
is(expectedValue));
}
@Test( expected = ValueFormatException.class )
public void shouldNotProvideBooleanForDouble() throws Exception {
- new JcrValue<Double>(factories, PropertyType.DOUBLE, 0.0).getBoolean();
+ new JcrValue(factories, PropertyType.DOUBLE, 0.0).getBoolean();
}
@Test
public void shouldProvideDateForDouble() throws Exception {
Calendar expectedValue = Calendar.getInstance();
expectedValue.setTime(new Date(0L));
- assertThat(new JcrValue<Double>(factories, PropertyType.DOUBLE, 0.0).getDate(), is(expectedValue));
+ assertThat(new JcrValue(factories, PropertyType.DOUBLE, 0.0).getDate(), is(expectedValue));
}
@Test
public void shouldProvideDoubleForDouble() throws Exception {
- assertThat(new JcrValue<Double>(factories, PropertyType.DOUBLE, 1.2).getDouble(), is(1.2));
+ assertThat(new JcrValue(factories, PropertyType.DOUBLE, 1.2).getDouble(), is(1.2));
}
@Test
public void shouldProvideLongForDouble() throws Exception {
- assertThat(new JcrValue<Double>(factories, PropertyType.DOUBLE, 1.0).getLong(), is(1L));
- assertThat(new JcrValue<Double>(factories, PropertyType.DOUBLE, Double.MAX_VALUE).getLong(), is(Long.MAX_VALUE));
+ assertThat(new JcrValue(factories, PropertyType.DOUBLE, 1.0).getLong(), is(1L));
+ assertThat(new JcrValue(factories, PropertyType.DOUBLE, Double.MAX_VALUE).getLong(), is(Long.MAX_VALUE));
}
@Test
public void shouldProvideStreamForDouble() throws Exception {
- testProvidesStream(new JcrValue<Double>(factories, PropertyType.DOUBLE, 1.0));
+ testProvidesStream(new JcrValue(factories, PropertyType.DOUBLE, 1.0));
}
@Test
public void shouldProvideStringForDouble() throws Exception {
- assertThat(new JcrValue<Double>(factories, PropertyType.DOUBLE, 1.0).getString(), is("1.0"));
+ assertThat(new JcrValue(factories, PropertyType.DOUBLE, 1.0).getString(), is("1.0"));
}
@Test( expected = ValueFormatException.class )
public void shouldNotProvideBooleanForLong() throws Exception {
- new JcrValue<Long>(factories, PropertyType.LONG, 0L).getBoolean();
+ new JcrValue(factories, PropertyType.LONG, 0L).getBoolean();
}
@Test
public void shouldProvideDateForLong() throws Exception {
Calendar expectedValue = Calendar.getInstance();
expectedValue.setTime(new Date(0L));
- assertThat(new JcrValue<Long>(factories, PropertyType.LONG, 0L).getDate(), is(expectedValue));
+ assertThat(new JcrValue(factories, PropertyType.LONG, 0L).getDate(), is(expectedValue));
}
@Test
public void shouldProvideDoubleForLong() throws Exception {
- assertThat(new JcrValue<Long>(factories, PropertyType.LONG, 1L).getDouble(), is(1.0));
+ assertThat(new JcrValue(factories, PropertyType.LONG, 1L).getDouble(), is(1.0));
}
@Test
public void shouldProvideLongForLong() throws Exception {
- assertThat(new JcrValue<Long>(factories, PropertyType.LONG, 1L).getLong(), is(1L));
+ assertThat(new JcrValue(factories, PropertyType.LONG, 1L).getLong(), is(1L));
}
@Test
public void shouldProvideStreamForLong() throws Exception {
- testProvidesStream(new JcrValue<Long>(factories, PropertyType.LONG, 1L));
+ testProvidesStream(new JcrValue(factories, PropertyType.LONG, 1L));
}
@Test
public void shouldProvideStringForLong() throws Exception {
- assertThat(new JcrValue<Long>(factories, PropertyType.LONG, 1L).getString(), is("1"));
+ assertThat(new JcrValue(factories, PropertyType.LONG, 1L).getString(), is("1"));
}
@Test
public void shouldProvideBooleanForString() throws Exception {
- assertThat(new JcrValue<String>(factories, PropertyType.STRING, "true").getBoolean(), is(true));
- assertThat(new JcrValue<String>(factories, PropertyType.STRING, "yes").getBoolean(), is(false));
+ assertThat(new JcrValue(factories, PropertyType.STRING, "true").getBoolean(), is(true));
+ assertThat(new JcrValue(factories, PropertyType.STRING, "yes").getBoolean(), is(false));
}
@Test
public void shouldProvideDateForString() throws Exception {
- assertThat(new JcrValue<String>(factories, PropertyType.STRING, "2008").getDate(), notNullValue());
+ assertThat(new JcrValue(factories, PropertyType.STRING, "2008").getDate(), notNullValue());
}
@Test( expected = ValueFormatException.class )
public void shouldNotProvideDateForInvalidString() throws Exception {
- new JcrValue<String>(factories, PropertyType.STRING, "true").getDate();
+ new JcrValue(factories, PropertyType.STRING, "true").getDate();
}
@Test
public void shouldProvideDoubleForString() throws Exception {
- assertThat(new JcrValue<String>(factories, PropertyType.STRING, "1").getDouble(), is(1.0));
+ assertThat(new JcrValue(factories, PropertyType.STRING, "1").getDouble(), is(1.0));
}
@Test( expected = ValueFormatException.class )
public void shouldNotProvideDoubleForInvalidString() throws Exception {
- new JcrValue<String>(factories, PropertyType.STRING, "true").getDouble();
+ new JcrValue(factories, PropertyType.STRING, "true").getDouble();
}
@Test
public void shouldProvideLongForString() throws Exception {
- assertThat(new JcrValue<String>(factories, PropertyType.STRING, "1").getLong(), is(1L));
+ assertThat(new JcrValue(factories, PropertyType.STRING, "1").getLong(), is(1L));
}
@Test( expected = ValueFormatException.class )
public void shouldNotProvideLongForInvalidString() throws Exception {
- new JcrValue<String>(factories, PropertyType.STRING, "true").getLong();
+ new JcrValue(factories, PropertyType.STRING, "true").getLong();
}
@Test
public void shouldProvideStreamForString() throws Exception {
- testProvidesStream(new JcrValue<String>(factories, PropertyType.STRING, "true"));
+ testProvidesStream(new JcrValue(factories, PropertyType.STRING, "true"));
}
@Test
public void shouldProvideStringForString() throws Exception {
- assertThat(new JcrValue<String>(factories, PropertyType.STRING, "true").getString(), is("true"));
+ assertThat(new JcrValue(factories, PropertyType.STRING, "true").getString(), is("true"));
}
@Test
public void shouldProvideBooleanForUuid() throws Exception {
- assertThat(new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getBoolean(), is(false));
+ assertThat(new JcrValue(factories, PropertyType.STRING, UUID.randomUUID()).getBoolean(), is(false));
}
@Test( expected = ValueFormatException.class )
public void shouldNotProvideDateForUuid() throws Exception {
- new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getDate();
+ new JcrValue(factories, PropertyType.STRING, UUID.randomUUID()).getDate();
}
@Test( expected = ValueFormatException.class )
public void shouldNotProvideDoubleForUuid() throws Exception {
- new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getDouble();
+ new JcrValue(factories, PropertyType.STRING, UUID.randomUUID()).getDouble();
}
@Test( expected = ValueFormatException.class )
public void shouldNotProvideLongForUuid() throws Exception {
- new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getLong();
+ new JcrValue(factories, PropertyType.STRING, UUID.randomUUID()).getLong();
}
@Test
public void shouldProvideStreamForUuid() throws Exception {
- testProvidesStream(new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()));
+ testProvidesStream(new JcrValue(factories, PropertyType.STRING, UUID.randomUUID()));
}
@Test
public void shouldProvideStringForUuid() throws Exception {
String expectedValue = "40d373f7-75ad-4d84-900e-c72ebd98abb9";
- assertThat(new JcrValue<UUID>(factories, PropertyType.STRING, UUID.fromString(expectedValue)).getString(),
- is(expectedValue));
+ assertThat(new JcrValue(factories, PropertyType.STRING, UUID.fromString(expectedValue)).getString(), is(expectedValue));
}
@Test
public void shouldProvideLength() throws Exception {
- assertThat(new JcrValue<String>(factories, PropertyType.STRING, "test").getLength(), is(4L));
- assertThat(new JcrValue<Object>(factories, PropertyType.BINARY, "test").getLength(), is(4L));
+ assertThat(new JcrValue(factories, PropertyType.STRING, "test").getLength(), is(4L));
+ assertThat(new JcrValue(factories, PropertyType.BINARY, "test").getLength(), is(4L));
}
- private void testProvidesStream( JcrValue<?> value ) throws Exception {
+ private void testProvidesStream( JcrValue value ) throws Exception {
InputStream stream = value.getStream();
assertThat(stream, notNullValue());
stream.close();
15 years, 2 months
DNA SVN: r751 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-03 19:54:32 -0500 (Tue, 03 Mar 2009)
New Revision: 751
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java
Log:
DNA-289 AbstractJcrItem.isSame Does Not Match JCR 1.0 Specification
Applied the patch. One test had to be updated (minor issue), since it was updated for DNA-290 after the patch was uploaded. Also added another JCR TCK unit test to the mix, since all of its test methods were passing.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java 2009-03-04 00:36:43 UTC (rev 750)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java 2009-03-04 00:54:32 UTC (rev 751)
@@ -69,7 +69,26 @@
* @see javax.jcr.Item#isSame(javax.jcr.Item)
*/
public boolean isSame( Item otherItem ) throws RepositoryException {
- return (getSession().getWorkspace() == otherItem.getSession().getWorkspace());
+ assert getSession() != null;
+ assert otherItem.getSession() != null;
+ assert getSession().getRepository() != null;
+ assert otherItem.getSession().getRepository() != null;
+
+ if (getSession().getRepository() != otherItem.getSession().getRepository()) {
+ return false;
+ }
+
+ assert getSession().getWorkspace() != null;
+ assert otherItem.getSession().getWorkspace() != null;
+
+ String workspaceName = getSession().getWorkspace().getName();
+ String otherWorkspaceName = otherItem.getSession().getWorkspace().getName();
+
+ if (workspaceName == null) {
+ return otherWorkspaceName == null;
+ }
+
+ return workspaceName.equals(otherWorkspaceName);
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-03-04 00:36:43 UTC (rev 750)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-03-04 00:54:32 UTC (rev 751)
@@ -40,6 +40,7 @@
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.UnsupportedRepositoryOperationException;
@@ -461,9 +462,14 @@
* @throws UnsupportedOperationException always
* @see javax.jcr.Node#getReferences()
*/
- public final PropertyIterator getReferences() {
- // TODO: Need to provide this at the DNA layer first (probably via a connector query)
- throw new UnsupportedOperationException();
+ public final PropertyIterator getReferences() throws RepositoryException {
+ // Iterate through the properties to see which ones have a REFERENCE type ...
+ Set<Property> references = new HashSet<Property>();
+ for (Property property : properties) {
+ if (property.getType() == PropertyType.REFERENCE) references.add(property);
+ }
+ if (references.isEmpty()) return new JcrEmptyPropertyIterator();
+ return new JcrPropertyIterator(references);
}
/**
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-03-04 00:36:43 UTC (rev 750)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-03-04 00:54:32 UTC (rev 751)
@@ -40,6 +40,8 @@
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
@@ -110,6 +112,10 @@
private AbstractJcrNode node;
@Mock
private JcrSession session;
+ @Mock
+ private Workspace workspace;
+ @Mock
+ private Repository repository;
private List<Segment> children;
private Set<Property> properties;
@@ -317,9 +323,11 @@
node.getProperty("child/prop");
}
- @Test( expected = UnsupportedOperationException.class )
+ @Test
public void shouldNotAllowGetReferences() throws Exception {
- node.getReferences();
+ PropertyIterator iter = node.getReferences();
+ assertThat(iter, is(notNullValue()));
+ assertThat(iter.getSize(), is(0L));
}
@Test
@@ -465,9 +473,15 @@
@Test
public void shouldProvideIsSame() throws Exception {
stub(session.getWorkspace()).toReturn(Mockito.mock(Workspace.class));
+ stub(session.getRepository()).toReturn(repository);
JcrSession session2 = Mockito.mock(JcrSession.class);
+ JcrRepository repository2 = Mockito.mock(JcrRepository.class);
+
+ stub(session2.getRepository()).toReturn(repository2);
+ stub(session2.getWorkspace()).toReturn(workspace);
Node node2 = new MockAbstractJcrNode(session2, node.getName(), node.getParent());
assertThat(node.isSame(node2), is(false));
+
Property prop = Mockito.mock(Property.class);
stub(prop.getSession()).toReturn(session);
assertThat(node.isSame(prop), is(false));
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2009-03-04 00:36:43 UTC (rev 750)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2009-03-04 00:54:32 UTC (rev 751)
@@ -33,8 +33,10 @@
import javax.jcr.ItemVisitor;
import javax.jcr.Node;
import javax.jcr.Property;
+import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.Value;
+import javax.jcr.Workspace;
import javax.jcr.nodetype.PropertyDefinition;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.graph.ExecutionContext;
@@ -53,6 +55,10 @@
private AbstractJcrProperty prop;
@Mock
+ private Workspace workspace;
+ @Mock
+ private Repository repository;
+ @Mock
private Session session;
@Mock
private Node node;
@@ -66,6 +72,8 @@
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
+ stub(session.getWorkspace()).toReturn(workspace);
+ stub(session.getRepository()).toReturn(repository);
stub(node.getSession()).toReturn(session);
stub(executionContext.getNamespaceRegistry()).toReturn(namespaceRegistry);
prop = new MockAbstractJcrProperty(node, executionContext, name);
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java 2009-03-04 00:36:43 UTC (rev 750)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java 2009-03-04 00:54:32 UTC (rev 751)
@@ -73,7 +73,7 @@
// See https://jira.jboss.org/jira/browse/DNA-285
addTestSuite(org.apache.jackrabbit.test.api.RootNodeTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.NodeReadMethodsTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.NodeReadMethodsTest.class);
// addTestSuite(org.apache.jackrabbit.test.api.PropertyTypeTest.class);
addTestSuite(org.apache.jackrabbit.test.api.NodeDiscoveringNodeTypesTest.class);
addTestSuite(org.apache.jackrabbit.test.api.BinaryPropertyTest.class);
15 years, 2 months
DNA SVN: r750 - in trunk: dna-graph/src/main/java/org/jboss/dna/graph/property and 8 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-03 19:36:43 -0500 (Tue, 03 Mar 2009)
New Revision: 750
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyNodeIterator.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyPropertyIterator.java
Removed:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPathSegment.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java
Log:
DNA-290 Getting child nodes or properties by pattern is not implemented
Implemented the AbstractJcrNode.getNodes(String pattern) and AbstractJcrNode.getProperties(String pattern), which makes a few more of the JCR TCK tests pass. In the process, the way AbstractJcrNode stores children was (dramatically) simplified, and a few different kinds of NodeIterator and PropertyIterator implementations were added (including empty ones).
Also changed how DNA Path.Segment objects are created when no SNS index is specified, so the objects are now created with an index of 1 rather than -1. This was done because it was leaking -1 in some cases, and it also more closely aligns with JCR. Found and corrected minor related bugs in a few test cases.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/inmemory/InMemoryRepository.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -474,7 +474,7 @@
if (childrenWithSameNames.size() == 0) return;
if (childrenWithSameNames.size() == 1) {
InMemoryNode childWithSameName = childrenWithSameNames.get(0);
- Path.Segment newName = context.getValueFactories().getPathFactory().createSegment(name, Path.NO_INDEX);
+ Path.Segment newName = context.getValueFactories().getPathFactory().createSegment(name, Path.DEFAULT_INDEX);
childWithSameName.setName(newName);
return;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/Path.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -139,9 +139,9 @@
public static final String SELF = ".";
/**
- * The index that will be returned for a {@link Segment} that {@link Segment#hasIndex() has no index}.
+ * The default index for a {@link Segment}.
*/
- public static final int NO_INDEX = -1;
+ public static final int DEFAULT_INDEX = 1;
/**
* Representation of the segments that occur within a path.
@@ -159,7 +159,7 @@
public Name getName();
/**
- * Get the index for this segment, which will be {@link Path#NO_INDEX -1} if this segment has no specific index.
+ * Get the index for this segment, which will be 1 by default.
*
* @return the index
*/
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPathSegment.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPathSegment.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicPathSegment.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -48,7 +48,9 @@
* @throws IllegalArgumentException if the name is null or if the index is invalid
*/
public BasicPathSegment( Name name ) {
- this(name, Path.NO_INDEX);
+ assert name != null;
+ this.name = name;
+ this.index = Path.DEFAULT_INDEX;
}
/**
@@ -59,9 +61,9 @@
public BasicPathSegment( Name name,
int index ) {
assert name != null;
- assert index >= Path.NO_INDEX;
+ assert index >= Path.DEFAULT_INDEX;
this.name = name;
- this.index = (this.isSelfReference() || this.isParentReference()) ? Path.NO_INDEX : index;
+ this.index = (this.isSelfReference() || this.isParentReference()) ? Path.DEFAULT_INDEX : index;
}
/**
@@ -82,7 +84,7 @@
* {@inheritDoc}
*/
public boolean hasIndex() {
- return this.index != Path.NO_INDEX;
+ return this.index != Path.DEFAULT_INDEX;
}
/**
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicPathSegmentTest.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -84,7 +84,7 @@
@Test
public void shouldNotHaveIndexByDefault() {
segment = new BasicPathSegment(validName);
- assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX));
assertThat(segment.hasIndex(), is(false));
assertThat(segment.isSelfReference(), is(false));
assertThat(segment.isParentReference(), is(false));
@@ -94,7 +94,7 @@
@Test
public void shouldCreateSelfReferenceSegmentIfPassedSelfReferenceStringRegardlessOfIndex() {
segment = factory.createSegment(Path.SELF);
- assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX));
assertThat(segment.hasIndex(), is(false));
assertThat(segment.isSelfReference(), is(true));
assertThat(segment.isParentReference(), is(false));
@@ -102,7 +102,7 @@
assertThat(segment.getName().getNamespaceUri().length(), is(0));
segment = factory.createSegment(Path.SELF, 1);
- assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX));
assertThat(segment.hasIndex(), is(false));
assertThat(segment.isSelfReference(), is(true));
assertThat(segment.isParentReference(), is(false));
@@ -113,7 +113,7 @@
@Test
public void shouldCreateParentReferenceSegmentIfPassedParentReferenceStringRegardlessOfIndex() {
segment = factory.createSegment(Path.PARENT);
- assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX));
assertThat(segment.hasIndex(), is(false));
assertThat(segment.isSelfReference(), is(false));
assertThat(segment.isParentReference(), is(true));
@@ -121,7 +121,7 @@
assertThat(segment.getName().getNamespaceUri().length(), is(0));
segment = factory.createSegment(Path.PARENT, 1);
- assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX));
assertThat(segment.hasIndex(), is(false));
assertThat(segment.isSelfReference(), is(false));
assertThat(segment.isParentReference(), is(true));
@@ -143,14 +143,14 @@
@Test
public void shouldConsiderSegmentWithSameNameSiblingIndexOfOneToBeEqualToSegmentWithSameNameButNoIndex() {
- segment = new BasicPathSegment(validName, Path.NO_INDEX);
+ segment = new BasicPathSegment(validName, Path.DEFAULT_INDEX);
Path.Segment segment2 = new BasicPathSegment(validName, 1);
assertThat(segment, is(segment2));
}
@Test
public void shouldConsiderSegmentWithSameNameSiblingIndexOfTwoOrMoreToNotBeEqualToSegmentWithSameNameButNoIndex() {
- segment = new BasicPathSegment(validName, Path.NO_INDEX);
+ segment = new BasicPathSegment(validName, Path.DEFAULT_INDEX);
Path.Segment segment2 = new BasicPathSegment(validName, 2);
assertThat(segment, is(not(segment2)));
segment2 = new BasicPathSegment(validName, 3);
@@ -161,7 +161,7 @@
public void shouldUseDelimiterEncoderToEncodeDelimiterBetweenPrefixAndLocalPart() {
TextEncoder encoder = new Jsr283Encoder();
validName = new BasicName(DnaLexicon.Namespace.URI, "some:name:with:colons");
- segment = new BasicPathSegment(validName, Path.NO_INDEX);
+ segment = new BasicPathSegment(validName, Path.DEFAULT_INDEX);
TextEncoder delimiterEncoder = new TextEncoder() {
public String encode( String text ) {
if (":".equals(text)) return "\\:";
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -27,9 +27,11 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
+import java.util.regex.Pattern;
import javax.jcr.Item;
import javax.jcr.ItemNotFoundException;
import javax.jcr.ItemVisitor;
@@ -51,6 +53,9 @@
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.NamespaceRegistry;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.ValueFormatException;
import org.jboss.dna.graph.property.Path.Segment;
/**
@@ -61,8 +66,7 @@
private final JcrSession session;
Set<Property> properties;
- List<Name> children;
- List<Integer> childNameCounts;
+ List<Path.Segment> children;
private UUID uuid;
AbstractJcrNode( JcrSession session ) {
@@ -213,7 +217,8 @@
* @see javax.jcr.Node#getMixinNodeTypes()
*/
public NodeType[] getMixinNodeTypes() throws RepositoryException {
- PropertyIterator mixinProperties = getProperties(JcrLexicon.MIXIN_TYPES.getString(session.getExecutionContext().getNamespaceRegistry()));
+ PropertyIterator mixinProperties = getProperties(JcrLexicon.MIXIN_TYPES.getString(session.getExecutionContext()
+ .getNamespaceRegistry()));
List<NodeType> mixinNodeTypes = new ArrayList<NodeType>((int)mixinProperties.getSize());
while (mixinProperties.hasNext()) {
@@ -236,7 +241,8 @@
*/
public final Node getNode( String relativePath ) throws RepositoryException {
CheckArg.isNotEmpty(relativePath, "relativePath");
- Item item = getSession().getItem(getPath(getPath(), relativePath));
+ String path = getPath(getPath(), relativePath);
+ Item item = getSession().getItem(path);
if (item instanceof Node) {
return (Node)item;
}
@@ -249,7 +255,10 @@
* @see javax.jcr.Node#getNodes()
*/
public final NodeIterator getNodes() {
- return new JcrNodeIterator(this, children, childNameCounts);
+ if (children == null) {
+ return new JcrEmptyNodeIterator();
+ }
+ return new JcrChildNodeIterator(this, this.session.getExecutionContext().getNamespaceRegistry(), children);
}
/**
@@ -258,32 +267,35 @@
* @throws UnsupportedOperationException always
* @see javax.jcr.Node#getNodes(java.lang.String)
*/
- public NodeIterator getNodes( String namePattern ) {
- // TODO: Implement after changing impl to delegate to Graph API
- throw new UnsupportedOperationException();
- /*
- CheckArg.isNotEmpty(namePattern, "namePattern");
- String[] disjuncts = namePattern.split("\\|");
- List<Segment> nodes = new ArrayList<Segment>();
- for (String disjunct : disjuncts) {
- String pattern = disjunct.trim();
- CheckArg.isNotEmpty(pattern, "namePattern");
- String ndxPattern;
- int endNdx = pattern.length() - 1;
- if (pattern.charAt(endNdx) == ']') {
- int ndx = pattern.indexOf('[');
- ndxPattern = pattern.substring(ndx + 1, endNdx);
- pattern = pattern.substring(0, ndx);
- } else ndxPattern = null;
- for (Entry<Name, Integer> child : getChildCountsByName().entrySet()) {
- if (child.getKey().getLocalName().matches(pattern)) {
- if (ndxPattern != null && !child.getValue().toString().matches(ndxPattern)) continue;
- if (child.getValue() > 1) nodes.add(new BasicPathSegment(child.getKey(), child.getValue()));
- else nodes.add(new BasicPathSegment(child.getKey()));
+ public NodeIterator getNodes( String namePattern ) throws RepositoryException {
+ CheckArg.isNotNull(namePattern, "namePattern");
+ namePattern = namePattern.trim();
+ if (namePattern.length() == 0) return new JcrEmptyNodeIterator();
+ if ("*".equals(namePattern)) return getNodes();
+ List<Object> patterns = createPatternsFor(namePattern);
+
+ // Implementing exact-matching only for now to prototype types as properties
+ List<Path.Segment> matchingChildren = new LinkedList<Path.Segment>();
+ NamespaceRegistry registry = session.executionContext.getNamespaceRegistry();
+ boolean foundMatch = false;
+ for (Path.Segment child : children) {
+ String childName = child.getName().getString(registry);
+ for (Object patternOrMatch : patterns) {
+ if (patternOrMatch instanceof Pattern) {
+ Pattern pattern = (Pattern)patternOrMatch;
+ if (pattern.matcher(childName).matches()) foundMatch = true;
+ } else {
+ String match = (String)patternOrMatch;
+ if (childName.equals(match)) foundMatch = true;
}
+ if (foundMatch) {
+ foundMatch = false;
+ matchingChildren.add(child);
+ break;
+ }
}
}
- */
+ return new JcrChildNodeIterator(this, this.session.executionContext.getNamespaceRegistry(), matchingChildren);
}
/**
@@ -334,18 +346,89 @@
* @see javax.jcr.Node#getProperties(java.lang.String)
*/
public PropertyIterator getProperties( String namePattern ) throws RepositoryException {
- // TODO: Implement after changing impl to delegate to Graph API
+ CheckArg.isNotNull(namePattern, "namePattern");
+ namePattern = namePattern.trim();
+ if (namePattern.length() == 0) return new JcrEmptyPropertyIterator();
+ if ("*".equals(namePattern)) return new JcrPropertyIterator(properties);
+ List<Object> patterns = createPatternsFor(namePattern);
// Implementing exact-matching only for now to prototype types as properties
Set<Property> matchingProps = new HashSet<Property>();
- for (Property prop : properties) {
- String propName = prop.getName();
- if (propName.equals(namePattern)) matchingProps.add(prop);
+ for (Object patternOrMatch : patterns) {
+ if (patternOrMatch instanceof Pattern) {
+ Pattern pattern = (Pattern)patternOrMatch;
+ for (Property prop : properties) {
+ String propName = prop.getName();
+ if (pattern.matcher(propName).matches()) matchingProps.add(prop);
+ }
+ } else {
+ String match = (String)patternOrMatch;
+ for (Property prop : properties) {
+ String propName = prop.getName();
+ if (propName.equals(match)) matchingProps.add(prop);
+ }
+ }
}
-
return new JcrPropertyIterator(matchingProps);
}
+ protected static List<Object> createPatternsFor( String namePattern ) throws RepositoryException {
+ List<Object> patterns = new LinkedList<Object>();
+ for (String stringPattern : namePattern.split("[|]")) {
+ stringPattern = stringPattern.trim();
+ int length = stringPattern.length();
+ if (length == 0) continue;
+ if (stringPattern.indexOf("*") == -1) {
+ // Doesn't use wildcard, so use String not Pattern
+ patterns.add(stringPattern);
+ } else {
+ // We need to escape the regular expression characters ...
+ StringBuilder sb = new StringBuilder(length);
+ for (int i = 0; i != length; i++) {
+ char c = stringPattern.charAt(i);
+ switch (c) {
+ // Per the spec, the the following characters are not allowed in patterns:
+ case '/':
+ case '[':
+ case ']':
+ case '\'':
+ case '"':
+ case '|':
+ case '\t':
+ case '\n':
+ case '\r':
+ String msg = JcrI18n.invalidNamePattern.text(c, namePattern);
+ throw new RepositoryException(msg);
+ // The following characters must be escaped when used in regular expressions ...
+ case '?':
+ case '(':
+ case ')':
+ case '$':
+ case '^':
+ case '.':
+ case '{':
+ case '}':
+ case '\\':
+ sb.append("\\");
+ sb.append(c);
+ break;
+ case '*':
+ // replace with the regular expression wildcard
+ sb.append(".*");
+ break;
+ default:
+ sb.append(c);
+ break;
+ }
+ }
+ String escapedString = sb.toString();
+ Pattern pattern = Pattern.compile(escapedString);
+ patterns.add(pattern);
+ }
+ }
+ return patterns;
+ }
+
/**
* {@inheritDoc}
*
@@ -433,19 +516,17 @@
if (relativePath.indexOf('/') >= 0) {
return (getNode(relativePath) != null);
}
- int ndxNdx = relativePath.indexOf('[');
- String name = (ndxNdx < 0 ? relativePath : relativePath.substring(0, ndxNdx));
- CheckArg.isNotEmpty(name, "relativePath");
- int childNdx = 0;
if (children != null) {
- for (Name child : children) {
- if (name.equals(child.getString(session.getExecutionContext().getNamespaceRegistry()))) {
- if (ndxNdx >= 0) {
- return (Integer.parseInt(relativePath.substring(ndxNdx + 1, relativePath.length() - 1)) <= childNameCounts.get(childNdx));
- }
- return true;
+ try {
+ Path.Segment segment = session.getExecutionContext()
+ .getValueFactories()
+ .getPathFactory()
+ .createSegment(relativePath);
+ for (Path.Segment child : children) {
+ if (child.equals(segment)) return true;
}
- childNdx++;
+ } catch (ValueFormatException e) {
+ throw new RepositoryException(JcrI18n.invalidRelativePath.text(relativePath));
}
}
return false;
@@ -662,21 +743,7 @@
final void setChildren( List<Segment> children ) {
assert children != null;
- if (this.children == null) {
- this.children = new ArrayList<Name>(children.size());
- childNameCounts = new ArrayList<Integer>(children.size());
- }
- for (Segment seg : children) {
- Name name = seg.getName();
- int ndx = this.children.indexOf(name);
- if (ndx >= 0) {
- childNameCounts.set(ndx, childNameCounts.get(ndx) + 1);
- } else {
- this.children.add(name);
- childNameCounts.add(1);
- }
- }
- assert this.children.size() == childNameCounts.size();
+ this.children = children;
}
final void setInternalUuid( UUID uuid ) {
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ *
+ * JBoss DNA is free software. 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.jcr;
+
+import java.util.Iterator;
+import java.util.List;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.property.NamespaceRegistry;
+import org.jboss.dna.graph.property.Path;
+
+/**
+ * @author jverhaeg
+ */
+@Immutable
+final class JcrChildNodeIterator implements NodeIterator {
+
+ private final NamespaceRegistry registry;
+ private final Node parent;
+ private final Iterator<Path.Segment> iterator;
+ private int ndx;
+ private int size;
+
+ JcrChildNodeIterator( Node parent,
+ NamespaceRegistry registry,
+ List<Path.Segment> children ) {
+ assert parent != null;
+ assert registry != null;
+ assert children != null;
+ this.registry = registry;
+ this.parent = parent;
+ iterator = children.iterator();
+ size = children.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getPosition()
+ */
+ public long getPosition() {
+ return ndx;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getSize()
+ */
+ public long getSize() {
+ return size;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ return nextNode();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.NodeIterator#nextNode()
+ */
+ public Node nextNode() {
+ Path.Segment childSegment = iterator.next();
+ ndx++;
+ String childName = childSegment.getString(registry);
+ try {
+ return parent.getNode(childName);
+ } catch (RepositoryException error) {
+ throw new RuntimeException(error);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws IllegalArgumentException if <code>count</code> is negative.
+ * @see javax.jcr.RangeIterator#skip(long)
+ */
+ public void skip( long count ) {
+ CheckArg.isNonNegative(count, "count");
+ while (--count >= 0) {
+ nextNode();
+ }
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrChildNodeIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyNodeIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyNodeIterator.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyNodeIterator.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -0,0 +1,101 @@
+/*
+ * 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.jcr;
+
+import java.util.NoSuchElementException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import org.jboss.dna.common.util.CheckArg;
+
+/**
+ *
+ */
+public class JcrEmptyNodeIterator implements NodeIterator {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.NodeIterator#nextNode()
+ */
+ public Node nextNode() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getPosition()
+ */
+ public long getPosition() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getSize()
+ */
+ public long getSize() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#skip(long)
+ */
+ public void skip( long skipNum ) {
+ CheckArg.isNonNegative(skipNum, "skipNum");
+ if (skipNum == 0L) return;
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyNodeIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyPropertyIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyPropertyIterator.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyPropertyIterator.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -0,0 +1,101 @@
+/*
+ * 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.jcr;
+
+import java.util.NoSuchElementException;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import org.jboss.dna.common.util.CheckArg;
+
+/**
+ *
+ */
+public class JcrEmptyPropertyIterator implements PropertyIterator {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.PropertyIterator#nextProperty()
+ */
+ public Property nextProperty() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getPosition()
+ */
+ public long getPosition() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getSize()
+ */
+ public long getSize() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#skip(long)
+ */
+ public void skip( long skipNum ) {
+ CheckArg.isNonNegative(skipNum, "skipNum");
+ if (skipNum == 0L) return;
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrEmptyPropertyIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -58,14 +58,16 @@
public static I18n unableToRemapUriUsingPrefixUsedInNamespaceRegistry;
public static I18n errorWhileInitializingTheNamespaceRegistry;
+ public static I18n invalidRelativePath;
public static I18n invalidPathParameter;
+ public static I18n invalidNamePattern;
public static I18n typeNotFound;
-
+
// Used in AbstractJcrNode#getAncestor
public static I18n noNegativeDepth;
public static I18n tooDeep;
-
+
public static I18n REP_NAME_DESC;
public static I18n REP_VENDOR_DESC;
public static I18n SPEC_NAME_DESC;
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -1,143 +0,0 @@
-/*
- * 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.
- *
- * JBoss DNA is free software. 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.jcr;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.graph.property.Name;
-
-/**
- * @author jverhaeg
- */
-final class JcrNodeIterator implements NodeIterator {
-
- private final Node parent;
- private final Iterator<Name> childIterator;
- private final Iterator<Integer> childNameCountIterator;
- private transient Name child;
- private transient int childNameCount;
- private transient int childNdx = 1;
- private transient int ndx;
- private transient Node node;
-
- JcrNodeIterator( Node parent,
- List<Name> children,
- List<Integer> childNameCounts ) {
- assert parent != null;
- this.parent = parent;
- childIterator = (children == null ? null : children.iterator());
- childNameCountIterator = (childNameCounts == null ? null : childNameCounts.iterator());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.RangeIterator#getPosition()
- */
- public long getPosition() {
- return ndx;
- }
-
- /**
- * {@inheritDoc}
- *
- * @return -1L
- * @see javax.jcr.RangeIterator#getSize()
- */
- public long getSize() {
- return -1L;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext() {
- return ((childIterator != null && childIterator.hasNext()) || (child != null && childNdx <= childNameCount));
- }
-
- /**
- * {@inheritDoc}
- *
- * @see java.util.Iterator#next()
- */
- public Object next() {
- return nextNode();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.NodeIterator#nextNode()
- */
- public Node nextNode() {
- if (childIterator == null) {
- throw new NoSuchElementException();
- }
- if (child == null || childNdx > childNameCount) {
- child = childIterator.next();
- childNameCount = childNameCountIterator.next();
- childNdx = 1;
- }
- try {
- node = parent.getNode(child.getString(((JcrSession)parent.getSession()).getExecutionContext().getNamespaceRegistry())
- + '[' + childNdx + ']');
- childNdx++;
- ndx++;
- return node;
- } catch (RepositoryException error) {
- // TODO: Change to DnaException once DNA-180 is addressed
- throw new RuntimeException(error);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException always
- * @see java.util.Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws IllegalArgumentException if <code>count</code> is negative.
- * @see javax.jcr.RangeIterator#skip(long)
- */
- public void skip( long count ) {
- CheckArg.isNonNegative(count, "count");
- while (--count >= 0) {
- nextNode();
- }
- }
-}
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-04 00:36:43 UTC (rev 750)
@@ -48,7 +48,9 @@
unableToRemapUriUsingPrefixUsedInNamespaceRegistry = Unable to remap the namespace "{1}" to prefix "{0}" because the prefix is already used as the prefix for the namespace "{2}" in the workspace's namespace registry
errorWhileInitializingTheNamespaceRegistry = Error while initializing the namespace registry for workspace "{0}"
+invalidRelativePath = "{0}" is not a valid relative path
invalidPathParameter = The "{1}" parameter value "{0}" was not a valid path
+invalidNamePattern = The "{1}" name pattern contained the '{0}' character, which is not allowed in a name pattern
REP_NAME_DESC = DNA Repository
REP_VENDOR_DESC = JBoss - A division of Red Hat Middleware LLC
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -46,9 +46,7 @@
import javax.jcr.Workspace;
import javax.jcr.version.Version;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path.Segment;
-import org.jboss.dna.graph.property.basic.BasicName;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -66,10 +64,11 @@
List<Segment> children,
Node parent ) throws Exception {
MockAbstractJcrNode child = new MockAbstractJcrNode(session, name, parent);
- Segment seg = Mockito.mock(Segment.class);
- stub(seg.getName()).toReturn(new BasicName(null, name));
+ Segment seg = session.getExecutionContext().getValueFactories().getPathFactory().createSegment(name, index);
children.add(seg);
- stub(session.getItem(parent.getPath() + "/" + name + '[' + index + ']')).toReturn(child);
+ // Stub the session to return this node ...
+ String absolutePath = parent.getPath() + "/" + seg.getString(session.getExecutionContext().getNamespaceRegistry());
+ stub(session.getItem(absolutePath)).toReturn(child);
return child;
}
@@ -117,9 +116,7 @@
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
- NamespaceRegistry registry = Mockito.mock(NamespaceRegistry.class);
- ExecutionContext context = Mockito.mock(ExecutionContext.class);
- stub(context.getNamespaceRegistry()).toReturn(registry);
+ ExecutionContext context = new ExecutionContext();
stub(session.getExecutionContext()).toReturn(context);
children = new ArrayList<Segment>();
properties = new HashSet<Property>();
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -32,12 +32,10 @@
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path.Segment;
import org.jboss.dna.jcr.AbstractJcrNodeTest.MockAbstractJcrNode;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -54,9 +52,7 @@
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
- NamespaceRegistry registry = Mockito.mock(NamespaceRegistry.class);
- ExecutionContext context = Mockito.mock(ExecutionContext.class);
- stub(context.getNamespaceRegistry()).toReturn(registry);
+ ExecutionContext context = new ExecutionContext();
stub(session.getExecutionContext()).toReturn(context);
children = new ArrayList<Segment>();
node = new MockAbstractJcrNode(session, "node", null);
@@ -73,7 +69,7 @@
node.setChildren(children);
NodeIterator iter = node.getNodes();
assertThat(iter, notNullValue());
- assertThat(iter.getSize(), is(-1L));
+ assertThat(iter.getSize(), is(6L));
assertThat(iter.getPosition(), is(0L));
assertThat(iter.hasNext(), is(true));
assertThat((Node)iter.next(), is(child1));
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -131,7 +131,7 @@
while (childIterator.hasNext()) {
Location child = childIterator.next();
Name childName = child.getPath().getLastSegment().getName();
- int index = Path.NO_INDEX;
+ int index = Path.DEFAULT_INDEX;
Integer previous = childNames.put(childName, 1);
if (previous != null) {
int previousValue = previous.intValue();
Modified: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -172,8 +172,8 @@
assertThat(rule.getPathInRepository(sourcePath, pathFactory), is(repositoryPath));
assertThatGetPathInRepositoryReturnsCorrectPathInSource("");
assertThatGetPathInRepositoryReturnsCorrectPathInSource("m/n");
- assertThatGetPathInRepositoryReturnsCorrectPathInSource("m[0]");
- assertThatGetPathInRepositoryReturnsCorrectPathInSource("m[0]/n/o/p");
+ assertThatGetPathInRepositoryReturnsCorrectPathInSource("m[1]");
+ assertThatGetPathInRepositoryReturnsCorrectPathInSource("m[1]/n/o/p");
}
protected void assertThatGetPathInRepositoryReturnsCorrectPathInSource( String subpath ) {
@@ -199,8 +199,8 @@
assertThat(rule.getPathInSource(repositoryPath, pathFactory), is(sourcePath));
assertThatGetPathInSourceReturnsCorrectPathInRepository("");
assertThatGetPathInSourceReturnsCorrectPathInRepository("m/n");
- assertThatGetPathInSourceReturnsCorrectPathInRepository("m[0]");
- assertThatGetPathInSourceReturnsCorrectPathInRepository("m[0]/n/o/p");
+ assertThatGetPathInSourceReturnsCorrectPathInRepository("m[1]");
+ assertThatGetPathInSourceReturnsCorrectPathInRepository("m[1]/n/o/p");
}
Modified: trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java
===================================================================
--- trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java 2009-03-03 22:02:41 UTC (rev 749)
+++ trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java 2009-03-04 00:36:43 UTC (rev 750)
@@ -171,7 +171,7 @@
Location oldLocation = location2;
Location newLocation = Location.create(pathFactory.create("/a/b/c/d3/e[1]"));
assertThat(oldLocation.getPath().getString(namespaces), is("/a/b/c/e[2]"));
- assertThat(newLocation.getPath().getString(namespaces), is("/a/b/c/d3/e[1]"));
+ assertThat(newLocation.getPath().getString(namespaces), is("/a/b/c/d3/e")); // no SNS index
cache.addNewNode(workspaceId, location);
cache.addNewNode(workspaceId, location2);
for (Location loc : children)
@@ -296,7 +296,7 @@
Location oldLocation = location2;
Location newLocation = Location.create(pathFactory.create("/a/b/c/d3/e[1]"));
assertThat(oldLocation.getPath().getString(namespaces), is("/a/b/c/e[2]"));
- assertThat(newLocation.getPath().getString(namespaces), is("/a/b/c/d3/e[1]"));
+ assertThat(newLocation.getPath().getString(namespaces), is("/a/b/c/d3/e")); // no SNS index
cache.addNewNode(workspaceId, location);
cache.addNewNode(workspaceId, location2);
for (Location loc : children)
15 years, 2 months
DNA SVN: r749 - trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2009-03-03 17:02:41 -0500 (Tue, 03 Mar 2009)
New Revision: 749
Modified:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java
Log:
some coding enhancements
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java 2009-03-03 20:34:42 UTC (rev 748)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java 2009-03-03 22:02:41 UTC (rev 749)
@@ -23,6 +23,9 @@
*/
package org.jboss.dna.connector.svn;
+import java.io.File;
+import java.io.IOException;
+import org.jboss.dna.common.util.FileUtil;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
@@ -38,16 +41,19 @@
*/
public class SVNConnectorTestUtil {
-// public static void main( String[] args ) {
-// try {
-// System.out.println("hello ......");
-// SVNRepository repos = createRepository("file:////Users/sp/innoq-dev/innoq-jboss/jboss-dna/extensions/dna-connector-svn/src/test/resources/dummy_svn_repos", "sp", "p530020");
-// System.out.println("Repository Root: " + repos.getRepositoryRoot(true));
-// System.out.println("Repository UUID: " + repos.getRepositoryUUID(true));
-// System.out.println("hello ......");
-// } catch (SVNException e) {
-// }
-// }
+ public static void main( String[] args ) throws Exception {
+ try {
+ System.out.println("hello ......");
+ String svnUrl = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
+ String username = "sp";
+ String password = "";
+ SVNRepository repos = createRepository(svnUrl, username, password);
+ System.out.println("Repository Root: " + repos.getRepositoryRoot(true));
+ System.out.println("Repository UUID: " + repos.getRepositoryUUID(true));
+ System.out.println("hello ......");
+ } catch (SVNException e) {
+ }
+ }
/**
* Create a {@link SVNRepository} from a http protocol.
@@ -74,7 +80,21 @@
repository.setAuthenticationManager(authManager);
return repository;
}
+
+ public static String createURL(String src, String dst) throws IOException {
+ // First we need to find the absolute path. Note that Maven always runs the tests from the project's directory,
+ // so use new File to create an instance at the current location ...
+ File mySrc = new File(src);
+ File myDst = new File(dst);
+ // make sure the destination is empty before we copy
+ FileUtil.delete(myDst);
+ FileUtil.copy(mySrc, myDst);
+
+ // Now set the two path roots
+ String url = myDst.getCanonicalFile().toURL().toString();
+ return url.replaceFirst("file:/", "file://localhost/");
+ }
private SVNConnectorTestUtil() {
// prevent constructor
}
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2009-03-03 20:34:42 UTC (rev 748)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2009-03-03 22:02:41 UTC (rev 749)
@@ -23,17 +23,19 @@
*/
package org.jboss.dna.connector.svn;
+import static org.mockito.Mockito.stub;
+import static org.mockito.Mockito.verify;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsSame.sameInstance;
import static org.jboss.dna.graph.IsNodeWithChildren.hasChild;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.jboss.dna.common.text.UrlEncoder;
import org.jboss.dna.common.util.FileUtil;
import org.jboss.dna.graph.DnaLexicon;
@@ -78,6 +80,7 @@
private String uuidPropertyName;
private String sourceName;
private Graph graph;
+ private String svnUrl;
@Mock
private CachePolicy policy;
@@ -95,24 +98,9 @@
pathFactory = context.getValueFactories().getPathFactory();
propertyFactory = context.getPropertyFactory();
nameFactory = context.getValueFactories().getNameFactory();
-
- // First we need to find the absolute path. Note that Maven always runs the tests from the project's directory,
- // so use new File to create an instance at the current location ...
- File src = new File("src/test/resources/dummy_svn_repos");
- File dst = new File("target/copy_of dummy_svn_repos");
-
- // make sure the destination is empty before we copy
- FileUtil.delete(dst);
- FileUtil.copy(src, dst);
-
- // Now set the two path roots
- String svnUrl = dst.getCanonicalFile().toURL().toString();
- svnUrl = svnUrl.replaceFirst("file:/", "file://localhost/");
+ svnUrl = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
String username = "sp";
String password = "";
- // Create a Repository instance from the http-protocol, that use a anonymous credential.
- // String url = "http://anonsvn.jboss.org/repos/dna/trunk/extensions/dna-connector-svn/src...";
-
// Set up the appropriate factory for a particular protocol
repository = SVNConnectorTestUtil.createRepository(svnUrl, username, password);
sourceName = "the source name";
@@ -157,15 +145,13 @@
assertThat(connection.getDefaultCachePolicy(), is(sameInstance(policy)));
}
- // @Test
- // public void shouldGetTheSVNRepositoryRootFromTheSVNRepositoryWhenPinged() throws Exception {
- // CachePolicy policy = mock(CachePolicy.class);
- // repository = mock(SVNRepository.class);
- // connection = new SVNRepositoryConnection("the source name", policy, false, repository);
- // // stub(repository.getRepositoryRoot(true)).toReturn(null);
- // assertThat(connection.ping(1, TimeUnit.SECONDS), is(true));
- // verify(repository).getRepositoryRoot(true);
- // }
+ @Test
+ public void shouldGetTheSVNRepositoryRootFromTheSVNRepositoryWhenPinged() throws Exception {
+ CachePolicy policy = mock(CachePolicy.class);
+ repository = SVNConnectorTestUtil.createRepository(svnUrl, "sp", "");
+ connection = new SVNRepositoryConnection("the source name", policy, false, repository);
+ assertThat(connection.ping(1, TimeUnit.SECONDS), is(true));
+ }
@Test
public void shouldHaveNoOpListenerWhenCreated() {
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java 2009-03-03 20:34:42 UTC (rev 748)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java 2009-03-03 22:02:41 UTC (rev 749)
@@ -29,9 +29,11 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.mock;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -66,22 +68,9 @@
MockitoAnnotations.initMocks(this);
validName = "svn source";
validUuidPropertyName = "dna:uuid";
-
- // For file protocol access
- url = "file:///dummy_svn_repos";
-
- // For http protocol access
- // url = "http://anonsvn.jboss.org/repos/dna/trunk/extensions/dna-connector-svn/src...";
- username = "anonymous";
- password = "anonymous";
-
- // For https protocol access
- // For svn protocol access
- // For svn-ssh protocol access
-
+ url = SVNConnectorTestUtil.createURL("src/test/resources/dummy_svn_repos", "target/copy_of dummy_svn_repos");
validRootNodeUuid = UUID.randomUUID();
source = new SVNRepositorySource();
-
}
@After
@@ -244,12 +233,36 @@
}
// Only with local file protocol
-
-// @Test
-// public void shouldCreateFSRepositoryIfProtocolIsOfTypeFile() throws Exception {
-// this.source.setName(validName);
-// this.source.setSVNURL(url);
-// this.connection = source.getConnection();
-// assertThat(this.connection, is(notNullValue()));
-// }
+ @Test
+ public void shouldCreateFSRepositoryIfProtocolIsOfTypeFile() throws Exception {
+ this.source.setName(validName);
+ this.source.setSVNURL(url);
+ this.connection = source.getConnection();
+ assertThat(this.connection, is(notNullValue()));
+ }
+
+ @Test
+ public void shouldAllowMultipleConnectionsToBeOpenAtTheSameTime() throws Exception {
+ List<RepositoryConnection> connections = new ArrayList<RepositoryConnection>();
+ try {
+ for (int i = 0; i != 10; ++i) {
+ this.source.setName(validName);
+ this.source.setSVNURL(url);
+ RepositoryConnection conn = source.getConnection();
+ assertThat(conn, is(notNullValue()));
+ connections.add(conn);
+ }
+ } finally {
+ // Close all open connections ...
+ for (RepositoryConnection conn : connections) {
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ }
+ }
+ }
}
15 years, 2 months
DNA SVN: r748 - in trunk/dna-jcr/src: main/resources/org/jboss/dna/jcr and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-03 15:34:42 -0500 (Tue, 03 Mar 2009)
New Revision: 748
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
Log:
DNA-287 AbstractJcrNode.getAncestor Does Not Match JCR 1.0 Specification
Applied the patch that corrects the behavior of get ancestor, which per the spec is absolute and not relative (as was implemented).
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java 2009-03-03 19:20:59 UTC (rev 747)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java 2009-03-03 20:34:42 UTC (rev 748)
@@ -24,6 +24,7 @@
package org.jboss.dna.jcr;
import javax.jcr.Item;
+import javax.jcr.ItemNotFoundException;
import javax.jcr.RepositoryException;
/**
@@ -74,6 +75,45 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#getAncestor(int)
+ */
+ public final Item getAncestor( int depth ) throws RepositoryException {
+ if (depth < 0) {
+ throw new ItemNotFoundException(JcrI18n.noNegativeDepth.text(depth));
+ }
+
+ /*
+ * depth argument is absolute depth from root of content graph, not relative depth from current node.
+ * That is, if current node is at path /foo/bar/baz, getAncestor(1) returns node at /foo, getAncestor(2)
+ * returns node at /foo/bar, getAncestor(3) returns node at /foo/bar/baz, getAncestor(0) returns root node,
+ * and any other argument results in ItemNotFoundException.
+ * Next statement converts depth parameter from a relative depth to an absolute depth.
+ */
+ depth = getDepth() - depth;
+
+ if (depth < 0) {
+ throw new ItemNotFoundException(JcrI18n.tooDeep.text(depth));
+ }
+
+ Item ancestor = this;
+ while (--depth >= 0) {
+ ancestor = ancestor.getParent();
+ }
+ return ancestor;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() throws RepositoryException {
+ return getParent().getDepth() + 1;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @throws UnsupportedOperationException always
* @see javax.jcr.Item#refresh(boolean)
*/
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-03-03 19:20:59 UTC (rev 747)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-03-03 20:34:42 UTC (rev 748)
@@ -165,21 +165,6 @@
/**
* {@inheritDoc}
*
- * @throws IllegalArgumentException if <code>depth</code> is negative.
- * @see javax.jcr.Item#getAncestor(int)
- */
- public final Item getAncestor( int depth ) throws RepositoryException {
- CheckArg.isNonNegative(depth, "depth");
- Node ancestor = this;
- while (--depth >= 0) {
- ancestor = ancestor.getParent();
- }
- return ancestor;
- }
-
- /**
- * {@inheritDoc}
- *
* @throws UnsupportedRepositoryOperationException always
* @see javax.jcr.Node#getBaseVersion()
*/
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2009-03-03 19:20:59 UTC (rev 747)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2009-03-03 20:34:42 UTC (rev 748)
@@ -88,25 +88,6 @@
return new JcrValue<T>(valueFactories, propertyType, valueClass.cast(value));
}
- /**
- * {@inheritDoc}
- *
- * @throws IllegalArgumentException if <code>depth</code> is negative.
- * @see javax.jcr.Item#getAncestor(int)
- */
- public final Item getAncestor( int depth ) throws RepositoryException {
- return (depth == 0 ? this : node.getAncestor(depth - 1));
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#getDepth()
- */
- public int getDepth() throws RepositoryException {
- return getParent().getDepth() + 1;
- }
-
final ExecutionContext getExecutionContext() {
return executionContext;
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-03 19:20:59 UTC (rev 747)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-03-03 20:34:42 UTC (rev 748)
@@ -61,7 +61,11 @@
public static I18n invalidPathParameter;
public static I18n typeNotFound;
-
+
+ // Used in AbstractJcrNode#getAncestor
+ public static I18n noNegativeDepth;
+ public static I18n tooDeep;
+
public static I18n REP_NAME_DESC;
public static I18n REP_VENDOR_DESC;
public static I18n SPEC_NAME_DESC;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2009-03-03 19:20:59 UTC (rev 747)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2009-03-03 20:34:42 UTC (rev 748)
@@ -52,15 +52,6 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getDepth()
- */
- public int getDepth() throws RepositoryException {
- return getParent().getDepth() + 1;
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Node#getIndex()
*/
public int getIndex() {
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2009-03-03 19:20:59 UTC (rev 747)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2009-03-03 20:34:42 UTC (rev 748)
@@ -43,6 +43,7 @@
* @return 0;
* @see javax.jcr.Item#getDepth()
*/
+ @Override
public int getDepth() {
return 0;
}
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-03 19:20:59 UTC (rev 747)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-03 20:34:42 UTC (rev 748)
@@ -59,3 +59,6 @@
workspaceNameIsInvalid = "{1}" is not a valid workspace name for the "{0}" repository
errorVerifyingWorkspaceName =Error validating the workspace name "{1}" for the "{0}" repository\: {2}
typeNotFound=No type exists with name "{0}"
+
+noNegativeDepth=Depth parameter ({0}) cannot be negative
+tooDeep=Depth parameter ({0}) cannot be greater than the result of getDepth() for this node
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java 2009-03-03 19:20:59 UTC (rev 747)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java 2009-03-03 20:34:42 UTC (rev 748)
@@ -25,7 +25,6 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-import javax.jcr.Item;
import javax.jcr.ItemVisitor;
import javax.jcr.Node;
import javax.jcr.Session;
@@ -46,14 +45,6 @@
public void accept( ItemVisitor visitor ) {
}
- public Item getAncestor( int depth ) {
- return null;
- }
-
- public int getDepth() {
- return 0;
- }
-
public String getName() {
return null;
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-03-03 19:20:59 UTC (rev 747)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2009-03-03 20:34:42 UTC (rev 748)
@@ -86,6 +86,7 @@
this.parent = parent;
}
+ @Override
public int getDepth() {
return 0;
}
@@ -143,7 +144,7 @@
new MockAbstractJcrNode(null, null, null);
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ItemNotFoundException.class )
public void shouldNotAllowNegativeAncestorDepth() throws Exception {
node.getAncestor(-1);
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2009-03-03 19:20:59 UTC (rev 747)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2009-03-03 20:34:42 UTC (rev 748)
@@ -98,7 +98,7 @@
new MockAbstractJcrProperty(node, executionContext, null);
}
- @Test( expected = IllegalArgumentException.class )
+ @Test( expected = ItemNotFoundException.class )
public void shouldNotAllowNegativeAncestorDepth() throws Exception {
stub(node.getAncestor(-2)).toThrow(new IllegalArgumentException());
prop.getAncestor(-1);
@@ -106,9 +106,9 @@
@Test
public void shouldProvideAncestor() throws Exception {
- assertThat(prop.getAncestor(0), is((Item)prop));
- stub(node.getAncestor(0)).toReturn(node);
- assertThat(prop.getAncestor(1), is((Item)node));
+ assertThat(prop.getAncestor(prop.getDepth()), is((Item)prop));
+ stub(node.getAncestor(node.getDepth())).toReturn(node);
+ assertThat(prop.getAncestor(prop.getDepth() - 1), is((Item)node));
}
@Test( expected = ItemNotFoundException.class )
15 years, 2 months
DNA SVN: r747 - in trunk/dna-jcr/src: main/resources/org/jboss/dna/jcr and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-03 14:20:59 -0500 (Tue, 03 Mar 2009)
New Revision: 747
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java
trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties
Log:
DNA-288 JcrRepository.login Does Not Match JCR 1.0 Specification
Applied the patch that corrects the behavior when the workspace name submitted to the login method does not match the name of an existing workspace. The patch also adds to the JCR TCK tests.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-03-03 01:33:10 UTC (rev 746)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-03-03 19:20:59 UTC (rev 747)
@@ -295,8 +295,8 @@
// Verify that the workspace exists (or can be created) ...
Set<String> workspaces = graph.getWorkspaces();
if (!workspaces.contains(workspaceName)) {
- // Try to create it ...
- graph.createWorkspace().namedSomethingLike(workspaceName).getName();
+ // Per JCR 1.0 6.1.1, if the workspaceName is not recognized, a NoSuchWorkspaceException is thrown
+ throw new NoSuchWorkspaceException(JcrI18n.workspaceNameIsInvalid.text(sourceName, workspaceName));
}
workspaceName = graph.getCurrentWorkspace().getName();
} catch (InvalidWorkspaceException e) {
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-03 01:33:10 UTC (rev 746)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-03-03 19:20:59 UTC (rev 747)
@@ -25,7 +25,7 @@
credentialsMustProvideJaasMethod = The Credentials class "{0}" must implement either "public LoginContext getLoginContext();" or "public AccessControlContext getAccessControlContext();".
credentialsMustReturnAccessControlContext = The "getAccessControlContext()" method in Credentials class "{0}" must not return a null.
credentialsMustReturnLoginContext = The "getLoginContext()" method in Credentials class "{0}" must not return a null.
-defaultWorkspaceName = Default
+defaultWorkspaceName=
inputStreamConsumed = This value was already consumed as an input stream.
nonInputStreamConsumed = This value was already consumed as a non-input stream.
pathNotFound = No item exists at path {0}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java 2009-03-03 01:33:10 UTC (rev 746)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JackrabbitJcrTckTest.java 2009-03-03 19:20:59 UTC (rev 747)
@@ -75,7 +75,7 @@
addTestSuite(org.apache.jackrabbit.test.api.RootNodeTest.class);
// addTestSuite(org.apache.jackrabbit.test.api.NodeReadMethodsTest.class);
// addTestSuite(org.apache.jackrabbit.test.api.PropertyTypeTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.NodeDiscoveringNodeTypesTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.NodeDiscoveringNodeTypesTest.class);
addTestSuite(org.apache.jackrabbit.test.api.BinaryPropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.BooleanPropertyTest.class);
addTestSuite(org.apache.jackrabbit.test.api.DatePropertyTest.class);
@@ -96,7 +96,7 @@
addTestSuite(org.apache.jackrabbit.test.api.ReferenceableRootNodesTest.class);
// addTestSuite(org.apache.jackrabbit.test.api.ExportSysViewTest.class);
// addTestSuite(org.apache.jackrabbit.test.api.ExportDocViewTest.class);
- // addTestSuite(org.apache.jackrabbit.test.api.RepositoryLoginTest.class);
+ addTestSuite(org.apache.jackrabbit.test.api.RepositoryLoginTest.class);
// These might not all be level one tests
// addTestSuite(org.apache.jackrabbit.test.api.query.XPathPosIndexTest.class);
Modified: trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties 2009-03-03 01:33:10 UTC (rev 746)
+++ trunk/dna-jcr/src/test/resources/repositoryStubImpl.properties 2009-03-03 19:20:59 UTC (rev 747)
@@ -6,4 +6,4 @@
javax.jcr.tck.nodename4=node4
javax.jcr.tck.propertyname1=prop1
javax.jcr.tck.propertyname2=prop2
-javax.jcr.tck.workspacename=test
+javax.jcr.tck.workspacename=
15 years, 2 months
DNA SVN: r746 - trunk/dna-jcr/src/test/resources.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-03-02 20:33:10 -0500 (Mon, 02 Mar 2009)
New Revision: 746
Removed:
trunk/dna-jcr/src/test/resources/repositoryJackRabbitTck.xml
Log:
Attempted to correct case
Deleted: trunk/dna-jcr/src/test/resources/repositoryJackRabbitTck.xml
===================================================================
--- trunk/dna-jcr/src/test/resources/repositoryJackRabbitTck.xml 2009-03-03 01:30:03 UTC (rev 745)
+++ trunk/dna-jcr/src/test/resources/repositoryJackRabbitTck.xml 2009-03-03 01:33:10 UTC (rev 746)
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- ~
- ~ JBoss DNA is free software. 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 distribution; if not, write to:
- ~ Free Software Foundation, Inc.
- ~ 51 Franklin Street, Fifth Floor
- ~ Boston, MA 02110-1301 USA
- -->
-<testroot xmlns:jcr="http://www.jcp.org/jcr/1.0"
- xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
- jcr:primaryType="nt:unstructured">
- <nt:unstructured jcr:name="node1" jcr:primaryType="nt:unstructured" prop1="foo" />
- <nt:unstructured jcr:name="node2" jcr:primaryType="nt:unstructured" prop2="bar" />
- <nt:unstructured jcr:name="node3" jcr:primaryType="nt:unstructured" />
- <nt:unstructured jcr:name="node4" jcr:primaryType="nt:unstructured" />
-</testroot>
\ No newline at end of file
15 years, 2 months