jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r156972 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: ItemImpl.java NodeImpl.java WorkspaceImpl.java version/persistence/InternalVersionHistoryImpl.java version/persistence/NativePVM.java xml/SessionImporter.java xml/WorkspaceImporter.java
Date Thu, 10 Mar 2005 18:11:11 GMT
Author: stefan
Date: Thu Mar 10 10:10:51 2005
New Revision: 156972

URL: http://svn.apache.org/viewcvs?view=rev&rev=156972
Log:
- reset updateable item state mgr in case an update operation fails
- import on workspace (work in progress!)

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java?view=diff&r1=156971&r2=156972
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java Thu Mar 10
10:10:51 2005
@@ -1193,6 +1193,7 @@
                 Collection dirtyRefs =
                         checkReferences(dirty.iterator(), removed.iterator());
 
+                boolean succeeded = false;
                 try {
                     // start the update operation
                     stateMgr.edit();
@@ -1206,8 +1207,8 @@
                         // generated new transient state
                         dirty = getTransientStates();
 
-                        // and aswell the references
-                        dirtyRefs= checkReferences(dirty.iterator(), removed.iterator());
+                        // and the references as well
+                        dirtyRefs = checkReferences(dirty.iterator(), removed.iterator());
                     }
 
                     // process 'new' or 'modified' transient states
@@ -1234,13 +1235,17 @@
 
                     // end update operation
                     stateMgr.update();
-
+                    // update operation succeeded
+                    succeeded = true;
                 } catch (ItemStateException e) {
-
                     String msg = safeGetJCRPath() + ": unable to update item.";
                     log.debug(msg);
                     throw new RepositoryException(msg, e);
-
+                } finally {
+                    // update operation failed, cancel all modifications
+                    if (!succeeded) {
+                        stateMgr.cancel();
+                    }
                 }
 
                 // now it is safe to dispose the transient states:
@@ -1254,7 +1259,6 @@
                     // dispose the transient state, it is no longer used
                     stateMgr.disposeTransientItemStateInAttic(transientState);
                 }
