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();