jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r432630 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ operation/ state/ version/ xml/
Date Fri, 18 Aug 2006 16:29:30 GMT
Author: angela
Date: Fri Aug 18 09:29:27 2006
New Revision: 432630

URL: http://svn.apache.org/viewvc?rev=432630&view=rev
Log:
work in progress

- LazyItemIterator: fixing wrong usage in ItemManagerImpl
- LazyItemIterator: removing TODOs and workaround

- ItemStateFactory: remove unused method 
  'createPropertyState(PropertyId propertyId, ItemStateManager ism)'

- TransientItemStateFactory: slightly modify methods, adding additional
  parameters that are already known upon creation of the states and must
  not be changed later on (-> removing setters on NodeState/PropertyState)

- TransientItemStateManager:
  > rename create-methods to createNew...
  > adjust parameters according to modifications in TransientISF

- NodeState:
  > set QNodeDefinition upon creation
  > modify 'moveChildNodeEntry': additing 'newDefinition' parameter
  > remove 'setParent'
  > remove 'setDefinition'
  > remove 'getDefinition(NodeTypeRegistry). since definition is set upon
    creation, there is no need for this fallback method.

- PropertyState:
  > set QPropertyDefinition upon creation
  > 'multiValued' field is therefore redundant -> remove
  > remove 'setMultiValued'
  > remove 'setDefinition'
  > remove 'getDefinition(NodeTypeRegistry). since definition is set upon
    creation, there is no need for this fallback method.

- SetPropertyValue: 'isMultiValued()' is redundant. removed and replaced
  usage with 'getPropertyState().isMultiValued()'

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManagerImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/LazyItemIterator.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateFactory.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManagerImpl.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManagerImpl.java Fri Aug 18 09:29:27 2006
@@ -46,6 +46,9 @@
 import java.io.PrintStream;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * There's one <code>ItemManagerImpl</code> instance per <code>Session</code>
@@ -215,7 +218,17 @@
         session.checkIsAlive();
         checkAccess(parentState, true);
 