-
             } finally {
                 // turn off temporary path caching
                 stateMgr.enablePathCaching(false);

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java?view=diff&r1=156971&r2=156972
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NodeImpl.java Thu Mar 10
10:10:51 2005
@@ -103,7 +103,7 @@
     protected static final short CREATED = 0;
 
     /**
-     * Package private constructor.
+     * Protected constructor.
      *
      * @param itemMgr    the <code>ItemManager</code> that created this <code>Node</code>
instance
      * @param session    the <code>Session</code> through which this <code>Node</code>
is acquired

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java?view=diff&r1=156971&r2=156972
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java Thu
Mar 10 10:10:51 2005
@@ -37,6 +37,8 @@
 import org.apache.jackrabbit.core.state.TransactionalItemStateManager;
 import org.apache.jackrabbit.core.util.uuid.UUID;
 import org.apache.jackrabbit.core.xml.ImportHandler;
+import org.apache.jackrabbit.core.xml.Importer;
+import org.apache.jackrabbit.core.xml.WorkspaceImporter;
 import org.apache.log4j.Logger;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
@@ -139,10 +141,23 @@
         this.session = session;
     }
 
-    RepositoryImpl getRepository() {
-        return rep;
+    /**
+     * The hierarchy manager that reflects workspace state only
+     * (i.e. that is isolated from transient changes made through
+     * the session)
+     *
+     * @return the hierarchy manager of this workspace
+     */
+    public HierarchyManager getHierarchyManager() {
+        return hierMgr;
     }
 
+    /**
+     * Returns the item state manager associated with the workspace
+     * represented by <i>this</i> <code>Workspace</code> instance.
+     *
+     * @return the item state manager of this workspace
+     */
     public TransactionalItemStateManager getItemStateManager() {
         return stateMgr;
     }
@@ -176,7 +191,7 @@
      * @throws RepositoryException if this workspace has been rendered invalid
      *                             for some reason
      */
-    protected void sanityCheck() throws RepositoryException {
+    public void sanityCheck() throws RepositoryException {
         // check session status
         session.sanityCheck();
     }
@@ -208,7 +223,7 @@
      * @throws ItemExistsException
      * @throws RepositoryException
      */
-    protected void checkAddNode(Path nodePath, QName nodeTypeName)
+    public void checkAddNode(Path nodePath, QName nodeTypeName)
             throws ConstraintViolationException, AccessDeniedException,
             PathNotFoundException, ItemExistsException, RepositoryException {
 
@@ -263,7 +278,8 @@
             try {
                 conflictingState = (NodeState) stateMgr.getItemState(conflictingId);
             } catch (ItemStateException ise) {
-                String msg = "internal error: failed to retrieve state of " + hierMgr.safeGetJCRPath(conflictingId);
+                String msg = "internal error: failed to retrieve state of "
+                        + hierMgr.safeGetJCRPath(conflictingId);
                 log.debug(msg);
                 throw new RepositoryException(msg, ise);
             }
@@ -283,7 +299,7 @@
      * @throws PathNotFoundException
      * @throws RepositoryException
      */
-    protected void checkRemoveNode(Path nodePath)
+    public void checkRemoveNode(Path nodePath)
             throws ConstraintViolationException, AccessDeniedException,
             PathNotFoundException, LockException, RepositoryException {
 
@@ -404,7 +420,7 @@
      * @return the effective node type
      * @throws RepositoryException
      */
-    protected EffectiveNodeType getEffectiveNodeType(NodeState state)
+    public EffectiveNodeType getEffectiveNodeType(NodeState state)
             throws RepositoryException {
         // build effective node type of mixins & primary type:
         // existing mixin's
@@ -436,9 +452,9 @@
      *                                      could be found
      * @throws RepositoryException          if another error occurs
      */
-    protected ChildNodeDef findApplicableDefinition(QName name,
-                                                    QName nodeTypeName,
-                                                    NodeState parentState)
+    public ChildNodeDef findApplicableDefinition(QName name,
+                                                 QName nodeTypeName,
+                                                 NodeState parentState)
             throws RepositoryException, ConstraintViolationException {
         EffectiveNodeType entParent = getEffectiveNodeType(parentState);
         return entParent.getApplicableChildNodeDef(name, nodeTypeName);
@@ -603,6 +619,7 @@
 
         // 3. do copy operation (modify and persist affected states)
 
+        boolean succeeded = false;
         try {
             stateMgr.edit();
 
@@ -619,16 +636,22 @@
                             srcState.getNodeTypeName(), destParentState);
             newState.setDefinitionId(new NodeDefId(newNodeDef));
 
-            // persist states
+            // store states
             stateMgr.store(newState);
             stateMgr.store(destParentState);
 
             // finish update operations
             stateMgr.update();
+            succeeded = true;
         } catch (ItemStateException ise) {
             String msg = "internal error: failed to persist state of " + destAbsPath;
             log.debug(msg);
             throw new RepositoryException(msg, ise);
+        } finally {
+            // update operation failed, cancel all modifications
+            if (!succeeded) {
+                stateMgr.cancel();
+            }
         }
     }
 
@@ -838,6 +861,8 @@
         checkAddNode(destPath, targetState.getNodeTypeName());
 
         // 3. do move operation (modify and persist affected states)
+
+        boolean succeeded = false;
         try {
             stateMgr.edit();
             boolean renameOnly = srcParentState.getUUID().equals(destParentState.getUUID());
@@ -860,7 +885,7 @@
             int srcNameIndex = srcName.getIndex() == 0 ? 1 : srcName.getIndex();
             srcParentState.removeChildNodeEntry(srcName.getName(), srcNameIndex);
 
-            // persist states
+            // store states
             stateMgr.store(targetState);
             if (renameOnly) {
                 stateMgr.store(srcParentState);
@@ -871,10 +896,16 @@
 
             // finish update
             stateMgr.update();
+            succeeded = true;
         } catch (ItemStateException ise) {
             String msg = "internal error: failed to persist state of " + destAbsPath;
             log.debug(msg);
             throw new RepositoryException(msg, ise);
+        } finally {
+            // update operation failed, cancel all modifications
+            if (!succeeded) {
+                stateMgr.cancel();
+            }
         }
     }
 
@@ -950,7 +981,6 @@
         sanityCheck();
 
         // @todo filter workspaces according to access rights
-
         return session.getWorkspaceNames();
     }
 
@@ -966,27 +996,28 @@
         sanityCheck();
 
         // check path & retrieve state
-        Path targetPath;
-        NodeState targetState;
+        Path parentPath;
+        NodeState parentState;
 
         try {
-            targetPath = Path.create(parentAbsPath, session.getNamespaceResolver(), true);
-            targetState = getNodeState(targetPath);
+            parentPath = Path.create(parentAbsPath, session.getNamespaceResolver(), true);
+            parentState = getNodeState(parentPath);
         } catch (MalformedPathException mpe) {
             String msg = "invalid path: " + parentAbsPath;
             log.debug(msg);
             throw new RepositoryException(msg, mpe);
         }
 
-        // make sure target node is checked-out
-        verifyCheckedOut(targetPath);
+        // make sure import target node is checked-out
+        verifyCheckedOut(parentPath);
 
-        // @todo check locked-status
-
-        // check node type constraints & access rights
-        checkAddNode(targetPath, targetState.getNodeTypeName());
-
-        // @todo implement Workspace#getImportContentHandler
+        // check locked-status
+        getLockManager().checkLock(parentPath, session);
+/*
+        Importer importer = new WorkspaceImporter(parentState, this, uuidBehavior);
+        return new ImportHandler(importer, session.getNamespaceResolver(),
+                rep.getNamespaceRegistry());
+*/
         throw new RepositoryException("not yet implemented");
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java?view=diff&r1=156971&r2=156972
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/InternalVersionHistoryImpl.java
Thu Mar 10 10:10:51 2005
@@ -248,28 +248,37 @@
                 throw new VersionException(msg);
             }
 
+            boolean succeeded = false;
             UpdatableItemStateManager stateMgr = getVersionManager().getItemStateMgr();
-            stateMgr.edit();
+            try {
+                stateMgr.edit();
 
-            // remove from persistance state
-            node.removeNode(v.getNode().getName());
+                // remove from persistance state
+                node.removeNode(v.getNode().getName());
 
-            // unregister from labels
-            QName[] labels = v.internalGetLabels();
-            for (int i = 0; i < labels.length; i++) {
-                v.internalRemoveLabel(labels[i]);
-                labelNode.removeNode(labels[i]);
+                // unregister from labels
+                QName[] labels = v.internalGetLabels();
+                for (int i = 0; i < labels.length; i++) {
+                    v.internalRemoveLabel(labels[i]);
+                    labelNode.removeNode(labels[i]);
+                }
+                // detach from the version graph
+                v.internalDetach();
+
+                // and remove from history
+                versionCache.remove(v.getId());
+
+                // store changes
+                node.store();
+
+                stateMgr.update();
+                succeeded = true;
+            } finally {
+                // update operation failed, cancel all modifications
+                if (!succeeded) {
+                    stateMgr.cancel();
+                }
             }
-            // detach from the version graph
-            v.internalDetach();
-
-            // and remove from history
-            versionCache.remove(v.getId());
-
-            // store changes
-            node.store();
-
-            stateMgr.update();
         } catch (ItemStateException e) {
             throw new VersionException("Unable to store modifications", e);
         } catch (RepositoryException e) {
@@ -301,8 +310,9 @@
         }
         labelCache.put(label, version);
         ((InternalVersionImpl) version).internalAddLabel(label);
+        UpdatableItemStateManager stateMgr = getVersionManager().getItemStateMgr();
+        boolean succeeded = false;
         try {
-            UpdatableItemStateManager stateMgr = getVersionManager().getItemStateMgr();
             stateMgr.edit();
             PersistentNode lNode = labelNode.addNode(label, NT_UNSTRUCTURED);
             lNode.setPropertyValue(NativePVM.PROPNAME_NAME, InternalValue.create(label));
@@ -310,10 +320,16 @@
             labelNode.store();
 
             stateMgr.update();
+            succeeded = true;
         } catch (ItemStateException e) {
             throw new VersionException("Error while storing modifications", e);
         } catch (RepositoryException e) {
             throw new VersionException("Error while storing modifications", e);
+        } finally {
+            // update operation failed, cancel all modifications
+            if (!succeeded) {
+                stateMgr.cancel();
+            }
         }
         return prev;
     }
@@ -329,16 +345,23 @@
             throw new VersionException("Version label " + label + " is not in version history.");
         }
         v.internalRemoveLabel(label);
