You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2006/08/09 12:50:10 UTC

svn commit: r430031 [2/2] - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ nodetype/ state/ version/ xml/

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?rev=430031&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java (added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java Wed Aug  9 03:50:09 2006
@@ -0,0 +1,228 @@
+/*
+ * 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.jackrabbit.jcr2spi.state;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.NodeInfo;
+import org.apache.jackrabbit.spi.IdIterator;
+import org.apache.jackrabbit.spi.PropertyInfo;
+import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.spi.RepositoryService;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.value.QValue;
+
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * <code>WorkspaceItemStateFactory</code>...
+ */
+public class WorkspaceItemStateFactory implements ItemStateFactory {
+
+    private static Logger log = LoggerFactory.getLogger(WorkspaceItemStateFactory.class);
+
+    private final RepositoryService service;
+    private final SessionInfo sessionInfo;
+
+    public WorkspaceItemStateFactory(RepositoryService service, SessionInfo sessionInfo) {
+        this.service = service;
+        this.sessionInfo = sessionInfo;
+    }
+
+    /**
+     * Creates the node with information retrieved from the
+     * <code>RepositoryService</code>.
+     *
+     * @inheritDoc
+     * @see ItemStateFactory#createNodeState(NodeId, ItemStateManager)
+     */
+    public NodeState createNodeState(NodeId nodeId, ItemStateManager ism)
+            throws NoSuchItemStateException, ItemStateException {
+        try {
+            NodeInfo info = service.getNodeInfo(sessionInfo, nodeId);
+
+            // get parent
+            NodeId parentId = (info.getParentId() != null) ? info.getParentId() : null;
+            NodeState parent = (parentId != null) ? (NodeState) ism.getItemState(parentId) : null;
+
+            return createNodeState(info, parent);
+        } catch (PathNotFoundException e) {
+            throw new NoSuchItemStateException(e.getMessage(), e);
+        } catch (RepositoryException e) {
+            throw new ItemStateException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Creates the node with information retrieved from the
+     * <code>RepositoryService</code>.
+     *
+     * @inheritDoc
+     * @see ItemStateFactory#createNodeState(NodeId, NodeState)
+     */
+    public NodeState createNodeState(NodeId nodeId, NodeState parent)
+            throws NoSuchItemStateException, ItemStateException {
+        try {
+            NodeInfo info = service.getNodeInfo(sessionInfo, nodeId);
+            return createNodeState(info, parent);
+        } catch (PathNotFoundException e) {
+            throw new NoSuchItemStateException(e.getMessage(), e);
+        } catch (RepositoryException e) {
+            throw new ItemStateException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Creates the node with information retrieved from <code>info</code>.
+     *
+     * @param info   the <code>NodeInfo</code> to use to create the
+     *               <code>NodeState</code>.
+     * @param parent the parent <code>NodeState</code>.
+     * @return the new <code>NodeState</code>.
+     */
+    private NodeState createNodeState(NodeInfo info, NodeState parent)
+            throws NoSuchItemStateException, ItemStateException {
+        try {
+            QName ntName = info.getNodetype();
+
+            // build the node state
+            // NOTE: unable to retrieve definitionId -> needs to be retrieved
+            // by the itemManager upon Node creation.
+            NodeState state = new NodeState(info.getId(), parent, ntName, ItemState.STATUS_EXISTING, false, this);
+            // set mixin nodetypes
+            state.setMixinTypeNames(info.getMixins());
+
+            // references to child items
+            for (IdIterator it = info.getNodeIds(); it.hasNext(); ) {
+                NodeInfo childInfo = service.getNodeInfo(sessionInfo, (NodeId) it.nextId());
+                NodeId childId = childInfo.getId();
+                state.addChildNodeEntry(childInfo.getQName(), childId);
+            }
+
+            // references to properties
+            for (IdIterator it = info.getPropertyIds(); it.hasNext(); ) {
+                PropertyId pId = (PropertyId) it.nextId();
+                state.addPropertyName(pId.getQName());
+            }
+
+            // copied from local-state-mgr TODO... check
+            // register as listener
+            // TODO check if needed
+            //state.addListener(this);
+            return state;
+        } catch (PathNotFoundException e) {
+            throw new NoSuchItemStateException(e.getMessage(), e);
+        } catch (RepositoryException e) {
+            throw new ItemStateException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Creates the property with information retrieved from the
+     * <code>RepositoryService</code>.
+     *
+     * @inheritDoc
+     * @see ItemStateFactory#createPropertyState(PropertyId, ItemStateManager)
+     */
+    public PropertyState createPropertyState(PropertyId propertyId,
+                                             ItemStateManager ism)
+            throws NoSuchItemStateException, ItemStateException {
+        try {
+            PropertyInfo info = service.getPropertyInfo(sessionInfo, propertyId);
+            NodeState parent = (NodeState) ism.getItemState(info.getParentId());
+            return createPropertyState(info, parent);
+        } catch (PathNotFoundException e) {
+            throw new NoSuchItemStateException(e.getMessage(), e);
+        } catch (RepositoryException e) {
+            throw new ItemStateException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Creates the property with information retrieved from the
+     * <code>RepositoryService</code>.
+     *
+     * @inheritDoc
+     * @see ItemStateFactory#createPropertyState(PropertyId, NodeState)
+     */
+    public PropertyState createPropertyState(PropertyId propertyId,
+                                             NodeState parent)
+            throws NoSuchItemStateException, ItemStateException {
+        try {
+            PropertyInfo info = service.getPropertyInfo(sessionInfo, propertyId);
+            return createPropertyState(info, parent);
+        } catch (PathNotFoundException e) {
+            throw new NoSuchItemStateException(e.getMessage(), e);
+        } catch (RepositoryException e) {
+            throw new ItemStateException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Creates the property with information retrieved from <code>info</code>.
+     *
+     * @param info   the <code>PropertyInfo</code> to use to create the
+     *               <code>PropertyState</code>.
+     * @param parent the parent <code>NodeState</code>.
+     * @return the new <code>PropertyState</code>.
+     * @throws ItemStateException if an error occurs while retrieving the
+     *                            <code>PropertyState</code>.
+     */
+    private PropertyState createPropertyState(PropertyInfo info,
+                                              NodeState parent)
+            throws ItemStateException {
+        try {
+            // TODO: pass parent in constructor of PropertyState
+
+            // build the PropertyState
+            // NOTE: unable to retrieve definitionId -> needs to be retrieved
+            // by the itemManager upon Property creation.
+            PropertyState state = new PropertyState(info.getId(), parent, ItemState.STATUS_EXISTING, false);
+            state.setMultiValued(info.isMultiValued());
+            state.setType(info.getType());
+            QValue[] qValues;
+            if (info.getType() == PropertyType.BINARY) {
+                InputStream[] ins = info.getValuesAsStream();
+                qValues = new QValue[ins.length];
+                for (int i = 0; i < ins.length; i++) {
+                    qValues[i] = QValue.create(ins[i]);
+                }
+            } else {
+                String[] str = info.getValues();
+                qValues = new QValue[str.length];
+                for (int i = 0; i < str.length; i++) {
+                    qValues[i] = QValue.create(str[i], info.getType());
+                }
+            }
+
+            state.internalSetValues(qValues);
+
+            // register as listener
+            // TODO check if needed
+            // state.addListener(this);
+            return state;
+        } catch (IOException e) {
+            throw new ItemStateException(e.getMessage(), e);
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java?rev=430031&r1=430030&r2=430031&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java Wed Aug  9 03:50:09 2006
@@ -55,6 +55,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Collection;
 
 /**
  * <code>VersionHistoryImpl</code>...
@@ -104,8 +105,14 @@
      */
     public Version getRootVersion() throws RepositoryException {
         try {
-            NodeState vState = vhState.getChildNodeEntry(QName.JCR_ROOTVERSION, Path.INDEX_DEFAULT).getNodeState();
-            return (Version) itemMgr.getItem(vState);
+            if (vhState.hasChildNodeEntry(QName.JCR_ROOTVERSION)) {
+                NodeState vState = vhState.getChildNodeEntry(QName.JCR_ROOTVERSION, Path.INDEX_DEFAULT).getNodeState();
+                return (Version) itemMgr.getItem(vState);
+            } else {
+                String msg = "Unexpected error: VersionHistory state does not contain a root version child node entry.";
+                log.error(msg);
+                throw new RepositoryException(msg);
+            }
         } catch (ItemStateException e) {
             throw new RepositoryException(e);
         }
@@ -323,7 +330,7 @@
      * @return
      */
     private QName[] getQLabels() {
-        Set labelQNames = labelNodeState.getPropertyNames();
+        Collection labelQNames = labelNodeState.getPropertyNames();
         return (QName[]) labelQNames.toArray(new QName[labelQNames.size()]);
     }
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImporterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImporterImpl.java?rev=430031&r1=430030&r2=430031&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImporterImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImporterImpl.java Wed Aug  9 03:50:09 2006
@@ -188,7 +188,7 @@
            NodeState nodeState = null;
            if (parent.hasChildNodeEntry(nodeInfo.getName())) {
                // a node with that name already exists...
-               ChildNodeEntry entry = parent.getChildNodeEntry(nodeInfo.getName(), 1);
+               ChildNodeEntry entry = parent.getChildNodeEntry(nodeInfo.getName(), Path.INDEX_DEFAULT);
                NodeState existing = null;
                try {
                    existing = entry.getNodeState();
@@ -196,7 +196,7 @@
                    // should not occur. existance has been checked before
                    throw new RepositoryException(e);
                }
-               QNodeDefinition def = existing.getDefinition();
+               QNodeDefinition def = existing.getDefinition(session.getNodeTypeRegistry());
                if (!def.allowsSameNameSiblings()) {
                    // existing doesn't allow same-name siblings, check for conflicts
                    EffectiveNodeType entExisting = validator.getEffectiveNodeType(existing);
@@ -514,7 +514,7 @@
             // a property with that name already exists...
             try {
                 PropertyState existing = nodeState.getPropertyState(propName);
-                def = existing.getDefinition();
+                def = existing.getDefinition(session.getNodeTypeRegistry());
                 if (def.isProtected()) {
                     // skip protected property
                     log.debug("skipping protected property " + LogUtil.safeGetJCRPath(existing, session.getNamespaceResolver(), hierMgr));