jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r520408 [1/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
Author: angela
Date: Tue Mar 20 07:35:56 2007
New Revision: 520408

URL: http://svn.apache.org/viewvc?view=rev&rev=520408
Log:
- new interface EffectiveNodeTypeProvider
- new interface ItemDefinitionProvider
- limit access to NodeTypeRegistry and simplify the NodeTypeRegistry
  interface.
- avoid duplicate code dealing with logic of EffectiveNodeType
  and retrieval of QItemDefinitions.

Added:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java   (with props)
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java   (with props)
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProviderImpl.java   (with props)
Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ManagerProvider.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.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/nodetype/DefinitionValidator.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistry.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.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/TransientISFactory.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/xml/SessionImporter.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ManagerProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ManagerProvider.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ManagerProvider.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ManagerProvider.java Tue Mar 20 07:35:56 2007
@@ -21,6 +21,12 @@
 import org.apache.jackrabbit.jcr2spi.security.AccessManager;
 import org.apache.jackrabbit.jcr2spi.lock.LockManager;
 import org.apache.jackrabbit.jcr2spi.version.VersionManager;
+import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
+import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider;
+import org.apache.jackrabbit.spi.QValueFactory;
+
+import javax.jcr.ValueFactory;
+import javax.jcr.RepositoryException;
 
 /**
  * <code>ManagerProvider</code>...
@@ -33,7 +39,38 @@
 
     public AccessManager getAccessManager();
 
+    /**
+     * Returns the <code>AccessManager</code> associated with this
+     * <code>ManagerProvider</code>.
+     *
+     * @return the <code>AccessManager</code> associated with this
+     * <code>ManagerProvider</code>
+     */
     public LockManager getLockManager();
 
+    /**
+     * Returns the <code>VersionManager</code> associated with this
+     * <code>ManagerProvider</code>.
+     *
+     * @return the <code>VersionManager</code> associated with this
+     * <code>ManagerProvider</code>
+     */
     public VersionManager getVersionManager();
+
+    public ItemDefinitionProvider getItemDefinitionProvider();
+
+    public EffectiveNodeTypeProvider getEffectiveNodeTypeProvider();
+
+    /**
+     * Same as {@link Session#getValueFactory()} but omits the check, if this repository
+     * is really level 2 compliant. Therefore, this method may be used for
+     * internal functionality only, that require creation and conversion of
+     * JCR values.
+     *
+     * @return
+     * @throws RepositoryException
+     */
+    public ValueFactory getJcrValueFactory() throws RepositoryException;
+
+    public QValueFactory getQValueFactory() throws RepositoryException;
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java Tue Mar 20 07:35:56 2007
@@ -689,7 +689,7 @@
             QName[] allRemaining = (QName[]) mixinValue.toArray(new QName[mixinValue.size() + 1]);
             allRemaining[mixinValue.size()] = primaryTypeName;
             try {
-                entRemaining = session.getValidator().getEffectiveNodeType(allRemaining);
+                entRemaining = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(allRemaining);
             } catch (NodeTypeConflictException e) {
                 throw new ConstraintViolationException(e);
             }
@@ -1192,7 +1192,7 @@
 
         // check effective node type
         try {
-            EffectiveNodeType effnt = session.getValidator().getEffectiveNodeType(getNodeState().getNodeTypeNames());
+            EffectiveNodeType effnt = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(getNodeState().getNodeTypeNames());
             return effnt.includesNodeType(qName);
         } catch (NodeTypeConflictException e) {
             throw new RepositoryException(e);
@@ -1309,7 +1309,7 @@
         throws ItemExistsException, NoSuchNodeTypeException, VersionException,
         ConstraintViolationException, LockException, RepositoryException {
 
-        QNodeDefinition definition = session.getValidator().getApplicableNodeDefinition(nodeName, nodeTypeName, getNodeState());
+        QNodeDefinition definition = session.getItemDefinitionProvider().getQNodeDefinition(getNodeState(), nodeName, nodeTypeName);
         if (nodeTypeName == null) {
             // use default node type
             nodeTypeName = definition.getDefaultPrimaryType();
@@ -1475,7 +1475,7 @@
         // get list of existing nodetypes
         QName[] existingNts = getNodeState().getNodeTypeNames();
         // build effective node type representing primary type including existing mixin's
-        EffectiveNodeType entExisting = session.getValidator().getEffectiveNodeType(existingNts);
+        EffectiveNodeType entExisting = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(existingNts);
 
         // check if adding new mixin conflicts with existing nodetypes
         if (entExisting.includesNodeType(mixinName)) {
@@ -1488,7 +1488,7 @@
         QName[] resultingNts = new QName[existingNts.length + 1];
         System.arraycopy(existingNts, 0, resultingNts, 0, existingNts.length);
         resultingNts[existingNts.length] = mixinName;
-        session.getValidator().getEffectiveNodeType(resultingNts);
+        session.getEffectiveNodeTypeProvider().getEffectiveNodeType(resultingNts);
 
         // all validations succeeded: return true
         return true;
@@ -1672,7 +1672,6 @@
                                                                 int type,
                                                                 boolean multiValued)
             throws ConstraintViolationException, RepositoryException {
-        ItemStateValidator validator = session.getValidator();
-        return validator.getApplicablePropertyDefinition(propertyName, type, multiValued, getNodeState());
+        return session.getItemDefinitionProvider().getQPropertyDefinition(getNodeState(), propertyName, type, multiValued);
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java Tue Mar 20 07:35:56 2007
@@ -261,7 +261,7 @@
      */
     public Value getValue() throws ValueFormatException, RepositoryException {
         QValue value = getQValue();
-        return ValueFormat.getJCRValue(value, session.getNamespaceResolver(), session.internalGetValueFactory());
+        return ValueFormat.getJCRValue(value, session.getNamespaceResolver(), session.getJcrValueFactory());
     }
 
     /**
@@ -271,7 +271,7 @@
         QValue[] qValues = getQValues();
         Value[] values = new Value[qValues.length];
         for (int i = 0; i < qValues.length; i++) {
-            values[i] = ValueFormat.getJCRValue(qValues[i], session.getNamespaceResolver(), session.internalGetValueFactory());
+            values[i] = ValueFormat.getJCRValue(qValues[i], session.getNamespaceResolver(), session.getJcrValueFactory());
         }
         return values;
     }
@@ -365,7 +365,7 @@
                 length = value.getLength();
                 break;
             case PropertyType.NAME:
-                Value jcrValue = ValueFormat.getJCRValue(value, session.getNamespaceResolver(), session.internalGetValueFactory());
+                Value jcrValue = ValueFormat.getJCRValue(value, session.getNamespaceResolver(), session.getJcrValueFactory());
                 length = jcrValue.getString().length();
                 break;
         }

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?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- 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 Tue Mar 20 07:35:56 2007
@@ -20,6 +20,8 @@
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
+import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider;
 import org.apache.jackrabbit.jcr2spi.security.AccessManager;
 import org.apache.jackrabbit.jcr2spi.state.SessionItemStateManager;
 import org.apache.jackrabbit.jcr2spi.state.UpdatableItemStateManager;
@@ -136,8 +138,8 @@
         nsMappings = new LocalNamespaceMappings(workspace.getNamespaceRegistryImpl());
 
         // build nodetype manager
-        ntManager = new NodeTypeManagerImpl(workspace.getNodeTypeRegistry(), getNamespaceResolver(), internalGetValueFactory(), getQValueFactory());
-        validator = new ItemStateValidator(workspace.getNodeTypeRegistry(), this);
+        ntManager = new NodeTypeManagerImpl(workspace.getNodeTypeRegistry(), this, getJcrValueFactory(), getQValueFactory());
+        validator = new ItemStateValidator(this);
 
         itemStateManager = createSessionItemStateManager(workspace.getUpdatableItemStateManager(), workspace.getItemStateFactory());
         itemManager = createItemManager(getHierarchyManager());
@@ -338,20 +340,7 @@
         // must throw UnsupportedRepositoryOperationException if writing is
         // not supported
         checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
-        return internalGetValueFactory();
-    }
-
-    /**
-     * Same as {@link #getValueFactory()} but omits the check, if this repository
-     * is really level 2 compliant. Therefore, this method may be used for
-     * internal functionality only, that require creation and conversion of
-     * JCR values.
-     *
-     * @return
-     * @throws RepositoryException
-     */
-    ValueFactory internalGetValueFactory() throws RepositoryException {
-        return config.getValueFactory();
+        return getJcrValueFactory();
     }
 
     /**
@@ -653,7 +642,7 @@
     }
 
     protected SessionItemStateManager createSessionItemStateManager(UpdatableItemStateManager workspaceStateManager, ItemStateFactory isf) throws RepositoryException {
-        return new SessionItemStateManager(workspaceStateManager, getValidator(), getQValueFactory(), isf);
+        return new SessionItemStateManager(workspaceStateManager, getValidator(), getQValueFactory(), isf, this);
     }
     
     protected ItemManager createItemManager(HierarchyManager hierarchyManager) {
@@ -683,9 +672,6 @@
     }
 
     /**
-     * Returns the <code>AccessManager</code> associated with this session.
-     *
-     * @return the <code>AccessManager</code> associated with this session
      * @see ManagerProvider#getAccessManager()
      */
     public AccessManager getAccessManager() {
@@ -693,15 +679,40 @@
     }
 
     /**
-     * Returns the <code>VersionManager</code> associated with this session.
-     *
-     * @return the <code>VersionManager</code> associated with this session
      * @see ManagerProvider#getVersionManager()
      */
     public VersionManager getVersionManager() {
         return workspace.getVersionManager();
     }
 
+    /**
+     * @see ManagerProvider#getItemDefinitionProvider()
+     */
+    public ItemDefinitionProvider getItemDefinitionProvider() {
+        return workspace.getItemDefinitionProvider();
+    }
+
+    /**
+     * @see ManagerProvider#getEffectiveNodeTypeProvider()
+     */
+    public EffectiveNodeTypeProvider getEffectiveNodeTypeProvider() {
+        return workspace.getEffectiveNodeTypeProvider();
+    }
+
+    /**
+     * @see ManagerProvider#getQValueFactory()
+     */
+    public QValueFactory getQValueFactory() throws RepositoryException {
+        return config.getRepositoryService().getQValueFactory();
+    }
+
+    /**
+     * @see ManagerProvider#getJcrValueFactory()
+     */
+    public ValueFactory getJcrValueFactory() throws RepositoryException {
+        return config.getValueFactory();
+    }
+
     //--------------------------------------------------------------------------
 
     LocalNamespaceMappings getLocalNamespaceMappings() {
@@ -720,10 +731,6 @@
     // TODO public for SessionImport only. review
     public IdFactory getIdFactory() {
         return workspace.getIdFactory();
-    }
-
-    public QValueFactory getQValueFactory() throws RepositoryException {
-        return config.getRepositoryService().getQValueFactory();
     }
 
     /**

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?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- 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 Tue Mar 20 07:35:56 2007
@@ -24,6 +24,8 @@
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateFactory;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
+import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider;
 import org.apache.jackrabbit.jcr2spi.query.QueryManagerImpl;
 import org.apache.jackrabbit.jcr2spi.operation.Move;
 import org.apache.jackrabbit.jcr2spi.operation.Copy;
@@ -43,6 +45,7 @@
 import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.name.Path;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -67,6 +70,7 @@
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.InvalidSerializedDataException;
+import javax.jcr.ValueFactory;
 import java.io.InputStream;
 import java.io.IOException;
 
@@ -385,6 +389,25 @@
             versionManager = createVersionManager(wspManager);
         }
         return versionManager;
+    }
+
+    /**
+     * @see ManagerProvider#getItemDefinitionProvider()
+     */
+    public ItemDefinitionProvider getItemDefinitionProvider() {
+        return wspManager.getItemDefinitionProvider();
+    }
+
+    public EffectiveNodeTypeProvider getEffectiveNodeTypeProvider() {
+        return wspManager.getEffectiveNodeTypeProvider();
+    }
+
+    public ValueFactory getJcrValueFactory() throws RepositoryException {
+        return session.getJcrValueFactory();
+    }
+
+    public QValueFactory getQValueFactory() throws RepositoryException {
+        return session.getQValueFactory();
     }
 
     //------------------------------------< implementation specific methods >---

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?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- 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 Tue Mar 20 07:35:56 2007
@@ -19,6 +19,9 @@
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistryImpl;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeStorage;
+import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
+import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProviderImpl;
+import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider;
 import org.apache.jackrabbit.jcr2spi.name.NamespaceStorage;
 import org.apache.jackrabbit.jcr2spi.name.NamespaceRegistryImpl;
 import org.apache.jackrabbit.jcr2spi.state.ItemState;
@@ -129,6 +132,7 @@
 
     private final NamespaceRegistryImpl nsRegistry;
     private final NodeTypeRegistry ntRegistry;
+    private final ItemDefinitionProvider definitionProvider;
 
     /**
      * Mutex to synchronize the feed thread with client
@@ -158,8 +162,10 @@
 
         Map repositoryDescriptors = service.getRepositoryDescriptors();
         nsRegistry = createNamespaceRegistry(repositoryDescriptors);
-        ntRegistry = createNodeTypeRegistry(nsRegistry, repositoryDescriptors);
+        QNodeDefinition rootNodeDef = service.getNodeDefinition(sessionInfo, service.getRootId(sessionInfo));
+        ntRegistry = createNodeTypeRegistry(rootNodeDef, nsRegistry, repositoryDescriptors);
         changeFeed = createChangeFeed(pollTimeout);
+        definitionProvider = createDefinitionProvider(rootNodeDef, getEffectiveNodeTypeProvider());
 
         TransientItemStateFactory stateFactory = createItemStateFactory(ntRegistry);
         this.isf = stateFactory;
@@ -175,6 +181,14 @@
         return ntRegistry;
     }
 
+    public ItemDefinitionProvider getItemDefinitionProvider() {
+        return definitionProvider;
+    }
+
+    public EffectiveNodeTypeProvider getEffectiveNodeTypeProvider() {
+        return (NodeTypeRegistryImpl) ntRegistry;
+    }
+
     public HierarchyManager getHierarchyManager() {
         return hierarchyManager;
     }
@@ -335,8 +349,8 @@
      * @return
      */
     private TransientItemStateFactory createItemStateFactory(NodeTypeRegistry ntReg) {
-        ItemStateFactory isf = new WorkspaceItemStateFactory(service, sessionInfo, this);
-        TransientItemStateFactory tisf = new TransientISFactory(isf, ntReg);
+        ItemStateFactory isf = new WorkspaceItemStateFactory(service, sessionInfo, getItemDefinitionProvider());
+        TransientItemStateFactory tisf = new TransientISFactory(isf, getItemDefinitionProvider());
         return tisf;
     }
 
@@ -375,8 +389,7 @@
      * @return
      * @throws RepositoryException
      */
-    private NodeTypeRegistry createNodeTypeRegistry(NamespaceRegistry nsRegistry, Map descriptors) throws RepositoryException {
-        QNodeDefinition rootNodeDef = service.getNodeDefinition(sessionInfo, service.getRootId(sessionInfo));
+    private NodeTypeRegistry createNodeTypeRegistry(QNodeDefinition rootNodeDef, NamespaceRegistry nsRegistry, Map descriptors) throws RepositoryException {
         QNodeTypeDefinitionIterator it = service.getNodeTypeDefinitions(sessionInfo);
         List ntDefs = new ArrayList();
         while (it.hasNext()) {
@@ -394,6 +407,15 @@
             }
         };
         return NodeTypeRegistryImpl.create(ntDefs, ntst, rootNodeDef, nsRegistry);
+    }
+
+    /**
+     *
+     * @param ntReg
+     * @return
+     */
+    private ItemDefinitionProvider createDefinitionProvider(QNodeDefinition rootDefinition, EffectiveNodeTypeProvider entProvider) {
+        return new ItemDefinitionProviderImpl(rootDefinition, entProvider, service, sessionInfo);
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java Tue Mar 20 07:35:56 2007
@@ -43,12 +43,12 @@
 
     private static Logger log = LoggerFactory.getLogger(DefinitionValidator.class);
 
-    private final NodeTypeRegistry ntRegistry;
+    private final EffectiveNodeTypeProvider entProvider;
     private final NamespaceRegistry nsRegistry;
 
 
-    DefinitionValidator(NodeTypeRegistry ntRegistry, NamespaceRegistry nsRegistry) {
-        this.ntRegistry = ntRegistry;
+    DefinitionValidator(EffectiveNodeTypeProvider entProvider, NamespaceRegistry nsRegistry) {
+        this.entProvider = entProvider;
         this.nsRegistry = nsRegistry;
     }
 
@@ -185,7 +185,7 @@
          */
         if (supertypes.length > 0) {
             try {
-                EffectiveNodeType est = ntRegistry.getEffectiveNodeType(supertypes, validatedDefs);
+                EffectiveNodeType est = entProvider.getEffectiveNodeType(supertypes, validatedDefs);
                 // make sure that all primary types except nt:base extend from nt:base
                 if (!ntDef.isMixin() && !QName.NT_BASE.equals(ntDef.getQName())
                         && !est.includesNodeType(QName.NT_BASE)) {
@@ -330,14 +330,14 @@
                  */
                 try {
                     if (!referenceToSelf) {
-                        defaultENT = ntRegistry.getEffectiveNodeType(new QName[] {dpt}, validatedDefs);
+                        defaultENT = entProvider.getEffectiveNodeType(new QName[] {dpt}, validatedDefs);
                     } else {
                         /**
                          * the default primary type is identical with the node
                          * type just being registered; we have to instantiate it
                          * 'manually'
                          */
-                        ent = EffectiveNodeTypeImpl.create(ntRegistry, ntDef, validatedDefs);
+                        ent = EffectiveNodeTypeImpl.create(entProvider, ntDef, validatedDefs);
                         defaultENT = ent;
                     }
                     if (cnd.isAutoCreated()) {
@@ -404,7 +404,7 @@
                      */
                     try {
                         if (!referenceToSelf) {
-                            ntRegistry.getEffectiveNodeType(new QName[] {rpt}, validatedDefs);
+                            entProvider.getEffectiveNodeType(new QName[] {rpt}, validatedDefs);
                         } else {
                             /**
                              * the required primary type is identical with the
@@ -412,7 +412,7 @@
                              * instantiate it 'manually'
                              */
                             if (ent == null) {
-                                ent = EffectiveNodeTypeImpl.create(ntRegistry, ntDef, validatedDefs);
+                                ent = EffectiveNodeTypeImpl.create(entProvider, ntDef, validatedDefs);
                             }
                         }
                     } catch (NodeTypeConflictException ntce) {
@@ -437,7 +437,7 @@
          */
         if (ent == null) {
             try {
-                ent = EffectiveNodeTypeImpl.create(ntRegistry, ntDef, validatedDefs);
+                ent = EffectiveNodeTypeImpl.create(entProvider, ntDef, validatedDefs);
             } catch (NodeTypeConflictException ntce) {
                 String msg = "[" + name + "] failed to resolve node type definition";
                 log.debug(msg);
@@ -526,7 +526,7 @@
             }
         }
 
-        QNodeDefinition[] nodeDefs = childNodeENT.getAutoCreateNodeDefs();
+        QNodeDefinition[] nodeDefs = childNodeENT.getAutoCreateQNodeDefinitions();
         for (int i = 0; i < nodeDefs.length; i++) {
             QName dnt = nodeDefs[i].getDefaultPrimaryType();
             QName definingNT = nodeDefs[i].getDeclaringNodeType();
@@ -534,7 +534,7 @@
                 if (dnt != null) {
                     // check recursively
                     definingParentNTs.push(definingNT);
-                    EffectiveNodeType ent = ntRegistry.getEffectiveNodeType(new QName[] {dnt}, ntdMap);
+                    EffectiveNodeType ent = entProvider.getEffectiveNodeType(new QName[] {dnt}, ntdMap);
                     checkForCircularNodeAutoCreation(ent, definingParentNTs, ntdMap);
                     definingParentNTs.pop();
                 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java Tue Mar 20 07:35:56 2007
@@ -54,104 +54,42 @@
      */
     public boolean includesNodeTypes(QName[] nodeTypeNames);
 
-    public QNodeDefinition[] getAllNodeDefs();
+    public QNodeDefinition[] getAllQNodeDefinitions();
 
-    public QPropertyDefinition[] getAllPropDefs();
+    public QPropertyDefinition[] getAllQPropertyDefinitions();
 
-    public QNodeDefinition[] getAutoCreateNodeDefs();
+    public QNodeDefinition[] getAutoCreateQNodeDefinitions();
 
-    public QPropertyDefinition[] getAutoCreatePropDefs();
+    public QPropertyDefinition[] getAutoCreateQPropertyDefinitions();
 
-    public QPropertyDefinition[] getMandatoryPropDefs();
+    public QNodeDefinition[] getMandatoryQNodeDefinitions();
 
-    public QNodeDefinition[] getMandatoryNodeDefs();
+    public QPropertyDefinition[] getMandatoryQPropertyDefinitions();
 
-    /**
-     * Returns the applicable child node definition for a child node with the
-     * specified name and node type.
-     *
-     * @param name
-     * @param nodeTypeName
-     * @return
-     * @throws NoSuchNodeTypeException
-     * @throws ConstraintViolationException if no applicable child node definition
-     * could be found
-     */
-    public QNodeDefinition getApplicableNodeDefinition(QName name, QName nodeTypeName,
-                                                       NodeTypeRegistry ntReg)
-            throws NoSuchNodeTypeException, ConstraintViolationException;
+    public QNodeDefinition[] getNamedQNodeDefinitions(QName name);
 
-    /**
-     * Returns the applicable property definition for a property with the
-     * specified name, type and multiValued characteristic. 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
-     * @return
-     * @throws ConstraintViolationException if no applicable property definition
-     *                                      could be found
-     */
-    public QPropertyDefinition getApplicablePropertyDefinition(QName name, int type,
-                                                               boolean multiValued)
-            throws ConstraintViolationException;
+    public QPropertyDefinition[] getNamedQPropertyDefinitions(QName name);
 
-    /**
-     * Returns all applicable property definitions for a property with the
-     * specified name, type and multiValued characteristics.
-     * @throws ConstraintViolationException if no applicable property definition
-     *                                      could be found
-     */
-    public QPropertyDefinition[] getApplicablePropertyDefinitions(QName name, int type,
-                                                                  boolean multiValued)
-            throws ConstraintViolationException;
+    public QNodeDefinition[] getUnnamedQNodeDefinitions();
 
-    /**
-     * Returns the applicable property definition for a property with the
-     * specified name and type. The multiValued flag is not taken into account
-     * in the selection algorithm. Other than
-     * <code>{@link #getApplicablePropertyDefinition(QName, int, boolean)}</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
-     * @return
-     * @throws ConstraintViolationException if no applicable property definition
-     *                                      could be found
-     */
-    public QPropertyDefinition getApplicablePropertyDefinition(QName name, int type)
-            throws ConstraintViolationException;
+    public QPropertyDefinition[] getUnnamedQPropertyDefinitions();
 
     /**
      * @param name
-     * @param ntReg
+     * @param definitionProvider
      * @throws ConstraintViolationException
      */
-    public void checkAddNodeConstraints(QName name, NodeTypeRegistry ntReg)
+    public void checkAddNodeConstraints(QName name, ItemDefinitionProvider definitionProvider)
             throws ConstraintViolationException;
 
     /**
      * @param name
      * @param nodeTypeName
-     * @param ntReg
+     * @param definitionProvider
      * @throws ConstraintViolationException
      * @throws NoSuchNodeTypeException
      */
-    public void checkAddNodeConstraints(QName name, QName nodeTypeName, NodeTypeRegistry ntReg)
+    public void checkAddNodeConstraints(QName name, QName nodeTypeName, ItemDefinitionProvider definitionProvider)
             throws ConstraintViolationException, NoSuchNodeTypeException;
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java?view=diff&rev=520408&r1=520407&r2=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java Tue Mar 20 07:35:56 2007
@@ -24,11 +24,9 @@
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
-import javax.jcr.PropertyType;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -84,7 +82,7 @@
      * @throws NodeTypeConflictException
      * @throws NoSuchNodeTypeException
      */
-    static EffectiveNodeTypeImpl create(NodeTypeRegistry ntReg, QNodeTypeDefinition ntd, Map ntdMap)
+    static EffectiveNodeTypeImpl create(EffectiveNodeTypeProvider entProvider, QNodeTypeDefinition ntd, Map ntdMap)
             throws NodeTypeConflictException, NoSuchNodeTypeException {
         // create empty effective node type instance
         EffectiveNodeTypeImpl ent = new EffectiveNodeTypeImpl();
@@ -199,7 +197,7 @@
         // resolve supertypes recursively
         QName[] supertypes = ntd.getSupertypes();
         if (supertypes.length > 0) {
-            EffectiveNodeTypeImpl effSuperType = (EffectiveNodeTypeImpl)ntReg.getEffectiveNodeType(supertypes, ntdMap);
+            EffectiveNodeTypeImpl effSuperType = (EffectiveNodeTypeImpl)entProvider.getEffectiveNodeType(supertypes, ntdMap);
             ent.internalMerge(effSuperType, true);
         }
 
@@ -218,30 +216,30 @@
 
     //--------------------------------------------------< EffectiveNodeType >---
     /**
-     * @inheritDoc
+     * @see EffectiveNodeType#getInheritedNodeTypes()
      */
     public QName[] getInheritedNodeTypes() {
         return (QName[]) inheritedNodeTypes.toArray(new QName[inheritedNodeTypes.size()]);
     }
 
     /**
-     * @inheritDoc
+     * @see EffectiveNodeType#getAllNodeTypes()
      */
     public QName[] getAllNodeTypes() {
         return (QName[]) allNodeTypes.toArray(new QName[allNodeTypes.size()]);
     }
 
     /**
-     * @inheritDoc
+     * @see EffectiveNodeType#getMergedNodeTypes()
      */
     public QName[] getMergedNodeTypes() {
         return (QName[]) mergedNodeTypes.toArray(new QName[mergedNodeTypes.size()]);
     }
 
     /**
-     * @inheritDoc
+     * @see EffectiveNodeType#getAllQNodeDefinitions()
      */
-    public QNodeDefinition[] getAllNodeDefs() {
+    public QNodeDefinition[] getAllQNodeDefinitions() {
         if (namedItemDefs.size() == 0 && unnamedItemDefs.size() == 0) {
             return QNodeDefinition.EMPTY_ARRAY;
         }
@@ -271,9 +269,9 @@
     }
 
     /**
-     * @inheritDoc
+     * @see EffectiveNodeType#getAllQPropertyDefinitions()
      */
-    public QPropertyDefinition[] getAllPropDefs() {
+    public QPropertyDefinition[] getAllQPropertyDefinitions() {
         if (namedItemDefs.size() == 0 && unnamedItemDefs.size() == 0) {
             return QPropertyDefinition.EMPTY_ARRAY;
         }
@@ -303,9 +301,9 @@
     }
 
     /**
-     * @inheritDoc
+     * @see EffectiveNodeType#getAutoCreateQNodeDefinitions()
      */
-    public QNodeDefinition[] getAutoCreateNodeDefs() {
+    public QNodeDefinition[] getAutoCreateQNodeDefinitions() {
         // since auto-create items must have a name,
         // we're only searching the named item definitions
         if (namedItemDefs.size() == 0) {
@@ -330,9 +328,9 @@
     }
 
     /**
-     * @inheritDoc
+     * @see EffectiveNodeType#getAutoCreateQPropertyDefinitions()
      */
-    public QPropertyDefinition[] getAutoCreatePropDefs() {
+    public QPropertyDefinition[] getAutoCreateQPropertyDefinitions() {
         // since auto-create items must have a name,
         // we're only searching the named item definitions
         if (namedItemDefs.size() == 0) {
@@ -357,9 +355,9 @@
     }
 
     /**
-     * @inheritDoc
+     * @see EffectiveNodeType#getMandatoryQPropertyDefinitions()
      */
-    public QPropertyDefinition[] getMandatoryPropDefs() {
+    public QPropertyDefinition[] getMandatoryQPropertyDefinitions() {
         // since mandatory items must have a name,
         // we're only searching the named item definitions
         if (namedItemDefs.size() == 0) {
@@ -384,9 +382,9 @@
     }
 
     /**
-     * @inheritDoc
+     * @see EffectiveNodeType#getMandatoryQNodeDefinitions()
      */
-    public QNodeDefinition[] getMandatoryNodeDefs() {
+    public QNodeDefinition[] getMandatoryQNodeDefinitions() {
         // since mandatory items must have a name,
         // we're only searching the named item definitions
         if (namedItemDefs.size() == 0) {
@@ -411,6 +409,92 @@
     }
 
     /**
+     * @see EffectiveNodeType#getNamedQNodeDefinitions(QName)
+     */
+    public QNodeDefinition[] getNamedQNodeDefinitions(QName name) {
+        List list = (List) namedItemDefs.get(name);
+        if (list == null || list.size() == 0) {
+            return QNodeDefinition.EMPTY_ARRAY;
+        }
+        ArrayList defs = new ArrayList(list.size());
+        Iterator iter = list.iterator();
+        while (iter.hasNext()) {
+            QItemDefinition qDef = (QItemDefinition) iter.next();
+            if (qDef.definesNode()) {
+                defs.add(qDef);
+            }
+        }
+        if (defs.size() == 0) {
+            return QNodeDefinition.EMPTY_ARRAY;
+        }
+        return (QNodeDefinition[]) defs.toArray(new QNodeDefinition[defs.size()]);
+    }
+
+    /**
+     * @see EffectiveNodeType#getUnnamedQNodeDefinitions()
+     */
+    public QNodeDefinition[] getUnnamedQNodeDefinitions() {
+        if (unnamedItemDefs.size() == 0) {
+            return QNodeDefinition.EMPTY_ARRAY;
+        }
+        ArrayList defs = new ArrayList(unnamedItemDefs.size());
+        Iterator iter = unnamedItemDefs.iterator();
+        while (iter.hasNext()) {
+            QItemDefinition qDef = (QItemDefinition) iter.next();
+            if (qDef.definesNode()) {
+                defs.add(qDef);
+            }
+        }
+        if (defs.size() == 0) {
+            return QNodeDefinition.EMPTY_ARRAY;
+        }
+        return (QNodeDefinition[]) defs.toArray(new QNodeDefinition[defs.size()]);
+    }
+
+    /**
+     * @see EffectiveNodeType#getNamedQPropertyDefinitions(QName)
+     */
+    public QPropertyDefinition[] getNamedQPropertyDefinitions(QName name) {
+        List list = (List) namedItemDefs.get(name);
+        if (list == null || list.size() == 0) {
+            return QPropertyDefinition.EMPTY_ARRAY;
+        }
+        ArrayList defs = new ArrayList(list.size());
+        Iterator iter = list.iterator();
+        while (iter.hasNext()) {
+            QItemDefinition qDef = (QItemDefinition) iter.next();
+            if (!qDef.definesNode()) {
+                defs.add(qDef);
+            }
+        }
+        if (defs.size() == 0) {
+            return QPropertyDefinition.EMPTY_ARRAY;
+        }
+        return (QPropertyDefinition[]) defs.toArray(new QPropertyDefinition[defs.size()]);
+    }
+
+    /**
+     * @see EffectiveNodeType#getUnnamedQPropertyDefinitions()
+     */
+    public QPropertyDefinition[] getUnnamedQPropertyDefinitions() {
+        if (unnamedItemDefs.size() == 0) {
+            return QPropertyDefinition.EMPTY_ARRAY;
+        }
+        ArrayList defs = new ArrayList(unnamedItemDefs.size());
+        Iterator iter = unnamedItemDefs.iterator();
+        while (iter.hasNext()) {
+            QItemDefinition qDef = (QItemDefinition) iter.next();
+            if (!qDef.definesNode()) {
+                defs.add(qDef);
+            }
+        }
+        if (defs.size() == 0) {
+            return QPropertyDefinition.EMPTY_ARRAY;
+        }
+        return (QPropertyDefinition[]) defs.toArray(new QPropertyDefinition[defs.size()]);
+    }
+
+    /**
      * @inheritDoc
      */
     public boolean includesNodeType(QName nodeTypeName) {
@@ -426,11 +510,12 @@
 
     /**
      * @inheritDoc
+     * @see EffectiveNodeType#checkAddNodeConstraints(QName, ItemDefinitionProvider)
      */
-    public void checkAddNodeConstraints(QName name, NodeTypeRegistry ntReg)
+    public void checkAddNodeConstraints(QName name, ItemDefinitionProvider definitionProvider)
             throws ConstraintViolationException {
         try {
-            getApplicableNodeDefinition(name, null, ntReg);
+            definitionProvider.getQNodeDefinition(this, name, null);
         } catch (NoSuchNodeTypeException e) {
             String msg = "internal eror: inconsistent node type";
             log.debug(msg);
@@ -440,10 +525,11 @@
 
     /**
      * @inheritDoc
+     * @see EffectiveNodeType#checkAddNodeConstraints(QName, ItemDefinitionProvider)
      */
-    public void checkAddNodeConstraints(QName name, QName nodeTypeName, NodeTypeRegistry ntReg)
+    public void checkAddNodeConstraints(QName name, QName nodeTypeName, ItemDefinitionProvider definitionProvider)
             throws ConstraintViolationException, NoSuchNodeTypeException {
-        QNodeDefinition nd = getApplicableNodeDefinition(name, nodeTypeName, ntReg);
+        QNodeDefinition nd = definitionProvider.getQNodeDefinition(this, name, nodeTypeName);
         if (nd.isProtected()) {
             throw new ConstraintViolationException(name + " is protected");
         }
@@ -454,6 +540,7 @@
 
     /**
      * @inheritDoc
+     * @see EffectiveNodeType#checkRemoveItemConstraints(QName)
      */
     public void checkRemoveItemConstraints(QName name) throws ConstraintViolationException {
         /**
@@ -473,140 +560,6 @@
         }
     }
 
-    /**
-     * @inheritDoc
-     */
-    public QNodeDefinition getApplicableNodeDefinition(QName name, QName nodeTypeName,
-                                                       NodeTypeRegistry ntReg)
-            throws NoSuchNodeTypeException, ConstraintViolationException {
-        EffectiveNodeType entTarget;
-        if (nodeTypeName != null) {
-            entTarget = ntReg.getEffectiveNodeType(nodeTypeName);
-        } else {
-            entTarget = null;
-        }
-
-        // try named node definitions first
-        QItemDefinition[] defs = getNamedItemDefs(name);
-        if (defs != null) {
-            for (int i = 0; i < defs.length; i++) {
-                QItemDefinition def = defs[i];
-                if (def.definesNode()) {
-                    QNodeDefinition nd = (QNodeDefinition) def;
-                    // 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 = getUnnamedNodeDefs();
-        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);
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public QPropertyDefinition getApplicablePropertyDefinition(QName name, int type,
-                                                               boolean multiValued)
-        throws ConstraintViolationException {
-        // try named property definitions first
-        QPropertyDefinition match =
-                getMatchingPropDef(getNamedPropDefs(name), type, multiValued);
-        if (match != null) {
-            return match;
-        }
-
-        // no item with that name defined;
-        // try residual property definitions
-        match = getMatchingPropDef(getUnnamedPropDefs(), type, multiValued);
-        if (match != null) {
-            return match;
-        }
-
-        // no applicable definition found
-        throw new ConstraintViolationException("no matching property definition found for " + name);
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public QPropertyDefinition[] getApplicablePropertyDefinitions(QName name, int type, boolean multiValued) throws ConstraintViolationException {
-      
-        QPropertyDefinition named[] = getNamedPropDefs(name);
-        QPropertyDefinition unnamed[] = getUnnamedPropDefs();
-        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;
-        }
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public QPropertyDefinition getApplicablePropertyDefinition(QName name, int type)
-            throws ConstraintViolationException {
-        // try named property definitions first
-        QPropertyDefinition match = getMatchingPropDef(getNamedPropDefs(name), type);
-        if (match != null) {
-            return match;
-        }
-
-        // no item with that name defined;
-        // try residual property definitions
-        match = getMatchingPropDef(getUnnamedPropDefs(), type);
-        if (match != null) {
-            return match;
-        }
-
-        // no applicable definition found
-        throw new ConstraintViolationException("no matching property definition found for " + name);
-    }
-
     //---------------------------------------------< impl. specific methods >---
 
     private QItemDefinition[] getNamedItemDefs() {
@@ -624,172 +577,19 @@
         return (QItemDefinition[]) defs.toArray(new QItemDefinition[defs.size()]);
     }
 
-    private QItemDefinition[] getUnnamedItemDefs() {
-        if (unnamedItemDefs.size() == 0) {
-            return QItemDefinition.EMPTY_ARRAY;
-        }
-        return (QItemDefinition[]) unnamedItemDefs.toArray(new QItemDefinition[unnamedItemDefs.size()]);
-    }
-
     private QItemDefinition[] getNamedItemDefs(QName name) {
-        List defs = (List) namedItemDefs.get(name);
-        if (defs == null || defs.size() == 0) {
-            return QItemDefinition.EMPTY_ARRAY;
-        }
-        return (QItemDefinition[]) defs.toArray(new QItemDefinition[defs.size()]);
-    }
-
-    private QNodeDefinition[] getUnnamedNodeDefs() {
-        if (unnamedItemDefs.size() == 0) {
-            return QNodeDefinition.EMPTY_ARRAY;
-        }
-        ArrayList defs = new ArrayList(unnamedItemDefs.size());
-        Iterator iter = unnamedItemDefs.iterator();
-        while (iter.hasNext()) {
-            QItemDefinition qDef = (QItemDefinition) iter.next();
-            if (qDef.definesNode()) {
-                defs.add(qDef);
-            }
-        }
-        if (defs.size() == 0) {
-            return QNodeDefinition.EMPTY_ARRAY;
-        }
-        return (QNodeDefinition[]) defs.toArray(new QNodeDefinition[defs.size()]);
-    }
-
-    private QPropertyDefinition[] getNamedPropDefs(QName name) {
         List list = (List) namedItemDefs.get(name);
         if (list == null || list.size() == 0) {
-            return QPropertyDefinition.EMPTY_ARRAY;
-        }
-        ArrayList defs = new ArrayList(list.size());
-        Iterator iter = list.iterator();
-        while (iter.hasNext()) {
-            QItemDefinition qDef = (QItemDefinition) iter.next();
-            if (!qDef.definesNode()) {
-                defs.add(qDef);
-            }
-        }
-        if (defs.size() == 0) {
-            return QPropertyDefinition.EMPTY_ARRAY;
+            return QNodeDefinition.EMPTY_ARRAY;
         }
-        return (QPropertyDefinition[]) defs.toArray(new QPropertyDefinition[defs.size()]);
+        return (QItemDefinition[]) list.toArray(new QItemDefinition[list.size()]);
     }
 
-    private QPropertyDefinition[] getUnnamedPropDefs() {
+    private QItemDefinition[] getUnnamedItemDefs() {
         if (unnamedItemDefs.size() == 0) {
-            return QPropertyDefinition.EMPTY_ARRAY;
-        }
-        ArrayList defs = new ArrayList(unnamedItemDefs.size());
-        Iterator iter = unnamedItemDefs.iterator();
-        while (iter.hasNext()) {
-            QItemDefinition qDef = (QItemDefinition) iter.next();
-            if (!qDef.definesNode()) {
-                defs.add(qDef);
-            }
-        }
-        if (defs.size() == 0) {
-            return QPropertyDefinition.EMPTY_ARRAY;
-        }
-        return (QPropertyDefinition[]) defs.toArray(new QPropertyDefinition[defs.size()]);
-    }
-
-    private 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 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 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 QItemDefinition.EMPTY_ARRAY;
         }
-        return (QPropertyDefinition[])result.toArray(QPropertyDefinition.EMPTY_ARRAY);
+        return (QItemDefinition[]) unnamedItemDefs.toArray(new QItemDefinition[unnamedItemDefs.size()]);
     }
 
     /**

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java?view=auto&rev=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java (added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java Tue Mar 20 07:35:56 2007
@@ -0,0 +1,75 @@
+/*
+ * 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.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.jcr2spi.state.NodeState;
+
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import java.util.Map;
+
+/**
+ * <code>EffectiveNodeTypeProvider</code>...
+ */
+public interface EffectiveNodeTypeProvider {
+
+    /**
+     * Build the <code>EffectiveNodeType</code> from the given qualified
+     * <code>NodeType</code> name.
+     *
+     * @param ntName
+     * @return
+     * @throws NoSuchNodeTypeException
+     */
+    public EffectiveNodeType getEffectiveNodeType(QName ntName)
+            throws NoSuchNodeTypeException;
+
+    /**
+     * Build the <code>EffectiveNodeType</code> from the given qualified
+     * <code>NodeType</code> names.
+     *
+     * @param ntNames
+     * @return
+     * @throws NodeTypeConflictException
+     * @throws NoSuchNodeTypeException
+     */
+    public EffectiveNodeType getEffectiveNodeType(QName[] ntNames)
+            throws NodeTypeConflictException, NoSuchNodeTypeException;
+
+    /**
+     * @param ntNames
+     * @param ntdMap
+     * @return
+     * @throws NodeTypeConflictException
+     * @throws NoSuchNodeTypeException
+     */
+    public EffectiveNodeType getEffectiveNodeType(QName[] ntNames, Map ntdMap)
+            throws NodeTypeConflictException, NoSuchNodeTypeException;
+
+    /**
+     * Build the effective (i.e. merged and resolved) node type representation
+     * of the specified node's primary and mixin node types.
+     *
+     * @param nodeState
+     * @return
+     * @throws NoSuchNodeTypeException
+     */
+    public EffectiveNodeType getEffectiveNodeType(NodeState nodeState)
+            throws NoSuchNodeTypeException, ConstraintViolationException;
+
+}
\ No newline at end of file

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

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

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java?view=auto&rev=520408
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java (added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java Tue Mar 20 07:35:56 2007
@@ -0,0 +1,146 @@
+/*
+ * 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.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.NodeInfo;
+import org.apache.jackrabbit.spi.PropertyInfo;
+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.name.QName;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.ConstraintViolationException;
+
+/**
+ * <code>ItemDefinitionManager</code>...
+ */
+public interface ItemDefinitionProvider {
+
+    public QNodeDefinition getRootNodeDefinition();
+
+    public QNodeDefinition getQNodeDefinition(NodeEntry nodeEntry, NodeInfo nodeInfo);
+
+    public QNodeDefinition getQNodeDefinition(NodeState nodeState) throws RepositoryException;
+
+    /**
+     * Returns the applicable child node definition for a child node with the
+     * specified name and node type.
+     *
+     * @param parentState
+     * @param name
+     * @param nodeTypeName
+     * @return
+     * @throws NoSuchNodeTypeException
+     * @throws ConstraintViolationException if no applicable child node definition
+     * could be found
+     */
+    public QNodeDefinition getQNodeDefinition(NodeState parentState, QName name, QName nodeTypeName)
+            throws NoSuchNodeTypeException, ConstraintViolationException;
+
+    /**
+     * Returns the applicable child node definition for a child node with the
+     * specified name and node type.
+     *
+     * @param ent
+     * @param name
+     * @param nodeTypeName
+     * @return
+     * @throws NoSuchNodeTypeException
+     * @throws ConstraintViolationException if no applicable child node definition
+     * could be found
+     */
+    public QNodeDefinition getQNodeDefinition(EffectiveNodeType ent, QName name, QName nodeTypeName)
+            throws NoSuchNodeTypeException, ConstraintViolationException;
+
+    public QPropertyDefinition getQPropertyDefinition(PropertyEntry propertyEntry, PropertyInfo propInfo);
+
+    public QPropertyDefinition getQPropertyDefinition(PropertyState propertyState) throws RepositoryException;
+
+    /**
+     * Returns the applicable property definition for a property with the
+     * specified name, type and multiValued characteristic. If there more than
+     * one applicable definitions that would apply to the given params a
+     * ConstraintViolationException is thrown.
+     *
+     * @param ntName
+     * @param propName
+     * @param type
+     * @param multiValued
+     * @return
+     * @throws NoSuchNodeTypeException If no node type with name <code>ntName</code>
+     * exists.
+     * @throws ConstraintViolationException if no applicable property definition
+     *                                      could be found
+     */
+    public QPropertyDefinition getQPropertyDefinition(QName ntName,
+                                                      QName propName, int type,
+                                                      boolean multiValued)
+            throws ConstraintViolationException, NoSuchNodeTypeException;
+
+    /**
+     * Returns the applicable property definition for a property with the
+     * specified name, type and multiValued characteristic. 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 parentState
+     * @param name
+     * @param type
+     * @param multiValued
+     * @return
+     * @throws ConstraintViolationException if no applicable property definition
+     *                                      could be found
+     */
+    public QPropertyDefinition getQPropertyDefinition(NodeState parentState,
+                                                      QName name, int type,
+                                                      boolean multiValued)
+            throws ConstraintViolationException, NoSuchNodeTypeException;
+
+    /**
+     * Returns the applicable property definition for a property with the
+     * specified name and type. The multiValued flag is not taken into account
+     * in the selection algorithm. Other than
+     * <code>{@link #getApplicablePropertyDefinition(QName, int, boolean)}</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 parentState
+     * @param name
+     * @param type
+     * @return
+     * @throws ConstraintViolationException if no applicable property definition
+     *                                      could be found
+     */
+    public QPropertyDefinition getQPropertyDefinition(NodeState parentState, QName name, int type)
+            throws ConstraintViolationException, NoSuchNodeTypeException;
+}
\ No newline at end of file

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

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



Mime
View raw message