[dna-commits] DNA SVN: r452 - in trunk/dna-jcr: src/main/java/org/jboss/dna/jcr and 2 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Aug 20 11:19:52 EDT 2008


Author: jverhaeg at redhat.com
Date: 2008-08-20 11:19:52 -0400 (Wed, 20 Aug 2008)
New Revision: 452

Added:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java
Removed:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java
Modified:
   trunk/dna-jcr/pom.xml
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
   trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
Log:
DNA-178: Completed basic functionality to  retrieve nodes and properties

Modified: trunk/dna-jcr/pom.xml
===================================================================
--- trunk/dna-jcr/pom.xml	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/pom.xml	2008-08-20 15:19:52 UTC (rev 452)
@@ -38,6 +38,13 @@
     </dependency>
     <dependency>
       <groupId>org.jboss.dna</groupId>
+      <artifactId>dna-spi</artifactId>
+      <version>${dna-version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.dna</groupId>
       <artifactId>dna-repository</artifactId>
     </dependency>
     <!-- 

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -23,7 +23,7 @@
 
 import java.io.InputStream;
 import java.util.Calendar;
-import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import javax.jcr.Item;
 import javax.jcr.ItemVisitor;
@@ -41,6 +41,8 @@
 import javax.jcr.version.VersionHistory;
 import net.jcip.annotations.NotThreadSafe;
 import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.graph.Path.Segment;
 
 /**
  * @author jverhaeg
@@ -49,13 +51,12 @@
 abstract class AbstractJcrNode implements Node {
 
     private final Session session;
-    private final Set<Property> properties;
+    private Set<Property> properties;
+    private List<Segment> children;
 
-    AbstractJcrNode( Session session,
-                     Set<Property> properties ) {
+    AbstractJcrNode( Session session ) {
         assert session != null;
         this.session = session;
-        this.properties = (properties == null ? new HashSet<Property>() : properties);
     }
 
     /**
@@ -325,8 +326,8 @@
      */
     public String getUUID() throws RepositoryException {
         // TODO: Check if node is referenceable
-        Property prop = getProperty("jcr:uuid");
-        return (prop == null ? null : prop.getValue().getString());
+        Property prop = getProperty(DnaLexicon.UUID.getString());
+        return (prop == null ? null : prop.getString());
     }
 
     /**
@@ -553,6 +554,16 @@
         throw new UnsupportedOperationException();
     }
 
+    void setChildren( List<Segment> children ) {
+        assert children != null;
+        this.children = children;
+    }
+
+    void setProperties( Set<Property> properties ) {
+        assert properties != null;
+        this.properties = properties;
+    }
+
     /**
      * {@inheritDoc}
      * 

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	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -27,10 +27,13 @@
 import javax.jcr.ItemVisitor;
 import javax.jcr.Node;
 import javax.jcr.Property;
+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.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
 
 /**
  * @author jverhaeg
@@ -38,119 +41,46 @@
 @NotThreadSafe
 abstract class AbstractJcrProperty implements Property {
 
-    private final Session session;
-    private final String name;
+    private final Node node;
+    private final ExecutionContext executionContext;
+    private final Name name;
 
-    AbstractJcrProperty( Session session,
-                         String name ) {
-        assert session != null;
-        this.session = session;
-        assert name != null && name.length() > 0;
+    AbstractJcrProperty( Node node,
+                         ExecutionContext executionContext,
+                         Name name ) {
+        assert node != null;
+        assert executionContext != null;
+        assert name != null;
+        this.node = node;
+        this.executionContext = executionContext;
         this.name = name;
     }
 
     /**
      * {@inheritDoc}
      * 
-     * @see javax.jcr.Property#getDate()
-     */
-    public Calendar getDate() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
      * @see javax.jcr.Property#getDefinition()
      */
     public PropertyDefinition getDefinition() {
         throw new UnsupportedOperationException();
     }
 
-    /**
-     * {@inheritDoc}
-     * 
-     * @see javax.jcr.Property#getDouble()
-     */
-    public double getDouble() {
-        throw new UnsupportedOperationException();
+    ExecutionContext getExecutionContext() {
+        return executionContext;
     }
 
     /**
      * {@inheritDoc}
      * 
-     * @see javax.jcr.Property#getLength()
-     */
-    public long getLength() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see javax.jcr.Property#getLengths()
-     */
-    public long[] getLengths() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see javax.jcr.Property#getLong()
-     */
-    public long getLong() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
      * @see javax.jcr.Property#getNode()
      */
     public Node getNode() {
-        throw new UnsupportedOperationException();
+        return node;
     }
 
     /**
      * {@inheritDoc}
      * 
-     * @see javax.jcr.Property#getStream()
-     */
-    public InputStream getStream() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see javax.jcr.Property#getString()
-     */
-    public String getString() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see javax.jcr.Property#getType()
-     */
-    public int getType() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see javax.jcr.Property#getValue()
-     */
-    public Value getValue() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
      * @see javax.jcr.Property#getValues()
      */
     public Value[] getValues() {
@@ -280,7 +210,7 @@
      * @see javax.jcr.Item#getName()
      */
     public String getName() {
-        return name;
+        return name.getString();
     }
 
     /**
@@ -306,8 +236,8 @@
      * 
      * @see javax.jcr.Item#getSession()
      */
-    public Session getSession() {
-        return session;
+    public Session getSession() throws RepositoryException {
+        return node.getSession();
     }
 
     /**

Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/GraphTools.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -1,127 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors. 
- *
- * This is free software; you can redistribute it and/or modify it
- * 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.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.jcr;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.jcr.Property;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-import org.jboss.dna.spi.ExecutionContext;
-import org.jboss.dna.spi.connector.RepositoryConnection;
-import org.jboss.dna.spi.graph.NameFactory;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.PathFactory;
-import org.jboss.dna.spi.graph.PropertyType;
-import org.jboss.dna.spi.graph.ValueFactories;
-import org.jboss.dna.spi.graph.commands.GraphCommand;
-import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
-
-/**
- * @author jverhaeg
- */
-class GraphTools {
-
-    private final ExecutionContext executionContext;
-    private Session session;
-    private final RepositoryConnection connection;
-
-    GraphTools( ExecutionContext executionContext,
-                RepositoryConnection connection ) {
-        assert executionContext != null;
-        assert connection != null;
-        this.executionContext = executionContext;
-        this.connection = connection;
-    }
-
-    private void execute( GraphCommand... commands ) throws RepositoryException {
-        try {
-            connection.execute(executionContext, commands);
-        } catch (RuntimeException error) {
-            throw error;
-        } catch (Exception error) {
-            throw new RepositoryException(error);
-        }
-    }
-
-    /**
-     * @return connection
-     */
-    public RepositoryConnection getConnection() {
-        return connection;
-    }
-
-    NodeContent getNodeContent( Path path ) throws RepositoryException {
-        assert session != null;
-        assert path != null;
-        // Get root node from source
-        ValueFactories valueFactories = executionContext.getValueFactories();
-        PathFactory pathFactory = valueFactories.getPathFactory();
-        BasicGetNodeCommand getRootNodeCommand = new BasicGetNodeCommand(path);
-        execute(getRootNodeCommand);
-        // Get primary type
-        NameFactory nameFactory = valueFactories.getNameFactory();
-        org.jboss.dna.spi.graph.Property primaryTypeProp = getRootNodeCommand.getPropertiesByName().get(nameFactory.create("jcr:primaryType"));
-        org.jboss.dna.spi.graph.ValueFactory<String> stringFactory = valueFactories.getStringFactory();
-        String primaryType = stringFactory.create(primaryTypeProp.getValues()).next();
-        // Process node's properties
-        NodeContent content = new NodeContent();
-        org.jboss.dna.spi.graph.ValueFactory<Boolean> booleanFactory = valueFactories.getBooleanFactory();
-        for (org.jboss.dna.spi.graph.Property prop : getRootNodeCommand.getProperties()) {
-            // Get property definition from node's primary type
-            BasicGetNodeCommand getPropDefCommand = new BasicGetNodeCommand(pathFactory.create("/dna:system/dna:jcr/"
-                                                                                               + primaryType + "/"
-                                                                                               + prop.getName()));
-            execute(getPropDefCommand);
-            // Create either a single- or multiple-valued property, as defined by the property definition
-            org.jboss.dna.spi.graph.Property isMultipleProp = getPropDefCommand.getPropertiesByName().get(nameFactory.create("jcr:multiple"));
-            org.jboss.dna.spi.graph.Property requiredTypeProp = getPropDefCommand.getPropertiesByName().get(nameFactory.create("jcr:requiredType"));
-            String type = stringFactory.create(requiredTypeProp.getValues()).next();
-            if (booleanFactory.create(isMultipleProp.getValues()).next().booleanValue()) {
-                // jcrProps.add(new JcrMultiValuedProperty(dnaProp.getName(), type, dnaProp.getValues()));
-            } else {
-                Value jcrValue;
-                ValueFactory jcrValueFactory = session.getValueFactory();
-                if (PropertyType.BINARY.equals(type)) {
-                    jcrValue = jcrValueFactory.createValue(valueFactories.getBinaryFactory().create(prop.getValues()).next().getStream());
-                } else {
-                    assert PropertyType.UUID.equals(type);
-                    jcrValue = jcrValueFactory.createValue(valueFactories.getStringFactory().create(prop.getValues()).next());
-                }
-                content.properties.add(new JcrProperty(session, prop.getName().toString(), jcrValue));
-            }
-        }
-        return content;
-    }
-
-    void setSession( Session session ) {
-        assert session != null;
-        this.session = session;
-    }
-
-    class NodeContent {
-
-        Set<Property> properties = new HashSet<Property>();
-    }
-}

Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrExecutionContext.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -1,112 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors. 
- *
- * This is free software; you can redistribute it and/or modify it
- * 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.
- *
- * This software 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.security.AccessControlContext;
-import javax.security.auth.Subject;
-import javax.security.auth.login.LoginContext;
-import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.spi.ExecutionContext;
-import org.jboss.dna.spi.connector.RepositoryConnection;
-import org.jboss.dna.spi.graph.NamespaceRegistry;
-import org.jboss.dna.spi.graph.PropertyFactory;
-import org.jboss.dna.spi.graph.ValueFactories;
-
-/**
- * @author jverhaeg
- */
- at NotThreadSafe
-class JcrExecutionContext implements ExecutionContext {
-
-    private final ExecutionContext delegate;
-    private final GraphTools tools;
-
-    JcrExecutionContext( ExecutionContext delegate,
-                         RepositoryConnection connection ) {
-        assert delegate != null;
-        assert connection != null;
-        this.delegate = delegate;
-        tools = new GraphTools(delegate, connection);
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see org.jboss.dna.spi.ExecutionContext#getAccessControlContext()
-     */
-    public AccessControlContext getAccessControlContext() {
-        return delegate.getAccessControlContext();
-    }
-
-    GraphTools getGraphTools() {
-        return tools;
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see org.jboss.dna.spi.ExecutionContext#getLoginContext()
-     */
-    public LoginContext getLoginContext() {
-        return delegate.getLoginContext();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see org.jboss.dna.spi.ExecutionContext#getNamespaceRegistry()
-     */
-    public NamespaceRegistry getNamespaceRegistry() {
-        return delegate.getNamespaceRegistry();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see org.jboss.dna.spi.ExecutionContext#getPropertyFactory()
-     */
-    public PropertyFactory getPropertyFactory() {
-        return delegate.getPropertyFactory();
-    }
-
-    RepositoryConnection getRepositoryConnection() {
-        return tools.getConnection();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see org.jboss.dna.spi.ExecutionContext#getSubject()
-     */
-    public Subject getSubject() {
-        return delegate.getSubject();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
-     * @see org.jboss.dna.spi.ExecutionContext#getValueFactories()
-     */
-    public ValueFactories getValueFactories() {
-        return delegate.getValueFactories();
-    }
-}

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	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -21,8 +21,6 @@
  */
 package org.jboss.dna.jcr;
 
-import java.util.Locale;
-import java.util.Set;
 import org.jboss.dna.common.i18n.I18n;
 
 /**
@@ -31,10 +29,14 @@
  */
 public final class JcrI18n {
 
+    public static I18n cannotConvertValue;
     public static I18n credentialsMustProvideJaasMethod;
     public static I18n credentialsMustReturnAccessControlContext;
     public static I18n credentialsMustReturnLoginContext;
     public static I18n defaultWorkspaceName;
+    public static I18n inputStreamConsumed;
+    public static I18n nonInputStreamConsumed;
+    public static I18n pathNotFound;
     public static I18n repositoryMustBeConfigured;
     public static I18n sourceInUse;
 
@@ -49,16 +51,4 @@
             System.err.println(err);
         }
     }
-
-    public static Set<Locale> getLocalizationProblemLocales() {
-        return I18n.getLocalizationProblemLocales(JcrI18n.class);
-    }
-
-    public static Set<String> getLocalizationProblems() {
-        return I18n.getLocalizationProblems(JcrI18n.class);
-    }
-
-    public static Set<String> getLocalizationProblems( Locale locale ) {
-        return I18n.getLocalizationProblems(JcrI18n.class, locale);
-    }
 }

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -21,7 +21,6 @@
  */
 package org.jboss.dna.jcr;
 
-import java.util.Set;
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.RepositoryException;
@@ -34,9 +33,8 @@
 @NotThreadSafe
 final class JcrNode extends AbstractJcrNode {
 
-    JcrNode( Session session,
-             Set<Property> properties ) {
-        super(session, properties);
+    JcrNode( Session session ) {
+        super(session);
     }
 
     /**

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	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -21,22 +21,54 @@
  */
 package org.jboss.dna.jcr;
 
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.ValueFactories;
 
 /**
  * @author jverhaeg
  */
 final class JcrProperty extends AbstractJcrProperty {
 
-    private Value value;
+    private JcrValue<?> jcrValue;
 
-    JcrProperty( Session session,
-                 String name,
-                 Value value ) {
-        super(session, name);
+    JcrProperty( Node node,
+                 ExecutionContext executionContext,
+                 Name name,
+                 Object value ) {
+        super(node, executionContext, name);
         assert value != null;
+        ValueFactories valueFactories = executionContext.getValueFactories();
+        if (value instanceof Boolean) {
+            jcrValue = new JcrValue<Boolean>(valueFactories, PropertyType.BOOLEAN, (Boolean)value);
+        } else if (value instanceof Date) {
+            jcrValue = new JcrValue<Date>(valueFactories, PropertyType.DATE, (Date)value);
+        } else if (value instanceof Calendar) {
+            jcrValue = new JcrValue<Calendar>(valueFactories, PropertyType.DATE, (Calendar)value);
+        } else if (value instanceof Double) {
+            jcrValue = new JcrValue<Double>(valueFactories, PropertyType.DOUBLE, (Double)value);
+        } else if (value instanceof Float) {
+            jcrValue = new JcrValue<Float>(valueFactories, PropertyType.DOUBLE, (Float)value);
+        } else if (value instanceof Integer) {
+            jcrValue = new JcrValue<Integer>(valueFactories, PropertyType.LONG, (Integer)value);
+        } else if (value instanceof Long) {
+            jcrValue = new JcrValue<Long>(valueFactories, PropertyType.LONG, (Long)value);
+        } else if (value instanceof UUID) {
+            jcrValue = new JcrValue<UUID>(valueFactories, PropertyType.STRING, (UUID)value);
+        } else if (value instanceof String) {
+            jcrValue = new JcrValue<String>(valueFactories, PropertyType.STRING, (String)value);
+        } else {
+            jcrValue = new JcrValue<Object>(valueFactories, PropertyType.BINARY, value);
+        }
     }
 
     /**
@@ -45,6 +77,87 @@
      * @see javax.jcr.Property#getBoolean()
      */
     public boolean getBoolean() throws RepositoryException {
-        return value.getBoolean();
+        return jcrValue.getBoolean();
     }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Property#getDate()
+     */
+    public Calendar getDate() throws RepositoryException {
+        return jcrValue.getDate();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Property#getDouble()
+     */
+    public double getDouble() throws RepositoryException {
+        return jcrValue.getDouble();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Property#getLength()
+     */
+    public long getLength() throws RepositoryException {
+        return jcrValue.getLength();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Property#getLengths()
+     */
+    public long[] getLengths() throws ValueFormatException {
+        throw new ValueFormatException();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Property#getLong()
+     */
+    public long getLong() throws RepositoryException {
+        return jcrValue.getLong();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Property#getStream()
+     */
+    public InputStream getStream() throws RepositoryException {
+        return jcrValue.getStream();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Property#getString()
+     */
+    public String getString() throws RepositoryException {
+        return jcrValue.getString();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Property#getType()
+     */
+    public int getType() {
+        return jcrValue.getType();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Property#getValue()
+     */
+    public Value getValue() {
+        return jcrValue;
+    }
 }

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -21,22 +21,25 @@
  */
 package org.jboss.dna.jcr;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 import java.security.AccessControlContext;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.WeakHashMap;
 import javax.jcr.Credentials;
 import javax.jcr.LoginException;
+import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
 import javax.security.auth.login.LoginContext;
 import net.jcip.annotations.ThreadSafe;
 import org.jboss.dna.common.util.ArgCheck;
 import org.jboss.dna.spi.ExecutionContext;
 import org.jboss.dna.spi.ExecutionContextFactory;
-import org.jboss.dna.spi.connector.RepositoryConnection;
 import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
 
 /**
@@ -48,13 +51,16 @@
  * implementation to which this JCR implementation delegates.
  * </p>
  * <p>
- * If {@link Credentials} are used to login, implementations <em>must</em> also implement one of the following methods:
+ * If {@link Credentials credentials} are used to login, implementations <em>must</em> also implement one of the following
+ * methods:
  * 
  * <pre>
  * public {@link AccessControlContext} getAccessControlContext();
  * public {@link LoginContext} getLoginContext();
  * </pre>
  * 
+ * Note, {@link Session#getAttributeNames() attributes} on credentials are not supported. JCR {@link SimpleCredentials} are also
+ * not supported.
  * </p>
  * 
  * @author John Verhaeg
@@ -246,9 +252,8 @@
         if (workspaceName == null) workspaceName = JcrI18n.defaultWorkspaceName.text();
         // Create session
         try {
-            RepositoryConnection connection = connectionFactory.createConnection(workspaceName);
-            assert connection != null;
-            return new JcrSession(this, new JcrExecutionContext(execContext, connection), workspaceName);
+            return new JcrSession(this, execContext, workspaceName, connectionFactory.createConnection(workspaceName),
+                                  new WeakHashMap<String, WeakReference<Node>>());
         } catch (InterruptedException error) {
             throw new RepositoryException(error);
         }

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -21,10 +21,8 @@
  */
 package org.jboss.dna.jcr;
 
-import java.util.Set;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.Node;
-import javax.jcr.Property;
 import javax.jcr.Session;
 import net.jcip.annotations.NotThreadSafe;
 
@@ -34,9 +32,8 @@
 @NotThreadSafe
 final class JcrRootNode extends AbstractJcrNode {
 
-    JcrRootNode( Session session,
-                 Set<Property> properties ) {
-        super(session, properties);
+    JcrRootNode( Session session ) {
+        super(session);
     }
 
     /**

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	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -23,11 +23,17 @@
 
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.ref.WeakReference;
 import java.security.Principal;
+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.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -36,7 +42,16 @@
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginException;
 import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.jcr.GraphTools.NodeContent;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Path.Segment;
+import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
 import org.xml.sax.ContentHandler;
 
 /**
@@ -46,23 +61,28 @@
 @NotThreadSafe
 final class JcrSession implements Session {
 
-    private final JcrRepository repository;
-    private final JcrExecutionContext executionContext;
+    private final Repository repository;
+    private final ExecutionContext executionContext;
+    private RepositoryConnection connection;
+    private final Map<String, WeakReference<Node>> uuid2NodeMap;
     private boolean isLive;
-    private JcrWorkspace workspace;
-    private Node rootNode;
+    private Workspace workspace;
+    private JcrRootNode rootNode;
 
-    // private final Map<String, Node> uuid2NodeMap = new HashMap<String, Node>();
-
-    JcrSession( JcrRepository repository,
-                JcrExecutionContext executionContext,
-                String workspaceName ) throws RepositoryException {
+    JcrSession( Repository repository,
+                ExecutionContext executionContext,
+                String workspaceName,
+                RepositoryConnection connection,
+                Map<String, WeakReference<Node>> uuid2NodeMap ) throws RepositoryException {
         assert repository != null;
         assert executionContext != null;
         assert workspaceName != null;
+        assert connection != null;
+        assert uuid2NodeMap != null;
         this.repository = repository;
         this.executionContext = executionContext;
-        executionContext.getGraphTools().setSession(this);
+        this.connection = connection;
+        this.uuid2NodeMap = uuid2NodeMap;
         this.isLive = true;
         // Following must be initialized after session's state is initialized
         this.workspace = new JcrWorkspace(this, workspaceName);
@@ -87,6 +107,16 @@
         throw new UnsupportedOperationException();
     }
 
+    private void execute( GraphCommand... commands ) throws RepositoryException {
+        try {
+            connection.execute(executionContext, commands);
+        } catch (RuntimeException error) {
+            throw error;
+        } catch (Exception error) {
+            throw new RepositoryException(error);
+        }
+    }
+
     /**
      * {@inheritDoc}
      * 
@@ -141,7 +171,7 @@
      * @see javax.jcr.Session#getAttribute(java.lang.String)
      */
     public Object getAttribute( String name ) {
-        throw new UnsupportedOperationException();
+        return null;
     }
 
     /**
@@ -150,7 +180,7 @@
      * @see javax.jcr.Session#getAttributeNames()
      */
     public String[] getAttributeNames() {
-        throw new UnsupportedOperationException();
+        return StringUtil.EMPTY_STRING_ARRAY;
     }
 
     /**
@@ -168,8 +198,32 @@
      * 
      * @see javax.jcr.Session#getItem(java.lang.String)
      */
-    public Item getItem( String absPath ) {
-        throw new UnsupportedOperationException();
+    public Item getItem( String absolutePath ) throws RepositoryException {
+        ArgCheck.isNotEmpty(absolutePath, "absolutePath");
+        // Return root node if path is "/"
+        Path path = executionContext.getValueFactories().getPathFactory().create(absolutePath);
+        if (path.isRoot()) {
+            return getRootNode();
+        }
+        // Since we don't know whether path refers to a node or property, get the parent contents, which must refer to a node
+        Path parentPath = path.getAncestor();
+        BasicGetNodeCommand getNodeCommand = new BasicGetNodeCommand(parentPath);
+        execute(getNodeCommand);
+        // First search for a child with the last name in the path
+        Name name = path.getLastSegment().getName();
+        for (Segment seg : getNodeCommand.getChildren()) {
+            if (seg.getName().equals(name)) {
+                return getNode(path);
+            }
+        }
+        // If a node isn't found & last segment contains no index, get parent node & search for a property with the last name in
+        // the path
+        Segment seg = path.getLastSegment();
+        if (!seg.hasIndex()) {
+            return getNode(parentPath).getProperty(seg.getString());
+        }
+        // If a property isn't found, throw a PathNotFoundException
+        throw new PathNotFoundException(JcrI18n.pathNotFound.text(path));
     }
 
     /**
@@ -208,6 +262,28 @@
         throw new UnsupportedOperationException();
     }
 
+    private Node getNode( Path path ) throws RepositoryException {
+        // Get node from source
+        BasicGetNodeCommand command = new BasicGetNodeCommand(path);
+        execute(command);
+        // First check if node already exists. We don't need to check for changes since that will be handled by an observer
+        org.jboss.dna.spi.graph.Property dnaUuidProp = command.getPropertiesByName().get(DnaLexicon.UUID);
+        if (dnaUuidProp != null) {
+            String uuid = executionContext.getValueFactories().getStringFactory().create(dnaUuidProp.getValues()).next();
+            WeakReference<Node> ref = uuid2NodeMap.get(uuid);
+            if (ref != null) {
+                Node node = ref.get();
+                if (node != null) {
+                    return node;
+                }
+            }
+        }
+        // If not create a new one & populate it
+        JcrNode node = new JcrNode(this);
+        populateNode(node, command);
+        return node;
+    }
+
     /**
      * {@inheritDoc}
      * 
@@ -232,16 +308,19 @@
      * @see javax.jcr.Session#getRootNode()
      */
     public Node getRootNode() throws RepositoryException {
-        // If root has no UUID, populate its contents from source
+        // Return cached root node if available
         if (rootNode != null) {
             return rootNode;
         }
         // Get root node from source
-        assert executionContext.getGraphTools() != null;
         assert executionContext.getValueFactories() != null;
         assert executionContext.getValueFactories().getPathFactory() != null;
-        NodeContent content = executionContext.getGraphTools().getNodeContent(executionContext.getValueFactories().getPathFactory().createRootPath());
-        rootNode = new JcrRootNode(this, content.properties);
+        rootNode = new JcrRootNode(this);
+        // Get root node from source
+        BasicGetNodeCommand getNodeCommand = new BasicGetNodeCommand(
+                                                                     executionContext.getValueFactories().getPathFactory().createRootPath());
+        execute(getNodeCommand);
+        populateNode(rootNode, getNodeCommand);
         return rootNode;
     }
 
@@ -329,9 +408,13 @@
      * @see javax.jcr.Session#logout()
      */
     public void logout() {
+        if (!isLive()) {
+            return;
+        }
         try {
-            if (executionContext.getRepositoryConnection() != null) {
-                executionContext.getRepositoryConnection().close();
+            if (connection != null) {
+                connection.close();
+                connection = null;
             }
             assert executionContext.getLoginContext() != null;
             executionContext.getLoginContext().logout();
@@ -353,6 +436,31 @@
         throw new UnsupportedOperationException();
     }
 
+    private void populateNode( AbstractJcrNode node,
+                               BasicGetNodeCommand getNodeCommand ) throws RepositoryException {
+        // TODO: What do we do to validate node against its primary type?
+        assert node != null;
+        assert getNodeCommand != null;
+        // Create JCR children for corresponding DNA children
+        node.setChildren(getNodeCommand.getChildren());
+        // Create JCR properties for corresponding DNA properties
+        Set<Property> properties = new HashSet<Property>();
+        boolean uuidFound = false;
+        for (org.jboss.dna.spi.graph.Property dnaProp : getNodeCommand.getProperties()) {
+            if (DnaLexicon.UUID.equals(dnaProp.getName())) {
+                uuidFound = true;
+            }
+            properties.add(new JcrProperty(node, executionContext, dnaProp.getName(), dnaProp.getValues().next()));
+        }
+        // Ensure a UUID property exists
+        if (!uuidFound) {
+            properties.add(new JcrProperty(node, executionContext, DnaLexicon.UUID, UUID.randomUUID()));
+        }
+        node.setProperties(properties);
+        // Setup node to be retrieved by UUID
+        uuid2NodeMap.put(node.getUUID(), new WeakReference<Node>(node));
+    }
+
     /**
      * {@inheritDoc}
      * 

Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java	                        (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -0,0 +1,188 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.ValueFactories;
+
+/**
+ * @param <T> the type of value to create.
+ * @author jverhaeg
+ */
+ at NotThreadSafe
+final class JcrValue<T> implements Value {
+
+    private final ValueFactories valueFactories;
+    private final int type;
+    private final T value;
+
+    JcrValue( ValueFactories valueFactories,
+              int type,
+              T 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;
+        assert value != null;
+        this.valueFactories = valueFactories;
+        this.type = type;
+        this.value = value;
+    }
+
+    private State state = State.NEVER_CONSUMED;
+
+    ValueFormatException createValueFormatException( Class<?> type ) {
+        return new ValueFormatException(JcrI18n.cannotConvertValue.text(value.getClass().getSimpleName(), type.getSimpleName()));
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Value#getBoolean()
+     */
+    public boolean getBoolean() throws ValueFormatException {
+        nonInputStreamConsumed();
+        try {
+            boolean convertedValue = valueFactories.getBooleanFactory().create(value);
+            state = State.NON_INPUT_STREAM_CONSUMED;
+            return convertedValue;
+        } catch (RuntimeException error) {
+            throw createValueFormatException(boolean.class);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Value#getDate()
+     */
+    public Calendar getDate() throws ValueFormatException {
+        nonInputStreamConsumed();
+        try {
+            Calendar convertedValue = valueFactories.getDateFactory().create(value).toCalendar();
+            state = State.NON_INPUT_STREAM_CONSUMED;
+            return convertedValue;
+        } catch (RuntimeException error) {
+            throw createValueFormatException(Calendar.class);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Value#getDouble()
+     */
+    public double getDouble() throws ValueFormatException {
+        nonInputStreamConsumed();
+        try {
+            double convertedValue = valueFactories.getDoubleFactory().create(value);
+            state = State.NON_INPUT_STREAM_CONSUMED;
+            return convertedValue;
+        } catch (RuntimeException error) {
+            throw createValueFormatException(double.class);
+        }
+    }
+
+    long getLength() throws RepositoryException {
+        if (type == PropertyType.BINARY) {
+            return valueFactories.getBinaryFactory().create(value).getSize();
+        }
+        return getString().length();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Value#getLong()
+     */
+    public long getLong() throws ValueFormatException {
+        nonInputStreamConsumed();
+        try {
+            long convertedValue = valueFactories.getLongFactory().create(value);
+            state = State.NON_INPUT_STREAM_CONSUMED;
+            return convertedValue;
+        } catch (RuntimeException error) {
+            throw createValueFormatException(long.class);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Value#getStream()
+     */
+    public InputStream getStream() throws ValueFormatException {
+        if (state == State.NON_INPUT_STREAM_CONSUMED) {
+            throw new IllegalStateException(JcrI18n.nonInputStreamConsumed.text());
+        }
+        try {
+            InputStream convertedValue = valueFactories.getBinaryFactory().create(value).getStream();
+            state = State.INPUT_STREAM_CONSUMED;
+            return convertedValue;
+        } catch (RuntimeException error) {
+            throw createValueFormatException(InputStream.class);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Value#getString()
+     */
+    public String getString() throws ValueFormatException {
+        nonInputStreamConsumed();
+        try {
+            String convertedValue = valueFactories.getStringFactory().create(value);
+            state = State.NON_INPUT_STREAM_CONSUMED;
+            return convertedValue;
+        } catch (RuntimeException error) {
+            throw createValueFormatException(String.class);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.jcr.Value#getType()
+     */
+    public int getType() {
+        return type;
+    }
+
+    void nonInputStreamConsumed() {
+        if (state == State.INPUT_STREAM_CONSUMED) {
+            throw new IllegalStateException(JcrI18n.inputStreamConsumed.text());
+        }
+    }
+
+    private enum State {
+        NEVER_CONSUMED,
+        INPUT_STREAM_CONSUMED,
+        NON_INPUT_STREAM_CONSUMED
+    }
+}


Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.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	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties	2008-08-20 15:19:52 UTC (rev 452)
@@ -19,10 +19,14 @@
 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 #
+cannotConvertValue = Cannot convert {0} value to {1}.
 credentialsMustProvideJaasMethod = The Credentials class "{0}" must implement either "public LoginContext getLoginContext();" or "public AccessControlContext getAccessControlContext();".
 credentialsMustReturnAccessControlContext = The "getAccessControlContext()" method in Credentials class "{0}" must not return a null.
 credentialsMustReturnLoginContext = The "getLoginContext()" method in Credentials class "{0}" must not return a null.
 defaultWorkspaceName = Default
+inputStreamConsumed = This value was already consumed as an input stream.
+nonInputStreamConsumed = This value was already consumed as a non-input stream.
+pathNotFound = No item exists at path {0}
 repositoryMustBeConfigured = DNA repositories must be configured with either a repository source factory or a repository source.
 sourceInUse = All sessions must end before a new repository source can be set.
 

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -29,7 +29,7 @@
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.Session;
-import javax.jcr.Value;
+import org.jboss.dna.spi.DnaLexicon;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -50,7 +50,7 @@
     public void before() {
         MockitoAnnotations.initMocks(this);
         properties = new HashSet<Property>();
-        node = new AbstractJcrNode(session, properties) {
+        node = new AbstractJcrNode(session) {
 
             public String getName() {
                 return null;
@@ -60,11 +60,12 @@
                 return null;
             }
         };
+        node.setProperties(properties);
     }
 
     @Test( expected = AssertionError.class )
     public void shouldNotAllowNoSession() throws Exception {
-        new AbstractJcrNode(null, properties) {
+        new AbstractJcrNode(null) {
 
             public String getName() {
                 return null;
@@ -84,10 +85,8 @@
     @Test
     public void shouldProvideUuid() throws Exception {
         Property property = Mockito.mock(Property.class);
-        stub(property.getName()).toReturn("jcr:uuid");
-        Value value = Mockito.mock(Value.class);
-        stub(value.getString()).toReturn("uuid");
-        stub(property.getValue()).toReturn(value);
+        stub(property.getName()).toReturn(DnaLexicon.UUID.getString());
+        stub(property.getString()).toReturn("uuid");
         properties.add(property);
         assertThat(node.getUUID(), is("uuid"));
     }

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	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -23,9 +23,17 @@
 
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
+import java.io.InputStream;
+import java.util.Calendar;
+import javax.jcr.Node;
 import javax.jcr.Session;
+import javax.jcr.Value;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.mockito.MockitoAnnotations.Mock;
 
@@ -36,56 +44,152 @@
 
     private AbstractJcrProperty prop;
     @Mock
-    private Session session;
+    private Node node;
+    @Mock
+    private ExecutionContext executionContext;
+    @Mock
+    private Name name;
 
     @Before
     public void before() {
         MockitoAnnotations.initMocks(this);
-        prop = new AbstractJcrProperty(session, "name") {
-
-            public boolean getBoolean() {
-                return false;
-            }
-        };
+        prop = new MockAbstractJcrProperty(node, executionContext, name);
     }
 
     @Test( expected = AssertionError.class )
     public void shouldNotAllowNoSession() throws Exception {
-        new AbstractJcrProperty(null, "name") {
-
-            public boolean getBoolean() {
-                return false;
-            }
-        };
+        new MockAbstractJcrProperty(null, executionContext, name);
     }
 
     @Test( expected = AssertionError.class )
-    public void shouldNotAllowNoName() throws Exception {
-        new AbstractJcrProperty(session, null) {
-
-            public boolean getBoolean() {
-                return false;
-            }
-        };
+    public void shouldNotAllowNoExecutionContext() throws Exception {
+        new MockAbstractJcrProperty(node, null, name);
     }
 
     @Test( expected = AssertionError.class )
-    public void shouldNotAllowEmptyName() throws Exception {
-        new AbstractJcrProperty(session, "") {
-
-            public boolean getBoolean() {
-                return false;
-            }
-        };
+    public void shouldNotAllowNoName() throws Exception {
+        new MockAbstractJcrProperty(node, executionContext, null);
     }
 
     @Test
     public void shouldProvideSession() throws Exception {
+        Session session = Mockito.mock(Session.class);
+        stub(node.getSession()).toReturn(session);
         assertThat(prop.getSession(), is(session));
     }
 
     @Test
+    public void shouldProvideExecutionContext() throws Exception {
+        assertThat(prop.getExecutionContext(), is(executionContext));
+    }
+
+    @Test
+    public void shouldProvideNode() throws Exception {
+        assertThat(prop.getNode(), is(node));
+    }
+
+    @Test
     public void shouldProvideName() throws Exception {
+        stub(name.getString()).toReturn("name");
         assertThat(prop.getName(), is("name"));
     }
+
+    private class MockAbstractJcrProperty extends AbstractJcrProperty {
+
+        MockAbstractJcrProperty( Node node,
+                                 ExecutionContext executionContext,
+                                 Name name ) {
+            super(node, executionContext, name);
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see javax.jcr.Property#getBoolean()
+         */
+        public boolean getBoolean() {
+            return false;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see javax.jcr.Property#getDate()
+         */
+        public Calendar getDate() {
+            return null;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see javax.jcr.Property#getDouble()
+         */
+        public double getDouble() {
+            return 0;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see javax.jcr.Property#getLength()
+         */
+        public long getLength() {
+            return 0;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see javax.jcr.Property#getLengths()
+         */
+        public long[] getLengths() {
+            return null;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see javax.jcr.Property#getLong()
+         */
+        public long getLong() {
+            return 0;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see javax.jcr.Property#getStream()
+         */
+        public InputStream getStream() {
+            return null;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see javax.jcr.Property#getString()
+         */
+        public String getString() {
+            return null;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see javax.jcr.Property#getType()
+         */
+        public int getType() {
+            return 0;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see javax.jcr.Property#getValue()
+         */
+        public Value getValue() {
+            return null;
+        }
+    }
 }

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -49,7 +49,8 @@
     public void before() throws Exception {
         MockitoAnnotations.initMocks(this);
         properties = new HashSet<Property>();
-        node = new JcrNode(session, properties);
+        node = new JcrNode(session);
+        node.setProperties(properties);
     }
 
     @Test

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	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -21,50 +21,121 @@
  */
 package org.jboss.dna.jcr;
 
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.UUID;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.junit.Before;
 import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
 
 /**
  * @author jverhaeg
  */
 public class JcrPropertyTest {
-    //
-    // private AbstractJcrProperty prop;
-    // @Mock
-    // private Session session;
-    //
-    // @Before
-    // public void before() {
-    // MockitoAnnotations.initMocks(this);
-    // prop = new AbstractJcrProperty(session, "name") {};
-    // }
-    //
-    // @Test( expected = AssertionError.class )
-    // public void shouldNotAllowNoSession() throws Exception {
-    // new AbstractJcrProperty(null, "name") {};
-    // }
-    //
-    // @Test( expected = AssertionError.class )
-    // public void shouldNotAllowNoName() throws Exception {
-    // new AbstractJcrProperty(session, null) {};
-    // }
-    //
-    // @Test( expected = AssertionError.class )
-    // public void shouldNotAllowEmptyName() throws Exception {
-    // new AbstractJcrProperty(session, "") {};
-    // }
-    //
-    // @Test
-    // public void shouldProvideSession() throws Exception {
-    // assertThat(prop.getSession(), is(session));
-    // }
-    //
-    // @Test
-    // public void shouldProvideName() throws Exception {
-    // assertThat(prop.getName(), is("name"));
-    // }
 
+    @Mock
+    private Node node;
+    private ExecutionContext executionContext = new BasicExecutionContext();
+    @Mock
+    Name name;
+
+    @Before
+    public void before() {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    @Test( expected = AssertionError.class )
+    public void shouldNotAllowNoValue() {
+        new JcrProperty(node, executionContext, name, null);
+    }
+
     @Test
-    public void should() {
+    public void shouldProvideBoolean() throws Exception {
+        Property prop = new JcrProperty(node, executionContext, name, true);
+        assertThat(prop.getBoolean(), is(true));
+    }
 
+    @Test
+    public void shouldProvideDate() throws Exception {
+        Calendar cal = Calendar.getInstance();
+        Property prop = new JcrProperty(node, executionContext, name, cal);
+        assertThat(prop.getDate(), is(cal));
+        prop = new JcrProperty(node, executionContext, name, cal.getTime());
+        assertThat(prop.getDate(), is(cal));
     }
+
+    @Test
+    public void shouldProvideDouble() throws Exception {
+        Property prop = new JcrProperty(node, executionContext, name, 1.0);
+        assertThat(prop.getDouble(), is(1.0));
+        prop = new JcrProperty(node, executionContext, name, 1.0F);
+        assertThat(prop.getDouble(), is(1.0));
+    }
+
+    @Test
+    public void shouldProvideLength() throws Exception {
+        assertThat(new JcrProperty(node, executionContext, name, "value").getLength(), is(5L));
+        Object obj = new Object();
+        assertThat(new JcrProperty(node, executionContext, name, obj).getLength(), is((long)obj.toString().length()));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotProvideLengths() throws Exception {
+        new JcrProperty(node, executionContext, name, "value").getLengths();
+    }
+
+    @Test
+    public void shouldProvideLong() throws Exception {
+        Property prop = new JcrProperty(node, executionContext, name, 1);
+        assertThat(prop.getLong(), is(1L));
+        prop = new JcrProperty(node, executionContext, name, 1L);
+        assertThat(prop.getLong(), is(1L));
+    }
+
+    @Test
+    public void shouldProvideStream() throws Exception {
+        Property prop = new JcrProperty(node, executionContext, name, "value");
+        InputStream stream = prop.getStream();
+        assertThat(stream, notNullValue());
+        stream.close();
+    }
+
+    @Test
+    public void shouldProvideString() throws Exception {
+        Property prop = new JcrProperty(node, executionContext, name, "value");
+        assertThat(prop.getString(), is("value"));
+    }
+
+    @Test
+    public void shouldProvideUuid() throws Exception {
+        UUID uuid = UUID.randomUUID();
+        Property prop = new JcrProperty(node, executionContext, name, uuid);
+        assertThat(prop.getString(), is(uuid.toString()));
+    }
+
+    @Test
+    public void shouldProvideType() throws Exception {
+        Property prop = new JcrProperty(node, executionContext, name, UUID.randomUUID());
+        assertThat(prop.getType(), is(PropertyType.STRING));
+    }
+
+    @Test
+    public void shouldProvideValue() throws Exception {
+        Property prop = new JcrProperty(node, executionContext, name, true);
+        Value val = prop.getValue();
+        assertThat(val, notNullValue());
+        assertThat(val.getBoolean(), is(true));
+    }
 }

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -48,7 +48,8 @@
     public void before() {
         MockitoAnnotations.initMocks(this);
         properties = new HashSet<Property>();
-        root = new JcrRootNode(session, properties);
+        root = new JcrRootNode(session);
+        root.setProperties(properties);
     }
 
     @Test

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java	2008-08-20 15:11:57 UTC (rev 451)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -22,19 +22,32 @@
 package org.jboss.dna.jcr;
 
 import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
 import static org.hamcrest.core.IsNull.notNullValue;
 import static org.hamcrest.core.IsNull.nullValue;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.stub;
+import java.lang.ref.WeakReference;
 import java.security.Principal;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Repository;
+import javax.jcr.Session;
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
-import org.jboss.dna.jcr.GraphTools.NodeContent;
-import org.jboss.dna.spi.graph.PathFactory;
-import org.jboss.dna.spi.graph.ValueFactories;
-import org.jboss.dna.spi.graph.impl.BasicPath;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.ExecutionContextFactory;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.SimpleRepository;
+import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
@@ -45,42 +58,87 @@
  */
 public class JcrSessionTest {
 
-    private JcrSession session;
+    private static final String WORKSPACE_NAME = JcrI18n.defaultWorkspaceName.text();
+
+    private static ExecutionContext executionContext;
+    private static SimpleRepository simpleRepository;
+    private static RepositoryConnectionFactory connectionFactory;
+    private static RepositoryConnection connection;
+    private static Repository repository;
+
+    @BeforeClass
+    public static void beforeClass() throws Exception {
+        ExecutionContextFactory factory = TestUtil.getExecutionContextFactory();
+        executionContext = factory.create();
+        simpleRepository = SimpleRepository.get(WORKSPACE_NAME);
+        simpleRepository.setProperty(executionContext, "/a/b", "booleanProperty", true);
+        simpleRepository.setProperty(executionContext, "/a/b/c", "stringProperty", "value");
+        connectionFactory = TestUtil.createJackRabbitConnectionFactory(simpleRepository, executionContext);
+        repository = new JcrRepository(factory, connectionFactory);
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        SimpleRepository.shutdownAll();
+    }
+
+    private Session session;
     @Mock
-    private JcrRepository repository;
-    @Mock
-    private JcrExecutionContext executionContext;
-    @Mock
-    private GraphTools tools;
-    @Mock
-    private LoginContext loginContext;
+    private Map<String, WeakReference<Node>> uuid2NodeMap;
 
     @Before
     public void before() throws Exception {
         MockitoAnnotations.initMocks(this);
-        stub(executionContext.getLoginContext()).toReturn(loginContext);
-        stub(executionContext.getGraphTools()).toReturn(tools);
-        session = new JcrSession(repository, executionContext, JcrI18n.defaultWorkspaceName.text());
+        session = repository.login();
     }
 
+    @After
+    public void after() throws Exception {
+        if (session.isLive()) {
+            session.logout();
+        }
+    }
+
     @Test( expected = AssertionError.class )
     public void shouldNotAllowNoRepository() throws Exception {
-        new JcrSession(null, executionContext, JcrI18n.defaultWorkspaceName.text());
+        new JcrSession(null, executionContext, WORKSPACE_NAME, connection, uuid2NodeMap);
     }
 
     @Test( expected = AssertionError.class )
     public void shouldNotAllowNoExecutionContext() throws Exception {
-        new JcrSession(repository, null, JcrI18n.defaultWorkspaceName.text());
+        new JcrSession(repository, null, WORKSPACE_NAME, connection, uuid2NodeMap);
     }
 
     @Test( expected = AssertionError.class )
     public void shouldNotAllowNoWorkspaceName() throws Exception {
-        new JcrSession(repository, executionContext, null);
+        new JcrSession(repository, executionContext, null, connection, uuid2NodeMap);
     }
 
+    @Test( expected = AssertionError.class )
+    public void shouldNotAllowNoConnection() throws Exception {
+        new JcrSession(repository, executionContext, WORKSPACE_NAME, null, uuid2NodeMap);
+    }
+
+    @Test( expected = AssertionError.class )
+    public void shouldNotAllowNoUuid2NodeMap() throws Exception {
+        new JcrSession(repository, executionContext, WORKSPACE_NAME, connection, null);
+    }
+
     @Test
+    public void shouldProvideNoAttributes() throws Exception {
+        assertThat(session.getAttribute(null), nullValue());
+    }
+
+    @Test
+    public void shouldProvideEmptyAttributeNames() throws Exception {
+        String[] names = session.getAttributeNames();
+        assertThat(names, notNullValue());
+        assertThat(names.length, is(0));
+    }
+
+    @Test
     public void shouldProvideAccessToRepository() throws Exception {
-        assertThat((JcrRepository)session.getRepository(), is(repository));
+        assertThat(session.getRepository(), is(repository));
     }
 
     @Test
@@ -110,19 +168,40 @@
         Principal principal = Mockito.mock(Principal.class);
         stub(principal.getName()).toReturn("name");
         Subject subject = new Subject(false, Collections.singleton(principal), Collections.EMPTY_SET, Collections.EMPTY_SET);
+        ExecutionContext executionContext = Mockito.mock(ExecutionContext.class);
         stub(executionContext.getSubject()).toReturn(subject);
-        assertThat(session.getUserID(), is("name"));
+        stub(executionContext.getLoginContext()).toReturn(Mockito.mock(LoginContext.class));
+        Session session = new JcrSession(repository, executionContext, WORKSPACE_NAME, Mockito.mock(RepositoryConnection.class),
+                                         uuid2NodeMap);
+        try {
+            assertThat(session.getUserID(), is("name"));
+        } finally {
+            session.logout();
+        }
     }
 
     @Test
     public void shouldProvideRootNode() throws Exception {
-        ValueFactories valueFactories = Mockito.mock(ValueFactories.class);
-        PathFactory pathFactory = Mockito.mock(PathFactory.class);
-        stub(pathFactory.createRootPath()).toReturn(BasicPath.ROOT);
-        stub(valueFactories.getPathFactory()).toReturn(pathFactory);
-        stub(executionContext.getValueFactories()).toReturn(valueFactories);
-        NodeContent content = tools.new NodeContent();
-        stub(tools.getNodeContent(BasicPath.ROOT)).toReturn(content);
-        assertThat(session.getRootNode(), notNullValue());
+        Map<String, WeakReference<Node>> uuid2NodeMap = new HashMap<String, WeakReference<Node>>();
+        Session session = new JcrSession(repository, executionContext, WORKSPACE_NAME,
+                                         connectionFactory.createConnection(WORKSPACE_NAME), uuid2NodeMap);
+        assertThat(uuid2NodeMap.isEmpty(), is(true));
+        Node root = session.getRootNode();
+        assertThat(root, notNullValue());
+        String uuid = root.getUUID();
+        assertThat(uuid, notNullValue());
+        WeakReference<Node> ref = uuid2NodeMap.get(uuid);
+        assertThat(ref, notNullValue());
+        assertThat(ref.get(), is(root));
     }
+
+    @Test
+    public void shouldProvideItemsByPath() throws Exception {
+        Item item = session.getItem("/a");
+        assertThat(item, instanceOf(Node.class));
+        item = session.getItem("/a/b");
+        assertThat(item, instanceOf(Node.class));
+        item = session.getItem("/a/b/booleanProperty");
+        assertThat(item, instanceOf(Property.class));
+    }
 }

Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java	                        (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -0,0 +1,311 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * 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.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+import javax.jcr.PropertyType;
+import javax.jcr.ValueFormatException;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.impl.StandardValueFactories;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrValueTest {
+
+    private ValueFactories factories;
+    private JcrValue<Boolean> value;
+
+    @Before
+    public void before() {
+        factories = new StandardValueFactories(Mockito.mock(NamespaceRegistry.class));
+        value = new JcrValue<Boolean>(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));
+    }
+
+    @Test( expected = IllegalStateException.class )
+    public void shouldNotAllowConsumingInputStreamAfterConsumingNonInputStream() throws Exception {
+        value.getBoolean();
+        value.getStream();
+    }
+
+    @Test( expected = IllegalStateException.class )
+    public void shouldNotAllowConsumingNonInputStreamAfterConsumingInputStream() throws Exception {
+        value.getBoolean();
+        value.getStream();
+    }
+
+    @Test
+    public void shouldProvideBooleanForBoolean() throws Exception {
+        assertThat(value.getBoolean(), is(true));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotProvideDateForBoolean() throws Exception {
+        value.getDate();
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotProvideDoubleForBoolean() throws Exception {
+        value.getDouble();
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotProvideLongForBoolean() throws Exception {
+        value.getLong();
+    }
+
+    @Test
+    public void shouldProvideStreamForBoolean() throws Exception {
+        testProvidesStream(value);
+    }
+
+    @Test
+    public void shouldProvideStringForBoolean() throws Exception {
+        assertThat(value.getString(), is("true"));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotProvideBooleanForDate() throws Exception {
+        new JcrValue<Date>(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));
+    }
+
+    @Test
+    public void shouldProvideDoubleForDate() throws Exception {
+        Date date = new Date();
+        assertThat(new JcrValue<Date>(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()));
+    }
+
+    @Test
+    public void shouldProvideStreamForDate() throws Exception {
+        testProvidesStream(new JcrValue<Date>(factories, PropertyType.DATE, new Date()));
+    }
+
+    @Test
+    public void shouldProvideStringForDate() throws Exception {
+        Calendar date = Calendar.getInstance();
+        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()),
+                   is(expectedValue));
+        assertThat(new JcrValue<Date>(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();
+    }
+
+    @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));
+    }
+
+    @Test
+    public void shouldProvideDoubleForDouble() throws Exception {
+        assertThat(new JcrValue<Double>(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));
+    }
+
+    @Test
+    public void shouldProvideStreamForDouble() throws Exception {
+        testProvidesStream(new JcrValue<Double>(factories, PropertyType.DOUBLE, 1.0));
+    }
+
+    @Test
+    public void shouldProvideStringForDouble() throws Exception {
+        assertThat(new JcrValue<Double>(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();
+    }
+
+    @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));
+    }
+
+    @Test
+    public void shouldProvideDoubleForLong() throws Exception {
+        assertThat(new JcrValue<Long>(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));
+    }
+
+    @Test
+    public void shouldProvideStreamForLong() throws Exception {
+        testProvidesStream(new JcrValue<Long>(factories, PropertyType.LONG, 1L));
+    }
+
+    @Test
+    public void shouldProvideStringForLong() throws Exception {
+        assertThat(new JcrValue<Long>(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));
+    }
+
+    @Test
+    public void shouldProvideDateForString() throws Exception {
+        assertThat(new JcrValue<String>(factories, PropertyType.STRING, "2008").getDate(), notNullValue());
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotProvideDateForInvalidString() throws Exception {
+        new JcrValue<String>(factories, PropertyType.STRING, "true").getDate();
+    }
+
+    @Test
+    public void shouldProvideDoubleForString() throws Exception {
+        assertThat(new JcrValue<String>(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();
+    }
+
+    @Test
+    public void shouldProvideLongForString() throws Exception {
+        assertThat(new JcrValue<String>(factories, PropertyType.STRING, "1").getLong(), is(1L));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotProvideLongForInvalidString() throws Exception {
+        new JcrValue<String>(factories, PropertyType.STRING, "true").getLong();
+    }
+
+    @Test
+    public void shouldProvideStreamForString() throws Exception {
+        testProvidesStream(new JcrValue<String>(factories, PropertyType.STRING, "true"));
+    }
+
+    @Test
+    public void shouldProvideStringForString() throws Exception {
+        assertThat(new JcrValue<String>(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));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotProvideDateForUuid() throws Exception {
+        new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getDate();
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotProvideDoubleForUuid() throws Exception {
+        new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getDouble();
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotProvideLongForUuid() throws Exception {
+        new JcrValue<UUID>(factories, PropertyType.STRING, UUID.randomUUID()).getLong();
+    }
+
+    @Test
+    public void shouldProvideStreamForUuid() throws Exception {
+        testProvidesStream(new JcrValue<UUID>(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));
+    }
+
+    @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));
+    }
+
+    private void testProvidesStream( JcrValue<?> value ) throws Exception {
+        InputStream stream = value.getStream();
+        assertThat(stream, notNullValue());
+        stream.close();
+    }
+}


Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrValueTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java	                        (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java	2008-08-20 15:19:52 UTC (rev 452)
@@ -0,0 +1,746 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * 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.
+ *
+ * This software 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.security.AccessControlContext;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginContext;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.ExecutionContextFactory;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.SimpleRepository;
+import org.jboss.dna.spi.connector.SimpleRepositorySource;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.mockito.Mockito;
+
+/**
+ * @author jverhaeg
+ */
+ at NotThreadSafe
+public class TestUtil {
+
+    public static RepositoryConnectionFactory createJackRabbitConnectionFactory( SimpleRepository repository,
+                                                                                 ExecutionContext context ) {
+        repository.setProperty(context, "/", "jcr:primaryType", "nt:unstructured");
+        // repository.setProperty(context, "/dna:system/dna:jcr", "jcr:primaryType", "nt:unstructured");
+        // repository.setProperty(context, "/dna:system/dna:jcr/jcr:versionStorage", "jcr:primaryType", "rep:versionStorage");
+        // repository.setProperty(context, "/dna:system/dna:jcr/jcr:nodeTypes", "jcr:primaryType", "rep:nodeTypes");
+        createNodeType(repository, context, "rep:nodeTypes", false, false);
+        createChildDefinition(repository, context, "rep:nodeTypes", false, "nt:nodeType", false, "ABORT", true, false);
+        createNodeType(repository, context, "mix:versionable", false, true);
+        createPropertyDefinition(repository,
+                                 context,
+                                 "mix:versionable",
+                                 1,
+                                 false,
+                                 false,
+                                 true,
+                                 "jcr:mergeFailed",
+                                 "ABORT",
+                                 true,
+                                 "REFERENCE");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "mix:versionable",
+                                 2,
+                                 false,
+                                 true,
+                                 true,
+                                 "jcr:predecessors",
+                                 "COPY",
+                                 true,
+                                 "REFERENCE");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "mix:versionable",
+                                 3,
+                                 true,
+                                 true,
+                                 false,
+                                 "jcr:isCheckedOut",
+                                 "IGNORE",
+                                 true,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "mix:versionable",
+                                 4,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:baseVersion",
+                                 "IGNORE",
+                                 true,
+                                 "REFERENCE");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "mix:versionable",
+                                 5,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:versionHistory",
+                                 "COPY",
+                                 true,
+                                 "REFERENCE");
+        createNodeType(repository, context, "nt:file", false, false);
+        createProperty(repository, context, "nt:file", "jcr:primaryItemName", "jcr:content");
+        createChildDefinition(repository, context, "nt:file", false, true, "jcr:content", "COPY", false, false);
+        createNodeType(repository, context, "nt:hierarchyNode", false, false);
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:hierarchyNode",
+                                 true,
+                                 false,
+                                 false,
+                                 "jcr:created",
+                                 "INITIALIZE",
+                                 true,
+                                 "DATE");
+        createNodeType(repository, context, "nt:versionedChild", false, false);
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:versionedChild",
+                                 true,
+                                 true,
+                                 false,
+                                 "jcr:childVersionHistory",
+                                 "ABORT",
+                                 true,
+                                 "REFERENCE");
+        createNodeType(repository, context, "nt:version", false, false);
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:version",
+                                 1,
+                                 false,
+                                 false,
+                                 true,
+                                 "jcr:successors",
+                                 "ABORT",
+                                 true,
+                                 "REFERENCE");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:version",
+                                 2,
+                                 false,
+                                 false,
+                                 true,
+                                 "jcr:predecessors",
+                                 "ABORT",
+                                 true,
+                                 "REFERENCE");
+        createPropertyDefinition(repository, context, "nt:version", 3, true, true, false, "jcr:created", "ABORT", true, "DATE");
+        createChildDefinition(repository, context, "nt:version", false, false, "jcr:frozenNode", "ABORT", true, false);
+        /*
+            <nt:versionLabels jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:versionLabels">
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="REFERENCE"/>
+            <nt:folder jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:folder">
+                <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:onParentVersion="VERSION" jcr:protected="false" jcr:sameNameSiblings="false"/>
+        */
+        createNodeType(repository, context, "nt:nodeType", false, false);
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:nodeType",
+                                 1,
+                                 false,
+                                 false,
+                                 false,
+                                 "jcr:primaryItemName",
+                                 "COPY",
+                                 false,
+                                 "NAME");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:nodeType",
+                                 2,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:hasOrderableChildNodes",
+                                 "COPY",
+                                 false,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:nodeType",
+                                 3,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:isMixin",
+                                 "COPY",
+                                 false,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:nodeType",
+                                 4,
+                                 false,
+                                 false,
+                                 true,
+                                 "jcr:supertypes",
+                                 "COPY",
+                                 false,
+                                 "NAME");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:nodeType",
+                                 5,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:nodeTypeName",
+                                 "COPY",
+                                 false,
+                                 "NAME");
+        createChildDefinition(repository,
+                              context,
+                              "nt:nodeType",
+                              1,
+                              false,
+                              "nt:childNodeDefinition",
+                              false,
+                              "jcr:childNodeDefinition",
+                              "VERSION",
+                              false,
+                              true);
+        createChildDefinition(repository,
+                              context,
+                              "nt:nodeType",
+                              2,
+                              false,
+                              "nt:propertyDefinition",
+                              false,
+                              "jcr:propertyDefinition",
+                              "VERSION",
+                              false,
+                              true);
+        createNodeType(repository, context, "nt:propertyDefinition", false, false);
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:propertyDefinition",
+                                 1,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:multiple",
+                                 "COPY",
+                                 false,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:propertyDefinition",
+                                 2,
+                                 false,
+                                 false,
+                                 true,
+                                 "jcr:defaultValues",
+                                 "COPY",
+                                 false,
+                                 "UNDEFINED");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:propertyDefinition",
+                                 3,
+                                 false,
+                                 false,
+                                 true,
+                                 "jcr:valueConstraints",
+                                 "COPY",
+                                 false,
+                                 "STRING");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:propertyDefinition",
+                                 4,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:requiredType",
+                                 "COPY",
+                                 false,
+                                 "STRING");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:propertyDefinition",
+                                 5,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:protected",
+                                 "COPY",
+                                 false,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:propertyDefinition",
+                                 6,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:onParentVersion",
+                                 "COPY",
+                                 false,
+                                 "STRING");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:propertyDefinition",
+                                 7,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:mandatory",
+                                 "COPY",
+                                 false,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:propertyDefinition",
+                                 8,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:autoCreated",
+                                 "COPY",
+                                 false,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:propertyDefinition",
+                                 9,
+                                 false,
+                                 false,
+                                 false,
+                                 "jcr:name",
+                                 "COPY",
+                                 false,
+                                 "NAME");
+        /*
+            <rep:versionStorage jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="rep:versionStorage">
+                <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="rep:versionStorage" jcr:mandatory="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="true"/>
+                <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="nt:versionHistory" jcr:mandatory="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="true"/>
+        */
+        createNodeType(repository, context, "nt:base", false, false);
+        createPropertyDefinition(repository, context, "nt:base", false, false, true, "jcr:mixinTypes", "COMPUTE", true, "NAME");
+        createPropertyDefinition(repository, context, "nt:base", true, true, false, "jcr:primaryType", "COMPUTE", true, "NAME");
+        /*
+            <nt:resource jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:resource" jcr:primaryItemName="jcr:data">
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:lastModified" jcr:onParentVersion="IGNORE" jcr:protected="false" jcr:requiredType="DATE"/>
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:data" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="BINARY"/>
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:mimeType" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="STRING"/>
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:encoding" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="STRING"/>
+        */
+        createNodeType(repository, context, "nt:childNodeDefinition", false, false);
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:childNodeDefinition",
+                                 1,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:sameNameSiblings",
+                                 "COPY",
+                                 false,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:childNodeDefinition",
+                                 2,
+                                 false,
+                                 false,
+                                 false,
+                                 "jcr:defaultPrimaryType",
+                                 "COPY",
+                                 false,
+                                 "NAME");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:childNodeDefinition",
+                                 3,
+                                 false,
+                                 true,
+                                 true,
+                                 "jcr:requiredPrimaryTypes",
+                                 "COPY",
+                                 false,
+                                 "NAME");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:childNodeDefinition",
+                                 4,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:protected",
+                                 "COPY",
+                                 false,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:childNodeDefinition",
+                                 5,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:onParentVersion",
+                                 "COPY",
+                                 false,
+                                 "STRING");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:childNodeDefinition",
+                                 6,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:mandatory",
+                                 "COPY",
+                                 false,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:childNodeDefinition",
+                                 7,
+                                 false,
+                                 true,
+                                 false,
+                                 "jcr:autoCreated",
+                                 "COPY",
+                                 false,
+                                 "BOOLEAN");
+        createPropertyDefinition(repository,
+                                 context,
+                                 "nt:childNodeDefinition",
+                                 8,
+                                 false,
+                                 false,
+                                 false,
+                                 "jcr:name",
+                                 "COPY",
+                                 false,
+                                 "NAME");
+        createNodeType(repository, context, "mix:referenceable", false, true);
+        createPropertyDefinition(repository,
+                                 context,
+                                 "mix:referenceable",
+                                 true,
+                                 true,
+                                 false,
+                                 "jcr:uuid",
+                                 "INITIALIZE",
+                                 true,
+                                 "STRING");
+        createNodeType(repository, context, "nt:unstructured", true, false);
+        createPropertyDefinition(repository, context, "nt:unstructured", false, false, false, "COPY", false, "UNDEFINED");
+        createPropertyDefinition(repository, context, "nt:unstructured", false, false, true, "COPY", false, "UNDEFINED");
+        createChildDefinition(repository, context, "nt:unstructured", false, "nt:unstructured", false, "VERSION", false, true);
+        /*
+            <nt:versionHistory jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:versionHistory">
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="true" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:versionableUuid" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="STRING"/>
+                <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="nt:version" jcr:mandatory="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="false"/>
+                <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="true" jcr:defaultPrimaryType="nt:versionLabels" jcr:mandatory="true" jcr:name="jcr:versionLabels" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="false"/>
+                <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="true" jcr:defaultPrimaryType="nt:version" jcr:mandatory="true" jcr:name="jcr:rootVersion" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="false"/>
+            <mix:lockable jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="true" jcr:nodeTypeName="mix:lockable">
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:lockIsDeep" jcr:onParentVersion="IGNORE" jcr:protected="true" jcr:requiredType="BOOLEAN"/>
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:lockOwner" jcr:onParentVersion="IGNORE" jcr:protected="true" jcr:requiredType="STRING"/>
+            <nt:frozenNode jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="true" jcr:isMixin="false" jcr:nodeTypeName="nt:frozenNode">
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="true" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="UNDEFINED"/>
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="UNDEFINED"/>
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="true" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:frozenUuid" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="STRING"/>
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="true" jcr:name="jcr:frozenMixinTypes" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="NAME"/>
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="true" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:frozenPrimaryType" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:requiredType="NAME"/>
+                <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="true"/>
+            <rep:system jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="true" jcr:isMixin="false" jcr:nodeTypeName="rep:system">
+                <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="nt:unstructured" jcr:mandatory="false" jcr:onParentVersion="IGNORE" jcr:protected="false" jcr:sameNameSiblings="true"/>
+                <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="rep:nodeTypes" jcr:mandatory="true" jcr:name="jcr:nodeTypes" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="false"/>
+                <jcr:childNodeDefinition jcr:primaryType="nt:childNodeDefinition" jcr:autoCreated="false" jcr:defaultPrimaryType="rep:versionStorage" jcr:mandatory="true" jcr:name="jcr:versionStorage" jcr:onParentVersion="ABORT" jcr:protected="true" jcr:sameNameSiblings="false"/>
+        */
+        createNodeType(repository, context, "rep:root", true, false);
+        createChildDefinition(repository, context, "rep:root", false, true, "jcr:system", false, false);
+        /*
+            <nt:query jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:query">
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:language" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="STRING"/>
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:statement" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="STRING"/>
+            </nt:query>
+            <nt:linkedFile jcr:primaryType="nt:nodeType" jcr:hasOrderableChildNodes="false" jcr:isMixin="false" jcr:nodeTypeName="nt:linkedFile" jcr:primaryItemName="jcr:content">
+                <jcr:propertyDefinition jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false" jcr:mandatory="true" jcr:multiple="false" jcr:name="jcr:content" jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="REFERENCE"/>
+            </nt:linkedFile>
+         */
+        final SimpleRepositorySource source = new SimpleRepositorySource();
+        source.setRepositoryName(repository.getRepositoryName());
+        source.setName(repository.getRepositoryName());
+        return new RepositoryConnectionFactory() {
+
+            public RepositoryConnection createConnection( String sourceName ) {
+                return source.getConnection();
+            }
+        };
+    }
+
+    public static ExecutionContextFactory getExecutionContextFactory() {
+        final ExecutionContext context = new BasicExecutionContext(Mockito.mock(LoginContext.class));
+        NamespaceRegistry registry = context.getNamespaceRegistry();
+        registry.register("dna", "http://www.jboss.org/dna/1.0");
+        registry.register("fn", "http://www.w3.org/2005/xpath-functions");
+        registry.register("fn_old", "http://www.w3.org/2004/10/xpath-functions");
+        registry.register("jcr", "http://www.jcp.org/jcr/1.0");
+        registry.register("mix", "http://www.jcp.org/jcr/mix/1.0");
+        registry.register("nt", "http://www.jcp.org/jcr/nt/1.0");
+        registry.register("rep", "internal");
+        registry.register("sv", "http://www.jcp.org/jcr/sv/1.0");
+        registry.register("xs", "http://www.w3.org/2001/XMLSchema");
+        return new ExecutionContextFactory() {
+
+            public ExecutionContext create() {
+                return context;
+            }
+
+            public ExecutionContext create( AccessControlContext accessControlContext ) {
+                return context;
+            }
+
+            public ExecutionContext create( LoginContext loginContext ) {
+                return context;
+            }
+
+            public ExecutionContext create( String name ) {
+                return context;
+            }
+
+            public ExecutionContext create( String name,
+                                            CallbackHandler callbackHandler ) {
+                return context;
+            }
+
+            public ExecutionContext create( String name,
+                                            Subject subject ) {
+                return context;
+            }
+
+            public ExecutionContext create( String name,
+                                            Subject subject,
+                                            CallbackHandler callbackHandler ) {
+                return context;
+            }
+        };
+    }
+
+    private static void createChildDefinition( SimpleRepository repository,
+                                               ExecutionContext context,
+                                               String node,
+                                               Boolean autoCreated,
+                                               Boolean mandatory,
+                                               String onParentVersion,
+                                               Boolean isProtected,
+                                               Boolean sameNameSiblings ) {
+        createChildDefinition(repository,
+                              context,
+                              node,
+                              0,
+                              autoCreated,
+                              null,
+                              mandatory,
+                              null,
+                              onParentVersion,
+                              isProtected,
+                              sameNameSiblings);
+    }
+
+    private static void createChildDefinition( SimpleRepository repository,
+                                               ExecutionContext context,
+                                               String node,
+                                               Boolean autoCreated,
+                                               Boolean mandatory,
+                                               String name,
+                                               String onParentVersion,
+                                               Boolean isProtected,
+                                               Boolean sameNameSiblings ) {
+        createChildDefinition(repository,
+                              context,
+                              node,
+                              0,
+                              autoCreated,
+                              null,
+                              mandatory,
+                              name,
+                              onParentVersion,
+                              isProtected,
+                              sameNameSiblings);
+    }
+
+    private static void createChildDefinition( SimpleRepository repository,
+                                               ExecutionContext context,
+                                               String node,
+                                               Boolean autoCreated,
+                                               String defaultPrimaryType,
+                                               Boolean mandatory,
+                                               String onParentVersion,
+                                               Boolean isProtected,
+                                               Boolean sameNameSiblings ) {
+        createChildDefinition(repository,
+                              context,
+                              node,
+                              0,
+                              autoCreated,
+                              defaultPrimaryType,
+                              mandatory,
+                              null,
+                              onParentVersion,
+                              isProtected,
+                              sameNameSiblings);
+    }
+
+    private static void createChildDefinition( SimpleRepository repository,
+                                               ExecutionContext context,
+                                               String node,
+                                               int index,
+                                               Boolean autoCreated,
+                                               String defaultPrimaryType,
+                                               Boolean mandatory,
+                                               String name,
+                                               String onParentVersion,
+                                               Boolean isProtected,
+                                               Boolean sameNameSiblings ) {
+        String defNode = node + "/jcr:childNodeDefinition";
+        if (index > 0) {
+            defNode += '[' + index + ']';
+        }
+        createProperty(repository, context, defNode, "jcr:primaryType", "nt:childNodeDefinition");
+        createProperty(repository, context, defNode, "jcr:autoCreated", autoCreated.toString());
+        if (defaultPrimaryType != null) {
+            createProperty(repository, context, defNode, "jcr:defaultPrimaryType", defaultPrimaryType);
+        }
+        createProperty(repository, context, defNode, "jcr:mandatory", mandatory.toString());
+        if (name != null) {
+            createProperty(repository, context, defNode, "jcr:name", name);
+        }
+        createProperty(repository, context, defNode, "jcr:onParentVersion", onParentVersion);
+        createProperty(repository, context, defNode, "jcr:protected", isProtected.toString());
+        createProperty(repository, context, defNode, "jcr:sameNameSiblings", sameNameSiblings.toString());
+    }
+
+    //
+    // private static void createChildDefinitionProperty( SimpleRepository repository,
+    // ExecutionContext context,
+    // String node,
+    // String property,
+    // String value ) {
+    // createProperty(repository, context, node + "/jcr:childNodeDefinition", property, value);
+    // }
+
+    private static void createNodeType( SimpleRepository repository,
+                                        ExecutionContext context,
+                                        String node,
+                                        Boolean hasOrderableChildNodes,
+                                        Boolean isMixin ) {
+        createProperty(repository, context, node, "jcr:primaryType", "nt:nodeType");
+        createProperty(repository, context, node, "jcr:hasOrderableChildNodes", hasOrderableChildNodes.toString());
+        createProperty(repository, context, node, "jcr:isMixin", isMixin.toString());
+        createProperty(repository, context, node, "jcr:nodeTypeName", node);
+    }
+
+    private static void createProperty( SimpleRepository repository,
+                                        ExecutionContext context,
+                                        String node,
+                                        String property,
+                                        String value ) {
+        repository.setProperty(context, "/dna:system/dna:jcr/" + node, property, value);
+    }
+
+    private static void createPropertyDefinition( SimpleRepository repository,
+                                                  ExecutionContext context,
+                                                  String node,
+                                                  Boolean autoCreated,
+                                                  Boolean mandatory,
+                                                  Boolean multiple,
+                                                  String onParentVersion,
+                                                  Boolean isProtected,
+                                                  String requiredType ) {
+        createPropertyDefinition(repository,
+                                 context,
+                                 node,
+                                 0,
+                                 autoCreated,
+                                 mandatory,
+                                 multiple,
+                                 null,
+                                 onParentVersion,
+                                 isProtected,
+                                 requiredType);
+    }
+
+    private static void createPropertyDefinition( SimpleRepository repository,
+                                                  ExecutionContext context,
+                                                  String node,
+                                                  Boolean autoCreated,
+                                                  Boolean mandatory,
+                                                  Boolean multiple,
+                                                  String name,
+                                                  String onParentVersion,
+                                                  Boolean isProtected,
+                                                  String requiredType ) {
+        createPropertyDefinition(repository,
+                                 context,
+                                 node,
+                                 0,
+                                 autoCreated,
+                                 mandatory,
+                                 multiple,
+                                 name,
+                                 onParentVersion,
+                                 isProtected,
+                                 requiredType);
+    }
+
+    private static void createPropertyDefinition( SimpleRepository repository,
+                                                  ExecutionContext context,
+                                                  String node,
+                                                  int index,
+                                                  Boolean autoCreated,
+                                                  Boolean mandatory,
+                                                  Boolean multiple,
+                                                  String name,
+                                                  String onParentVersion,
+                                                  Boolean isProtected,
+                                                  String requiredType ) {
+        String defNode = node + "/nt:propertyDefinition";
+        if (index > 0) {
+            defNode += '[' + index + ']';
+        }
+        createProperty(repository, context, defNode, "jcr:primaryType", "nt:propertyDefinition");
+        createProperty(repository, context, defNode, "jcr:autoCreated", autoCreated.toString());
+        createProperty(repository, context, defNode, "jcr:mandatory", mandatory.toString());
+        createProperty(repository, context, defNode, "jcr:multiple", multiple.toString());
+        if (name != null) {
+            createProperty(repository, context, defNode, "jcr:name", name);
+        }
+        createProperty(repository, context, defNode, "jcr:onParentVersion", onParentVersion);
+        createProperty(repository, context, defNode, "jcr:protected", isProtected.toString());
+        createProperty(repository, context, defNode, "jcr:requiredType", requiredType);
+    }
+}


Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the dna-commits mailing list