+        UpdatableItemStateManager stateMgr = getVersionManager().getItemStateMgr();
+        boolean succeeded = false;
         try {
-            UpdatableItemStateManager stateMgr = getVersionManager().getItemStateMgr();
             stateMgr.edit();
             labelNode.removeNode(label);
             labelNode.store();
             stateMgr.update();
+            succeeded = true;
         } catch (ItemStateException e) {
             throw new VersionException("Unable to store modifications", e);
         } catch (RepositoryException e) {
             throw new VersionException("Unable to store modifications", e);
+        } finally {
+            // update operation failed, cancel all modifications
+            if (!succeeded) {
+                stateMgr.cancel();
+            }
         }
 
         return v;

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java?view=diff&r1=156971&r2=156972
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/persistence/NativePVM.java
Thu Mar 10 10:10:51 2005
@@ -314,6 +314,7 @@
             return hist;
         }
 
+        boolean succeeded = false;
         try {
             stateMgr.edit();
 
@@ -335,10 +336,16 @@
 
             // end update
             stateMgr.update();
+            succeeded = true;
 
             initVirtualIds(hist.getId(), hist.getNode().getState());
         } catch (ItemStateException e) {
             throw new RepositoryException(e);
+        } finally {
+            // update operation failed, cancel all modifications
+            if (!succeeded) {
+                stateMgr.cancel();
+            }
         }
 
         log.info("Created new version history " + hist.getId() + " for " + node.safeGetJCRPath()
+ ". NumHistories=" + versionedUUIDs.size());
@@ -547,16 +554,23 @@
             } while (history.hasVersion(new QName("", versionName)));
         }
 
