jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r520408 [2/3] - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ nodetype/ state/ xml/
Date Tue, 20 Mar 2007 14:35:58 GMT
Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProviderImpl.java?view=auto&rev=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProviderImpl.java (added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProviderImpl.java Tue Mar 20 07:35:56 2007
@@ -0,0 +1,489 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi.nodetype;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.NodeInfo;
+import org.apache.jackrabbit.spi.PropertyInfo;
+import org.apache.jackrabbit.spi.RepositoryService;
+import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.spi.QItemDefinition;
+import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
+import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
+import org.apache.jackrabbit.jcr2spi.state.NodeState;
+import org.apache.jackrabbit.jcr2spi.state.PropertyState;
+import org.apache.jackrabbit.jcr2spi.state.Status;
+import org.apache.jackrabbit.name.QName;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import java.util.List;
+import java.util.Collections;
+import java.util.ArrayList;
+
+/**
+ * <code>ItemDefinitionManagerImpl</code>...
+ */
+public class ItemDefinitionProviderImpl implements ItemDefinitionProvider {
+
+    private static Logger log = LoggerFactory.getLogger(ItemDefinitionProviderImpl.class);
+
+    private final QNodeDefinition rootNodeDefintion;
+    private final EffectiveNodeTypeProvider entProvider;
+    private final RepositoryService service;
+    private final SessionInfo sessionInfo;
+
+    public ItemDefinitionProviderImpl(QNodeDefinition rootNodeDefintion, 
+                                      EffectiveNodeTypeProvider entProvider,
+                                      RepositoryService service,
+                                      SessionInfo sessionInfo) {
+        this.rootNodeDefintion = rootNodeDefintion;
+        this.entProvider = entProvider;
+        this.service = service;
+        this.sessionInfo = sessionInfo;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public QNodeDefinition getRootNodeDefinition() {
+        return rootNodeDefintion;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public QNodeDefinition getQNodeDefinition(NodeEntry nodeEntry, NodeInfo nodeInfo) {
+        QNodeDefinition definition = null;
+        NodeEntry parent = nodeEntry.getParent();
+        if (parent == null) {
+            // special case for root state
+            definition = getRootNodeDefinition();
+        } else if (parent.isAvailable() && parent.getStatus() == Status.EXISTING) {
+            // try to retrieve definition if the parent is available
+            try {
+                NodeState parentState = parent.getNodeState();
+                EffectiveNodeType ent = entProvider.getEffectiveNodeType(parentState);
+                EffectiveNodeType entTarget = getEffectiveNodeType(nodeInfo.getNodetype());
+                definition = getQNodeDefinition(ent, entTarget, nodeInfo.getQName());
+            } catch (RepositoryException e) {
+                // should not get here
+                log.warn("Internal error", e.getMessage());
+            }
+        }
+        return definition;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public QNodeDefinition getQNodeDefinition(NodeState nodeState) throws RepositoryException {
+        QNodeDefinition definition;
+        try {
+            /*
+             Don't use 'getEffectiveNodeType(NodeState) here:
+             for NEW-states the definition is always set upon creation.
+             for all other states the definion must be retrieved only taking
+             the effective nodetypes present on the parent into account
+             any kind of transiently added mixins must not have an effect
+             on the definition retrieved for an state that has been persisted
+             before. The effective NT must be evaluated as if it had been
+             evaluated upon creating the workspace state.
+             */
+            EffectiveNodeType ent = entProvider.getEffectiveNodeType(nodeState.getParent().getNodeTypeNames());
+            EffectiveNodeType entTarget = getEffectiveNodeType(nodeState.getNodeTypeName());
+            definition = getQNodeDefinition(ent, entTarget, nodeState.getQName());
+        } catch (RepositoryException e) {
+            definition = service.getNodeDefinition(sessionInfo, nodeState.getNodeEntry().getWorkspaceId());
+        } catch (NodeTypeConflictException e) {
+            definition = service.getNodeDefinition(sessionInfo, nodeState.getNodeEntry().getWorkspaceId());
+        }
+        return definition;
+    }
+
+   /**
+     * @inheritDoc
+     */
+    public QNodeDefinition getQNodeDefinition(NodeState parentState, QName name, QName nodeTypeName)
+            throws NoSuchNodeTypeException, ConstraintViolationException {
+       EffectiveNodeType ent = entProvider.getEffectiveNodeType(parentState);
+       EffectiveNodeType entTarget = getEffectiveNodeType(nodeTypeName);
+       return getQNodeDefinition(ent, entTarget, name);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public QNodeDefinition getQNodeDefinition(EffectiveNodeType ent, QName name, QName nodeTypeName) throws NoSuchNodeTypeException, ConstraintViolationException {
+        EffectiveNodeType entTarget = getEffectiveNodeType(nodeTypeName);
+        return getQNodeDefinition(ent, entTarget, name);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public QPropertyDefinition getQPropertyDefinition(PropertyEntry propertyEntry, PropertyInfo propInfo) {
+        QPropertyDefinition definition = null;
+        NodeEntry parent = propertyEntry.getParent();
+        if (parent.isAvailable() && parent.getStatus() == Status.EXISTING) {
+            try {
+                NodeState parentState = parent.getNodeState();
+                EffectiveNodeType ent = entProvider.getEffectiveNodeType(parentState.getNodeTypeNames());
+                QPropertyDefinition defs[] = getQPropertyDefinitions(ent, propInfo.getQName(), propInfo.getType(), propInfo.isMultiValued());
+                if (defs.length == 1) {
+                    definition = defs[0];
+                } else {
+                    definition = service.getPropertyDefinition(sessionInfo, propertyEntry.getId());
+                }
+            } catch (RepositoryException e) {
+                // should not get here
+                log.warn("Internal error", e.getMessage());
+            } catch (NodeTypeConflictException e) {
+                // should not get here
+                log.warn("Internal error", e.getMessage());
+            }
+        }
+        return definition;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public QPropertyDefinition getQPropertyDefinition(PropertyState propertyState) throws RepositoryException {
+        QPropertyDefinition definition;
+        try {
+            /*
+             Don't use 'getEffectiveNodeType(NodeState) here:
+             for NEW-states the definition is always set upon creation.
+             for all other states the definion must be retrieved only taking
+             the effective nodetypes present on the parent into account
+             any kind of transiently added mixins must not have an effect
+             on the definition retrieved for an state that has been persisted
+             before. The effective NT must be evaluated as if it had been
+             evaluated upon creating the workspace state.
+             */
+            EffectiveNodeType ent = entProvider.getEffectiveNodeType(propertyState.getParent().getNodeTypeNames());
+            definition = getQPropertyDefinition(ent, propertyState.getQName(), propertyState.getType(), propertyState.isMultiValued());
+        } catch (RepositoryException e) {
+            definition = service.getPropertyDefinition(sessionInfo, ((PropertyEntry) propertyState.getHierarchyEntry()).getWorkspaceId());
+        } catch (NodeTypeConflictException e) {
+            definition = service.getPropertyDefinition(sessionInfo, ((PropertyEntry) propertyState.getHierarchyEntry()).getWorkspaceId());
+        }
+        return definition;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public QPropertyDefinition getQPropertyDefinition(QName ntName, QName propName,
+                                                      int type, boolean multiValued)
+            throws ConstraintViolationException, NoSuchNodeTypeException {
+        EffectiveNodeType ent = entProvider.getEffectiveNodeType(ntName);
+        return getQPropertyDefinition(ent, propName, type, multiValued);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public QPropertyDefinition getQPropertyDefinition(NodeState parentState,
+                                                      QName name, int type,
+                                                      boolean multiValued)
+            throws ConstraintViolationException, NoSuchNodeTypeException {
+        EffectiveNodeType ent = entProvider.getEffectiveNodeType(parentState);
+        return getQPropertyDefinition(ent, name, type, multiValued);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public QPropertyDefinition getQPropertyDefinition(NodeState parentState,
+                                                      QName name, int type)
+            throws ConstraintViolationException, NoSuchNodeTypeException {
+        EffectiveNodeType ent = entProvider.getEffectiveNodeType(parentState);
+        return getQPropertyDefinition(ent, name, type);
+    }
+
+    //--------------------------------------------------------------------------
+    private EffectiveNodeType getEffectiveNodeType(QName ntName) throws NoSuchNodeTypeException {
+        if (ntName != null) {
+            return entProvider.getEffectiveNodeType(ntName);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     *
+     * @param ent
+     * @param name
+     * @param nodeTypeName
+     * @return
+     * @throws NoSuchNodeTypeException
+     * @throws ConstraintViolationException
+     */
+    static QNodeDefinition getQNodeDefinition(EffectiveNodeType ent,
+                                              EffectiveNodeType entTarget,
+                                              QName name)
+            throws ConstraintViolationException {
+
+        // try named node definitions first
+        QNodeDefinition[] defs = ent.getNamedQNodeDefinitions(name);
+        if (defs != null) {
+            for (int i = 0; i < defs.length; i++) {
+                QNodeDefinition nd = defs[i];
+                // node definition with that name exists
+                if (entTarget != null && nd.getRequiredPrimaryTypes() != null) {
+                    // check 'required primary types' constraint
+                    if (entTarget.includesNodeTypes(nd.getRequiredPrimaryTypes())) {
+                        // found named node definition
+                        return nd;
+                    }
+                } else {
+                    if (nd.getDefaultPrimaryType() != null) {
+                        // found node definition with default node type
+                        return nd;
+                    }
+                }
+            }
+        }
+
+        // no item with that name defined;
+        // try residual node definitions
+        QNodeDefinition[] nda = ent.getUnnamedQNodeDefinitions();
+        for (int i = 0; i < nda.length; i++) {
+            QNodeDefinition nd = nda[i];
+            if (entTarget != null && nd.getRequiredPrimaryTypes() != null) {
+                // check 'required primary types' constraint
+                if (entTarget.includesNodeTypes(nd.getRequiredPrimaryTypes())) {
+                    // found residual node definition
+                    return nd;
+                }
+            } else {
+                // since no node type has been specified for the new node,
+                // it must be determined from the default node type;
+                if (nd.getDefaultPrimaryType() != null) {
+                    // found residual node definition with default node type
+                    return nd;
+                }
+            }
+        }
+
+        // no applicable definition found
+        throw new ConstraintViolationException("no matching child node definition found for " + name);
+    }
+
+    /**
+     * Returns all applicable property definitions for a property with the
+     * specified name, type and multiValued characteristics.
+     *
+     * @param ent
+     * @param name
+     * @param type
+     * @param multiValued
+     * @return
+     * @throws ConstraintViolationException
+     */
+    private static QPropertyDefinition[] getQPropertyDefinitions(EffectiveNodeType ent,
+                                                                 QName name, int type,
+                                                                 boolean multiValued)
+            throws ConstraintViolationException {
+        QPropertyDefinition named[] = ent.getNamedQPropertyDefinitions(name);
+        QPropertyDefinition unnamed[] = ent.getUnnamedQPropertyDefinitions();
+        QPropertyDefinition all[] = new QPropertyDefinition[named.length + unnamed.length];
+        for (int i = 0; i < all.length; i++) {
+            if (i < named.length) {
+                all[i] = named[i];
+            }
+            else {
+                all[i] = unnamed[i - named.length];
+            }
+        }
+
+        QPropertyDefinition result[] = getMatchingPropDefs(all, type, multiValued);
+        if (result.length == 0) {
+            throw new ConstraintViolationException("no matching property definition found for " + name);
+        }
+        else {
+            return result;
+        }
+    }
+
+   /**
+     *
+     * @param ent
+     * @param name
+     * @param type
+     * @param multiValued
+     * @return
+     * @throws ConstraintViolationException
+     */
+    private static QPropertyDefinition getQPropertyDefinition(EffectiveNodeType ent,
+                                                              QName name, int type,
+                                                              boolean multiValued)
+           throws ConstraintViolationException {
+        // try named property definitions first
+        QPropertyDefinition[] defs = ent.getNamedQPropertyDefinitions(name);
+        QPropertyDefinition match = getMatchingPropDef(defs, type, multiValued);
+        if (match != null) {
+            return match;
+        }
+
+        // no item with that name defined;
+        // try residual property definitions
+        defs = ent.getUnnamedQPropertyDefinitions();
+        match = getMatchingPropDef(defs, type, multiValued);
+        if (match != null) {
+            return match;
+        }
+
+        // no applicable definition found
+        throw new ConstraintViolationException("no matching property definition found for " + name);
+    }
+
+    /**
+     *
+     * @param ent
+     * @param name
+     * @param type
+     * @return
+     * @throws ConstraintViolationException
+     */
+    private static QPropertyDefinition getQPropertyDefinition(EffectiveNodeType ent,
+                                                              QName name, int type)
+            throws ConstraintViolationException {
+        // try named property definitions first
+        QPropertyDefinition[] defs = ent.getNamedQPropertyDefinitions(name);
+        QPropertyDefinition match = getMatchingPropDef(defs, type);
+        if (match != null) {
+            return match;
+        }
+
+        // no item with that name defined;
+        // try residual property definitions
+        defs = ent.getUnnamedQPropertyDefinitions();
+        match = getMatchingPropDef(defs, type);
+        if (match != null) {
+            return match;
+        }
+
+        // no applicable definition found
+        throw new ConstraintViolationException("no matching property definition found for " + name);
+    }
+
+    private static QPropertyDefinition getMatchingPropDef(QPropertyDefinition[] defs, int type) {
+        QPropertyDefinition match = null;
+        for (int i = 0; i < defs.length; i++) {
+            QItemDefinition qDef = defs[i];
+            if (!qDef.definesNode()) {
+                QPropertyDefinition pd = (QPropertyDefinition) qDef;
+                int reqType = pd.getRequiredType();
+                // match type
+                if (reqType == PropertyType.UNDEFINED
+                        || type == PropertyType.UNDEFINED
+                        || reqType == type) {
+                    if (match == null) {
+                        match = pd;
+                    } else {
+                        // check if this definition is a better match than
+                        // the one we've already got
+                        if (match.getRequiredType() != pd.getRequiredType()) {
+                            if (match.getRequiredType() == PropertyType.UNDEFINED) {
+                                // found better match
+                                match = pd;
+                            }
+                        } else {
+                            if (match.isMultiple() && !pd.isMultiple()) {
+                                // found better match
+                                match = pd;
+                            }
+                        }
+                    }
+                    if (match.getRequiredType() != PropertyType.UNDEFINED
+                            && !match.isMultiple()) {
+                        // found best possible match, get outta here
+                        return match;
+                    }
+                }
+            }
+        }
+        return match;
+    }
+
+    private static QPropertyDefinition getMatchingPropDef(QPropertyDefinition[] defs, int type,
+                                                   boolean multiValued) {
+        QPropertyDefinition match = null;
+        for (int i = 0; i < defs.length; i++) {
+            QItemDefinition qDef = defs[i];
+            if (!qDef.definesNode()) {
+                QPropertyDefinition pd = (QPropertyDefinition) qDef;
+                int reqType = pd.getRequiredType();
+                // match type
+                if (reqType == PropertyType.UNDEFINED
+                        || type == PropertyType.UNDEFINED
+                        || reqType == type) {
+                    // match multiValued flag
+                    if (multiValued == pd.isMultiple()) {
+                        // found match
+                        if (pd.getRequiredType() != PropertyType.UNDEFINED) {
+                            // found best possible match, get outta here
+                            return pd;
+                        } else {
+                            if (match == null) {
+                                match = pd;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return match;
+    }
+
+    private static QPropertyDefinition[] getMatchingPropDefs(QPropertyDefinition[] defs, int type, boolean multiValued) {
+        List result = Collections.EMPTY_LIST;
+
+        for (int i = 0; i < defs.length; i++) {
+            QItemDefinition qDef = defs[i];
+            if (!qDef.definesNode()) {
+                QPropertyDefinition pd = (QPropertyDefinition)qDef;
+                int reqType = pd.getRequiredType();
+                // match type
+                if (reqType == PropertyType.UNDEFINED || type == PropertyType.UNDEFINED || reqType == type) {
+                    // match multiValued flag
+                    if (multiValued == pd.isMultiple()) {
+                        // found match
+                        if (result.isEmpty()) {
+                            result = Collections.singletonList(pd);
+                        }
+                        else {
+                            if (result.size() == 1) {
+                                result = new ArrayList(result);
+                            }
+                            result.add(pd);
+                        }
+                    }
+                }
+            }
+        }
+        return (QPropertyDefinition[])result.toArray(QPropertyDefinition.EMPTY_ARRAY);
+    }
+}
\ No newline at end of file

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

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

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java Tue Mar 20 07:35:56 2007
@@ -30,6 +30,7 @@
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.apache.jackrabbit.value.ValueFormat;
+import org.apache.jackrabbit.jcr2spi.ManagerProvider;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -54,23 +55,7 @@
     private final QNodeTypeDefinition ntd;
     private final EffectiveNodeType ent;
     private final NodeTypeManagerImpl ntMgr;
-    /**
-     * Namespace resolver used to translate qualified names to JCR names
-     */
-    private final NamespaceResolver nsResolver;
-    /**
-     * ValueFactory used to convert JCR values to qualified ones in order to
-     * determine whether a property specified by name and value(s) would be allowed.
-     *
-     * @see NodeType#canSetProperty(String, Value)
-     * @see NodeType#canSetProperty(String, Value[])
-     */
-    private final ValueFactory valueFactory;
-    /**
-     * ValueFactory used to convert JCR values to qualified ones in order to
-     * determine value constraints within the NodeType interface.
-     */
-    private final QValueFactory qValueFactory;
+    private final ManagerProvider mgrProvider;
 
     /**
      * Package private constructor
@@ -85,16 +70,40 @@
      * @param nsResolver namespace resolver
      */
     NodeTypeImpl(EffectiveNodeType ent, QNodeTypeDefinition ntd,
-                 NodeTypeManagerImpl ntMgr, NamespaceResolver nsResolver,
-                 ValueFactory valueFactory, QValueFactory qValueFactory) {
+                 NodeTypeManagerImpl ntMgr, ManagerProvider mgrProvider) {
         this.ent = ent;
         this.ntMgr = ntMgr;
-        this.nsResolver = nsResolver;
-        this.valueFactory = valueFactory;
-        this.qValueFactory = qValueFactory;
+        this.mgrProvider = mgrProvider;
         this.ntd = ntd;
     }
 
+    private NamespaceResolver nsResolver() {
+        return mgrProvider.getNamespaceResolver();
+    }
+
+    private ItemDefinitionProvider definitionProvider() {
+        return mgrProvider.getItemDefinitionProvider();
+    }
+
+    /**
+     * ValueFactory used to convert JCR values to qualified ones in order to
+     * determine whether a property specified by name and value(s) would be allowed.
+     *
+     * @see NodeType#canSetProperty(String, Value)
+     * @see NodeType#canSetProperty(String, Value[])
+     */
+    private ValueFactory valueFactory() throws RepositoryException {
+        return mgrProvider.getJcrValueFactory();
+    }
+
+    /**
+     * ValueFactory used to convert JCR values to qualified ones in order to
+     * determine value constraints within the NodeType interface.
+     */
+    private QValueFactory qValueFactory() throws RepositoryException {
+        return mgrProvider.getQValueFactory();
+    }
+    
     /**
      * Returns the applicable property definition for a property with the
      * specified name and type.
@@ -108,7 +117,7 @@
      */
     private QPropertyDefinition getApplicablePropDef(QName propertyName, int type, boolean multiValued)
             throws RepositoryException {
-        return ent.getApplicablePropertyDefinition(propertyName, type, multiValued);
+        return definitionProvider().getQPropertyDefinition(getQName(), propertyName, type, multiValued);
     }
 
     /**
@@ -157,7 +166,7 @@
      */
     public String getName() {
         try {
-            return NameFormat.format(ntd.getQName(), nsResolver);
+            return NameFormat.format(ntd.getQName(), nsResolver());
         } catch (NoPrefixDeclaredException npde) {
             // should never get here
             log.error("encountered unregistered namespace in node type name", npde);
@@ -172,7 +181,7 @@
         try {
             QName piName = ntd.getPrimaryItemName();
             if (piName != null) {
-                return NameFormat.format(piName, nsResolver);
+                return NameFormat.format(piName, nsResolver());
             } else {
                 return null;
             }
@@ -196,7 +205,7 @@
     public boolean isNodeType(String nodeTypeName) {
         QName ntName;
         try {
-            ntName = NameFormat.parse(nodeTypeName, nsResolver);
+            ntName = NameFormat.parse(nodeTypeName, nsResolver());
         } catch (IllegalNameException ine) {
             log.warn("invalid node type name: " + nodeTypeName, ine);
             return false;
@@ -236,7 +245,7 @@
      * {@inheritDoc}
      */
     public NodeDefinition[] getChildNodeDefinitions() {
-        QNodeDefinition[] cnda = ent.getAllNodeDefs();
+        QNodeDefinition[] cnda = ent.getAllQNodeDefinitions();
         NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length];
         for (int i = 0; i < cnda.length; i++) {
             nodeDefs[i] = ntMgr.getNodeDefinition(cnda[i]);
@@ -248,7 +257,7 @@
      * {@inheritDoc}
      */
     public PropertyDefinition[] getPropertyDefinitions() {
-        QPropertyDefinition[] pda = ent.getAllPropDefs();
+        QPropertyDefinition[] pda = ent.getAllQPropertyDefinitions();
         PropertyDefinition[] propDefs = new PropertyDefinition[pda.length];
         for (int i = 0; i < pda.length; i++) {
             propDefs[i] = ntMgr.getPropertyDefinition(pda[i]);
@@ -295,7 +304,7 @@
             return canRemoveItem(propertyName);
         }
         try {
-            QName name = NameFormat.parse(propertyName, nsResolver);
+            QName name = NameFormat.parse(propertyName, nsResolver());
             QPropertyDefinition def;
             try {
                 // try to get definition that matches the given value type
@@ -314,13 +323,13 @@
             if (def.getRequiredType() != PropertyType.UNDEFINED
                     && def.getRequiredType() != value.getType()) {
                 // type conversion required
-                v =  ValueHelper.convert(value, def.getRequiredType(), valueFactory);
+                v =  ValueHelper.convert(value, def.getRequiredType(), valueFactory());
             } else {
                 // no type conversion required
                 v = value;
             }
             // create QValue from Value
-            QValue qValue = ValueFormat.getQValue(v, nsResolver, qValueFactory);
+            QValue qValue = ValueFormat.getQValue(v, nsResolver(), qValueFactory());
             checkSetPropertyValueConstraints(def, new QValue[]{qValue});
             return true;
         } catch (NameException be) {
@@ -340,7 +349,7 @@
             return canRemoveItem(propertyName);
         }
         try {
-            QName name = NameFormat.parse(propertyName, nsResolver);
+            QName name = NameFormat.parse(propertyName, nsResolver());
             // determine type of values
             int type = PropertyType.UNDEFINED;
             for (int i = 0; i < values.length; i++) {
@@ -387,8 +396,8 @@
                 if (values[i] != null) {
                     // create QValue from Value and perform
                     // type conversion as necessary
-                    Value v = ValueHelper.convert(values[i], targetType, valueFactory);
-                    QValue qValue = ValueFormat.getQValue(v, nsResolver, qValueFactory);
+                    Value v = ValueHelper.convert(values[i], targetType, valueFactory());
+                    QValue qValue = ValueFormat.getQValue(v, nsResolver(), qValueFactory());
                     list.add(qValue);
                 }
             }
@@ -408,8 +417,7 @@
      */
     public boolean canAddChildNode(String childNodeName) {
         try {
-            ent.checkAddNodeConstraints(NameFormat.parse(childNodeName, nsResolver),
-                ntMgr.getNodeTypeRegistry());
+            ent.checkAddNodeConstraints(NameFormat.parse(childNodeName, nsResolver()), definitionProvider());
             return true;
         } catch (NameException be) {
             // implementation specific exception, fall through
@@ -424,8 +432,8 @@
      */
     public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
         try {
-            ent.checkAddNodeConstraints(NameFormat.parse(childNodeName, nsResolver),
-                NameFormat.parse(nodeTypeName, nsResolver), ntMgr.getNodeTypeRegistry());
+            ent.checkAddNodeConstraints(NameFormat.parse(childNodeName, nsResolver()),
+                NameFormat.parse(nodeTypeName, nsResolver()), definitionProvider());
             return true;
         } catch (NameException be) {
             // implementation specific exception, fall through
@@ -440,7 +448,7 @@
      */
     public boolean canRemoveItem(String itemName) {
         try {
-            ent.checkRemoveItemConstraints(NameFormat.parse(itemName, nsResolver));
+            ent.checkRemoveItemConstraints(NameFormat.parse(itemName, nsResolver()));
             return true;
         } catch (NameException be) {
             // implementation specific exception, fall through

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java Tue Mar 20 07:35:56 2007
@@ -25,6 +25,7 @@
 import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.util.IteratorHelper;
 import org.apache.jackrabbit.jcr2spi.util.Dumpable;
+import org.apache.jackrabbit.jcr2spi.ManagerProvider;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
@@ -61,14 +62,14 @@
     private static Logger log = LoggerFactory.getLogger(NodeTypeManagerImpl.class);
 
     /**
-     * The wrapped node type registry.
+     * The ManagerProvider
      */
-    private final NodeTypeRegistry ntReg;
+    private final ManagerProvider mgrProvider;
 
     /**
-     * The namespace resolver used to translate qualified names to JCR names.
+     * The wrapped node type registry.
      */
-    private final NamespaceResolver nsResolver;
+    private final NodeTypeRegistry ntReg;
 
     /**
      * The ValueFactory used to convert qualified values to JCR values.
@@ -104,9 +105,9 @@
      * @param ntReg      node type registry
      * @param nsResolver namespace resolver
      */
-    public NodeTypeManagerImpl(NodeTypeRegistry ntReg, NamespaceResolver nsResolver,
+    public NodeTypeManagerImpl(NodeTypeRegistry ntReg, ManagerProvider mgrProvider,
                                ValueFactory valueFactory, QValueFactory qValueFactory) {
-        this.nsResolver = nsResolver;
+        this.mgrProvider = mgrProvider;
         this.ntReg = ntReg;
         this.ntReg.addListener(this);
         this.valueFactory = valueFactory;
@@ -118,11 +119,22 @@
         ndCache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
 
         // setup root definition and update cache
-        QNodeDefinition rootDef = ntReg.getRootNodeDef();
-        NodeDefinition rootNodeDefinition = new NodeDefinitionImpl(rootDef, this, nsResolver);
+        QNodeDefinition rootDef = defProvider().getRootNodeDefinition();
+        NodeDefinition rootNodeDefinition = new NodeDefinitionImpl(rootDef, this, nsResolver());
         ndCache.put(rootDef, rootNodeDefinition);
     }
 
+    private NamespaceResolver nsResolver() {
+        return mgrProvider.getNamespaceResolver();
+    }
+
+    private ItemDefinitionProvider defProvider() {
+        return mgrProvider.getItemDefinitionProvider();
+    }
+
+    private EffectiveNodeTypeProvider entProvider() {
+        return mgrProvider.getEffectiveNodeTypeProvider();
+    }
     //--------------------------------------------------------------------------
     /**
      * @param name
@@ -133,9 +145,9 @@
         synchronized (ntCache) {
             NodeTypeImpl nt = (NodeTypeImpl) ntCache.get(name);
             if (nt == null) {
-                EffectiveNodeType ent = ntReg.getEffectiveNodeType(name);
+                EffectiveNodeType ent = entProvider().getEffectiveNodeType(name);
                 QNodeTypeDefinition def = ntReg.getNodeTypeDefinition(name);
-                nt = new NodeTypeImpl(ent, def, this, nsResolver, valueFactory, qValueFactory);
+                nt = new NodeTypeImpl(ent, def, this, mgrProvider);
                 ntCache.put(name, nt);
             }
             return nt;
@@ -166,7 +178,7 @@
         synchronized (ndCache) {
             NodeDefinition ndi = (NodeDefinition) ndCache.get(def);
             if (ndi == null) {
-                ndi = new NodeDefinitionImpl(def, this, nsResolver);
+                ndi = new NodeDefinitionImpl(def, this, nsResolver());
                 ndCache.put(def, ndi);
             }
             return ndi;
@@ -184,7 +196,7 @@
         synchronized (pdCache) {
             PropertyDefinition pdi = (PropertyDefinition) pdCache.get(def);
             if (pdi == null) {
-                pdi = new PropertyDefinitionImpl(def, this, nsResolver, valueFactory);
+                pdi = new PropertyDefinitionImpl(def, this, nsResolver(), valueFactory);
                 pdCache.put(def, pdi);
             }
             return pdi;
@@ -212,7 +224,7 @@
         // flush all affected cache entries
         ntCache.remove(ntName);
         try {
-            String name = NameFormat.format(ntName, nsResolver);
+            String name = NameFormat.format(ntName, nsResolver());
             synchronized (pdCache) {
                 Iterator iter = pdCache.values().iterator();
                 while (iter.hasNext()) {
@@ -249,7 +261,7 @@
         // flush all affected cache entries
         ntCache.remove(ntName);
         try {
-            String name = NameFormat.format(ntName, nsResolver);
+            String name = NameFormat.format(ntName, nsResolver());
             synchronized (pdCache) {
                 Iterator iter = pdCache.values().iterator();
                 while (iter.hasNext()) {
@@ -328,7 +340,7 @@
     public NodeType getNodeType(String nodeTypeName)
             throws NoSuchNodeTypeException {
         try {
-            QName qName = NameFormat.parse(nodeTypeName, nsResolver);
+            QName qName = NameFormat.parse(nodeTypeName, nsResolver());
             return getNodeType(qName);
         } catch (UnknownPrefixException upe) {
             throw new NoSuchNodeTypeException(nodeTypeName, upe);

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistry.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistry.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistry.java Tue Mar 20 07:35:56 2007
@@ -18,12 +18,10 @@
 
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
-import org.apache.jackrabbit.spi.QNodeDefinition;
 
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.RepositoryException;
 import java.util.Collection;
-import java.util.Map;
 
 /**
  * <code>NodeTypeRegistry</code>...
@@ -32,13 +30,6 @@
 public interface NodeTypeRegistry {
 
     /**
-     * Return the <code>QNodeDefinition</code> of the root node.
-     *
-     * @return
-     */
-    QNodeDefinition getRootNodeDef();
-
-    /**
      * Returns the node type definition of the node type with the given name.
      *
      * @param nodeTypeName name of node type whose definition should be returned.
@@ -48,38 +39,6 @@
      */
     QNodeTypeDefinition getNodeTypeDefinition(QName nodeTypeName)
             throws NoSuchNodeTypeException;
-
-    /**
-     *
-     *
-     * @param ntName
-     * @return
-     * @throws NoSuchNodeTypeException
-     */
-    EffectiveNodeType getEffectiveNodeType(QName ntName)
-            throws NoSuchNodeTypeException;
-
-    /**
-     *
-     *
-     * @param ntNames
-     * @return
-     * @throws NodeTypeConflictException
-     * @throws NoSuchNodeTypeException
-     */
-    EffectiveNodeType getEffectiveNodeType(QName[] ntNames)
-            throws NodeTypeConflictException, NoSuchNodeTypeException;
-
-    /**
-     * @param ntNames
-     * @param ntdMap
-     * @return
-     * @throws NodeTypeConflictException
-     * @throws NoSuchNodeTypeException
-     */
-    EffectiveNodeType getEffectiveNodeType(QName[] ntNames, Map ntdMap)
-            throws NodeTypeConflictException, NoSuchNodeTypeException;
-
 
     /**
      * Add a <code>NodeTypeRegistryListener</code>

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java Tue Mar 20 07:35:56 2007
@@ -18,6 +18,9 @@
 
 import org.apache.commons.collections.map.ReferenceMap;
 import org.apache.jackrabbit.jcr2spi.util.Dumpable;
+import org.apache.jackrabbit.jcr2spi.state.NodeState;
+import org.apache.jackrabbit.jcr2spi.state.Status;
+import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
@@ -30,6 +33,7 @@
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.version.OnParentVersionAction;
 import java.io.PrintStream;
 import java.util.Collection;
@@ -45,7 +49,7 @@
 /**
  * A <code>NodeTypeRegistry</code> ...
  */
-public class NodeTypeRegistryImpl implements Dumpable, NodeTypeRegistry {
+public class NodeTypeRegistryImpl implements Dumpable, NodeTypeRegistry, EffectiveNodeTypeProvider {
 
     private static Logger log = LoggerFactory.getLogger(NodeTypeRegistryImpl.class);
 
@@ -130,10 +134,9 @@
         }
     }
 
-
-
+    //---------------------------------------------------< NodeTypeRegistry >---
     /**
-     * @inheritDoc
+     * @see NodeTypeRegistry#addListener(NodeTypeRegistryListener)
      */
     public void addListener(NodeTypeRegistryListener listener) {
         if (!listeners.containsKey(listener)) {
@@ -142,14 +145,14 @@
     }
 
     /**
-     * @inheritDoc
+     * @see NodeTypeRegistry#removeListener(NodeTypeRegistryListener)
      */
     public void removeListener(NodeTypeRegistryListener listener) {
         listeners.remove(listener);
     }
 
     /**
-     * @inheritDoc
+     * @see NodeTypeRegistry#getRegisteredNodeTypes()
      */
     public QName[] getRegisteredNodeTypes() {
         return (QName[]) registeredNTDefs.keySet().toArray(new QName[registeredNTDefs.size()]);
@@ -157,21 +160,143 @@
 
 
     /**
-     * @inheritDoc
+     * @see NodeTypeRegistry#isRegistered(QName)
      */
     public boolean isRegistered(QName nodeTypeName) {
         return registeredNTDefs.containsKey(nodeTypeName);
     }
 
+   /**
+     * @see NodeTypeRegistry#registerNodeType(QNodeTypeDefinition)
+     */
+    public synchronized EffectiveNodeType registerNodeType(QNodeTypeDefinition ntDef)
+            throws InvalidNodeTypeDefException, RepositoryException {
+        // validate the new nodetype definition
+        EffectiveNodeTypeImpl ent = validator.validateNodeTypeDef(ntDef, registeredNTDefs);
+
+        // persist new node type definition
+        storage.registerNodeTypes(new QNodeTypeDefinition[] {ntDef});
+
+        // update internal caches
+        internalRegister(ntDef, ent);
+
+        // notify listeners
+        notifyRegistered(ntDef.getQName());
+        return ent;
+    }
+
     /**
-     * @inheritDoc
+     * @see NodeTypeRegistry#registerNodeTypes(Collection)
      */
-    public QNodeDefinition getRootNodeDef() {
-        return rootNodeDef;
+    public synchronized void registerNodeTypes(Collection ntDefs)
+            throws InvalidNodeTypeDefException, RepositoryException {
+
+        // validate new nodetype definitions
+        Map defMap = validator.validateNodeTypeDefs(ntDefs, registeredNTDefs);
+        storage.registerNodeTypes((QNodeTypeDefinition[])ntDefs.toArray(new QNodeTypeDefinition[ntDefs.size()]));
+
+        // update internal cache
+        internalRegister(defMap);
+
+        // notify listeners
+        for (Iterator iter = ntDefs.iterator(); iter.hasNext();) {
+            QName ntName = ((QNodeTypeDefinition)iter.next()).getQName();
+            notifyRegistered(ntName);
+        }
     }
 
     /**
-     * @inheritDoc
+     * @see NodeTypeRegistry#unregisterNodeType(QName)
+     */
+    public void unregisterNodeType(QName nodeTypeName) throws NoSuchNodeTypeException, RepositoryException {
+        HashSet ntNames = new HashSet();
+        ntNames.add(nodeTypeName);
+        unregisterNodeTypes(ntNames);
+    }
+
+    /**
+     * @see NodeTypeRegistry#unregisterNodeTypes(Collection)
+     */
+    public synchronized void unregisterNodeTypes(Collection nodeTypeNames)
+            throws NoSuchNodeTypeException, RepositoryException {
+        // do some preliminary checks
+        for (Iterator iter = nodeTypeNames.iterator(); iter.hasNext();) {
+            QName ntName = (QName) iter.next();
+            if (!registeredNTDefs.containsKey(ntName)) {
+                throw new NoSuchNodeTypeException(ntName.toString());
+            }
+
+            // check for node types other than those to be unregistered
+            // that depend on the given node types
+            Set dependents = getDependentNodeTypes(ntName);
+            dependents.removeAll(nodeTypeNames);
+            if (dependents.size() > 0) {
+                StringBuffer msg = new StringBuffer();
+                msg.append(ntName
+                        + " can not be removed because the following node types depend on it: ");
+                for (Iterator depIter = dependents.iterator(); depIter.hasNext();) {
+                    msg.append(depIter.next());
+                    msg.append(" ");
+                }
+                throw new RepositoryException(msg.toString());
+            }
+        }
+
+        // persist removal of node type definitions
+        // NOTE: conflict with existing content not asserted on client
+        storage.unregisterNodeTypes((QName[]) nodeTypeNames.toArray(new QName[nodeTypeNames.size()]));
+
+
+        // all preconditions are met, node types can now safely be unregistered
+        internalUnregister(nodeTypeNames);
+
+        // notify listeners
+        for (Iterator iter = nodeTypeNames.iterator(); iter.hasNext();) {
+            QName ntName = (QName) iter.next();
+            notifyUnregistered(ntName);
+        }
+    }
+
+    /**
+     * @see NodeTypeRegistry#reregisterNodeType(QNodeTypeDefinition)
+     */
+    public synchronized EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd)
+            throws NoSuchNodeTypeException, InvalidNodeTypeDefException,
+            RepositoryException {
+        QName name = ntd.getQName();
+        if (!registeredNTDefs.containsKey(name)) {
+            throw new NoSuchNodeTypeException(name.toString());
+        }
+        /* validate new node type definition */
+        EffectiveNodeTypeImpl ent = validator.validateNodeTypeDef(ntd, registeredNTDefs);
+
+        // first call reregistering on storage
+        storage.reregisterNodeTypes(new QNodeTypeDefinition[]{ntd});
+
+        // unregister old node type definition
+        internalUnregister(name);
+        // register new definition
+        internalRegister(ntd, ent);
+
+        // notify listeners
+        notifyReRegistered(name);
+        return ent;
+    }
+
+    /**
+     * @see NodeTypeRegistry#getNodeTypeDefinition(QName)
+     */
+    public QNodeTypeDefinition getNodeTypeDefinition(QName nodeTypeName)
+        throws NoSuchNodeTypeException {
+        QNodeTypeDefinition def = (QNodeTypeDefinition) registeredNTDefs.get(nodeTypeName);
+        if (def == null) {
+            throw new NoSuchNodeTypeException(nodeTypeName.toString());
+        }
+        return def;
+    }
+    //------------------------------------------< EffectiveNodeTypeProvider >---
+    /**
+     * @see EffectiveNodeTypeProvider#getEffectiveNodeType(QName)
      */
     public synchronized EffectiveNodeType getEffectiveNodeType(QName ntName)
             throws NoSuchNodeTypeException {
@@ -179,7 +304,7 @@
     }
 
     /**
-     * @inheritDoc
+     * @see EffectiveNodeTypeProvider#getEffectiveNodeType(QName[])
      */
     public synchronized EffectiveNodeType getEffectiveNodeType(QName[] ntNames)
             throws NodeTypeConflictException, NoSuchNodeTypeException {
@@ -187,7 +312,7 @@
     }
 
     /**
-     * @inheritDoc
+     * @see EffectiveNodeTypeProvider#getEffectiveNodeType(QName[], Map)
      */
     public EffectiveNodeType getEffectiveNodeType(QName[] ntNames, Map ntdMap)
         throws NodeTypeConflictException, NoSuchNodeTypeException {
@@ -195,6 +320,43 @@
     }
 
     /**
+     * @see EffectiveNodeTypeProvider#getEffectiveNodeType(NodeState)
+     * @inheritDoc
+     * In case the status of the given node state is not {@link Status#EXISTING}
+     * the transiently added mixin types are taken into account as well.
+     */
+    public EffectiveNodeType getEffectiveNodeType(NodeState nodeState) throws ConstraintViolationException, NoSuchNodeTypeException {
+        try {
+            QName[] allNtNames;
+            if (nodeState.getStatus() == Status.EXISTING) {
+                allNtNames = nodeState.getNodeTypeNames();
+            } else {
+                // TODO: check if correct (and only used for creating new)
+                QName primaryType = nodeState.getNodeTypeName();
+                allNtNames = new QName[] { primaryType }; // default
+                PropertyEntry mixins = nodeState.getNodeEntry().getPropertyEntry(QName.JCR_MIXINTYPES);
+                if (mixins != null) {
+                    try {
+                        QValue[] values = mixins.getPropertyState().getValues();
+                        allNtNames = new QName[values.length + 1];
+                        for (int i = 0; i < values.length; i++) {
+                            allNtNames[i] = values[i].getQName();
+                        }
+                        allNtNames[values.length] = primaryType;
+                    } catch (RepositoryException e) {
+                        // ignore
+                    }
+                }
+            }
+            return getEffectiveNodeType(allNtNames);
+        } catch (NodeTypeConflictException e) {
+            String msg = "Internal error: failed to build effective node type from node types defined with " + nodeState;
+            log.debug(msg);
+            throw new ConstraintViolationException(msg, e);
+        }
+    }
+
+    /**
      *
      * @param ntName
      * @param entCache
@@ -312,134 +474,7 @@
         return result;
     }
 
-    /**
-     * @inheritDoc
-     */
-    public synchronized EffectiveNodeType registerNodeType(QNodeTypeDefinition ntDef)
-            throws InvalidNodeTypeDefException, RepositoryException {
-        // validate the new nodetype definition
-        EffectiveNodeTypeImpl ent = validator.validateNodeTypeDef(ntDef, registeredNTDefs);
-
-        // persist new node type definition
-        storage.registerNodeTypes(new QNodeTypeDefinition[] {ntDef});
-
-        // update internal caches
-        internalRegister(ntDef, ent);
-
-        // notify listeners
-        notifyRegistered(ntDef.getQName());
-        return ent;
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public synchronized void registerNodeTypes(Collection ntDefs)
-            throws InvalidNodeTypeDefException, RepositoryException {
-
-        // validate new nodetype definitions
-        Map defMap = validator.validateNodeTypeDefs(ntDefs, registeredNTDefs);
-        storage.registerNodeTypes((QNodeTypeDefinition[])ntDefs.toArray(new QNodeTypeDefinition[ntDefs.size()]));
-
-        // update internal cache
-        internalRegister(defMap);
-
-        // notify listeners
-        for (Iterator iter = ntDefs.iterator(); iter.hasNext();) {
-            QName ntName = ((QNodeTypeDefinition)iter.next()).getQName();
-            notifyRegistered(ntName);
-        }
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public void unregisterNodeType(QName nodeTypeName) throws NoSuchNodeTypeException, RepositoryException {
-        HashSet ntNames = new HashSet();
-        ntNames.add(nodeTypeName);
-        unregisterNodeTypes(ntNames);
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public synchronized void unregisterNodeTypes(Collection nodeTypeNames)
-            throws NoSuchNodeTypeException, RepositoryException {
-        // do some preliminary checks
-        for (Iterator iter = nodeTypeNames.iterator(); iter.hasNext();) {
-            QName ntName = (QName) iter.next();
-            if (!registeredNTDefs.containsKey(ntName)) {
-                throw new NoSuchNodeTypeException(ntName.toString());
-            }
-
-            // check for node types other than those to be unregistered
-            // that depend on the given node types
-            Set dependents = getDependentNodeTypes(ntName);
-            dependents.removeAll(nodeTypeNames);
-            if (dependents.size() > 0) {
-                StringBuffer msg = new StringBuffer();
-                msg.append(ntName
-                        + " can not be removed because the following node types depend on it: ");
-                for (Iterator depIter = dependents.iterator(); depIter.hasNext();) {
-                    msg.append(depIter.next());
-                    msg.append(" ");
-                }
-                throw new RepositoryException(msg.toString());
-            }
-        }
-
-        // persist removal of node type definitions
-        // NOTE: conflict with existing content not asserted on client
-        storage.unregisterNodeTypes((QName[]) nodeTypeNames.toArray(new QName[nodeTypeNames.size()]));
-
-
-        // all preconditions are met, node types can now safely be unregistered
-        internalUnregister(nodeTypeNames);
-
-        // notify listeners
-        for (Iterator iter = nodeTypeNames.iterator(); iter.hasNext();) {
-            QName ntName = (QName) iter.next();
-            notifyUnregistered(ntName);
-        }
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public synchronized EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd)
-            throws NoSuchNodeTypeException, InvalidNodeTypeDefException,
-            RepositoryException {
-        QName name = ntd.getQName();
-        if (!registeredNTDefs.containsKey(name)) {
-            throw new NoSuchNodeTypeException(name.toString());
-        }
-        /* validate new node type definition */
-        EffectiveNodeTypeImpl ent = validator.validateNodeTypeDef(ntd, registeredNTDefs);
-
-        // first call reregistering on storage
-        storage.reregisterNodeTypes(new QNodeTypeDefinition[]{ntd});
-
-        // unregister old node type definition
-        internalUnregister(name);
-        // register new definition
-        internalRegister(ntd, ent);
 
-        // notify listeners
-        notifyReRegistered(name);
-        return ent;
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public QNodeTypeDefinition getNodeTypeDefinition(QName nodeTypeName)
-        throws NoSuchNodeTypeException {
-        QNodeTypeDefinition def = (QNodeTypeDefinition) registeredNTDefs.get(nodeTypeName);
-        if (def == null) {
-            throw new NoSuchNodeTypeException(nodeTypeName.toString());
-        }
-        return def;
-    }
 
     //------------------------------------------------------------< private >---
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java Tue Mar 20 07:35:56 2007
@@ -26,9 +26,7 @@
 import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
-import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
+import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -71,8 +69,7 @@
      */
     final ItemStateFactory isf;
 
-    // TODO: find better solution..... needed to retrieve definition.
-    private final NodeTypeRegistry ntReg;
+    final ItemDefinitionProvider definitionProvider;
 
     /**
      * the backing persistent item state (may be null)
@@ -86,7 +83,7 @@
      * @param isWorkspaceState
      */
     protected ItemState(int initialStatus, boolean isWorkspaceState,
-                        ItemStateFactory isf, NodeTypeRegistry ntReg) {
+                        ItemStateFactory isf, ItemDefinitionProvider definitionProvider) {
         switch (initialStatus) {
             case Status.EXISTING:
             case Status.NEW:
@@ -100,7 +97,7 @@
         overlayedState = null;
 
         this.isf = isf;
-        this.ntReg = ntReg;
+        this.definitionProvider = definitionProvider;
         this.isWorkspaceState = isWorkspaceState;
     }
 
@@ -125,7 +122,7 @@
         }
         this.isf = isf;
         this.isWorkspaceState = false;
-        this.ntReg = overlayedState.ntReg;
+        this.definitionProvider = overlayedState.definitionProvider;
         connect(overlayedState);
     }
 
@@ -491,26 +488,5 @@
                 String msg = "Cannot mark item state with status " + status + " modified.";
                 throw new IllegalStateException(msg);
         }
-    }
-
-    EffectiveNodeType getEffectiveParentNodeType() throws RepositoryException {
-        try {
-            /*
-            for NEW-states the definition is always set upon creation.
-            for all other states the definion must be retrieved only taking
-            the effective nodetypes present on the parent into account
-            any kind of transiently added mixins must not have an effect
-            on the definition retrieved for an state that has been persisted
-            before. The effective NT must be evaluated as if it had been
-            evaluated upon creating the workspace state.
-            */
-            return getNodeTypeRegistry().getEffectiveNodeType(getParent().getNodeTypeNames());
-        } catch (NodeTypeConflictException e) {
-            throw new RepositoryException("Error while accessing Definition ", e);
-        }
-    }
-
-    NodeTypeRegistry getNodeTypeRegistry() {
-        return ntReg;
     }
 }

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?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- 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 Tue Mar 20 07:35:56 2007
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.jcr2spi.state;
 
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
@@ -38,7 +36,6 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QItemDefinition;
-import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.NamespaceResolver;
@@ -92,11 +89,6 @@
     public static final int CHECK_ALL = CHECK_ACCESS | CHECK_LOCK | CHECK_VERSIONING | CHECK_CONSTRAINTS | CHECK_COLLISION;
 
     /**
-     * node type registry
-     */
-    private final NodeTypeRegistry ntReg;
-
-    /**
      * manager provider
      */
     private final ManagerProvider mgrProvider;
@@ -104,11 +96,9 @@
     /**
      * Creates a new <code>ItemStateValidator</code> instance.
      *
-     * @param ntReg      node type registry
      * @param mgrProvider manager provider
      */
-    public ItemStateValidator(NodeTypeRegistry ntReg, ManagerProvider mgrProvider) {
-        this.ntReg = ntReg;
+    public ItemStateValidator(ManagerProvider mgrProvider) {
         this.mgrProvider = mgrProvider;
     }
 
@@ -131,9 +121,7 @@
     public void validate(NodeState nodeState) throws ConstraintViolationException,
         RepositoryException {
         // effective primary node type
-        EffectiveNodeType entPrimary = ntReg.getEffectiveNodeType(nodeState.getNodeTypeName());
-        // effective node type (primary type incl. mixins)
-        EffectiveNodeType entPrimaryAndMixins = getEffectiveNodeType(nodeState);
+        EffectiveNodeType entPrimary = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeState.getNodeTypeName());
         QNodeDefinition def = nodeState.getDefinition();
 
         // check if primary type satisfies the 'required node types' constraint
@@ -148,7 +136,9 @@
             }
         }
         // mandatory properties
-        QPropertyDefinition[] pda = entPrimaryAndMixins.getMandatoryPropDefs();
+        // effective node type (primary type incl. mixins)
+        EffectiveNodeType entPrimaryAndMixins = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeState);
+        QPropertyDefinition[] pda = entPrimaryAndMixins.getMandatoryQPropertyDefinitions();
         for (int i = 0; i < pda.length; i++) {
             QPropertyDefinition pd = pda[i];
             if (!nodeState.hasPropertyName(pd.getQName())) {
@@ -160,7 +150,7 @@
             }
         }
         // mandatory child nodes
-        QNodeDefinition[] cnda = entPrimaryAndMixins.getMandatoryNodeDefs();
+        QNodeDefinition[] cnda = entPrimaryAndMixins.getMandatoryQNodeDefinitions();
         for (int i = 0; i < cnda.length; i++) {
             QNodeDefinition cnd = cnda[i];
             if (!nodeState.getNodeEntry().hasNodeEntry(cnd.getQName())) {
@@ -175,74 +165,6 @@
 
     //-------------------------------------------------< misc. helper methods >
     /**
-     * Helper method that builds the effective (i.e. merged and resolved)
-     * node type representation of the specified node's primary and mixin
-     * node types.
-     *
-     * @param nodeState
-     * @return the effective node type
-     * @throws RepositoryException
-     */
-    public EffectiveNodeType getEffectiveNodeType(NodeState nodeState)
-            throws RepositoryException {
-        try {
-            QName[] allNtNames;
-            if (nodeState.getStatus() == Status.EXISTING) {
-                allNtNames = nodeState.getNodeTypeNames();
-            } else {
-                // TODO: check if correct (and only used for creating new)
-                QName primaryType = nodeState.getNodeTypeName();
-                allNtNames = new QName[] { primaryType }; // default
-                PropertyEntry mixins = nodeState.getNodeEntry().getPropertyEntry(QName.JCR_MIXINTYPES);
-                if (mixins != null) {
-                    try {
-                        QValue[] values = mixins.getPropertyState().getValues();
-                        allNtNames = new QName[values.length + 1];
-                        for (int i = 0; i < values.length; i++) {
-                            allNtNames[i] = values[i].getQName();
-                        }
-                        allNtNames[values.length] = primaryType;
-                    } catch (RepositoryException e) {
-                        // ignore
-                    }
-                }
-            }
-
-            return getEffectiveNodeType(allNtNames);
-        } catch (NodeTypeConflictException ntce) {
-            String msg = "Internal error: failed to build effective node type from node types defined with " + safeGetJCRPath(nodeState);
-            log.debug(msg);
-            throw new RepositoryException(msg, ntce);
-        }
-    }
-
-    /**
-     * Helper method that builds the effective (i.e. merged and resolved)
-     * node type representation of the specified node types.
-     *
-     * @param nodeTypeNames
-     * @return the effective node type
-     * @throws NodeTypeConflictException
-     * @throws NoSuchNodeTypeException
-     */
-    public EffectiveNodeType getEffectiveNodeType(QName[] nodeTypeNames)
-            throws NodeTypeConflictException, NoSuchNodeTypeException  {
-        return ntReg.getEffectiveNodeType(nodeTypeNames);
-    }
-
-    /**
-     * Helper method that builds the effective (i.e. merged and resolved)
-     * node type representation of the specified node type.
-     *
-     * @param nodeTypeName
-     * @return the effective node type
-     * @throws NoSuchNodeTypeException
-     */
-    public EffectiveNodeType getEffectiveNodeType(QName nodeTypeName) throws NoSuchNodeTypeException  {
-        return ntReg.getEffectiveNodeType(nodeTypeName);
-    }
-
-    /**
      * Failsafe translation of internal <code>ItemState</code> to JCR path for use
      * in error messages etc.
      *
@@ -254,88 +176,6 @@
         return LogUtil.safeGetJCRPath(itemState, mgrProvider.getNamespaceResolver());
     }
 
-    /**
-     * Helper method that finds the applicable definition for a child node with
-     * the given name and node type in the parent node's node type and
-     * mixin types.
-     *
-     * @param name
-     * @param nodeTypeName
-     * @param parentState
-     * @return a <code>QNodeDefinition</code>
-     *
-     * @throws ConstraintViolationException if no applicable child node definition
-     * could be found
-     * @throws NoSuchNodeTypeException if the given nodeTypeName does not exist.
-     * @throws RepositoryException if another error occurs
-     */
-    public QNodeDefinition getApplicableNodeDefinition(QName name,
-                                                       QName nodeTypeName,
-                                                       NodeState parentState)
-        throws NoSuchNodeTypeException, ConstraintViolationException, RepositoryException {
-        EffectiveNodeType entParent = getEffectiveNodeType(parentState);
-        return entParent.getApplicableNodeDefinition(name, nodeTypeName, ntReg);
-    }
-
-    /**
-     * Helper method that finds the applicable definition for a property with
-     * the given name, type and multiValued characteristic in the parent node's
-     * node type and mixin types. If there more than one applicable definitions
-     * then the following rules are applied:
-     * <ul>
-     * <li>named definitions are preferred to residual definitions</li>
-     * <li>definitions with specific required type are preferred to definitions
-     * with required type UNDEFINED</li>
-     * </ul>
-     *
-     * @param name
-     * @param type
-     * @param multiValued
-     * @param parentState
-     * @return a <code>QPropertyDefinition</code>
-     * @throws ConstraintViolationException if no applicable property definition
-     *                                      could be found
-     * @throws RepositoryException          if another error occurs
-     */
-    public QPropertyDefinition getApplicablePropertyDefinition(QName name,
-                                                               int type,
-                                                               boolean multiValued,
-                                                               NodeState parentState)
-        throws ConstraintViolationException, RepositoryException {
-        EffectiveNodeType entParent = getEffectiveNodeType(parentState);
-        return entParent.getApplicablePropertyDefinition(name, type, multiValued);
-    }
-
-    /**
-     * Helper method that finds the applicable definition for a property with
-     * the given name, type in the parent node's node type and mixin types.
-     * Other than <code>{@link #getApplicablePropertyDefinition(QName, int, boolean, NodeState)}</code>
-     * this method does not take the multiValued flag into account in the
-     * selection algorithm. If there more than one applicable definitions then
-     * the following rules are applied:
-     * <ul>
-     * <li>named definitions are preferred to residual definitions</li>
-     * <li>definitions with specific required type are preferred to definitions
-     * with required type UNDEFINED</li>
-     * <li>single-value definitions are preferred to multiple-value definitions</li>
-     * </ul>
-     *
-     * @param name
-     * @param type
-     * @param parentState
-     * @return a <code>QPropertyDefinition</code>
-     * @throws ConstraintViolationException if no applicable property definition
-     *                                      could be found
-     * @throws RepositoryException          if another error occurs
-     */
-    public QPropertyDefinition getApplicablePropertyDefinition(QName name,
-                                                               int type,
-                                                               NodeState parentState)
-        throws RepositoryException, ConstraintViolationException {
-        EffectiveNodeType entParent = getEffectiveNodeType(parentState);
-        return entParent.getApplicablePropertyDefinition(name, type);
-    }
-
     //------------------------------------------------------< check methods >---
     /**
      *
@@ -539,8 +379,8 @@
         // node type constraints
         if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
             // make sure there's an applicable definition for new child node
-            EffectiveNodeType entParent = getEffectiveNodeType(parentState);
-            entParent.checkAddNodeConstraints(nodeName, nodeTypeName, ntReg);
+            EffectiveNodeType entParent = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(parentState);
+            entParent.checkAddNodeConstraints(nodeName, nodeTypeName, mgrProvider.getItemDefinitionProvider());
         }
         // collisions
         if ((options & CHECK_COLLISION) == CHECK_COLLISION) {
@@ -747,7 +587,7 @@
             try {
                 NodeState conflictingState = parentState.getChildNodeState(nodeName, Path.INDEX_DEFAULT);
                 QNodeDefinition conflictDef = conflictingState.getDefinition();
-                QNodeDefinition newDef = getApplicableNodeDefinition(nodeName, nodeTypeName, parentState);
+                QNodeDefinition newDef = mgrProvider.getItemDefinitionProvider().getQNodeDefinition(parentState, nodeName, nodeTypeName);
 
                 // check same-name sibling setting of both target and existing node
                 if (!(conflictDef.allowsSameNameSiblings() && newDef.allowsSameNameSiblings())) {

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?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- 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 Tue Mar 20 07:35:56 2007
@@ -22,7 +22,7 @@
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry;
 import org.apache.jackrabbit.jcr2spi.util.StateUtility;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.ItemId;
@@ -74,8 +74,8 @@
     protected NodeState(NodeEntry entry, QName nodeTypeName, QName[] mixinTypeNames,
                         QNodeDefinition definition, int initialStatus,
                         boolean isWorkspaceState,
-                        ItemStateFactory isf, NodeTypeRegistry ntReg) {
-        super(initialStatus, isWorkspaceState, isf, ntReg);
+                        ItemStateFactory isf, ItemDefinitionProvider definitionProvider) {
+        super(initialStatus, isWorkspaceState, isf, definitionProvider);
         this.hierarchyEntry = entry;
         this.nodeTypeName = nodeTypeName;
         setMixinTypeNames(mixinTypeNames);
@@ -251,7 +251,7 @@
      */
     public QNodeDefinition getDefinition() throws RepositoryException {
         if (definition == null) {
-            definition = getEffectiveParentNodeType().getApplicableNodeDefinition(getQName(), getNodeTypeName(), getNodeTypeRegistry());
+            definition = definitionProvider.getQNodeDefinition(this);
         }
         return definition;
     }

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?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- 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 Tue Mar 20 07:35:56 2007
@@ -26,7 +26,7 @@
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.jcr2spi.nodetype.ValueConstraint;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry;
@@ -94,8 +94,8 @@
      */
     protected PropertyState(PropertyEntry entry, boolean multiValued, QPropertyDefinition definition,
                             int initialStatus, boolean isWorkspaceState,
-                            ItemStateFactory isf, NodeTypeRegistry ntReg) {
-        super(initialStatus, isWorkspaceState, isf, ntReg);
+                            ItemStateFactory isf, ItemDefinitionProvider definitionProvider) {
+        super(initialStatus, isWorkspaceState, isf, definitionProvider);
 
         this.hierarchyEntry = entry;
         this.definition = definition;
@@ -224,7 +224,7 @@
      */
     public QPropertyDefinition getDefinition() throws RepositoryException {
         if (definition == null) {
-            definition = getEffectiveParentNodeType().getApplicablePropertyDefinition(getQName(), getType(), isMultiValued());
+            definition = definitionProvider.getQPropertyDefinition(this);
         }
         return definition;
     }

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?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- 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 Tue Mar 20 07:35:56 2007
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.jcr2spi.util.ReferenceChangeTracker;
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
+import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
 import org.apache.jackrabbit.jcr2spi.operation.OperationVisitor;
 import org.apache.jackrabbit.jcr2spi.operation.AddNode;
@@ -44,6 +45,7 @@
 import org.apache.jackrabbit.jcr2spi.operation.WorkspaceImport;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
+import org.apache.jackrabbit.jcr2spi.ManagerProvider;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -95,15 +97,18 @@
 
     private final QValueFactory qValueFactory;
 
+    private final ManagerProvider mgrProvider;
+
     /**
      * Creates a new <code>SessionItemStateManager</code> instance.
      *
      * @param workspaceItemStateMgr
+     * @param definitionProvider
      */
     public SessionItemStateManager(UpdatableItemStateManager workspaceItemStateMgr,
                                    ItemStateValidator validator,
                                    QValueFactory qValueFactory,
-                                   ItemStateFactory isf) {
+                                   ItemStateFactory isf, ManagerProvider mgrProvider) {
         
         this.workspaceItemStateMgr = workspaceItemStateMgr;
         this.transientStateMgr = new TransientItemStateManager();
@@ -111,6 +116,7 @@
 
         this.validator = validator;
         this.qValueFactory = qValueFactory;
+        this.mgrProvider = mgrProvider;
     }
 
     /**
@@ -252,7 +258,8 @@
             | ItemStateValidator.CHECK_VERSIONING | ItemStateValidator.CHECK_CONSTRAINTS;
 
         NodeState parent = operation.getParentState();
-        QNodeDefinition def = validator.getApplicableNodeDefinition(operation.getNodeName(), operation.getNodeTypeName(), parent);
+        ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
+        QNodeDefinition def = defProvider.getQNodeDefinition(parent, operation.getNodeName(), operation.getNodeTypeName());
         addNodeState(parent, operation.getNodeName(), operation.getNodeTypeName(), operation.getUuid(), def, options);
 
         transientStateMgr.addOperation(operation);
@@ -307,7 +314,8 @@
             | ItemStateValidator.CHECK_CONSTRAINTS);
         
         // retrieve applicable definition at the new place
-        QNodeDefinition newDefinition = validator.getApplicableNodeDefinition(operation.getDestinationName(), srcState.getNodeTypeName(), destParent);
+        ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
+        QNodeDefinition newDefinition = defProvider.getQNodeDefinition(destParent, operation.getDestinationName(), srcState.getNodeTypeName());
 
         // perform the move (modifying states)
         srcParent.moveChildNodeEntry(destParent, srcState, operation.getDestinationName(), newDefinition);
@@ -354,8 +362,8 @@
                 setPropertyStateValue(pState, getQValues(mixinNames, qValueFactory), PropertyType.NAME, options);
             } else {
                 // create new jcr:mixinTypes property
-                EffectiveNodeType ent = validator.getEffectiveNodeType(nState);
-                QPropertyDefinition pd = ent.getApplicablePropertyDefinition(QName.JCR_MIXINTYPES, PropertyType.NAME, true);
+                ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
+                QPropertyDefinition pd = defProvider.getQPropertyDefinition(nState, QName.JCR_MIXINTYPES, PropertyType.NAME, true);
                 QValue[] mixinValue = getQValues(mixinNames, qValueFactory);
                 int options = ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_VERSIONING;
                 addPropertyState(nState, pd.getQName(), pd.getRequiredType(), mixinValue, pd, options);
@@ -601,7 +609,7 @@
         // autocreated child nodes that may be 'protected'.
         validator.checkAddNode(parent, nodeName, nodeTypeName, options);
         // a new NodeState doesn't have mixins defined yet -> ent is ent of primarytype
-        EffectiveNodeType ent = validator.getEffectiveNodeType(nodeTypeName);
+        EffectiveNodeType ent = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeTypeName);
 
         if (nodeTypeName == null) {
             // no primary node type specified,
@@ -619,13 +627,13 @@
         NodeState nodeState = transientStateMgr.createNewNodeState(nodeName, null, nodeTypeName, definition, parent);
         if (uuid != null) {
             QValue[] value = getQValues(uuid, qValueFactory);
-            EffectiveNodeType effnt = validator.getEffectiveNodeType(QName.MIX_REFERENCEABLE);
-            QPropertyDefinition pDef = effnt.getApplicablePropertyDefinition(QName.JCR_UUID, PropertyType.STRING, false);
+            ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
+            QPropertyDefinition pDef = defProvider.getQPropertyDefinition(QName.MIX_REFERENCEABLE, QName.JCR_UUID, PropertyType.STRING, false);
             addPropertyState(nodeState, QName.JCR_UUID, PropertyType.STRING, value, pDef, 0);
         }
 
         // add 'auto-create' properties defined in node type
-        QPropertyDefinition[] pda = ent.getAutoCreatePropDefs();
+        QPropertyDefinition[] pda = ent.getAutoCreateQPropertyDefinitions();
         for (int i = 0; i < pda.length; i++) {
             QPropertyDefinition pd = pda[i];
             if (!nodeState.hasPropertyName(pd.getQName())) {
@@ -639,7 +647,7 @@
         }
 
         // recursively add 'auto-create' child nodes defined in node type
-        QNodeDefinition[] nda = ent.getAutoCreateNodeDefs();
+        QNodeDefinition[] nda = ent.getAutoCreateQNodeDefinitions();
         for (int i = 0; i < nda.length; i++) {
             QNodeDefinition nd = nda[i];
             // execute 'addNode' without adding the operation.

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java Tue Mar 20 07:35:56 2007
@@ -25,7 +25,7 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
-import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ItemNotFoundException;
@@ -39,11 +39,11 @@
     private static Logger log = LoggerFactory.getLogger(TransientISFactory.class);
 
     private final ItemStateFactory workspaceStateFactory;
-    private final NodeTypeRegistry ntReg;
+    private final ItemDefinitionProvider defProvider;
 
-    public TransientISFactory(ItemStateFactory workspaceStateFactory, NodeTypeRegistry ntReg) {
+    public TransientISFactory(ItemStateFactory workspaceStateFactory, ItemDefinitionProvider defProvider) {
         this.workspaceStateFactory = workspaceStateFactory;
-        this.ntReg = ntReg;
+        this.defProvider = defProvider;
     }
 
     //------------------------------------------< TransientItemStateFactory >---
@@ -54,7 +54,7 @@
     public NodeState createNewNodeState(NodeEntry entry, QName nodetypeName,
                                         QNodeDefinition definition) {
 
-        NodeState nodeState = new NodeState(entry, nodetypeName, QName.EMPTY_ARRAY, definition, Status.NEW, false, this, ntReg);
+        NodeState nodeState = new NodeState(entry, nodetypeName, QName.EMPTY_ARRAY, definition, Status.NEW, false, this, defProvider);
 
         // notify listeners that a node state has been created
         notifyCreated(nodeState);
@@ -67,7 +67,7 @@
      * @see TransientItemStateFactory#createNewPropertyState(PropertyEntry, QPropertyDefinition)
      */
     public PropertyState createNewPropertyState(PropertyEntry entry, QPropertyDefinition definition) {
-        PropertyState propState = new PropertyState(entry, definition.isMultiple(), definition, Status.NEW, false, this, ntReg);
+        PropertyState propState = new PropertyState(entry, definition.isMultiple(), definition, Status.NEW, false, this, defProvider);
 
         // notify listeners that a property state has been created
         notifyCreated(propState);



Mime
View raw message