-        return new LazyItemIterator(this, parentState.getChildNodeEntries());
+        Collection nodeEntries = parentState.getChildNodeEntries();
+        List childStates = new ArrayList(nodeEntries.size());
+        for (Iterator it = nodeEntries.iterator(); it.hasNext();) {
+            try {
+                childStates.add(((ChildNodeEntry) it.next()).getNodeState());
+            } catch (ItemStateException e) {
+                // should not occur
+                throw new RepositoryException(e);
+            }
+        }
+        return new LazyItemIterator(this, childStates);
     }
 
     /**
@@ -252,7 +265,17 @@
         session.checkIsAlive();
         checkAccess(parentState, true);
 
-        return new LazyItemIterator(this, parentState.getPropertyEntries());
+        Collection propEntries = parentState.getPropertyEntries();
+        List childStates = new ArrayList(propEntries.size());
+        for (Iterator it = propEntries.iterator(); it.hasNext();) {
+            try {
+                childStates.add(((ChildPropertyEntry)it.next()).getPropertyState());
+            } catch (ItemStateException e) {
+                // should not occur
+                throw new RepositoryException(e);
+            }
+        }
+        return new LazyItemIterator(this, childStates);
     }
 
     //----------------------------------------------< ItemLifeCycleListener >---
@@ -361,7 +384,7 @@
      */
     private NodeImpl createNodeInstance(NodeState state) throws RepositoryException {
         // 1. get definition of the specified node
-        QNodeDefinition qnd = state.getDefinition(session.getNodeTypeRegistry());
+        QNodeDefinition qnd = state.getDefinition();
         NodeDefinition def = session.getNodeTypeManager().getNodeDefinition(qnd);
 
         // 2. create instance
@@ -391,7 +414,7 @@
     private PropertyImpl createPropertyInstance(PropertyState state)
             throws RepositoryException {
         // 1. get definition for the specified property
-        QPropertyDefinition qpd = state.getDefinition(session.getNodeTypeRegistry());
+        QPropertyDefinition qpd = state.getDefinition();
         PropertyDefinition def = session.getNodeTypeManager().getPropertyDefinition(qpd);
 
         // 2. create instance

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/LazyItemIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/LazyItemIterator.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/LazyItemIterator.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/LazyItemIterator.java Fri Aug 18 09:29:27 2006
@@ -17,8 +17,6 @@
 package org.apache.jackrabbit.jcr2spi;
 
 import org.apache.jackrabbit.jcr2spi.state.ItemState;
-import org.apache.jackrabbit.jcr2spi.state.ChildItemReference;
-import org.apache.jackrabbit.jcr2spi.state.ItemStateException;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -33,8 +31,8 @@
 import javax.jcr.version.Version;
 import java.util.List;
 import java.util.NoSuchElementException;
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.ArrayList;
 
 /**
  * <code>LazyItemIterator</code> is an id-based iterator that instantiates
@@ -89,29 +87,16 @@
         // reset
         next = null;
         while (next == null && pos < stateList.size()) {
-            // TODO: make sure only ItemStates or ChildItemReferences are used, not both!
-            // TODO: check constructors of LazyItemIterator
-            Object refOrState = stateList.get(pos);
+            ItemState state = (ItemState) stateList.get(pos);
             try {
-                ItemState state;
-                if (refOrState instanceof ChildItemReference) {
-                    state = ((ChildItemReference) refOrState).resolve();
-                } else {
-                    state = (ItemState) refOrState;
-                }
                 next = itemMgr.getItem(state);
             } catch (ItemNotFoundException e) {
-                log.debug("ignoring nonexistent item " + refOrState);
+                log.debug("ignoring nonexistent item " + state);
                 // remove invalid id
                 stateList.remove(pos);
                 // try next
             } catch (RepositoryException e) {
-                log.error("failed to fetch item " + refOrState + ", skipping...", e);
-                // remove invalid id
-                stateList.remove(pos);
-                // try next
-            } catch (ItemStateException e) {
-                log.debug("ignoring nonexistent item " + refOrState);
+                log.error("failed to fetch item " + state + ", skipping...", e);
                 // remove invalid id
                 stateList.remove(pos);
                 // try next

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java Fri Aug 18 09:29:27 2006
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.jcr2spi;
 
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.jcr2spi.security.SecurityConstants;
 import org.apache.jackrabbit.jcr2spi.security.AccessManager;
 import org.apache.jackrabbit.jcr2spi.state.SessionItemStateManager;
@@ -766,11 +765,6 @@
 
     NodeTypeManagerImpl getNodeTypeManager() {
         return ntManager;
-    }
-
-    // TODO public for SessionImport only. review
-    public NodeTypeRegistry getNodeTypeRegistry() {
-        return workspace.getNodeTypeRegistry();
     }
 
     //--------------------------------------------------------------------------

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java Fri Aug 18 09:29:27 2006
@@ -107,7 +107,7 @@
         this.name = name;
         this.session = session;
 
-        wspManager = this.createManager(service, sessionInfo);
+        wspManager = createManager(service, sessionInfo);
     }
 
     //----------------------------------------------------------< Workspace >---

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java Fri Aug 18 09:29:27 2006
@@ -137,7 +137,7 @@
         this.service = service;
         this.sessionInfo = sessionInfo;
 
-        ItemStateFactory isf = createItemStateFactory();
+        ItemStateFactory isf = new WorkspaceItemStateFactory(service, sessionInfo, this);
         cache = new WorkspaceItemStateManager(isf, service.getIdFactory());
         addEventListener(cache);
 
@@ -240,10 +240,6 @@
     }
 
     //--------------------------------------------------------------------------
-    private ItemStateFactory createItemStateFactory() {
-        return new WorkspaceItemStateFactory(service, sessionInfo);
-    }
-
     private NamespaceRegistryImpl createNamespaceRegistry() throws RepositoryException {
         return new NamespaceRegistryImpl(this, service.getRegisteredNamespaces(sessionInfo));
     }
@@ -626,9 +622,10 @@
         }
 
         public void visit(SetPropertyValue operation) throws RepositoryException {
-            PropertyId id = operation.getPropertyState().getPropertyId();
+            PropertyState pState = operation.getPropertyState();
+            PropertyId id = pState.getPropertyId();
             int type = operation.getPropertyType();
-            if (operation.isMultiValued()) {
+            if (pState.isMultiValued()) {
                 QValue[] values = operation.getValues();
                 if (type == PropertyType.BINARY) {
                     InputStream[] ins = new InputStream[values.length];

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java Fri Aug 18 09:29:27 2006
@@ -37,13 +37,11 @@
     private final PropertyState propertyState;
     private final QValue[] values;
     private final int propertyType;
-    private final boolean isMultiValued;
 
-    private SetPropertyValue(PropertyState propertyState, int propertyType, QValue[] values, boolean isMultiValued) {
+    private SetPropertyValue(PropertyState propertyState, int propertyType, QValue[] values) {
         this.propertyState = propertyState;
         this.propertyType = propertyType;
         this.values = values;
-        this.isMultiValued = isMultiValued;
         
         addAffectedItemState(propertyState);
     }
@@ -70,14 +68,10 @@
         return values;
     }
 
-    public boolean isMultiValued() {
-        return isMultiValued;
-    }
-
     //------------------------------------------------------------< Factory >---
     public static Operation create(PropertyState propState, QValue[] iva,
                                    int valueType) {
-        SetPropertyValue sv = new SetPropertyValue(propState, valueType, iva, propState.isMultiValued());
+        SetPropertyValue sv = new SetPropertyValue(propState, valueType, iva);
         return sv;
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java Fri Aug 18 09:29:27 2006
@@ -60,22 +60,6 @@
      * <code>propertyId</code>.
      *
      * @param propertyId the id of the <code>PropertyState</code> to create.
-     * @param ism        the item state manager to retrievev the parent of the
-     *                   <code>PropertyState</code> to create.
-     * @return the created <code>PropertyState</code>.
-     * @throws NoSuchItemStateException if there is no such <code>PropertyState</code>.
-     * @throws ItemStateException       if an error occurs while retrieving the
-     *                                  <code>PropertyState</code>.
-     */
-    public PropertyState createPropertyState(PropertyId propertyId,
-                                             ItemStateManager ism)
-            throws NoSuchItemStateException, ItemStateException;
-
-    /**
-     * Creates the <code>PropertyState</code> with the given
-     * <code>propertyId</code>.
-     *
-     * @param propertyId the id of the <code>PropertyState</code> to create.
      * @param parent the parent of the <code>PropertyState</code> to create.
      * @return the created <code>PropertyState</code>.
      * @throws NoSuchItemStateException if there is no such <code>PropertyState</code>.

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java Fri Aug 18 09:29:27 2006
@@ -140,7 +140,7 @@
         EffectiveNodeType entPrimary = ntReg.getEffectiveNodeType(nodeState.getNodeTypeName());
         // effective node type (primary type incl. mixins)
         EffectiveNodeType entPrimaryAndMixins = getEffectiveNodeType(nodeState);
-        QNodeDefinition def = nodeState.getDefinition(ntReg);
+        QNodeDefinition def = nodeState.getDefinition();
 
         // check if primary type satisfies the 'required node types' constraint
         QName[] requiredPrimaryTypes = def.getRequiredPrimaryTypes();
@@ -418,7 +418,7 @@
         VersionException, LockException, ItemNotFoundException,
         ItemExistsException, PathNotFoundException, RepositoryException {
 
-        QPropertyDefinition def = propState.getDefinition(ntReg);
+        QPropertyDefinition def = propState.getDefinition();
         checkWriteProperty(propState.getParent(), propState.getQName(), def, options);
     }
 
@@ -688,9 +688,9 @@
         throws ConstraintViolationException, RepositoryException {
         QItemDefinition def;
         if (itemState.isNode()) {
-            def = ((NodeState)itemState).getDefinition(ntReg);
+            def = ((NodeState)itemState).getDefinition();
         } else {
-            def = ((PropertyState)itemState).getDefinition(ntReg);
+            def = ((PropertyState)itemState).getDefinition();
         }
         checkProtection(def);
     }
@@ -719,9 +719,9 @@
         throws ConstraintViolationException, RepositoryException {
         QItemDefinition definition;
         if (itemState.isNode()) {
-            definition = ((NodeState)itemState).getDefinition(ntReg);
+            definition = ((NodeState)itemState).getDefinition();
         } else {
-            definition = ((PropertyState)itemState).getDefinition(ntReg);
+            definition = ((PropertyState)itemState).getDefinition();
         }
         checkProtection(definition);
         if (definition.isMandatory()) {
@@ -778,7 +778,7 @@
                 ChildNodeEntry cne = parentState.getChildNodeEntry(nodeName, Path.INDEX_DEFAULT);
                 // cne must not be null, since existence has been checked before
                 NodeState conflictingState = cne.getNodeState();
-                QNodeDefinition conflictDef = conflictingState.getDefinition(ntReg);
+                QNodeDefinition conflictDef = conflictingState.getDefinition();
                 QNodeDefinition newDef = getApplicableNodeDefinition(nodeName, nodeTypeName, parentState);
 
                 // check same-name sibling setting of both target and existing node

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java Fri Aug 18 09:29:27 2006
@@ -25,9 +25,6 @@
 import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
-import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -75,11 +72,6 @@
     private QName nodeTypeName;
 
     /**
-     * the names of this node's mixin types
-     */
-    private QName[] mixinTypeNames = new QName[0];
-
-    /**
      * The UUID of this node state or <code>null</code> if this node state
      * cannot be identified with a uuid.
      */
@@ -93,7 +85,12 @@
     /**
      * Definition of this node state
      */
-    private QNodeDefinition def;
+    private QNodeDefinition definition;
+
+    /**
+     * the names of this node's mixin types
+     */
+    private QName[] mixinTypeNames = new QName[0];
 
     /**
      * insertion-ordered collection of ChildNodeEntry objects
@@ -132,21 +129,23 @@
      *                      this node state cannot be identified with a UUID.
      * @param parent        the parent of this NodeState
      * @param nodeTypeName  node type of this node
+     * @param definition
      * @param initialStatus the initial status of the node state object
      * @param isTransient   flag indicating whether this state is transient or
      *                      not.
      * @param isf           the item state factory responsible for creating node
      *                      states.
      * @param idFactory     the <code>IdFactory</code> to create new id
-     *                      instance.
      */
     protected NodeState(QName name, String uuid, NodeState parent,
-                        QName nodeTypeName, int initialStatus, boolean isTransient,
+                        QName nodeTypeName, QNodeDefinition definition,
+                        int initialStatus, boolean isTransient,
                         ItemStateFactory isf, IdFactory idFactory) {
         super(parent, initialStatus, isTransient, idFactory);
         this.name = name;
         this.uuid = uuid;
         this.nodeTypeName = nodeTypeName;
+        this.definition = definition;
         this.isf = isf;
     }
 
@@ -181,7 +180,7 @@
             //parent = nodeState.parent; // TODO: parent from wrong ism layer
             nodeTypeName = nodeState.nodeTypeName;
             mixinTypeNames = nodeState.mixinTypeNames;
-            def = nodeState.def;
+            definition = nodeState.definition;
             // re-create property references
             propertiesInAttic.clear();
             properties.clear(); // TODO: any more cleanup work to do? try some kind of merging?
@@ -227,18 +226,6 @@
     }
 
     /**
-     * Sets the the parent <code>NodeState</code>.
-     *
-     * @param parent the parent <code>NodeState</code> or <code>null</code>
-     * if either this node state should represent the root node or this node
-     * state should be 'free floating', i.e. detached from the repository's
-     * hierarchy.
-     */
-    private void setParent(NodeState parent) {
-        this.parent = parent;
-    }
-
-    /**
      * {@inheritDoc}
      */
     public ItemId getId() {
@@ -284,16 +271,6 @@
     }
 
     /**
-     * Set the node type name. Needed for deserialization and should therefore
-     * not change the internal status.
-     *
-     * @param nodeTypeName node type name
-     */
-    synchronized void setNodeTypeName(QName nodeTypeName) {
-        this.nodeTypeName = nodeTypeName;
-    }
-
-    /**
      * Returns the names of this node's mixin types.
      *
      * @return a set of the names of this node's mixin types.
@@ -332,55 +309,13 @@
 
     /**
      * Returns the {@link QNodeDefinition definition} defined for this
-     * node state or <code>null</code> if the definition has not been
-     * set before (i.e. the corresponding item has not been accessed before).
+     * node state. Note, that the definition has been set upon creation or
+     * upon move.
      *
      * @return definition of this state
-     * @see #getDefinition(NodeTypeRegistry) for the corresponding method
-     * that never returns <code>null</code>.
      */
     public QNodeDefinition getDefinition() {
-        return def;
-    }
-
-    /**
-     * Returns the definition applicable to this node state. Since the definition
-     * is not defined upon state creation this state may have to retrieve
-     * the definition from the given <code>NodeTypeRegistry</code> first.
-     *
-     * @param ntRegistry
-     * @return the definition of this state
-     * @see #getDefinition()
-     */
-    public QNodeDefinition getDefinition(NodeTypeRegistry ntRegistry)
-        throws RepositoryException {
-        // make sure the state has the definition set now
-        if (def == null) {
-            NodeState parentState = getParent();
-            if (parentState == null) {
-                // special case for root state
-                def = ntRegistry.getRootNodeDef();
-            } else {
-                try {
-                    EffectiveNodeType ent = ntRegistry.getEffectiveNodeType(parentState.getNodeTypeNames());
-                    def = ent.getApplicableNodeDefinition(getName(), getNodeTypeName());
-                } catch (NodeTypeConflictException e) {
-                    String msg = "internal error: failed to build effective node type.";
-                    log.debug(msg);
-                    throw new RepositoryException(msg, e);
-                }
-            }
-        }
-        return def;
-    }
-
-    /**
-     * Sets the id of the definition applicable to this node state.
-     *
-     * @param def the definition
-     */
-    void setDefinition(QNodeDefinition def) {
-        this.def = def;
+        return definition;
     }
 
     /**
@@ -454,7 +389,7 @@
      * @see #addChildNodeEntry
      */
     public synchronized Collection getChildNodeEntries() {
-        // NOTE: List representation of 'ChildNodeEntries' is already unmodifiable
+        // NOTE: 'childNodeEntries' are already unmodifiable
         return childNodeEntries;
     }
 
@@ -913,7 +848,9 @@
     }
 
     /**
-     * Renames a new <code>ChildNodeEntry</code>.
+     * Moves a <code>ChildNodeEntry</code> to a new parent. If the new parent
+     * is this <code>NodeState</code>, the child state is renamed and moved
+     * to the end of the child entries collection.
      *
      * @param newParent
      * @param childState
@@ -922,13 +859,15 @@
      * @throws RepositoryException if the given child state is not a child
      * of this node state.
      */