+        boolean succeeded = false;
         try {
             stateMgr.edit();
             InternalVersionImpl v = history.checkin(new QName("", versionName), node);
             stateMgr.update();
+            succeeded = true;
 
             initVirtualIds(v.getId(), v.getNode().getState());
 
             return v;
         } catch (ItemStateException e) {
             throw new RepositoryException(e);
+        } finally {
+            // update operation failed, cancel all modifications
+            if (!succeeded) {
+                stateMgr.cancel();
+            }
         }
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java?view=diff&r1=156971&r2=156972
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
Thu Mar 10 10:10:51 2005
@@ -227,7 +227,7 @@
     /**
      * {@inheritDoc}
      */
-    public void endNode(NodeInfo node) throws RepositoryException {
+    public void endNode(NodeInfo nodeInfo) throws RepositoryException {
         parents.pop();
     }
 

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java?view=auto&rev=156972
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
Thu Mar 10 10:10:51 2005
@@ -0,0 +1,402 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+  *
+ * Licensed 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.core.xml;
+
+import org.apache.jackrabbit.core.HierarchyManager;
+import org.apache.jackrabbit.core.NamespaceResolver;
+import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.WorkspaceImpl;
+import org.apache.jackrabbit.core.nodetype.ChildNodeDef;
+import org.apache.jackrabbit.core.nodetype.NodeDefId;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.UpdatableItemStateManager;
+import org.apache.log4j.Logger;
+
+import javax.jcr.RepositoryException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Stack;
+
+/**
+ * <code>WorkspaceImporter</code> ...
+ */
+public class WorkspaceImporter implements Importer {
+
+    private static Logger log = Logger.getLogger(WorkspaceImporter.class);
+
+    private final WorkspaceImpl wsp;
+    private final HierarchyManager hierMgr;
+    private final UpdatableItemStateManager stateMgr;
+
+    private final int uuidBehavior;
+
+    private boolean aborted;
+    private Stack parents;
+
+    /**
+     * mapping <original uuid> to <new uuid> of mix:referenceable nodes
+     */
+    private final HashMap uuidMap;
+    /**
+     * list of imported reference properties that might need correcting
+     */
+    private final ArrayList references;
+
+    public WorkspaceImporter(NodeState importTargetState,
+                             WorkspaceImpl wsp,
+                             int uuidBehavior) {
+        this.wsp = wsp;
+
+        hierMgr = wsp.getHierarchyManager();
+        stateMgr = wsp.getItemStateManager();
+
+        this.uuidBehavior = uuidBehavior;
+
+        aborted = false;
+
+        uuidMap = new HashMap();
+        references = new ArrayList();
+
+        parents = new Stack();
+        parents.push(importTargetState);
+    }
+
+    protected NodeState createNode(NodeState parent,
+                                   QName nodeName,
+                                   QName nodeTypeName,
+                                   QName[] mixinNames,
+                                   String uuid)
+            throws RepositoryException {
+        NodeState node = stateMgr.createNew(uuid, nodeTypeName, parent.getUUID());
+        node.setMixinTypeNames(new HashSet(Arrays.asList(mixinNames)));
+        ChildNodeDef nodeDef =
+                wsp.findApplicableDefinition(nodeName, nodeTypeName, parent);
+        node.setDefinitionId(new NodeDefId(nodeDef));
+
+        // now add new child node entry to parent
+        parent.addChildNodeEntry(nodeName, node.getUUID());
+
+        return node;
+    }
+
+    protected NodeState resolveUUIDConflict(NodeState parent,
+                                            NodeState conflicting,
+                                            NodeInfo nodeInfo)
+            throws RepositoryException {
+        NodeState node = null;
+/*
+        if (uuidBehavior == IMPORT_UUID_CREATE_NEW) {
+            // create new with new uuid
+            node = createNode(parent, nodeInfo.getName(),
+                    nodeInfo.getNodeTypeName(), nodeInfo.getMixinNames(), null);
+            // remember uuid mapping
+            if (node.isNodeType(Constants.MIX_REFERENCEABLE)) {
+                uuidMap.put(nodeInfo.getUUID(), node.getUUID());
+            }
+        } else if (uuidBehavior == IMPORT_UUID_COLLISION_THROW) {
+            String msg = "a node with uuid " + nodeInfo.getUUID() + " already exists!";
+            log.debug(msg);
+            throw new ItemExistsException(msg);
+        } else if (uuidBehavior == IMPORT_UUID_COLLISION_REMOVE_EXISTING) {
+            // make sure conflicting node is not importTargetNode or an ancestor thereof
+            if (importTargetNode.getPath().startsWith(conflicting.getPath())) {
+                String msg = "cannot remove ancestor node";
+                log.debug(msg);
+                throw new RepositoryException(msg);
+            }
+            // remove conflicting
+            conflicting.remove();
+            // create new with given uuid
+            node = createNode(parent, nodeInfo.getName(),
+                    nodeInfo.getNodeTypeName(), nodeInfo.getMixinNames(),
+                    nodeInfo.getUUID());
+        } else if (uuidBehavior == IMPORT_UUID_COLLISION_REPLACE_EXISTING) {
+            if (conflicting.getDepth() == 0) {
+                String msg = "root node cannot be replaced";
+                log.debug(msg);
+                throw new RepositoryException(msg);
+            }
+            // @todo implement IMPORT_UUID_COLLISION_REPLACE_EXISTING behavior
+            throw new RepositoryException("uuidBehavior IMPORT_UUID_COLLISION_REPLACE_EXISTING
is not yet implemented");
+        } else {
+            String msg = "unknown uuidBehavior: " + uuidBehavior;
+            log.debug(msg);
+            throw new RepositoryException(msg);
+        }
+*/
+        return node;
+    }
+
+    //-------------------------------------------------------------< Importer >
+    /**
+     * {@inheritDoc}
+     */
+    public void start() throws RepositoryException {
+        try {
+            // start update operation
+            stateMgr.edit();
+        } catch (ItemStateException ise) {
+            aborted = true;
+            String msg = "internal error: failed to start update operation";
+            log.debug(msg);
+            throw new RepositoryException(msg, ise);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void startNode(NodeInfo nodeInfo, List propInfos,
+                          NamespaceResolver nsContext)
+            throws RepositoryException {
+        if (aborted) {
+            // the import has been aborted, get outta here...
+            return;
+        }
+
+        boolean succeeded = false;
+        try {
+            // check sanity of workspace/session first
+            wsp.sanityCheck();
+
+            NodeState parent = (NodeState) parents.peek();
+
+            // process node
+
+            NodeState node;
+            String uuid = nodeInfo.getUUID();
+            QName nodeName = nodeInfo.getName();
+            QName ntName = nodeInfo.getNodeTypeName();
+            QName[] mixins = nodeInfo.getMixinNames();
+/*
+            if (uuid == null) {
+                // no potential uuid conflict, always add new node
+                node = createNode(parent, nodeName, ntName, mixins, null);
+            } else {
+                // potential uuid conflict
+                NodeState conflicting;
+                try {
+                    conflicting = (NodeImpl) session.getNodeByUUID(uuid);
+                } catch (ItemNotFoundException infe) {
+                    conflicting = null;
+                }
+                if (conflicting != null) {
+                    // resolve uuid conflict
+                    node = resolveUUIDConflict(parent, conflicting, nodeInfo);
+                } else {
+                    // create new with given uuid
+                    node = createNode(parent, nodeName, ntName, mixins, uuid);
+                }
+            }
+*/
+/*
+            // store state
+            stateMgr.store(state);
+            succeeded = true;
+        } catch (ItemStateException ise) {
+            String msg = "internal error: failed to persist state of " + parentAbsPath;
+            log.debug(msg);
+            throw new RepositoryException(msg, ise);
+*/
+        } finally {
+            // update operation failed, cancel all modifications
+            if (!succeeded) {
+                aborted = true;
+                stateMgr.cancel();
+            }
+        }
+
+/*
+
+        // process node
+
+        NodeImpl node;
+        String uuid = nodeInfo.getUUID();
+        QName nodeName = nodeInfo.getName();
+        QName ntName = nodeInfo.getNodeTypeName();
+        QName[] mixins = nodeInfo.getMixinNames();
+        if (uuid == null) {
+            // no potential uuid conflict, always add new node
+            node = createNode(parent, nodeName, ntName, mixins, null);
+        } else {
+            // potential uuid conflict
+            NodeImpl conflicting;
+            try {
+                conflicting = (NodeImpl) session.getNodeByUUID(uuid);
+            } catch (ItemNotFoundException infe) {
+                conflicting = null;
+            }
+            if (conflicting != null) {
+                // resolve uuid conflict
+                node = resolveUUIDConflict(parent, conflicting, nodeInfo);
+            } else {
+                // create new with given uuid
+                node = createNode(parent, nodeName, ntName, mixins, uuid);
+            }
+        }
+
+        // process properties
+
+        Iterator iter = propInfos.iterator();
+        while (iter.hasNext()) {
+            PropInfo pi = (PropInfo) iter.next();
+            QName propName = pi.getName();
+            Value[] vals = pi.getValues();
+            int type = pi.getType();
+            if (node.hasProperty(propName)) {
+                PropertyDef def = node.getProperty(propName).getDefinition();
+                if (def.isProtected()) {
+                    // skip protected property
+                    log.debug("skipping protected property " + propName);
+                    continue;
+                }
+            }
+            // multi- or single-valued property?
+            if (vals.length == 1) {
+                // could be single- or multi-valued (n == 1)
+                try {
+                    // try setting single-value
+                    node.setProperty(propName, vals[0]);
+                } catch (ValueFormatException vfe) {
+                    // try setting value array
+                    node.setProperty(propName, vals, type);
+                } catch (ConstraintViolationException vfe) {
+                    // try setting value array
+                    node.setProperty(propName, vals, type);
+                }
+            } else {
+                // can only be multi-valued (n == 0 || n > 1)
+                node.setProperty(propName, vals, type);
+            }
+            if (type == PropertyType.REFERENCE) {
+                // store reference for later resolution
+                references.add(node.getProperty(propName));
+            }
+        }
+
+        parents.push(node);
+*/
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void endNode(NodeInfo nodeInfo) throws RepositoryException {
+        if (aborted) {
+            // the import has been aborted, get outta here...
+            return;
+        }
+        NodeState node = (NodeState) parents.pop();
+        boolean succeeded = false;
+        try {
+            // check sanity of workspace/session first
+            wsp.sanityCheck();
+
+            // we're done with that node, now store its state
+            stateMgr.store(node);
+            succeeded = true;
+        } finally {
+            // update operation failed, cancel all modifications
+            if (!succeeded) {
+                aborted = true;
+                stateMgr.cancel();
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void end() throws RepositoryException {
+        if (aborted) {
+            // the import has been aborted, get outta here...
+            return;
+        }
+
+        boolean succeeded = false;
+        try {
+            // check sanity of workspace/session first
+            wsp.sanityCheck();
+
+            /**
+             * adjust references that refer to uuid's which have been mapped to
+             * newly gererated uuid's on import
+             */
+/*
+            Iterator iter = references.iterator();
+            while (iter.hasNext()) {
+                PropertyState prop = (PropertyState) iter.next();
+                // being paranoid...
+                if (prop.getType() != PropertyType.REFERENCE) {
+                    continue;
+                }
+                if (prop.getDefinition().isMultiple()) {
+                    Value[] values = prop.getValues();
+                    Value[] newVals = new Value[values.length];
+                    for (int i = 0; i < values.length; i++) {
+                        Value val = values[i];
+                        String original = val.getString();
+                        String adjusted = (String) uuidMap.get(original);
+                        if (adjusted != null) {
+                            newVals[i] = new ReferenceValue(wsp.getSession().getNodeByUUID(adjusted));
+                        } else {
+                            // reference doesn't need adjusting, just copy old value
+                            newVals[i] = val;
+                        }
+                    }
+                    prop.setValue(newVals);
+                } else {
+                    Value val = prop.getValue();
+                    String original = val.getString();
+                    String adjusted = (String) uuidMap.get(original);
+                    if (adjusted != null) {
+                        prop.setValue(session.getNodeByUUID(adjusted));
+                    }
+                }
+            }
+*/
+
+            // finally pop the last item from the stack, the import target node
+            NodeState importTarget = (NodeState) parents.pop();
+            // we're done with it, store its state
+            stateMgr.store(importTarget);
+            succeeded = true;
+        } finally {
+            // update operation failed, cancel all modifications
+            if (!succeeded) {
+                aborted = true;
+                stateMgr.cancel();
+            }
+        }
+
+        if (!aborted) {
+            try {
+                // finish update
+                stateMgr.update();
+            } catch (ItemStateException ise) {
+                aborted = true;
+                String msg = "internal error: failed to finish update operation";
+                log.debug(msg);
+                throw new RepositoryException(msg, ise);
+            }
+        }
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message