chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1182520 [1/2] - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src: main/java/org/apache/chemistry/opencmis/jcr/ main/java/org/apache/chemistry/opencmis/jcr/impl/ main/java/org/apache/chemistry/opencmi...
Date Wed, 12 Oct 2011 18:45:14 GMT
Author: mduerig
Date: Wed Oct 12 18:45:13 2011
New Revision: 1182520

URL: http://svn.apache.org/viewvc?rev=1182520&view=rev
Log:
CMIS-440: Introduce type handlers to allow different content structures

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/AbstractJcrTypeHandler.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentIdentifierMap.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentTypeHandler.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultFolderTypeHandler.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultIdentifierMapBase.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultUnversionedDocumentTypeHandler.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/IdentifierMapBase.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrDocumentTypeHandler.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrFolderTypeHandler.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandler.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandlerManager.java
Removed:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/DefaultJcrTypeManager.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrNodeFactory.java
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrConverter.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrDocument.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrFolder.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrNode.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrPrivateWorkingCopy.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrRepository.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrUnversionedDocument.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersion.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslator.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Predicate.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/XPathBuilderTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrConverter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrConverter.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrConverter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrConverter.java Wed Oct 12 18:45:13 2011
@@ -81,7 +81,7 @@ public final class JcrConverter {
      * @return the escaped name
      */    
     public static String toJcrName(String cmisName) {
-        StringBuffer buffer = new StringBuffer(cmisName.length() * 2);
+        StringBuilder buffer = new StringBuilder(cmisName.length() * 2);
         for (int i = 0; i < cmisName.length(); i++) {
             char ch = cmisName.charAt(i);
             if (ch == '%' || ch == '/' || ch == ':' || ch == '[' || ch == ']' || ch == '*' || ch == '|'

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrDocument.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrDocument.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrDocument.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrDocument.java Wed Oct 12 18:45:13 2011
@@ -30,6 +30,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
 import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -51,8 +52,8 @@ public abstract class JcrDocument extend
 
     public static final String MIME_UNKNOWN = "application/octet-stream";
 
-    protected JcrDocument(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrNodeFactory nodeFactory) {
-        super(node, typeManager, pathManager, nodeFactory);
+    protected JcrDocument(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrTypeHandlerManager typeHandlerManager) {
+        super(node, typeManager, pathManager, typeHandlerManager);
     }
 
     /**

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrFolder.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrFolder.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrFolder.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrFolder.java Wed Oct 12 18:45:13 2011
@@ -20,7 +20,6 @@
 package org.apache.chemistry.opencmis.jcr;
 
 import org.apache.chemistry.opencmis.commons.PropertyIds;
-import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.data.Properties;
 import org.apache.chemistry.opencmis.commons.data.PropertyData;
 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
@@ -28,33 +27,26 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.enums.Action;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.Updatability;
-import org.apache.chemistry.opencmis.commons.enums.VersioningState;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
-import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.FailedToDeleteDataImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
 import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
 import org.apache.chemistry.opencmis.jcr.util.FilterIterator;
 import org.apache.chemistry.opencmis.jcr.util.Predicate;
 import org.apache.chemistry.opencmis.jcr.util.Util;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.jcr.Binary;
 import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Property;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 import javax.jcr.version.Version;
-import java.io.BufferedInputStream;
-import java.io.IOException;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -67,8 +59,8 @@ import java.util.Set;
 public class JcrFolder extends JcrNode {
     private static final Log log = LogFactory.getLog(JcrFolder.class);
 
-    public JcrFolder(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrNodeFactory nodeFactory) {
-        super(node, typeManager, pathManager, nodeFactory);
+    public JcrFolder(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrTypeHandlerManager typeHandlerManager) {
+        super(node, typeManager, pathManager, typeHandlerManager);
     }
 
     /**
@@ -80,7 +72,7 @@ public class JcrFolder extends JcrNode {
      */
     public Iterator<JcrNode> getNodes() {
         try {
-            final NodeIterator nodes = getNode().getNodes();
+            final FilterIterator<Node> nodes = new FilterIterator<Node>(getNode().getNodes(), typeHandlerManager.getNodePredicate());
 
             Iterator<JcrNode> jcrNodes = new Iterator<JcrNode>() {
                 public boolean hasNext() {
@@ -88,7 +80,7 @@ public class JcrFolder extends JcrNode {
                 }
 
                 public JcrNode next() {
-                    return create(nodes.nextNode());
+                    return create(nodes.next());
                 }
 
                 public void remove() {
@@ -124,64 +116,6 @@ public class JcrFolder extends JcrNode {
     }
 
     /**
-     * See CMIS 1.0 section 2.2.4.1 createDocument
-     *
-     * @throws CmisStorageException
-     */
-    public JcrNode addNode(String name, String typeId, Properties properties, ContentStream contentStream,
-            VersioningState versioningState) {
-        
-        try {
-            Node fileNode = getNode().addNode(name, NodeType.NT_FILE);
-            if (versioningState != VersioningState.NONE) {
-                fileNode.addMixin(NodeType.MIX_SIMPLE_VERSIONABLE);
-            }
-
-            Node contentNode = fileNode.addNode(Node.JCR_CONTENT, NodeType.NT_RESOURCE);
-            contentNode.addMixin(NodeType.MIX_CREATED);
-
-            // compile the properties
-            setProperties(contentNode, typeId, properties);
-
-            // write content, if available
-            Binary binary = contentStream == null || contentStream.getStream() == null
-                    ? JcrBinary.EMPTY
-                    : new JcrBinary(new BufferedInputStream(contentStream.getStream()));
-            try {
-                contentNode.setProperty(Property.JCR_DATA, binary);
-                if (contentStream != null && contentStream.getMimeType() != null) {
-                    contentNode.setProperty(Property.JCR_MIMETYPE, contentStream.getMimeType());
-                }
-            }
-            finally {
-                binary.dispose();
-            }
-
-            fileNode.getSession().save();
-            JcrNode jcrFileNode = create(fileNode);
-            if (versioningState == VersioningState.NONE) {
-                return jcrFileNode;
-            }
-
-            JcrVersionBase jcrVersion = jcrFileNode.asVersion();
-            if (versioningState == VersioningState.MINOR || versioningState == VersioningState.MAJOR) {
-                return jcrVersion.checkin(null, null, "auto checkin");
-            }
-            else {
-                return jcrVersion.getPwc();
-            }
-        }
-        catch (RepositoryException e) {
-            log.debug(e.getMessage(), e);
-            throw new CmisStorageException(e.getMessage(), e);
-        }
-        catch (IOException e) {
-            log.debug(e.getMessage(), e);
-            throw new CmisStorageException(e.getMessage(), e);
-        }
-    }
-
-    /**
      * See CMIS 1.0 section 2.2.4.2 createDocumentFromSource
      *
      * @throws CmisStorageException
@@ -209,29 +143,6 @@ public class JcrFolder extends JcrNode {
     }
 
     /**
-     * See CMIS 1.0 section 2.2.4.3 createFolder
-     *
-     * @throws CmisStorageException
-     */
-    public JcrNode addFolder(String name, String typeId, Properties properties) {
-        try {
-            Node node = getNode().addNode(name, NodeType.NT_FOLDER);
-            node.addMixin(NodeType.MIX_CREATED);
-            node.addMixin(NodeType.MIX_LAST_MODIFIED);
-
-            // compile the properties
-            setProperties(node, typeId, properties);
-
-            node.getSession().save();
-            return create(node);
-        }
-        catch (RepositoryException e) {
-            log.debug(e.getMessage(), e);
-            throw new CmisStorageException(e.getMessage(), e);
-        }
-    }
-
-    /**
      * See CMIS 1.0 section 2.2.4.14 deleteObject
      *
      * @throws CmisRuntimeException
@@ -340,21 +251,13 @@ public class JcrFolder extends JcrNode {
         return JcrTypeManager.FOLDER_TYPE_ID;
     }
 
-    //------------------------------------------< private >---
-
-    private void setProperties(Node node, String typeId, Properties properties) {
+    public static void setProperties(Node node, TypeDefinition type, Properties properties) {
         if (properties == null || properties.getProperties() == null) {
             throw new CmisConstraintException("No properties!");
         }
 
         Set<String> addedProps = new HashSet<String>();
 
-        // get the property definitions
-        TypeDefinition type = typeManager.getType(typeId);
-        if (type == null) {
-            throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
-        }
-
         try {
             // check if all required properties are there
             for (PropertyData<?> prop : properties.getProperties().values()) {
@@ -413,6 +316,8 @@ public class JcrFolder extends JcrNode {
         }
     }
 
+    //------------------------------------------< private >---
+
     private static boolean hasCheckOuts(Node node) throws RepositoryException {
         // Build xpath query of the form
         // '//path/to/node//*[jcr:isCheckedOut='true']'

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrNode.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrNode.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrNode.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrNode.java Wed Oct 12 18:45:13 2011
@@ -47,6 +47,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl;
 import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
 import org.apache.chemistry.opencmis.commons.server.ObjectInfoHandler;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
 import org.apache.chemistry.opencmis.jcr.util.Util;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -95,7 +96,7 @@ public abstract class JcrNode {
     private final Node node;
     protected final JcrTypeManager typeManager;
     protected final PathManager pathManager;
-    private final JcrNodeFactory nodeFactory;
+    protected final JcrTypeHandlerManager typeHandlerManager;
 
     /**
      * Create a new instance wrapping a JCR <code>node</code>.
@@ -103,13 +104,13 @@ public abstract class JcrNode {
      * @param node  the JCR <code>node</code> to represent
      * @param typeManager
      * @param pathManager
-     * @param nodeFactory
+     * @param typeHandlerManager
      */
-    protected JcrNode(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrNodeFactory nodeFactory) {
+    protected JcrNode(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrTypeHandlerManager typeHandlerManager) {
         this.node = node;
         this.typeManager = typeManager;
         this.pathManager = pathManager;
-        this.nodeFactory = nodeFactory;
+        this.typeHandlerManager = typeHandlerManager;
     }
 
     /**
@@ -615,7 +616,7 @@ public abstract class JcrNode {
      * @return  a new <code>JcrNode</code>
      */
     protected final JcrNode create(Node node) {
-        return nodeFactory.create(node);
+        return typeHandlerManager.create(node);
     }
 
     /**

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrPrivateWorkingCopy.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrPrivateWorkingCopy.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrPrivateWorkingCopy.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrPrivateWorkingCopy.java Wed Oct 12 18:45:13 2011
@@ -20,6 +20,7 @@
 package org.apache.chemistry.opencmis.jcr;
 
 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -39,9 +40,9 @@ public class JcrPrivateWorkingCopy exten
     public static final String PWC_NAME = "pwc";
 
     public JcrPrivateWorkingCopy(Node node, JcrTypeManager typeManager, PathManager pathManager,
-            JcrNodeFactory nodeFactory) {
+            JcrTypeHandlerManager typeHandlerManager) {
         
-        super(node, typeManager, pathManager, nodeFactory);
+        super(node, typeManager, pathManager, typeHandlerManager);
     }
 
     /**

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrRepository.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrRepository.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrRepository.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrRepository.java Wed Oct 12 18:45:13 2011
@@ -58,6 +58,9 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.ObjectInfoHandler;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
 import org.apache.chemistry.opencmis.jcr.query.QueryTranslator;
+import org.apache.chemistry.opencmis.jcr.type.JcrDocumentTypeHandler;
+import org.apache.chemistry.opencmis.jcr.type.JcrFolderTypeHandler;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
 import org.apache.chemistry.opencmis.jcr.util.Util;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -92,22 +95,21 @@ public class JcrRepository {
     private final Repository repository;
     private final JcrTypeManager typeManager;
     private final PathManager pathManager;
-    private final JcrNodeFactory nodeFactory;
+    private final JcrTypeHandlerManager typeHandlerManager;
 
     /**
      * Create a new <code>JcrRepository</code> instance backed by a JCR repository.
      *
      * @param repository  the JCR repository
-     * @param rootPath  path in the JCR repository which is exposed as root folder in CMIS
+     * @param pathManager
      * @param typeManager  
-     * @param nodeFactory
+     * @param typeHandlerManager
      */
-    public JcrRepository(Repository repository, String rootPath, JcrTypeManager typeManager, JcrNodeFactory nodeFactory) {
+    public JcrRepository(Repository repository, PathManager pathManager, JcrTypeManager typeManager, JcrTypeHandlerManager typeHandlerManager) {
         this.repository = repository;
         this.typeManager = typeManager;
-        this.nodeFactory = nodeFactory;
-        pathManager = new PathManager(rootPath);
-        nodeFactory.initialize(typeManager, pathManager);
+        this.typeHandlerManager = typeHandlerManager;
+        this.pathManager = pathManager;
     }
 
     /**
@@ -236,7 +238,8 @@ public class JcrRepository {
 
         // get parent Node and create child
         JcrFolder parent = getJcrNode(session, folderId).asFolder();
-        JcrNode jcrNode = parent.addNode(name, typeId, properties, contentStream, versioningState);
+        JcrDocumentTypeHandler typeHandler = typeHandlerManager.getDocumentTypeHandler(typeId);
+        JcrNode jcrNode = typeHandler.createDocument(parent, name, properties, contentStream, versioningState);
         return jcrNode.getId();
     }
 
@@ -294,7 +297,8 @@ public class JcrRepository {
 
         // get parent Node
         JcrFolder parent = getJcrNode(session, folderId).asFolder();
-        JcrNode jcrNode = parent.addFolder(name, typeId, properties);
+        JcrFolderTypeHandler typeHandler = typeHandlerManager.getFolderTypeHandler(typeId);
+        JcrNode jcrNode = typeHandler.createFolder(parent, name, properties);
         return jcrNode.getId();
     }
 
@@ -663,7 +667,7 @@ public class JcrRepository {
             NodeIterator nodes = queryResult.getNodes();
             while (nodes.hasNext()) {
                 Node node = nodes.nextNode();
-                JcrNode jcrNode = nodeFactory.create(node); 
+                JcrNode jcrNode = typeHandlerManager.create(node);
                 if (!jcrNode.isVersionable()) {
                     continue;
                 }
@@ -869,17 +873,17 @@ public class JcrRepository {
 
             @Override
             protected String jcrPathFromCol(TypeDefinition fromType, String name) {
-                return nodeFactory.getIdentifierMap(fromType).jcrPathFromCol(name);
+                return typeHandlerManager.getIdentifierMap(fromType.getId()).jcrPathFromCol(name);
             }
 
             @Override
             protected String jcrTypeName(TypeDefinition fromType) {
-                return nodeFactory.getIdentifierMap(fromType).jcrTypeName();
+                return typeHandlerManager.getIdentifierMap(fromType.getId()).jcrTypeName();
             }
 
             @Override
             protected String jcrTypeCondition(TypeDefinition fromType) {
-                return nodeFactory.getIdentifierMap(fromType).jcrTypeCondition();
+                return typeHandlerManager.getIdentifierMap(fromType.getId()).jcrTypeCondition();
             }
         };
 
@@ -908,7 +912,7 @@ public class JcrRepository {
             NodeIterator nodes = queryResult.getNodes();
             while (nodes.hasNext() && result.getObjects().size() < max) {
                 Node node = nodes.nextNode();
-                JcrNode jcrNode = nodeFactory.create(node);
+                JcrNode jcrNode = typeHandlerManager.create(node);
                 count++;
 
                 // Get pwc if this node is versionable and checked out
@@ -994,7 +998,7 @@ public class JcrRepository {
             }
 
             if (id.equals(PathManager.CMIS_ROOT_ID)) {
-                return nodeFactory.create(getRootNode(session));
+                return typeHandlerManager.create(getRootNode(session));
             }
 
             int k = id.indexOf('/');
@@ -1004,7 +1008,7 @@ public class JcrRepository {
 
                 Node node = session.getNodeByIdentifier(nodeId);
 
-                JcrNode jcrNode = nodeFactory.create(node);
+                JcrNode jcrNode = typeHandlerManager.create(node);
                 if (JcrPrivateWorkingCopy.denotesPwc(versionName)) {
                     return jcrNode.asVersion().getPwc();
                 }
@@ -1014,7 +1018,7 @@ public class JcrRepository {
             }
             else {
                 Node node = session.getNodeByIdentifier(id);
-                return nodeFactory.create(node);
+                return typeHandlerManager.create(node);
             }
 
         }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java Wed Oct 12 18:45:13 2011
@@ -24,6 +24,10 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
+import org.apache.chemistry.opencmis.jcr.impl.DefaultDocumentTypeHandler;
+import org.apache.chemistry.opencmis.jcr.impl.DefaultFolderTypeHandler;
+import org.apache.chemistry.opencmis.jcr.impl.DefaultUnversionedDocumentTypeHandler;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
 import org.apache.chemistry.opencmis.server.support.CmisServiceWrapper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -63,7 +67,9 @@ public class JcrServiceFactory extends A
     public void init(Map<String, String> parameters) {
         typeManager = createTypeManager();
         readConfiguration(parameters);
-        jcrRepository = new JcrRepository(acquireJcrRepository(jcrConfig), mountPath, typeManager, new JcrNodeFactory());
+        PathManager pathManger = new PathManager(mountPath);
+        JcrTypeHandlerManager typeHandlerManager = createTypeHandlerManager(pathManger, typeManager);
+        jcrRepository = new JcrRepository(acquireJcrRepository(jcrConfig), pathManger, typeManager, typeHandlerManager);
     }
 
     @Override
@@ -131,7 +137,15 @@ public class JcrServiceFactory extends A
     }
 
     protected JcrTypeManager createTypeManager() {
-        return new DefaultJcrTypeManager();
+        return new JcrTypeManager();
+    }
+
+    protected JcrTypeHandlerManager createTypeHandlerManager(PathManager pathManager, JcrTypeManager typeManager) {
+        JcrTypeHandlerManager typeHandlerManager = new JcrTypeHandlerManager(pathManager, typeManager);
+        typeHandlerManager.addHandler(new DefaultFolderTypeHandler());
+        typeHandlerManager.addHandler(new DefaultDocumentTypeHandler());
+        typeHandlerManager.addHandler(new DefaultUnversionedDocumentTypeHandler());
+        return typeHandlerManager;
     }
 
     //------------------------------------------< private >---

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrUnversionedDocument.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrUnversionedDocument.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrUnversionedDocument.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrUnversionedDocument.java Wed Oct 12 18:45:13 2011
@@ -20,6 +20,8 @@
 package org.apache.chemistry.opencmis.jcr;
 
 import org.apache.chemistry.opencmis.commons.enums.Action;
+import org.apache.chemistry.opencmis.jcr.impl.DefaultUnversionedDocumentTypeHandler;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -30,8 +32,8 @@ import java.util.Set;
  */
 public class JcrUnversionedDocument extends JcrDocument {
     
-    public JcrUnversionedDocument(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrNodeFactory nodeFactory) {
-        super(node, typeManager, pathManager, nodeFactory);
+    public JcrUnversionedDocument(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrTypeHandlerManager typeHandlerManager) {
+        super(node, typeManager, pathManager, typeHandlerManager);
     }
 
     //------------------------------------------< protected >--- 
@@ -53,7 +55,7 @@ public class JcrUnversionedDocument exte
 
     @Override
     protected String getTypeIdInternal() {
-        return DefaultJcrTypeManager.DOCUMENT_UNVERSIONED_TYPE_ID;
+        return DefaultUnversionedDocumentTypeHandler.DOCUMENT_UNVERSIONED_TYPE_ID;
     }
 
     @Override

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersion.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersion.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersion.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersion.java Wed Oct 12 18:45:13 2011
@@ -19,6 +19,8 @@
 
 package org.apache.chemistry.opencmis.jcr;
 
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
+
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.version.Version;
@@ -37,9 +39,9 @@ public class JcrVersion extends JcrVersi
     private final Version version;
 
     public JcrVersion(Node node, Version version, JcrTypeManager typeManager, PathManager pathManager,
-            JcrNodeFactory nodeFactory) {
+            JcrTypeHandlerManager typeHandlerManager) {
 
-        super(node, typeManager, pathManager, nodeFactory);
+        super(node, typeManager, pathManager, typeHandlerManager);
         this.version = version;
     }
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java Wed Oct 12 18:45:13 2011
@@ -28,6 +28,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
 import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -48,11 +49,8 @@ import java.util.Set;
 public abstract class JcrVersionBase extends JcrDocument {
     private static final Log log = LogFactory.getLog(JcrVersionBase.class);
 
-    private final JcrNodeFactory nodeFactory;
-
-    public JcrVersionBase(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrNodeFactory nodeFactory) {
-        super(node, typeManager, pathManager, nodeFactory);
-        this.nodeFactory = nodeFactory;
+    protected JcrVersionBase(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrTypeHandlerManager typeHandlerManager) {
+        super(node, typeManager, pathManager, typeHandlerManager);
     }
 
     /**
@@ -69,7 +67,7 @@ public abstract class JcrVersionBase ext
                 }
 
                 public JcrVersion next() {
-                    return new JcrVersion(getNode(), versions.nextVersion(), typeManager, pathManager, nodeFactory);
+                    return new JcrVersion(getNode(), versions.nextVersion(), typeManager, pathManager, typeHandlerManager);
                 }
 
                 public void remove() {
@@ -189,7 +187,7 @@ public abstract class JcrVersionBase ext
         try {
             Node node = getNode();
             if (node.isCheckedOut()) {
-                return new JcrPrivateWorkingCopy(getNode(), typeManager, pathManager, nodeFactory);
+                return new JcrPrivateWorkingCopy(getNode(), typeManager, pathManager, typeHandlerManager);
             }
             else {
                 throw new CmisObjectNotFoundException("Not checked out document has no private working copy");
@@ -213,7 +211,7 @@ public abstract class JcrVersionBase ext
             Node node = getNode();
             VersionHistory versionHistory = getVersionHistory(node);
             Version version = versionHistory.getVersion(name);
-            return new JcrVersion(node, version, typeManager, pathManager, nodeFactory);
+            return new JcrVersion(node, version, typeManager, pathManager, typeHandlerManager);
         }
         catch (UnsupportedRepositoryOperationException e) {
             log.debug(e.getMessage(), e);
@@ -232,12 +230,12 @@ public abstract class JcrVersionBase ext
     //------------------------------------------< protected >---
 
     /**
-     * @return  Id of the version representing the base of this verions series
+     * @return  Id of the version representing the base of this versions series
      * @throws RepositoryException
      */
     protected String getBaseNodeId() throws RepositoryException {
         Version baseVersion = getBaseVersion(getNode());
-        JcrNode baseNode = new JcrVersion(getNode(), baseVersion, typeManager, pathManager, nodeFactory);
+        JcrNode baseNode = new JcrVersion(getNode(), baseVersion, typeManager, pathManager, typeHandlerManager);
         return baseNode.getId();
     }
 

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/AbstractJcrTypeHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/AbstractJcrTypeHandler.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/AbstractJcrTypeHandler.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/AbstractJcrTypeHandler.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.impl;
+
+import org.apache.chemistry.opencmis.jcr.JcrTypeManager;
+import org.apache.chemistry.opencmis.jcr.PathManager;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandler;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
+
+/**
+ * This abstract class takes care of collecting references set when the handler is added to
+ * {@link JcrTypeHandlerManager}.
+ */
+public abstract class AbstractJcrTypeHandler implements JcrTypeHandler {
+
+    protected JcrTypeManager typeManager;
+    protected PathManager pathManager;
+    protected JcrTypeHandlerManager typeHandlerManager;
+
+    public void initialize(PathManager pathManager, JcrTypeManager typeManager, JcrTypeHandlerManager typeHandlerManager) {
+        this.typeManager = typeManager;
+        this.pathManager = pathManager;
+        this.typeHandlerManager = typeHandlerManager;
+    }
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentIdentifierMap.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentIdentifierMap.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentIdentifierMap.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentIdentifierMap.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.impl;
+
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+
+/**
+ * Provides mappings to standard jcr properties for documents.
+ */
+public class DefaultDocumentIdentifierMap extends DefaultIdentifierMapBase {
+
+    private final boolean isVersionable;
+
+    public DefaultDocumentIdentifierMap(boolean isVersionable) {
+        super("nt:file");
+        this.isVersionable = isVersionable;
+        cmis2Jcr.put(PropertyIds.CREATED_BY, "jcr:content/@jcr:createdBy");
+        cmis2Jcr.put(PropertyIds.CREATION_DATE, "jcr:content/@jcr:created");
+        cmis2Jcr.put(PropertyIds.LAST_MODIFIED_BY, "jcr:content/@jcr:lastModifiedBy");
+        cmis2Jcr.put(PropertyIds.LAST_MODIFICATION_DATE, "jcr:content/@jcr:lastModified");
+        cmis2Jcr.put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "jcr:content/@jcr:mimeType");
+        cmis2Jcr.put(PropertyIds.CONTENT_STREAM_FILE_NAME, "fn:name()");
+        // xxx not supported: IS_IMMUTABLE, IS_LATEST_VERSION, IS_MAJOR_VERSION, IS_LATEST_MAJOR_VERSION,
+        // VERSION_LABEL, VERSION_SERIES_ID, IS_VERSION_SERIES_CHECKED_OUT, VERSION_SERIES_CHECKED_OUT_ID
+        // VERSION_SERIES_CHECKED_OUT_BY, CHECKIN_COMMENT, CONTENT_STREAM_ID, CONTENT_STREAM_LENGTH
+    }
+
+    @Override
+    public String jcrTypeCondition() {
+        return (isVersionable ? "" : "not") +
+                "(@jcr:mixinTypes = 'mix:simpleVersionable')";
+    }
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentTypeHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentTypeHandler.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentTypeHandler.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentTypeHandler.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.impl;
+
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl;
+import org.apache.chemistry.opencmis.jcr.JcrBinary;
+import org.apache.chemistry.opencmis.jcr.JcrDocument;
+import org.apache.chemistry.opencmis.jcr.JcrFolder;
+import org.apache.chemistry.opencmis.jcr.JcrNode;
+import org.apache.chemistry.opencmis.jcr.JcrTypeManager;
+import org.apache.chemistry.opencmis.jcr.JcrVersion;
+import org.apache.chemistry.opencmis.jcr.JcrVersionBase;
+import org.apache.chemistry.opencmis.jcr.query.IdentifierMap;
+import org.apache.chemistry.opencmis.jcr.type.JcrDocumentTypeHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jcr.Binary;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+
+/**
+ * Type handler that provides cmis:document.
+ */
+public class DefaultDocumentTypeHandler extends AbstractJcrTypeHandler implements JcrDocumentTypeHandler {
+
+    private static final Log log = LogFactory.getLog(JcrFolder.class);
+
+    public String getTypeId() {
+        return BaseTypeId.CMIS_DOCUMENT.value();
+    }
+
+    public TypeDefinition getTypeDefinition() {
+        DocumentTypeDefinitionImpl documentType = new DocumentTypeDefinitionImpl();
+        documentType.setBaseTypeId(BaseTypeId.CMIS_DOCUMENT);
+        documentType.setIsControllableAcl(false);
+        documentType.setIsControllablePolicy(false);
+        documentType.setIsCreatable(true);
+        documentType.setDescription("Document");
+        documentType.setDisplayName("Document");
+        documentType.setIsFileable(true);
+        documentType.setIsFulltextIndexed(false);
+        documentType.setIsIncludedInSupertypeQuery(true);
+        documentType.setLocalName("Document");
+        documentType.setLocalNamespace(JcrTypeManager.NAMESPACE);
+        documentType.setIsQueryable(true);
+        documentType.setQueryName(JcrTypeManager.DOCUMENT_TYPE_ID);
+        documentType.setId(JcrTypeManager.DOCUMENT_TYPE_ID);
+        documentType.setIsVersionable(true);
+        documentType.setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
+
+        JcrTypeManager.addBasePropertyDefinitions(documentType);
+        JcrTypeManager.addDocumentPropertyDefinitions(documentType);
+
+        return documentType;
+    }
+
+    public IdentifierMap getIdentifierMap() {
+        return new DefaultDocumentIdentifierMap(true);
+    }
+
+    public JcrDocument getJcrNode(Node node) throws RepositoryException {
+        VersionManager versionManager = node.getSession().getWorkspace().getVersionManager();
+        Version version = versionManager.getBaseVersion(node.getPath());
+        return new JcrVersion(node, version, typeManager, pathManager, typeHandlerManager);
+    }
+
+    public boolean canHandle(Node node) throws RepositoryException {
+        return node.isNodeType(NodeType.NT_FILE) && node.isNodeType(NodeType.MIX_SIMPLE_VERSIONABLE);
+    }
+
+    public JcrNode createDocument(JcrFolder parentFolder, String name, Properties properties, ContentStream contentStream, VersioningState versioningState) {
+        try {
+            Node fileNode = parentFolder.getNode().addNode(name, NodeType.NT_FILE);
+            if (versioningState != VersioningState.NONE) {
+                fileNode.addMixin(NodeType.MIX_SIMPLE_VERSIONABLE);
+            }
+
+            Node contentNode = fileNode.addNode(Node.JCR_CONTENT, NodeType.NT_RESOURCE);
+            contentNode.addMixin(NodeType.MIX_CREATED);
+
+            // compile the properties
+            JcrFolder.setProperties(contentNode, getTypeDefinition(), properties);
+
+            // write content, if available
+            Binary binary = contentStream == null || contentStream.getStream() == null
+                    ? JcrBinary.EMPTY
+                    : new JcrBinary(new BufferedInputStream(contentStream.getStream()));
+            try {
+                contentNode.setProperty(Property.JCR_DATA, binary);
+                if (contentStream != null && contentStream.getMimeType() != null) {
+                    contentNode.setProperty(Property.JCR_MIMETYPE, contentStream.getMimeType());
+                }
+            }
+            finally {
+                binary.dispose();
+            }
+
+            fileNode.getSession().save();
+            JcrNode jcrFileNode = getJcrNode(fileNode);
+            if (versioningState == VersioningState.NONE) {
+                return jcrFileNode;
+            }
+
+            JcrVersionBase jcrVersion = jcrFileNode.asVersion();
+            if (versioningState == VersioningState.MINOR || versioningState == VersioningState.MAJOR) {
+                return jcrVersion.checkin(null, null, "auto checkin");
+            } else {
+                return jcrVersion.getPwc();
+            }
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisStorageException(e.getMessage(), e);
+        }
+        catch (IOException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisStorageException(e.getMessage(), e);
+        }
+    }
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultFolderTypeHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultFolderTypeHandler.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultFolderTypeHandler.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultFolderTypeHandler.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.impl;
+
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.FolderTypeDefinitionImpl;
+import org.apache.chemistry.opencmis.jcr.JcrFolder;
+import org.apache.chemistry.opencmis.jcr.JcrTypeManager;
+import org.apache.chemistry.opencmis.jcr.query.IdentifierMap;
+import org.apache.chemistry.opencmis.jcr.type.JcrFolderTypeHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+
+/**
+ * Type handler that provides cmis:folder.
+ */
+public class DefaultFolderTypeHandler extends AbstractJcrTypeHandler implements JcrFolderTypeHandler {
+
+    private static final Log log = LogFactory.getLog(DefaultFolderTypeHandler.class);
+
+    private static class FolderIdentifierMap extends DefaultIdentifierMapBase {
+
+        public FolderIdentifierMap() {
+            super("nt:folder");
+            // xxx not supported: PARENT_ID, ALLOWED_CHILD_OBJECT_TYPE_IDS, PATH
+        }
+    }
+
+    public String getTypeId() {
+        return BaseTypeId.CMIS_FOLDER.value();
+    }
+
+    public TypeDefinition getTypeDefinition() {
+        FolderTypeDefinitionImpl folderType = new FolderTypeDefinitionImpl();
+        folderType.setBaseTypeId(BaseTypeId.CMIS_FOLDER);
+        folderType.setIsControllableAcl(false);
+        folderType.setIsControllablePolicy(false);
+        folderType.setIsCreatable(true);
+        folderType.setDescription("Folder");
+        folderType.setDisplayName("Folder");
+        folderType.setIsFileable(true);
+        folderType.setIsFulltextIndexed(false);
+        folderType.setIsIncludedInSupertypeQuery(true);
+        folderType.setLocalName("Folder");
+        folderType.setLocalNamespace(JcrTypeManager.NAMESPACE);
+        folderType.setIsQueryable(true);
+        folderType.setQueryName(JcrTypeManager.FOLDER_TYPE_ID);
+        folderType.setId(JcrTypeManager.FOLDER_TYPE_ID);
+
+        JcrTypeManager.addBasePropertyDefinitions(folderType);
+        JcrTypeManager.addFolderPropertyDefinitions(folderType);
+
+        return folderType;
+    }
+
+    public IdentifierMap getIdentifierMap() {
+        return new FolderIdentifierMap();
+    }
+
+    public JcrFolder getJcrNode(Node node) {
+        return new JcrFolder(node, typeManager, pathManager, typeHandlerManager);
+    }
+
+    public boolean canHandle(Node node) throws RepositoryException {
+        return node.isNodeType(NodeType.NT_FOLDER) || node.getDepth() == 0;
+    }
+
+    public JcrFolder createFolder(JcrFolder parentFolder, String name, Properties properties) {
+        try {
+            Node node = parentFolder.getNode().addNode(name, NodeType.NT_FOLDER);
+            node.addMixin(NodeType.MIX_CREATED);
+            node.addMixin(NodeType.MIX_LAST_MODIFIED);
+
+            // compile the properties
+            JcrFolder.setProperties(node, getTypeDefinition(), properties);
+
+            node.getSession().save();
+            return getJcrNode(node);
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisStorageException(e.getMessage(), e);
+        }
+    }
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultIdentifierMapBase.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultIdentifierMapBase.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultIdentifierMapBase.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultIdentifierMapBase.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.impl;
+
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.jcr.query.IdentifierMapBase;
+
+/**
+ * Provides mappings to standard jcr properties.
+ */
+public class DefaultIdentifierMapBase extends IdentifierMapBase {
+
+    public DefaultIdentifierMapBase(String jcrTypeName) {
+        super(jcrTypeName);
+        cmis2Jcr.put(PropertyIds.OBJECT_ID, "@jcr:uuid");
+        cmis2Jcr.put(PropertyIds.NAME, "fn:name()");
+        cmis2Jcr.put(PropertyIds.CREATED_BY, "@jcr:createdBy");
+        cmis2Jcr.put(PropertyIds.CREATION_DATE, "@jcr:created");
+        cmis2Jcr.put(PropertyIds.LAST_MODIFIED_BY, "@jcr:lastModifiedBy");
+        cmis2Jcr.put(PropertyIds.LAST_MODIFICATION_DATE, "@jcr:lastModified");
+        // xxx not supported: BASE_TYPE_ID, CHANGE_TOKEN
+    }
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultUnversionedDocumentTypeHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultUnversionedDocumentTypeHandler.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultUnversionedDocumentTypeHandler.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultUnversionedDocumentTypeHandler.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.impl;
+
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl;
+import org.apache.chemistry.opencmis.jcr.JcrDocument;
+import org.apache.chemistry.opencmis.jcr.JcrTypeManager;
+import org.apache.chemistry.opencmis.jcr.JcrUnversionedDocument;
+import org.apache.chemistry.opencmis.jcr.query.IdentifierMap;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+
+/**
+ * Type handler that provides cmis:unversioned-document.
+ */
+public class DefaultUnversionedDocumentTypeHandler extends DefaultDocumentTypeHandler {
+
+    public static final String DOCUMENT_UNVERSIONED_TYPE_ID = "cmis:unversioned-document";
+
+    @Override
+    public String getTypeId() {
+        return DOCUMENT_UNVERSIONED_TYPE_ID;
+    }
+
+    @Override
+    public TypeDefinition getTypeDefinition() {
+
+        DocumentTypeDefinitionImpl unversionedDocument = new DocumentTypeDefinitionImpl();
+        unversionedDocument.initialize(super.getTypeDefinition());
+
+        unversionedDocument.setDescription("Unversioned document");
+        unversionedDocument.setDisplayName("Unversioned document");
+        unversionedDocument.setLocalName("Unversioned document");
+        unversionedDocument.setIsQueryable(true);
+        unversionedDocument.setQueryName(DOCUMENT_UNVERSIONED_TYPE_ID);
+        unversionedDocument.setId(DOCUMENT_UNVERSIONED_TYPE_ID);
+        unversionedDocument.setParentTypeId(JcrTypeManager.DOCUMENT_TYPE_ID);
+
+        unversionedDocument.setIsVersionable(false);
+        unversionedDocument.setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
+
+        JcrTypeManager.addBasePropertyDefinitions(unversionedDocument);
+        JcrTypeManager.addDocumentPropertyDefinitions(unversionedDocument);
+
+        return unversionedDocument;
+    }
+
+    @Override
+    public IdentifierMap getIdentifierMap() {
+        return new DefaultDocumentIdentifierMap(false);
+    }
+
+    @Override
+    public boolean canHandle(Node node) throws RepositoryException {
+        return node.isNodeType(NodeType.NT_FILE) && !node.isNodeType(NodeType.MIX_SIMPLE_VERSIONABLE);
+    }
+
+    @Override
+    public JcrDocument getJcrNode(Node node) {
+        return new JcrUnversionedDocument(node, typeManager, pathManager, typeHandlerManager);
+    }
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/IdentifierMapBase.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/IdentifierMapBase.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/IdentifierMapBase.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/IdentifierMapBase.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.query;
+
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This abstract base class provides support for implementing {@link IdentifierMap}.
+ */
+public abstract class IdentifierMapBase implements IdentifierMap {
+
+    private final String jcrTypeName;
+    protected final Map<String, String> cmis2Jcr = new HashMap<String, String>();
+
+    protected IdentifierMapBase(String jcrTypeName) {
+        this.jcrTypeName = jcrTypeName;
+    }
+
+    public String jcrPathFromCol(String name) {
+        String jcrPath = cmis2Jcr.get(name);
+        if (jcrPath == null) {
+            throw new CmisRuntimeException("Not supported: query on column " + name);
+        } else {
+            return jcrPath;
+        }
+    }
+
+    public String jcrTypeName() {
+        return jcrTypeName;
+    }
+
+    public String jcrTypeCondition() {
+        return null;
+    }
+}

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.java Wed Oct 12 18:45:13 2011
@@ -77,12 +77,12 @@ public class ParseTreeWalker<T> implemen
     //------------------------------------------< protected >---
 
     /** For extensibility. */
-    protected T walkOtherExpr(Evaluator evaluator, Tree node) {
+    protected T walkOtherExpr(Evaluator<?> evaluator, Tree node) {
         throw new CmisRuntimeException("Unknown node type: " + node.getType() + " (" + node.getText() + ")");
     }
 
     /** For extensibility. */
-    protected T walkOtherPredicate(Evaluator evaluator, Tree node) {
+    protected T walkOtherPredicate(Evaluator<?> evaluator, Tree node) {
         throw new CmisRuntimeException("Unknown node type: " + node.getType() + " (" + node.getText() + ")");
     }
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslator.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslator.java Wed Oct 12 18:45:13 2011
@@ -48,7 +48,7 @@ public abstract class QueryTranslator {
      * 
      * @param typeManager
      */
-    public QueryTranslator(JcrTypeManager typeManager) {
+    protected QueryTranslator(JcrTypeManager typeManager) {
         this.typeManager = typeManager;
         evaluator = new EvaluatorXPath() {
 

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrDocumentTypeHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrDocumentTypeHandler.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrDocumentTypeHandler.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrDocumentTypeHandler.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.type;
+
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+import org.apache.chemistry.opencmis.jcr.JcrDocument;
+import org.apache.chemistry.opencmis.jcr.JcrFolder;
+import org.apache.chemistry.opencmis.jcr.JcrNode;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * Implemented by type handlers that provides a type that is or inherits from cmis:document.
+ */
+public interface JcrDocumentTypeHandler extends JcrTypeHandler {
+
+    JcrDocument getJcrNode(Node node) throws RepositoryException;
+
+    /**
+     * See CMIS 1.0 section 2.2.4.1 createDocument
+     *
+     * @throws org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException
+     *
+     */
+    JcrNode createDocument(JcrFolder parentFolder, String name, Properties properties, ContentStream contentStream, VersioningState versioningState);
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrFolderTypeHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrFolderTypeHandler.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrFolderTypeHandler.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrFolderTypeHandler.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.type;
+
+import org.apache.chemistry.opencmis.commons.data.Properties;
+import org.apache.chemistry.opencmis.jcr.JcrFolder;
+
+import javax.jcr.Node;
+
+/**
+ * Implemented by type handlers that provides a type that is or inherits from cmis:folder.
+ */
+public interface JcrFolderTypeHandler extends JcrTypeHandler {
+
+    JcrFolder getJcrNode(Node node);
+
+    /**
+     * See CMIS 1.0 section 2.2.4.3 createFolder
+     *
+     * @throws org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException
+     *
+     */
+    JcrFolder createFolder(JcrFolder parentFolder, String name, Properties properties);
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandler.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandler.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandler.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.type;
+
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.jcr.JcrNode;
+import org.apache.chemistry.opencmis.jcr.JcrTypeManager;
+import org.apache.chemistry.opencmis.jcr.PathManager;
+import org.apache.chemistry.opencmis.jcr.query.IdentifierMap;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * Provides operations for a specific CMIS object type.
+ *
+ * @see JcrTypeHandlerManager
+ */
+public interface JcrTypeHandler {
+
+    /**
+     * Called by {@link JcrTypeHandlerManager} when the handler is added.
+     */
+    void initialize(PathManager pathManager, JcrTypeManager typeManager, JcrTypeHandlerManager typeHandlerManager);
+
+    String getTypeId();
+
+    TypeDefinition getTypeDefinition();
+
+    boolean canHandle(Node node) throws RepositoryException;
+
+    JcrNode getJcrNode(Node node) throws RepositoryException;
+
+    /**
+     * Used by QueryTranslator to translate CMIS queries to JCR queries.
+     *
+     * @see org.apache.chemistry.opencmis.jcr.query.QueryTranslator
+     * @see org.apache.chemistry.opencmis.jcr.JcrRepository#query(javax.jcr.Session, java.lang.String, java.lang.Boolean, java.lang.Boolean, java.math.BigInteger, java.math.BigInteger)
+     */
+    IdentifierMap getIdentifierMap();
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandlerManager.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandlerManager.java?rev=1182520&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandlerManager.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandlerManager.java Wed Oct 12 18:45:13 2011
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.jcr.type;
+
+import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.jcr.JcrNode;
+import org.apache.chemistry.opencmis.jcr.JcrTypeManager;
+import org.apache.chemistry.opencmis.jcr.PathManager;
+import org.apache.chemistry.opencmis.jcr.query.IdentifierMap;
+import org.apache.chemistry.opencmis.jcr.util.Predicate;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Manages a set of registered type handlers.
+ */
+public class JcrTypeHandlerManager {
+
+    private static final Log log = LogFactory.getLog(JcrTypeHandlerManager.class);
+
+    private final PathManager pathManager;
+    private final JcrTypeManager typeManager;
+    private final Map<String, JcrTypeHandler> typeHandlers = new HashMap<String, JcrTypeHandler>();
+
+    public JcrTypeHandlerManager(PathManager pathManager, JcrTypeManager typeManager) {
+        this.pathManager = pathManager;
+        this.typeManager = typeManager;
+    }
+
+    public void addHandler(JcrTypeHandler typeHandler) {
+        if (typeManager.addType(typeHandler.getTypeDefinition())) {
+            typeHandlers.put(typeHandler.getTypeId(), typeHandler);
+            typeHandler.initialize(pathManager, typeManager, this);
+        }
+    }
+
+    public JcrTypeHandler getTypeHandler(String typeId) {
+        JcrTypeHandler typeHandler = typeHandlers.get(typeId);
+        if (typeHandler == null) {
+            throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
+        }
+        return typeHandler;
+    }
+
+    public JcrFolderTypeHandler getFolderTypeHandler(String typeId) {
+        JcrTypeHandler typeHandler = getTypeHandler(typeId);
+        if (!(typeHandler instanceof JcrFolderTypeHandler)) {
+            throw new CmisObjectNotFoundException("Type '" + typeId + "' is not a folder!");
+        }
+        return (JcrFolderTypeHandler) typeHandler;
+    }
+
+    public JcrDocumentTypeHandler getDocumentTypeHandler(String typeId) {
+        JcrTypeHandler typeHandler = getTypeHandler(typeId);
+        if (!(typeHandler instanceof JcrDocumentTypeHandler)) {
+            throw new CmisObjectNotFoundException("Type '" + typeId + "' is not a document!");
+        }
+        return (JcrDocumentTypeHandler) typeHandler;
+    }
+
+    public Predicate<Node> getNodePredicate() {
+        return new Predicate<Node>() {
+            public boolean evaluate(Node node) {
+                try {
+                    for (JcrTypeHandler typeHandler : typeHandlers.values()) {
+                        if (typeHandler.canHandle(node)) {
+                            return true;
+                        }
+                    }
+                    return false;
+                }
+                catch (RepositoryException e) {
+                    log.debug(e.getMessage(), e);
+                    throw new CmisRuntimeException(e.getMessage(), e);
+                }
+            }
+        };
+    }
+
+    public IdentifierMap getIdentifierMap(String typeId) {
+        JcrTypeHandler typeHandler = getTypeHandler(typeId);
+        IdentifierMap identifierMap = typeHandler.getIdentifierMap();
+        if (identifierMap == null) {
+            throw new CmisRuntimeException("Not supported: query for type " + typeId);
+        }
+        return identifierMap;
+    }
+
+    public JcrNode create(Node node) {
+        try {
+            for (JcrTypeHandler typeHandler : typeHandlers.values()) {
+                if (typeHandler.canHandle(node)) {
+                    return typeHandler.getJcrNode(node);
+                }
+            }
+            throw new CmisObjectNotFoundException("No object type for object '" + node.getIdentifier() + "'");
+        }
+        catch (RepositoryException e) {
+            log.debug(e.getMessage(), e);
+            throw new CmisObjectNotFoundException(e.getMessage(), e);
+        }
+    }
+}

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Predicate.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Predicate.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Predicate.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/util/Predicate.java Wed Oct 12 18:45:13 2011
@@ -36,7 +36,7 @@ public interface Predicate<T> {
     /**
      * Constant predicate that returns <code>true</code> for all objects.
      */
-    Predicate TRUE = new Predicate<Object>() {
+    Predicate<?> TRUE = new Predicate<Object>() {
         public boolean evaluate(Object object) {
             return true;
         }
@@ -45,7 +45,7 @@ public interface Predicate<T> {
     /**
      * Constant predicate that returns <code>false</code> for all objects.
      */
-    Predicate FALSE = new Predicate<Object>() {
+    Predicate<?> FALSE = new Predicate<Object>() {
         public boolean evaluate(Object object) {
             return false;
         }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java?rev=1182520&r1=1182519&r2=1182520&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java Wed Oct 12 18:45:13 2011
@@ -22,9 +22,15 @@ package org.apache.chemistry.opencmis.jc
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
-import org.apache.chemistry.opencmis.jcr.DefaultJcrTypeManager;
+import org.apache.chemistry.opencmis.jcr.JcrTypeManager;
+import org.apache.chemistry.opencmis.jcr.PathManager;
+import org.apache.chemistry.opencmis.jcr.impl.DefaultDocumentTypeHandler;
+import org.apache.chemistry.opencmis.jcr.impl.DefaultFolderTypeHandler;
+import org.apache.chemistry.opencmis.jcr.impl.DefaultUnversionedDocumentTypeHandler;
+import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
 import org.apache.chemistry.opencmis.jcr.util.ISO8601;
 import org.apache.chemistry.opencmis.server.support.query.CalendarHelper;
+import org.junit.Before;
 import org.junit.Test;
 
 import java.util.GregorianCalendar;
@@ -34,32 +40,45 @@ import static org.junit.Assert.*;
 public class QueryTranslatorTest {
     private String jcrTypeCondition;
 
-    final QueryTranslator queryTranslator = new QueryTranslator(new DefaultJcrTypeManager()) {
-        @Override
-        protected String jcrPathFromId(String id) {
-            assertNotNull(id);
-            return "/jcr:" + id;
-        }
-
-        @Override
-        protected String jcrPathFromCol(TypeDefinition fromType, String name) {
-            assertNotNull(fromType);
-            assertNotNull(name);
-            return name.replace("cmis:", "@jcr:");
-        }
+    private QueryTranslator queryTranslator;
 
-        @Override
-        protected String jcrTypeName(TypeDefinition fromType) {
-            assertNotNull(fromType);
-            return fromType.getQueryName().replace("cmis:", "jcr:");
-        }
-
-        @Override
-        protected String jcrTypeCondition(TypeDefinition fromType) {
-            assertNotNull(fromType);
-            return jcrTypeCondition;
-        }
-    };
+    @Before
+    public void setUp() throws Exception {
+        JcrTypeManager typeManager = new JcrTypeManager();
+        PathManager pathManager = new PathManager(PathManager.CMIS_ROOT_PATH);
+        JcrTypeHandlerManager typeHandlerManager = new JcrTypeHandlerManager(pathManager, typeManager);
+        typeHandlerManager.addHandler(new DefaultFolderTypeHandler());
+        typeHandlerManager.addHandler(new DefaultDocumentTypeHandler());
+        typeHandlerManager.addHandler(new DefaultUnversionedDocumentTypeHandler());
+
+        queryTranslator = new QueryTranslator(typeManager) {
+
+            @Override
+            protected String jcrPathFromId(String id) {
+                assertNotNull(id);
+                return "/jcr:" + id;
+            }
+
+            @Override
+            protected String jcrPathFromCol(TypeDefinition fromType, String name) {
+                assertNotNull(fromType);
+                assertNotNull(name);
+                return name.replace("cmis:", "@jcr:");
+            }
+
+            @Override
+            protected String jcrTypeName(TypeDefinition fromType) {
+                assertNotNull(fromType);
+                return fromType.getQueryName().replace("cmis:", "jcr:");
+            }
+
+            @Override
+            protected String jcrTypeCondition(TypeDefinition fromType) {
+                assertNotNull(fromType);
+                return jcrTypeCondition;
+            }
+        };
+    }
 
     @Test
     public void testQueryTranslator() {



Mime
View raw message