-    synchronized void moveChildNodeEntry(NodeState newParent, NodeState childState, QName newName)
+    synchronized void moveChildNodeEntry(NodeState newParent, NodeState childState, QName newName, QNodeDefinition newDefinition)
         throws RepositoryException {
         ChildNodeEntry oldEntry = childNodeEntries.remove(childState);
         if (oldEntry != null) {
             childState.rename(newName);
             // re-parent target node
-            childState.setParent(newParent);
+            childState.parent = newParent;
+            // set definition according to new definition required by the new parent
+            childState.definition = newDefinition;
             // add child node entry to new parent
             newParent.childNodeEntries.add(childState);
         } else {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java Fri Aug 18 09:29:27 2006
@@ -18,7 +18,6 @@
 
 import javax.jcr.PropertyType;
 import javax.jcr.ValueFormatException;
-import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.name.QName;
@@ -26,9 +25,6 @@
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.value.QValue;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
-import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,11 +53,6 @@
     private int type;
 
     /**
-     * Flag indicating if this is a multivalue property
-     */
-    private boolean multiValued;
-
-    /**
      * Property definition
      */
     private QPropertyDefinition def;
@@ -70,9 +61,11 @@
      * Constructs a new property state that is initially connected to an
      * overlayed state.
      *
-     * @param overlayedState the backing property state being overlayed
-     * @param initialStatus  the initial status of the property state object
-     * @param isTransient    flag indicating whether this state is transient or not
+     * @param overlayedState
+     * @param parent
+     * @param initialStatus
+     * @param isTransient
+     * @param idFactory
      */
     protected PropertyState(PropertyState overlayedState, NodeState parent,
                             int initialStatus, boolean isTransient, IdFactory idFactory) {
@@ -83,18 +76,21 @@
     /**
      * Create a new <code>PropertyState</code>
      *
-     * @param name          the name of the property
-     * @param initialStatus the initial status of the property state object
-     * @param isTransient   flag indicating whether this state is transient or
-     *                      not
+     * @param name
+     * @param parent
+     * @param definition
+     * @param initialStatus
+     * @param isTransient
+     * @param idFactory
      */
-    protected PropertyState(QName name, NodeState parent, int initialStatus,
+    protected PropertyState(QName name, NodeState parent, QPropertyDefinition definition, int initialStatus,
                             boolean isTransient, IdFactory idFactory) {
         super(parent, initialStatus, isTransient, idFactory);
         this.name = name;
+        this.def = definition;
+
         type = PropertyType.UNDEFINED;
         values = QValue.EMPTY_ARRAY;
-        multiValued = false;
     }
 
     /**
@@ -161,7 +157,6 @@
             type = propState.type;
             def = propState.def;
             values = propState.values;
-            multiValued = propState.multiValued;
         }
     }
 
@@ -231,69 +226,18 @@
      * @return true if this property is multi-valued, otherwise false.
      */
     public boolean isMultiValued() {
-        return multiValued;
-    }
-
-    /**
-     * Sets the flag indicating whether this property is multi-valued.
-     *
-     * @param multiValued flag indicating whether this property is multi-valued
-     */
-    void setMultiValued(boolean multiValued) {
-        this.multiValued = multiValued;
+        return def.isMultiple();
     }
 
-
     /**
      * Returns the {@link QPropertyDefinition definition} defined for this
-     * property state or <code>null</code> if the definition has not been
-     * set before (i.e. the corresponding item has not been accessed before).
+     * property state. Note that the definition has been set upon creation of
+     * this <code>PropertyState</code>.
      *
      * @return definition of this state
-     * @see #getDefinition(NodeTypeRegistry) for the corresponding method
-     * that never returns <code>null</code>.
      */
     public QPropertyDefinition getDefinition() {
         return def;
-    }
-
-    /**
-     * Returns the definition applicable to this property state. Since the definition
-     * is not defined upon state creation this state may have to retrieve
-     * the definition from the given <code>NodeTypeRegistry</code> first.
-     *
-     * @param ntRegistry
-     * @return definition of this state
-     * @see #getDefinition()
-     */
-    public QPropertyDefinition getDefinition(NodeTypeRegistry ntRegistry)
-        throws RepositoryException {
-        if (def == null) {
-            try {
-                NodeState parentState = getParent();
-                if (parentState == null) {
-                    String msg = "Internal error: cannot determine definition for orphaned state.";
-                    log.debug(msg);
-                    throw new RepositoryException(msg);
-                }
-                EffectiveNodeType ent = ntRegistry.getEffectiveNodeType(parentState.getNodeTypeNames());
-                setDefinition(ent.getApplicablePropertyDefinition(getQName(), getType(), isMultiValued()));
-            } catch (NodeTypeConflictException e) {
-                String msg = "internal error: failed to build effective node type.";
-                log.debug(msg);
-                throw new RepositoryException(msg, e);
-            }
-        }
-        return def;
-    }
-
-    /**
-     * Sets the id of the definition applicable to this property state.
-     *
-     * @param def the id of the definition
-     */
-    void setDefinition(QPropertyDefinition def) {
-        this.def = def;
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java Fri Aug 18 09:29:27 2006
@@ -203,7 +203,7 @@
      * {@inheritDoc}
      * Since node references cannot be managed within the transient space,
      * this call is delegated to the workspace itemstate manager.
-     * 
+     *
      * @see ItemStateManager#hasReferingStates(NodeState)
      * @param nodeState
      */
@@ -855,13 +855,11 @@
             | ItemStateValidator.CHECK_CONSTRAINTS);
         // retrieve applicable definition at the new place
         // TODO: improve. definition has already retrieve within the checkAddNode...
+        // TODO: improve. if move is simple rename, the definition must not be calculated again.
         QNodeDefinition newDefinition = validator.getApplicableNodeDefinition(operation.getDestinationName(), srcState.getNodeTypeName(), destParent);
 
         // perform the move (modifying states)
-        srcParent.moveChildNodeEntry(destParent, srcState, operation.getDestinationName());
-
-        // change definition of target node
-        srcState.setDefinition(newDefinition);
+        srcParent.moveChildNodeEntry(destParent, srcState, operation.getDestinationName(), newDefinition);
 
         // remember operation
         transientStateMgr.addOperation(operation);
@@ -1087,12 +1085,10 @@
         validator.validate(propertyType, values, pDef);
 
         // create property state
-        PropertyState propState = transientStateMgr.createPropertyState(parent, propertyName);
-        propState.setDefinition(pDef);
+        PropertyState propState = transientStateMgr.createNewPropertyState(propertyName, parent, pDef);
 
         // NOTE: callers must make sure, the property type is not 'undefined'
         propState.setType(propertyType);
-        propState.setMultiValued(pDef.isMultiple());
         propState.setValues(values);
     }
 
@@ -1120,8 +1116,7 @@
             }
         }
 
-        NodeState nodeState = transientStateMgr.createNodeState(nodeName, uuid, nodeTypeName, parent);
-        nodeState.setDefinition(definition);
+        NodeState nodeState = transientStateMgr.createNewNodeState(nodeName, uuid, nodeTypeName, definition, parent);
 
         EffectiveNodeType ent = validator.getEffectiveNodeType(nodeState);
         // add 'auto-create' properties defined in node type
@@ -1140,7 +1135,7 @@
         QNodeDefinition[] nda = ent.getAutoCreateNodeDefs();
         for (int i = 0; i < nda.length; i++) {
             QNodeDefinition nd = nda[i];
-            // execute 'addNode' without validation and adding operation.
+            // execute 'addNode' without adding the operation.
             int opt = ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_COLLISION;
             addNodeState(nodeState, nd.getQName(), nd.getDefaultPrimaryType(), null, nd, opt);
         }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateFactory.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateFactory.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateFactory.java Fri Aug 18 09:29:27 2006
@@ -17,6 +17,8 @@
 package org.apache.jackrabbit.jcr2spi.state;
 
 import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
 
 /**
  * <code>TransientItemStateFactory</code> extends the item state factory and
@@ -33,11 +35,13 @@
      *               <code>null</code> if the created <code>NodeState</code>
      *               cannot be identified by a UUID.
      * @param parent the parent of the <code>NodeState</code> to create.
+     * @param nodeTypeName name of the primary nodetype
+     * @param definition the definition for this new NodeState
      * @return the created <code>NodeState</code>.
      */
-    public NodeState createNewNodeState(QName name,
-                                        String uuid,
-                                        NodeState parent);
+    public NodeState createNewNodeState(QName name, String uuid,
+                                        NodeState parent, QName nodeTypeName,
+                                        QNodeDefinition definition);
 
     /**
      * Creates a transient <code>PropertyState</code> with the given
@@ -45,8 +49,10 @@
      *
      * @param name   the name of the <code>PropertyState</code> to create.
      * @param parent the parent of the <code>PropertyState</code> to create.
+     * @param definition definition for this new property state.
      * @return the created <code>PropertyState</code>.
      */
     public PropertyState createNewPropertyState(QName name,
-                                                NodeState parent);
+                                                NodeState parent,
+                                                QPropertyDefinition definition);
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java Fri Aug 18 09:29:27 2006
@@ -22,6 +22,8 @@
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.commons.collections.iterators.IteratorChain;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -38,8 +40,8 @@
  * still valid. This item state manager also provides methods to create new
  * item states. While all other modifications can be invoked on the item state
  * instances itself, creating a new node state is done using
- * {@link #createNodeState(QName, String, QName, NodeState)} and
- * {@link #createPropertyState(NodeState, QName)}.
+ * {@link #createNewNodeState(QName,String,QName,NodeState)} and
+ * {@link #createNewPropertyState(NodeState, QName)}.
  */
 public class TransientItemStateManager extends CachingItemStateManager
         implements ItemStateLifeCycleListener {
@@ -220,15 +222,14 @@
      *                     <code>null</code> if the created <code>NodeState</code>
      *                     cannot be identified by a UUID.
      * @param nodeTypeName name of the node type of the new node state.
+     * @param definition   The qualified definition for the new node state.
      * @param parent       the parent of the new node state.
      * @return a new transient {@link NodeState}.
      */
-    public NodeState createNodeState(QName nodeName,
-                                     String uuid,
-                                     QName nodeTypeName,
-                                     NodeState parent) {
-        NodeState nodeState = isf.createNewNodeState(nodeName, uuid, parent);
-        nodeState.setNodeTypeName(nodeTypeName);
+    NodeState createNewNodeState(QName nodeName, String uuid, QName nodeTypeName,
+                                 QNodeDefinition definition, NodeState parent) {
+        NodeState nodeState = isf.createNewNodeState(nodeName, uuid, parent, nodeTypeName, definition);
+
         parent.addChildNodeState(nodeState, uuid);
         changeLog.added(nodeState);
         nodeState.addListener(this);
@@ -239,15 +240,17 @@
      * Creates a new transient property state for a given <code>parent</code>
      * node state.
      *
-     * @param parent   the node state where to the new property is added.
      * @param propName the name of the property state to create.
+     * @param parent   the node state where to the new property is added.
+     * @param definition
      * @return the created property state.
      * @throws ItemExistsException if <code>parent</code> already has a property
      *                             with the given name.
      */
-    public PropertyState createPropertyState(NodeState parent, QName propName)
+    PropertyState createNewPropertyState(QName propName, NodeState parent, QPropertyDefinition definition)
             throws ItemExistsException {
-        PropertyState propState = isf.createNewPropertyState(propName, parent);
+        PropertyState propState = isf.createNewPropertyState(propName, parent, definition);
+
         parent.addPropertyState(propState);
         changeLog.added(propState);
         propState.addListener(this);
@@ -559,11 +562,13 @@
 
         /**
          * @inheritDoc
-         * @see TransientItemStateFactory#createNewNodeState(QName, String, NodeState)
+         * @see TransientItemStateFactory#createNewNodeState(QName, String, NodeState, QName, QNodeDefinition)
          */
-        public NodeState createNewNodeState(QName name, String uuid, NodeState parent) {
-            NodeState nodeState = new NodeState(name, uuid, parent, null,
-                    ItemState.STATUS_NEW, true, this, idFactory);
+        public NodeState createNewNodeState(QName name, String uuid,
+                                            NodeState parent, QName nodetypeName,
+                                            QNodeDefinition definition) {
+            NodeState nodeState = new NodeState(name, uuid, parent, nodetypeName,
+                definition, ItemState.STATUS_NEW, true, this, idFactory);
             // get a notification when this item state is saved or invalidated
             nodeState.addListener(listener);
             // notify listener that a node state has been created
@@ -573,11 +578,11 @@
 
         /**
          * @inheritDoc
-         * @see TransientItemStateFactory#createNewPropertyState(QName, NodeState)
+         * @see TransientItemStateFactory#createNewPropertyState(QName, NodeState, QPropertyDefinition)
          */
-        public PropertyState createNewPropertyState(QName name, NodeState parent) {
+        public PropertyState createNewPropertyState(QName name, NodeState parent, QPropertyDefinition definition) {
             PropertyState propState = new PropertyState(name, parent,
-                    ItemState.STATUS_NEW, true, idFactory);
+                definition, ItemState.STATUS_NEW, true, idFactory);
             // get a notification when this item state is saved or invalidated
             propState.addListener(listener);
             // notify listener that a property state has been created
@@ -587,7 +592,7 @@
 
         /**
          * @inheritDoc
-         * @see TransientItemStateFactory#createNodeState(NodeId, ItemStateManager)
+         * @see ItemStateFactory#createNodeState(NodeId, ItemStateManager)
          */
         public NodeState createNodeState(NodeId nodeId, ItemStateManager ism)
                 throws NoSuchItemStateException, ItemStateException {
@@ -606,7 +611,7 @@
 
         /**
          * @inheritDoc
-         * @see TransientItemStateFactory#createNodeState(NodeId, NodeState)
+         * @see ItemStateFactory#createNodeState(NodeId, NodeState)
          */
         public NodeState createNodeState(NodeId nodeId, NodeState parentState)
                 throws NoSuchItemStateException, ItemStateException {
@@ -620,24 +625,7 @@
 
         /**
          * @inheritDoc
-         * @see TransientItemStateFactory#createPropertyState(PropertyId, ItemStateManager)
-         */
-        public PropertyState createPropertyState(PropertyId propertyId,
-                                                 ItemStateManager ism)
-                throws NoSuchItemStateException, ItemStateException {
-            // retrieve state to overlay
-            PropertyState overlayedState = (PropertyState) parent.getItemState(propertyId);
-            NodeId parentId = overlayedState.getParent().getNodeId();
-            NodeState parentState = (NodeState) ism.getItemState(parentId);
-            PropertyState propState = new PropertyState(overlayedState, parentState,
-                    ItemState.STATUS_EXISTING, true, idFactory);
-            propState.addListener(listener);
-            return propState;
-        }
-
-        /**
-         * @inheritDoc
-         * @see TransientItemStateFactory#createPropertyState(PropertyId, NodeState)
+         * @see ItemStateFactory#createPropertyState(PropertyId, NodeState)
          */
         public PropertyState createPropertyState(PropertyId propertyId,
                                                  NodeState parentState)

Modified: 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=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java Fri Aug 18 09:29:27 2006
@@ -25,12 +25,18 @@
 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.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.jcr2spi.WorkspaceManager;
+import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
+import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
 
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.PropertyType;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
 import java.io.InputStream;
 import java.io.IOException;
 import java.util.HashSet;
@@ -48,10 +54,12 @@
 
     private final RepositoryService service;
     private final SessionInfo sessionInfo;
+    private final WorkspaceManager wspManager;
 
-    public WorkspaceItemStateFactory(RepositoryService service, SessionInfo sessionInfo) {
+    public WorkspaceItemStateFactory(RepositoryService service, SessionInfo sessionInfo, WorkspaceManager wspManager) {
         this.service = service;
         this.sessionInfo = sessionInfo;
+        this.wspManager = wspManager;
     }
 
     /**
@@ -108,17 +116,24 @@
     private NodeState createNodeState(NodeInfo info, NodeState parent)
             throws NoSuchItemStateException, ItemStateException {
         try {
-            QName ntName = info.getNodetype();
+            // retrieve definition
+            QNodeDefinition definition;
+            if (parent == null) {
+                // special case for root state
+                definition = wspManager.getNodeTypeRegistry().getRootNodeDef();
+            } else {
+                EffectiveNodeType ent = wspManager.getNodeTypeRegistry().getEffectiveNodeType(parent.getNodeTypeNames());
+                definition = ent.getApplicableNodeDefinition(info.getQName(), info.getNodetype());
+            }
 
             // build the node state
-            // NOTE: unable to retrieve definitionId -> needs to be retrieved
-            // by the itemManager upon Node creation.
             String uuid = null;
             if (info.getId().getRelativePath() == null) {
                 uuid = info.getId().getUUID();
             }
-            NodeState state = new NodeState(info.getQName(), uuid, parent, ntName,
-                    ItemState.STATUS_EXISTING, false, this, service.getIdFactory());
+            NodeState state = new NodeState(info.getQName(), uuid, parent, info.getNodetype(),
+                definition, ItemState.STATUS_EXISTING, false, this, service.getIdFactory());
+
             // set mixin nodetypes
             state.setMixinTypeNames(info.getMixins());
 
@@ -152,27 +167,18 @@
             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 (NodeTypeConflictException e) {
+            String msg = "internal error: failed to retrieve node definition.";
+            log.debug(msg);
+            throw new ItemStateException(msg, e);
+        } catch (ConstraintViolationException e) {
+            String msg = "internal error: failed to retrieve node definition.";
+            log.debug(msg);
+            throw new ItemStateException(msg, e);
+        } catch (NoSuchNodeTypeException e) {
+            String msg = "internal error: failed to retrieve node definition.";
+            log.debug(msg);
+            throw new ItemStateException(msg, e);
         } catch (RepositoryException e) {
             throw new ItemStateException(e.getMessage(), e);
         }
@@ -212,12 +218,14 @@
                                               NodeState parent)
             throws ItemStateException {
         try {
+
+            // retrieve property definition
+            EffectiveNodeType ent = wspManager.getNodeTypeRegistry().getEffectiveNodeType(parent.getNodeTypeNames());
+            QPropertyDefinition def = ent.getApplicablePropertyDefinition(info.getQName(), info.getType(), info.isMultiValued());
+
             // build the PropertyState
-            // NOTE: unable to retrieve definitionId -> needs to be retrieved
-            // by the itemManager upon Property creation.
             PropertyState state = new PropertyState(info.getQName(), parent,
-                    ItemState.STATUS_EXISTING, false, service.getIdFactory());
-            state.setMultiValued(info.isMultiValued());
+                def, ItemState.STATUS_EXISTING, false, service.getIdFactory());
             state.setType(info.getType());
             QValue[] qValues;
             if (info.getType() == PropertyType.BINARY) {
@@ -242,6 +250,18 @@
             return state;
         } catch (IOException e) {
             throw new ItemStateException(e.getMessage(), e);
+        } catch (NodeTypeConflictException e) {
+            String msg = "internal error: failed to retrieve property definition.";
+            log.debug(msg);
+            throw new ItemStateException(msg, e);
+        } catch (ConstraintViolationException e) {
+            String msg = "internal error: failed to retrieve property definition.";
+            log.debug(msg);
+            throw new ItemStateException(msg, e);
+        } catch (NoSuchNodeTypeException e) {
+            String msg = "internal error: failed to retrieve property definition.";
+            log.debug(msg);
+            throw new ItemStateException(msg, e);
         }
     }
 

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=432630&r1=432629&r2=432630&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 Fri Aug 18 09:29:27 2006
@@ -45,9 +45,7 @@
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.nodetype.NodeDefinition;
-import java.util.Set;
 import java.util.Iterator;
-import java.util.HashSet;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -122,8 +120,7 @@
      */
     public VersionIterator getAllVersions() throws RepositoryException {
         Iterator childIter = vhState.getChildNodeEntries().iterator();
-        Set versionStates = new HashSet();
-
+        List versionStates = new ArrayList();
         // all child-nodes except from jcr:versionLabels point to Versions.
         while (childIter.hasNext()) {
             ChildNodeEntry entry = (ChildNodeEntry) childIter.next();

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java?rev=432630&r1=432629&r2=432630&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java Fri Aug 18 09:29:27 2006
@@ -179,7 +179,7 @@
                // should not occur. existance has been checked before
                throw new RepositoryException(e);
            }
-           QNodeDefinition def = existing.getDefinition(session.getNodeTypeRegistry());
+           QNodeDefinition def = existing.getDefinition();
            if (!def.allowsSameNameSiblings()) {
                // existing doesn't allow same-name siblings, check for conflicts
                EffectiveNodeType entExisting = session.getValidator().getEffectiveNodeType(existing);
@@ -488,7 +488,7 @@
             // a property with that name already exists...
             try {
                 PropertyState existing = parentState.getPropertyState(propName);
-                def = existing.getDefinition(session.getNodeTypeRegistry());
+                def = existing.getDefinition();
                 if (def.isProtected()) {
                     // skip protected property
                     log.debug("skipping protected property " + LogUtil.safeGetJCRPath(existing, session.getNamespaceResolver(), session.getHierarchyManager()));



Mime
View raw message