You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2009/10/21 13:38:44 UTC

svn commit: r827966 [5/15] - in /jackrabbit/sandbox/JCR-1456: ./ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/management/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/...

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java Wed Oct 21 11:38:31 2009
@@ -35,38 +35,37 @@
 import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.Value;
 import javax.jcr.ValueFactory;
-import javax.jcr.ValueFormatException;
 import javax.jcr.nodetype.InvalidNodeTypeDefinitionException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeDefinition;
 import javax.jcr.nodetype.NodeTypeExistsException;
 import javax.jcr.nodetype.NodeTypeIterator;
-import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.commons.collections.map.ReferenceMap;
 import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
 import org.apache.jackrabbit.commons.NamespaceHelper;
+import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.commons.cnd.ParseException;
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
 import org.apache.jackrabbit.core.util.Dumpable;
-import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
-import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping;
-import org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeTypeManager;
-import org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException;
-import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefReader;
-import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException;
-import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
+import org.apache.jackrabbit.spi.commons.nodetype.*;
+import org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.nodetype.QDefinitionBuilderFactory;
+import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
@@ -107,13 +106,13 @@
      * A cache for <code>PropertyDefinition</code> instances created by this
      * <code>NodeTypeManager</code>
      */
-    private final Map<PropDefId, PropertyDefinitionImpl> pdCache;
+    private final Map<QPropertyDefinition, PropertyDefinitionImpl> pdCache;
 
     /**
      * A cache for <code>NodeDefinition</code> instances created by this
      * <code>NodeTypeManager</code>
      */
-    private final Map<NodeDefId, NodeDefinitionImpl> ndCache;
+    private final Map<QNodeDefinition, NodeDefinitionImpl> ndCache;
 
     private final DataStore store;
 
@@ -143,7 +142,7 @@
 
         rootNodeDef =
             new NodeDefinitionImpl(ntReg.getRootNodeDef(), this, session);
-        ndCache.put(rootNodeDef.unwrap().getId(), rootNodeDef);
+        ndCache.put(rootNodeDef.unwrap(), rootNodeDef);
     }
 
     /**
@@ -154,36 +153,30 @@
     }
 
     /**
-     * @param id node def id
+     * @param def the QNodeDefinition
      * @return the node definition
      */
-    public NodeDefinitionImpl getNodeDefinition(NodeDefId id) {
+    public NodeDefinitionImpl getNodeDefinition(QNodeDefinition def) {
         synchronized (ndCache) {
-            NodeDefinitionImpl ndi = ndCache.get(id);
+            NodeDefinitionImpl ndi = ndCache.get(def);
             if (ndi == null) {
-                NodeDef nd = ntReg.getNodeDef(id);
-                if (nd != null) {
-                    ndi = new NodeDefinitionImpl(nd, this, session);
-                    ndCache.put(id, ndi);
-                }
+                ndi = new NodeDefinitionImpl(def, this, session);
+                ndCache.put(def, ndi);
             }
             return ndi;
         }
     }
 
     /**
-     * @param id prop def id
+     * @param def prop def
      * @return the property definition
      */
-    public PropertyDefinitionImpl getPropertyDefinition(PropDefId id) {
+    public PropertyDefinitionImpl getPropertyDefinition(QPropertyDefinition def) {
         synchronized (pdCache) {
-            PropertyDefinitionImpl pdi = pdCache.get(id);
+            PropertyDefinitionImpl pdi = pdCache.get(def);
             if (pdi == null) {
-                PropDef pd = ntReg.getPropDef(id);
-                if (pd != null) {
-                    pdi = new PropertyDefinitionImpl(pd, this, session, valueFactory);
-                    pdCache.put(id, pdi);
-                }
+                pdi = new PropertyDefinitionImpl(def, this, session, valueFactory);
+                pdCache.put(def, pdi);
             }
             return pdi;
         }
@@ -199,7 +192,7 @@
             NodeTypeImpl nt = ntCache.get(name);
             if (nt == null) {
                 EffectiveNodeType ent = ntReg.getEffectiveNodeType(name);
-                NodeTypeDef def = ntReg.getNodeTypeDef(name);
+                QNodeTypeDefinition def = ntReg.getNodeTypeDef(name);
                 nt = new NodeTypeImpl(ent, def, this, session, valueFactory, store);
                 ntCache.put(name, nt);
             }
@@ -208,7 +201,7 @@
     }
 
     /**
-     * @see org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeTypeManager#getNamePathResolver() 
+     * @see org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeTypeManager#getNamePathResolver()
      */
     public NamePathResolver getNamePathResolver() {
         return session;
@@ -242,7 +235,7 @@
 
         try {
             Map<String, String> namespaceMap = new HashMap<String, String>();
-            List<NodeTypeDef> nodeTypeDefs = new ArrayList<NodeTypeDef>();
+            List<QNodeTypeDefinition> nodeTypeDefs = new ArrayList<QNodeTypeDefinition>();
 
             if (contentType.equalsIgnoreCase(TEXT_XML)
                     || contentType.equalsIgnoreCase(APPLICATION_XML)) {
@@ -259,7 +252,7 @@
                         }
                     }
 
-                    NodeTypeDef[] defs = ntr.getNodeTypeDefs();
+                    QNodeTypeDefinition[] defs = ntr.getNodeTypeDefs();
                     nodeTypeDefs.addAll(Arrays.asList(defs));
                 } catch (NameException e) {
                     throw new RepositoryException("Illegal JCR name", e);
@@ -267,12 +260,15 @@
             } else if (contentType.equalsIgnoreCase(TEXT_X_JCR_CND)) {
                 try {
                     NamespaceMapping mapping = new NamespaceMapping(session);
-                    CompactNodeTypeDefReader reader = new CompactNodeTypeDefReader(
-                            new InputStreamReader(in), "cnd input stream", mapping);
+
+                    CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping> reader =
+                        new CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping>(
+                            new InputStreamReader(in), "cnd input stream", mapping,
+                            new QDefinitionBuilderFactory());
 
                     namespaceMap.putAll(mapping.getPrefixToURIMapping());
                     for (QNodeTypeDefinition ntDef: reader.getNodeTypeDefinitions()) {
-                        nodeTypeDefs.add(new NodeTypeDef(ntDef));
+                        nodeTypeDefs.add(ntDef);
                     }
                 } catch (ParseException e) {
                     IOException e2 = new IOException(e.getMessage());
@@ -290,9 +286,9 @@
                 // split the node types into new and already registered node types.
                 // this way we can register new node types together with already
                 // registered node types which make circular dependencies possible
-                List<NodeTypeDef> newNodeTypeDefs = new ArrayList<NodeTypeDef>();
-                List<NodeTypeDef> registeredNodeTypeDefs = new ArrayList<NodeTypeDef>();
-                for (NodeTypeDef nodeTypeDef: nodeTypeDefs) {
+                List<QNodeTypeDefinition> newNodeTypeDefs = new ArrayList<QNodeTypeDefinition>();
+                List<QNodeTypeDefinition> registeredNodeTypeDefs = new ArrayList<QNodeTypeDefinition>();
+                for (QNodeTypeDefinition nodeTypeDef: nodeTypeDefs) {
                     if (ntReg.isRegistered(nodeTypeDef.getName())) {
                         registeredNodeTypeDefs.add(nodeTypeDef);
                     } else {
@@ -306,7 +302,7 @@
                 nodeTypes.addAll(registerNodeTypes(newNodeTypeDefs));
 
                 // re-register already existing node types
-                for (NodeTypeDef nodeTypeDef: registeredNodeTypeDefs) {
+                for (QNodeTypeDefinition nodeTypeDef: registeredNodeTypeDefs) {
                     ntReg.reregisterNodeType(nodeTypeDef);
                     nodeTypes.add(getNodeType(nodeTypeDef.getName()));
                 }
@@ -347,7 +343,7 @@
         synchronized (ndCache) {
             Iterator iter = ndCache.values().iterator();
             while (iter.hasNext()) {
-                NodeDefinitionImpl nd = (NodeDefinitionImpl) iter.next();
+                NodeDefinitionImpl nd = (org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl) iter.next();
                 if (ntName.equals(nd.unwrap().getDeclaringNodeType())) {
                     iter.remove();
                 }
@@ -447,17 +443,17 @@
      * Internal helper method for registering a list of node type definitions.
      * Returns a collection containing the registered node types.
      *
-     * @param defs a collection of <code>NodeTypeDef<code> objects
+     * @param defs a collection of <code>QNodeTypeDefinition<code> objects
      * @return registered node types
      * @throws InvalidNodeTypeDefException if a nodetype is invalid
      * @throws RepositoryException if an error occurs
      */
-    private Collection<NodeType> registerNodeTypes(List<NodeTypeDef> defs)
+    private Collection<NodeType> registerNodeTypes(List<QNodeTypeDefinition> defs)
             throws InvalidNodeTypeDefException, RepositoryException {
         ntReg.registerNodeTypes(defs);
 
         Set<NodeType> types = new HashSet<NodeType>();
-        for (NodeTypeDef def : defs) {
+        for (QNodeTypeDefinition def : defs) {
             try {
                 types.add(getNodeType(def.getName()));
             } catch (NoSuchNodeTypeException e) {
@@ -566,11 +562,11 @@
         // split the node types into new and already registered node types.
         // this way we can register new node types together with already
         // registered node types which make circular dependencies possible
-        List<NodeTypeDef> addedDefs = new ArrayList<NodeTypeDef>();
-        List<NodeTypeDef> modifiedDefs = new ArrayList<NodeTypeDef>();
+        List<QNodeTypeDefinition> addedDefs = new ArrayList<QNodeTypeDefinition>();
+        List<QNodeTypeDefinition> modifiedDefs = new ArrayList<QNodeTypeDefinition>();
         for (NodeTypeDefinition definition : definitions) {
-            // convert to NodeTypeDef
-            NodeTypeDef def = toNodeTypeDef(definition);
+            // convert to QNodeTypeDefinition
+            QNodeTypeDefinition def = toNodeTypeDef(definition);
             if (ntReg.isRegistered(def.getName())) {
               if (allowUpdate) {
                   modifiedDefs.add(def);
@@ -589,7 +585,7 @@
             result.addAll(registerNodeTypes(addedDefs));
 
             // re-register already existing node types
-            for (NodeTypeDef nodeTypeDef: modifiedDefs) {
+            for (QNodeTypeDefinition nodeTypeDef: modifiedDefs) {
                 ntReg.reregisterNodeType(nodeTypeDef);
                 result.add(getNodeType(nodeTypeDef.getName()));
             }
@@ -640,180 +636,9 @@
      * @throws InvalidNodeTypeDefinitionException if the definiton is invalid
      * @throws RepositoryException if a repository error occurs
      */
-    private NodeTypeDef toNodeTypeDef(NodeTypeDefinition definition)
+    private QNodeTypeDefinition toNodeTypeDef(NodeTypeDefinition definition)
             throws InvalidNodeTypeDefinitionException, RepositoryException {
-        NodeTypeDef def = new NodeTypeDef();
-
-        // name
-        String name = definition.getName();
-        if (name == null) {
-            throw new InvalidNodeTypeDefinitionException("No node type name specified");
-        }
-        try {
-            def.setName(session.getQName(name));
-        } catch (NamespaceException e) {
-            throw new InvalidNodeTypeDefinitionException("Invalid name: " + name, e);
-        } catch (NameException e) {
-            throw new InvalidNodeTypeDefinitionException("Invalid name: " + name, e);
-        }
-
-        // supertypes
-        String[] names = definition.getDeclaredSupertypeNames();
-        Name[] qnames = new Name[names.length];
-        for (int i = 0; i < names.length; i++) {
-            try {
-                qnames[i] = session.getQName(names[i]);
-            } catch (NamespaceException e) {
-                throw new InvalidNodeTypeDefinitionException("Invalid supertype name: " + names[i], e);
-            } catch (NameException e) {
-                throw new InvalidNodeTypeDefinitionException("Invalid supertype name: " + names[i], e);
-            }
-        }
-        def.setSupertypes(qnames);
-
-        // primary item
-        name = definition.getPrimaryItemName();
-        if (name != null) {
-            try {
-                def.setPrimaryItemName(session.getQName(name));
-            } catch (NamespaceException e) {
-                throw new InvalidNodeTypeDefinitionException("Invalid primary item name: " + name, e);
-            } catch (NameException e) {
-                throw new InvalidNodeTypeDefinitionException("Invalid primary item name: " + name, e);
-            }
-        }
-
-        // misc. flags
-        def.setMixin(definition.isMixin());
-        def.setAbstract(definition.isAbstract());
-        def.setOrderableChildNodes(definition.hasOrderableChildNodes());
-
-        // child nodes
-        NodeDefinition[] ndefs = definition.getDeclaredChildNodeDefinitions();
-        if (ndefs != null) {
-            NodeDef[] qndefs = new NodeDef[ndefs.length];
-            for (int i = 0; i < ndefs.length; i++) {
-                NodeDefImpl qndef = new NodeDefImpl();
-                // declaring node type
-                qndef.setDeclaringNodeType(def.getName());
-                // name
-                name = ndefs[i].getName();
-                if (name != null) {
-                    if (name.equals("*")) {
-                        qndef.setName(ItemDef.ANY_NAME);
-                    } else {
-                        try {
-                            qndef.setName(session.getQName(name));
-                        } catch (NamespaceException e) {
-                            throw new InvalidNodeTypeDefinitionException("Invalid node name: " + name, e);
-                        } catch (NameException e) {
-                            throw new InvalidNodeTypeDefinitionException("Invalid node name: " + name, e);
-                        }
-                    }
-                }
-                // default primary type
-                name = ndefs[i].getDefaultPrimaryTypeName();
-                if (name != null) {
-                    try {
-                        qndef.setDefaultPrimaryType(session.getQName(name));
-                    } catch (NamespaceException e) {
-                        throw new InvalidNodeTypeDefinitionException("Invalid default primary type: " + name, e);
-                    } catch (NameException e) {
-                        throw new InvalidNodeTypeDefinitionException("Invalid default primary type: " + name, e);
-                    }
-                }
-                // required primary types
-                names = ndefs[i].getRequiredPrimaryTypeNames();
-                qnames = new Name[names.length];
-                for (int j = 0; j < names.length; j++) {
-                    try {
-                        qnames[j] = session.getQName(names[j]);
-                    } catch (NamespaceException e) {
-                        throw new InvalidNodeTypeDefinitionException("Invalid required primary type: " + names[j], e);
-                    } catch (NameException e) {
-                        throw new InvalidNodeTypeDefinitionException("Invalid required primary type: " + names[j], e);
-                    }
-                }
-                qndef.setRequiredPrimaryTypes(qnames);
-
-                // misc. flags/attributes
-                qndef.setAutoCreated(ndefs[i].isAutoCreated());
-                qndef.setMandatory(ndefs[i].isMandatory());
-                qndef.setProtected(ndefs[i].isProtected());
-                qndef.setOnParentVersion(ndefs[i].getOnParentVersion());
-                qndef.setAllowsSameNameSiblings(ndefs[i].allowsSameNameSiblings());
-
-                qndefs[i] = qndef;
-            }
-            def.setChildNodeDefs(qndefs);
-        }
-
-        // properties
-        PropertyDefinition[] pdefs = definition.getDeclaredPropertyDefinitions();
-        if (pdefs != null) {
-            PropDef[] qpdefs = new PropDef[pdefs.length];
-            for (int i = 0; i < pdefs.length; i++) {
-                PropDefImpl qpdef = new PropDefImpl();
-                // declaring node type
-                qpdef.setDeclaringNodeType(def.getName());
-                // name
-                name = pdefs[i].getName();
-                if (name != null) {
-                    if (name.equals("*")) {
-                        qpdef.setName(ItemDef.ANY_NAME);
-                    } else {
-                        try {
-                            qpdef.setName(session.getQName(name));
-                        } catch (NamespaceException e) {
-                            throw new InvalidNodeTypeDefinitionException("Invalid property name: " + name, e);
-                        } catch (NameException e) {
-                            throw new InvalidNodeTypeDefinitionException("Invalid property name: " + name, e);
-                        }
-                    }
-                }
-                // misc. flags/attributes
-                int type = pdefs[i].getRequiredType();
-                qpdef.setRequiredType(type);
-                qpdef.setAutoCreated(pdefs[i].isAutoCreated());
-                qpdef.setMandatory(pdefs[i].isMandatory());
-                qpdef.setProtected(pdefs[i].isProtected());
-                qpdef.setOnParentVersion(pdefs[i].getOnParentVersion());
-                qpdef.setMultiple(pdefs[i].isMultiple());
-                // value constraints
-                String[] constraints = pdefs[i].getValueConstraints();
-                if (constraints != null) {
-                    QValueConstraint[] qconstraints = new QValueConstraint[constraints.length];
-                    for (int j = 0; j < constraints.length; j++) {
-                        try {
-                            qconstraints[j] = ValueConstraint.create(type, constraints[j], session);
-                        } catch (InvalidConstraintException e) {
-                            throw new InvalidNodeTypeDefinitionException(
-                                    "Invalid value constraint: " + constraints[j], e);
-                        }
-                    }
-                    qpdef.setValueConstraints(qconstraints);
-                }
-                // default values
-                Value[] values = pdefs[i].getDefaultValues();
-                if (values != null) {
-                    InternalValue[] qvalues = new InternalValue[values.length];
-                    for (int j = 0; j < values.length; j++) {
-                        try {
-                            qvalues[j] = InternalValue.create(values[j], session);
-                        } catch (ValueFormatException e) {
-                            throw new InvalidNodeTypeDefinitionException(
-                                    "Invalid default value format: " + values[j], e);
-                        }
-                    }
-                    qpdef.setDefaultValues(qvalues);
-                }
-
-                qpdefs[i] = qpdef;
-            }
-            def.setPropertyDefs(qpdefs);
-        }
-
-        return def;
+        return new QNodeTypeDefinitionImpl(definition, session, QValueFactoryImpl.getInstance());
     }
 
     //-------------------------------------------------------------< Dumpable >

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java Wed Oct 21 11:38:31 2009
@@ -31,6 +31,8 @@
 import java.util.Set;
 import java.util.Stack;
 import java.util.TreeSet;
+import java.util.List;
+import java.util.ArrayList;
 
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.PropertyType;
@@ -47,11 +49,16 @@
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.util.Dumpable;
-import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder;
+import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -69,8 +76,6 @@
     private static final String CUSTOM_NODETYPES_RESOURCE_NAME =
             "custom_nodetypes.xml";
 
-    // file system where node type registrations are persisted
-    private final FileSystem ntStore;
     /**
      * resource holding custom node type definitions which are represented as
      * nodes in the repository; it is needed in order to make the registrations
@@ -86,15 +91,10 @@
     private EffectiveNodeTypeCache entCache;
 
     // map of node type names and node type definitions
-    private final Map<Name, NodeTypeDef> registeredNTDefs;
+    private final Map<Name, QNodeTypeDefinition> registeredNTDefs;
 
     // definition of the root node
-    private final NodeDef rootNodeDef;
-
-    // map of id's and property definitions
-    private final Map<PropDefId, PropDef> propDefs;
-    // map of id's and node definitions
-    private final Map<NodeDefId, NodeDef> nodeDefs;
+    private final QNodeDefinition rootNodeDef;
 
     /**
      * namespace registry for resolving prefixes and namespace URI's;
@@ -123,8 +123,7 @@
      */
     public static NodeTypeRegistry create(NamespaceRegistry nsReg, FileSystem ntStore)
             throws RepositoryException {
-        NodeTypeRegistry ntMgr = new NodeTypeRegistry(nsReg, ntStore);
-        return ntMgr;
+        return new NodeTypeRegistry(nsReg, ntStore);
     }
 
     //----------------------------------------< public NodeTypeRegistry 'api' >
@@ -175,7 +174,7 @@
      * @throws InvalidNodeTypeDefException if the given node type definition is invalid.
      * @throws RepositoryException if a repository error occurs.
      */
-    public synchronized EffectiveNodeType registerNodeType(NodeTypeDef ntd)
+    public synchronized EffectiveNodeType registerNodeType(QNodeTypeDefinition ntd)
             throws InvalidNodeTypeDefException, RepositoryException {
         // validate and register new node type definition
         EffectiveNodeType ent = internalRegister(ntd);
@@ -185,7 +184,7 @@
         persistCustomNodeTypeDefs(customNTDefs);
 
         if (eventChannel != null) {
-            Set<NodeTypeDef> ntDefs = new HashSet<NodeTypeDef>();
+            Set<QNodeTypeDefinition> ntDefs = new HashSet<QNodeTypeDefinition>();
             ntDefs.add(ntd);
             eventChannel.registered(ntDefs);
         }
@@ -197,18 +196,18 @@
     }
 
     /**
-     * Same as <code>{@link #registerNodeType(NodeTypeDef)}</code> except
+     * Same as <code>{@link #registerNodeType(QNodeTypeDefinition)}</code> except
      * that a collection of <code>NodeTypeDef</code>s is registered instead of
      * just one.
      * <p/>
      * This method can be used to register a set of node types that have
      * dependencies on each other.
      *
-     * @param ntDefs a collection of <code>NodeTypeDef<code> objects
+     * @param ntDefs a collection of <code>QNodeTypeDefinition<code> objects
      * @throws InvalidNodeTypeDefException if the given node type definition is invalid.
      * @throws RepositoryException if a repository error occurs.
      */
-    public void registerNodeTypes(Collection<NodeTypeDef> ntDefs)
+    public void registerNodeTypes(Collection<QNodeTypeDefinition> ntDefs)
             throws InvalidNodeTypeDefException, RepositoryException {
 
         registerNodeTypes(ntDefs, false);
@@ -217,19 +216,19 @@
     /**
      * Internal implementation of {@link #registerNodeTypes(Collection)}
      *
-     * @param ntDefs a collection of <code>NodeTypeDef<code> objects
+     * @param ntDefs a collection of <code>QNodeTypeDefinition<code> objects
      * @param external whether this invocation should be considered external
      * @throws InvalidNodeTypeDefException if the given node type definition is invalid.
      * @throws RepositoryException if a repository error occurs.
      */
-    private synchronized void registerNodeTypes(Collection<NodeTypeDef> ntDefs,
+    private synchronized void registerNodeTypes(Collection<QNodeTypeDefinition> ntDefs,
                                                 boolean external)
             throws InvalidNodeTypeDefException, RepositoryException {
 
         // validate and register new node type definitions
         internalRegister(ntDefs);
         // persist new node type definitions
-        for (NodeTypeDef ntDef: ntDefs) {
+        for (QNodeTypeDefinition ntDef: ntDefs) {
             customNTDefs.add(ntDef);
         }
         persistCustomNodeTypeDefs(customNTDefs);
@@ -240,7 +239,7 @@
         }
 
         // notify listeners
-        for (NodeTypeDef ntDef : ntDefs) {
+        for (QNodeTypeDefinition ntDef : ntDefs) {
             notifyRegistered(ntDef.getName());
         }
     }
@@ -357,7 +356,7 @@
      *                                     is invalid
      * @throws RepositoryException if another error occurs
      */
-    public EffectiveNodeType reregisterNodeType(NodeTypeDef ntd)
+    public EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd)
             throws NoSuchNodeTypeException, InvalidNodeTypeDefException,
             RepositoryException {
 
@@ -365,7 +364,7 @@
     }
 
     /**
-     * Internal implementation of {@link #reregisterNodeType(NodeTypeDef)}.
+     * Internal implementation of {@link #reregisterNodeType(QNodeTypeDefinition)}.
      *
      * @param ntd node type definition
      * @param external whether this invocation should be considered external
@@ -376,7 +375,7 @@
      *                                     is invalid
      * @throws RepositoryException if another error occurs
      */
-    private synchronized EffectiveNodeType reregisterNodeType(NodeTypeDef ntd,
+    private synchronized EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd,
                                                               boolean external)
             throws NoSuchNodeTypeException, InvalidNodeTypeDefException,
             RepositoryException {
@@ -393,13 +392,13 @@
         /**
          * validate new node type definition
          */
-        checkNtBaseSubtyping(ntd, registeredNTDefs);
+        ntd = checkNtBaseSubtyping(ntd, registeredNTDefs);
         validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
 
         /**
          * build diff of current and new definition and determine type of change
          */
-        NodeTypeDef ntdOld = registeredNTDefs.get(name);
+        QNodeTypeDefinition ntdOld = registeredNTDefs.get(name);
         NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntdOld, ntd);
         if (!diff.isModified()) {
             // the definition has not been modified, there's nothing to do here...
@@ -513,7 +512,7 @@
          * node type
          */
         HashSet<Name> names = new HashSet<Name>();
-        for (NodeTypeDef ntd : registeredNTDefs.values()) {
+        for (QNodeTypeDefinition ntd : registeredNTDefs.values()) {
             if (ntd.getDependencies().contains(nodeTypeName)) {
                 names.add(ntd.getName());
             }
@@ -529,14 +528,13 @@
      * @throws NoSuchNodeTypeException if a node type with the given name
      *                                 does not exist
      */
-    public NodeTypeDef getNodeTypeDef(Name nodeTypeName)
+    public QNodeTypeDefinition getNodeTypeDef(Name nodeTypeName)
             throws NoSuchNodeTypeException {
-        NodeTypeDef def = registeredNTDefs.get(nodeTypeName);
+        QNodeTypeDefinition def = registeredNTDefs.get(nodeTypeName);
         if (def == null) {
             throw new NoSuchNodeTypeException(nodeTypeName.toString());
         }
-        // return clone to make sure nobody messes around with the 'live' definition
-        return (NodeTypeDef) def.clone();
+        return def;
     }
 
     /**
@@ -558,22 +556,6 @@
     }
 
     /**
-     * @param id node def id
-     * @return the node definition for the given id.
-     */
-    public NodeDef getNodeDef(NodeDefId id) {
-        return nodeDefs.get(id);
-    }
-
-    /**
-     * @param id property def id
-     * @return the property definition for the given id.
-     */
-    public PropDef getPropDef(PropDefId id) {
-        return propDefs.get(id);
-    }
-
-    /**
      * Add a <code>NodeTypeRegistryListener</code>
      *
      * @param listener the new listener to be informed on (un)registration
@@ -603,7 +585,7 @@
         ps.println();
         ps.println("Registered NodeTypes:");
         ps.println();
-        for (NodeTypeDef ntd : registeredNTDefs.values()) {
+        for (QNodeTypeDefinition ntd : registeredNTDefs.values()) {
             ps.println(ntd.getName());
             Name[] supertypes = ntd.getSupertypes();
             ps.println("\tSupertypes");
@@ -613,10 +595,10 @@
             ps.println("\tMixin\t" + ntd.isMixin());
             ps.println("\tOrderableChildNodes\t" + ntd.hasOrderableChildNodes());
             ps.println("\tPrimaryItemName\t" + (ntd.getPrimaryItemName() == null ? "<null>" : ntd.getPrimaryItemName().toString()));
-            PropDef[] pd = ntd.getPropertyDefs();
-            for (PropDef aPd : pd) {
+            QPropertyDefinition[] pd = ntd.getPropertyDefs();
+            for (QPropertyDefinition aPd : pd) {
                 ps.print("\tPropertyDefinition");
-                ps.println(" (declared in " + aPd.getDeclaringNodeType() + ") id=" + aPd.getId());
+                ps.println(" (declared in " + aPd.getDeclaringNodeType() + ")");
                 ps.println("\t\tName\t\t" + (aPd.definesResidual() ? "*" : aPd.getName().toString()));
                 String type = aPd.getRequiredType() == 0 ? "null" : PropertyType.nameFromValue(aPd.getRequiredType());
                 ps.println("\t\tRequiredType\t" + type);
@@ -633,12 +615,12 @@
                     }
                 }
                 ps.println("\t\tValueConstraints\t" + constraints.toString());
-                InternalValue[] defVals = aPd.getDefaultValues();
+                QValue[] defVals = aPd.getDefaultValues();
                 StringBuffer defaultValues = new StringBuffer();
                 if (defVals == null) {
                     defaultValues.append("<null>");
                 } else {
-                    for (InternalValue defVal : defVals) {
+                    for (QValue defVal : defVals) {
                         if (defaultValues.length() > 0) {
                             defaultValues.append(", ");
                         }
@@ -652,10 +634,10 @@
                 ps.println("\t\tProtected\t" + aPd.isProtected());
                 ps.println("\t\tMultiple\t" + aPd.isMultiple());
             }
-            NodeDef[] nd = ntd.getChildNodeDefs();
-            for (NodeDef aNd : nd) {
+            QNodeDefinition[] nd = ntd.getChildNodeDefs();
+            for (QNodeDefinition aNd : nd) {
                 ps.print("\tNodeDefinition");
-                ps.println(" (declared in " + aNd.getDeclaringNodeType() + ") id=" + aNd.getId());
+                ps.println(" (declared in " + aNd.getDeclaringNodeType() + ")");
                 ps.println("\t\tName\t\t" + (aNd.definesResidual() ? "*" : aNd.getName().toString()));
                 Name[] reqPrimaryTypes = aNd.getRequiredPrimaryTypes();
                 if (reqPrimaryTypes != null && reqPrimaryTypes.length > 0) {
@@ -684,7 +666,7 @@
     /**
      * {@inheritDoc}
      */
-    public void externalRegistered(Collection ntDefs)
+    public void externalRegistered(Collection<QNodeTypeDefinition> ntDefs)
             throws RepositoryException, InvalidNodeTypeDefException {
 
         registerNodeTypes(ntDefs, true);
@@ -693,7 +675,7 @@
     /**
      * {@inheritDoc}
      */
-    public void externalReregistered(NodeTypeDef ntDef)
+    public void externalReregistered(QNodeTypeDefinition ntDef)
             throws NoSuchNodeTypeException, InvalidNodeTypeDefException,
             RepositoryException {
 
@@ -703,7 +685,7 @@
     /**
      * {@inheritDoc}
      */
-    public void externalUnregistered(Collection ntNames)
+    public void externalUnregistered(Collection<Name> ntNames)
             throws RepositoryException, NoSuchNodeTypeException {
 
         unregisterNodeTypes(ntNames, true);
@@ -721,9 +703,8 @@
     protected NodeTypeRegistry(NamespaceRegistry nsReg, FileSystem ntStore)
             throws RepositoryException {
         this.nsReg = nsReg;
-        this.ntStore = ntStore;
         customNodeTypesResource =
-                new FileSystemResource(this.ntStore, CUSTOM_NODETYPES_RESOURCE_NAME);
+                new FileSystemResource(ntStore, CUSTOM_NODETYPES_RESOURCE_NAME);
         try {
             // make sure path to resource exists
             if (!customNodeTypesResource.exists()) {
@@ -741,12 +722,9 @@
         // for the old one)
         entCache = new BitsetENTCacheImpl();
         registeredNTDefs = new ConcurrentReaderHashMap();
-        propDefs = new ConcurrentReaderHashMap();
-        nodeDefs = new ConcurrentReaderHashMap();
 
         // setup definition of root node
         rootNodeDef = createRootNodeDef();
-        nodeDefs.put(rootNodeDef.getId(), rootNodeDef);
 
         // load and register pre-defined (i.e. built-in) node types
         builtInNTDefs = new NodeTypeDefStore();
@@ -934,7 +912,7 @@
      * @throws RepositoryException If there is conflicting content or if the
      *                             check failed for some other reason.
      */
-    protected void checkForConflictingContent(NodeTypeDef ntd)
+    protected void checkForConflictingContent(QNodeTypeDefinition ntd)
             throws RepositoryException {
         /**
          * collect names of node types that have dependencies on the given
@@ -979,7 +957,7 @@
     /**
      * @return the definition of the root node
      */
-    public NodeDef getRootNodeDef() {
+    public QNodeDefinition getRootNodeDef() {
         return rootNodeDef;
     }
 
@@ -1003,7 +981,7 @@
      */
     static EffectiveNodeType getEffectiveNodeType(Name ntName,
                                                   EffectiveNodeTypeCache entCache,
-                                                  Map<Name, NodeTypeDef> ntdCache)
+                                                  Map<Name, QNodeTypeDefinition> ntdCache)
             throws NoSuchNodeTypeException {
         // 1. check if effective node type has already been built
         EffectiveNodeTypeCache.Key key = entCache.getKey(new Name[]{ntName});
@@ -1013,7 +991,7 @@
         }
 
         // 2. make sure we've got the definition of the specified node type
-        NodeTypeDef ntd = ntdCache.get(ntName);
+        QNodeTypeDefinition ntd = ntdCache.get(ntName);
         if (ntd == null) {
             throw new NoSuchNodeTypeException(ntName.toString());
         }
@@ -1049,7 +1027,7 @@
      */
     static EffectiveNodeType getEffectiveNodeType(Name[] ntNames,
                                                   EffectiveNodeTypeCache entCache,
-                                                  Map<Name, NodeTypeDef> ntdCache)
+                                                  Map<Name, QNodeTypeDefinition> ntdCache)
             throws NodeTypeConflictException, NoSuchNodeTypeException {
 
         EffectiveNodeTypeCache.Key key = entCache.getKey(ntNames);
@@ -1092,7 +1070,7 @@
                      */
                     Name[] remainder = key.getNames();
                     for (Name aRemainder : remainder) {
-                        NodeTypeDef ntd = ntdCache.get(aRemainder);
+                        QNodeTypeDefinition ntd = ntdCache.get(aRemainder);
                         EffectiveNodeType ent =
                                 EffectiveNodeType.create(ntd, entCache, ntdCache);
                         // store new effective node type
@@ -1120,7 +1098,7 @@
 
     static void checkForCircularInheritance(Name[] supertypes,
                                             Stack<Name> inheritanceChain,
-                                            Map<Name, NodeTypeDef> ntDefCache)
+                                            Map<Name, QNodeTypeDefinition> ntDefCache)
             throws InvalidNodeTypeDefException, RepositoryException {
         for (Name nt : supertypes) {
             int pos = inheritanceChain.lastIndexOf(nt);
@@ -1139,7 +1117,7 @@
             }
 
             try {
-                NodeTypeDef ntd = ntDefCache.get(nt);
+                QNodeTypeDefinition ntd = ntDefCache.get(nt);
                 Name[] sta = ntd.getSupertypes();
                 if (sta.length > 0) {
                     // check recursively
@@ -1158,7 +1136,7 @@
     static void checkForCircularNodeAutoCreation(EffectiveNodeType childNodeENT,
                                                  Stack<Name> definingParentNTs,
                                                  EffectiveNodeTypeCache anEntCache,
-                                                 Map<Name, NodeTypeDef> ntDefCache)
+                                                 Map<Name, QNodeTypeDefinition> ntDefCache)
             throws InvalidNodeTypeDefException {
         // check for circularity through default node types of auto-created child nodes
         // (node type 'a' defines auto-created child node with default node type 'a')
@@ -1183,8 +1161,8 @@
             }
         }
 
-        NodeDef[] nodeDefs = childNodeENT.getAutoCreateNodeDefs();
-        for (NodeDef nodeDef : nodeDefs) {
+        QNodeDefinition[] nodeDefs = childNodeENT.getAutoCreateNodeDefs();
+        for (QNodeDefinition nodeDef : nodeDefs) {
             Name dnt = nodeDef.getDefaultPrimaryType();
             Name definingNT = nodeDef.getDeclaringNodeType();
             try {
@@ -1204,7 +1182,7 @@
         }
     }
 
-    private EffectiveNodeType internalRegister(NodeTypeDef ntd)
+    private EffectiveNodeType internalRegister(QNodeTypeDefinition ntd)
             throws InvalidNodeTypeDefException, RepositoryException {
         Name name = ntd.getName();
         if (name != null && registeredNTDefs.containsKey(name)) {
@@ -1213,27 +1191,15 @@
             throw new InvalidNodeTypeDefException(msg);
         }
 
-        checkNtBaseSubtyping(ntd, registeredNTDefs);
+        ntd = checkNtBaseSubtyping(ntd, registeredNTDefs);
         EffectiveNodeType ent =
                 validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
 
         // store new effective node type instance
         entCache.put(ent);
 
-        // register clone of node type definition
-        ntd = (NodeTypeDef) ntd.clone();
         registeredNTDefs.put(name, ntd);
 
-        // store property & child node definitions of new node type by id
-        PropDef[] pda = ntd.getPropertyDefs();
-        for (PropDef aPda : pda) {
-            propDefs.put(aPda.getId(), aPda);
-        }
-        NodeDef[] nda = ntd.getChildNodeDefs();
-        for (NodeDef aNda : nda) {
-            nodeDefs.put(aNda.getId(), aNda);
-        }
-
         return ent;
     }
 
@@ -1250,7 +1216,7 @@
      * @throws RepositoryException if an error occurs
      * @see #registerNodeType
      */
-    private void internalRegister(Collection<NodeTypeDef> ntDefs)
+    private void internalRegister(Collection<QNodeTypeDefinition> ntDefs)
             throws InvalidNodeTypeDefException, RepositoryException {
         internalRegister(ntDefs, false);
     }
@@ -1265,15 +1231,18 @@
      * that can be exposed in a property definition because it is
      * system-generated (such as jcr:primaryType in nt:base).
      */
-    private void internalRegister(Collection<NodeTypeDef> ntDefs, boolean lenient)
+    private void internalRegister(Collection<QNodeTypeDefinition> ntDefs, boolean lenient)
             throws InvalidNodeTypeDefException, RepositoryException {
 
+        // need a list/collection that can be modified
+        List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>(ntDefs);
+
         // map of node type names and node type definitions
-        Map<Name, NodeTypeDef> tmpNTDefCache = new HashMap<Name, NodeTypeDef>(registeredNTDefs);
+        Map<Name, QNodeTypeDefinition> tmpNTDefCache = new HashMap<Name, QNodeTypeDefinition>(registeredNTDefs);
 
         // temporarily register the node type definition
         // and do some preliminary checks
-        for (NodeTypeDef ntd : ntDefs) {
+        for (QNodeTypeDefinition ntd : defs) {
             Name name = ntd.getName();
             if (name != null && tmpNTDefCache.containsKey(name)) {
                 String msg = name + " already exists";
@@ -1288,14 +1257,21 @@
         }
 
         // check if all node type defs have proper nt:base subtyping
-        for (NodeTypeDef ntd : ntDefs) {
-            checkNtBaseSubtyping(ntd, tmpNTDefCache);
+        for (int i = 0; i < defs.size(); i++) {
+            QNodeTypeDefinition ntd = defs.get(i);
+            QNodeTypeDefinition mod = checkNtBaseSubtyping(ntd, tmpNTDefCache);
+            if (mod != ntd) {
+                // check fixed subtyping
+                // -> update cache and list of defs
+                tmpNTDefCache.put(mod.getName(), mod);
+                defs.set(i, mod);
+            }
         }
 
         // create working copies of current ent & ntd caches:
         // cache of pre-built aggregations of node types
         EffectiveNodeTypeCache tmpENTCache = (EffectiveNodeTypeCache) entCache.clone();
-        for (NodeTypeDef ntd : ntDefs) {
+        for (QNodeTypeDefinition ntd : defs) {
             EffectiveNodeType ent = validateNodeTypeDef(ntd, tmpENTCache,
                     tmpNTDefCache, nsReg, lenient);
 
@@ -1305,19 +1281,8 @@
 
         // since no exception was thrown so far the definitions are assumed to
         // be valid
-        for (NodeTypeDef ntd : ntDefs) {
-            // register clone of node type definition
-            ntd = (NodeTypeDef) ntd.clone();
+        for (QNodeTypeDefinition ntd : defs) {
             registeredNTDefs.put(ntd.getName(), ntd);
-            // store property & child node definitions of new node type by id
-            PropDef[] pda = ntd.getPropertyDefs();
-            for (PropDef aPda : pda) {
-                propDefs.put(aPda.getId(), aPda);
-            }
-            NodeDef[] nda = ntd.getChildNodeDefs();
-            for (NodeDef aNda : nda) {
-                nodeDefs.put(aNda.getId(), aNda);
-            }
         }
 
         // finally add newly created effective node types to entCache
@@ -1325,22 +1290,12 @@
     }
 
     private void internalUnregister(Name name) throws NoSuchNodeTypeException {
-        NodeTypeDef ntd = registeredNTDefs.get(name);
+        QNodeTypeDefinition ntd = registeredNTDefs.get(name);
         if (ntd == null) {
             throw new NoSuchNodeTypeException(name.toString());
         }
         registeredNTDefs.remove(name);
         entCache.invalidate(name);
-
-        // remove property & child node definitions
-        PropDef[] pda = ntd.getPropertyDefs();
-        for (PropDef aPda : pda) {
-            propDefs.remove(aPda.getId());
-        }
-        NodeDef[] nda = ntd.getChildNodeDefs();
-        for (NodeDef aNda : nda) {
-            nodeDefs.remove(aNda.getId());
-        }
     }
 
     private void internalUnregister(Collection<Name> ntNames)
@@ -1374,15 +1329,16 @@
      *
      * @param ntd the node type def to check
      * @param ntdCache cache for lookup
-     * @return <code>true</code> if the ntd was modified
+     * @return the node type definition that was given to check or a new
+     *          instance if it had to be fixed up.
      */
-    private static boolean checkNtBaseSubtyping(NodeTypeDef ntd, Map<Name, NodeTypeDef> ntdCache) {
+    private static QNodeTypeDefinition checkNtBaseSubtyping(QNodeTypeDefinition ntd, Map<Name, QNodeTypeDefinition> ntdCache) {
         if (NameConstants.NT_BASE.equals(ntd.getName())) {
-            return false;
+            return ntd;
         }
         Set<Name> supertypes = new TreeSet<Name>(Arrays.asList(ntd.getSupertypes()));
         if (supertypes.isEmpty()) {
-            return false;
+            return ntd;
         }
         boolean modified;
         if (ntd.isMixin()) {
@@ -1393,7 +1349,7 @@
             boolean allMixins = true;
             for (Name name: supertypes) {
                 if (!name.equals(NameConstants.NT_BASE)) {
-                    NodeTypeDef def = ntdCache.get(name);
+                    QNodeTypeDefinition def = ntdCache.get(name);
                     if (def != null && !def.isMixin()) {
                         allMixins = false;
                         break;
@@ -1408,14 +1364,19 @@
                 // ntd is a primary node type and at least one of the supertypes
                 // is too, so ensure that no nt:base is added. note that the
                 // trivial case, where there would be no supertype left is handled
-                // in the NodeTypeDef directly
+                // in the QNodeTypeDefinition directly
                 modified = supertypes.remove(NameConstants.NT_BASE);
             }
         }
         if (modified) {
-            ntd.setSupertypes(supertypes.toArray(new Name[supertypes.size()]));
+            ntd = new QNodeTypeDefinitionImpl(ntd.getName(),
+                    supertypes.toArray(new Name[supertypes.size()]),
+                    ntd.getSupportedMixinTypes(), ntd.isMixin(),
+                    ntd.isAbstract(), ntd.isQueryable(),
+                    ntd.hasOrderableChildNodes(), ntd.getPrimaryItemName(),
+                    ntd.getPropertyDefs(), ntd.getChildNodeDefs());
         }
-        return modified;
+        return ntd;
     }
 
     /**
@@ -1427,13 +1388,13 @@
      * @param ntdCache cache of 'known' node type definitions, used to resolve dependencies
      * @param nsReg    namespace registry used for validatingatch names
      * @param lenient flag governing whether validation can be lenient or has to be strict
-     * @return an effective node type representation of the specified <code>NodeTypeDef</code>
+     * @return an effective node type representation of the specified <code>QNodeTypeDefinition</code>
      * @throws InvalidNodeTypeDefException if the node type is not valid
      * @throws RepositoryException         if another error occurs
      */
-    private static EffectiveNodeType validateNodeTypeDef(NodeTypeDef ntd,
+    private static EffectiveNodeType validateNodeTypeDef(QNodeTypeDefinition ntd,
                                                          EffectiveNodeTypeCache entCache,
-                                                         Map<Name, NodeTypeDef> ntdCache,
+                                                         Map<Name, QNodeTypeDefinition> ntdCache,
                                                          NamespaceRegistry nsReg,
                                                          boolean lenient)
             throws InvalidNodeTypeDefException, RepositoryException {
@@ -1525,8 +1486,8 @@
         checkNamespace(ntd.getPrimaryItemName(), nsReg);
 
         // validate property definitions
-        PropDef[] pda = ntd.getPropertyDefs();
-        for (PropDef pd : pda) {
+        QPropertyDefinition[] pda = ntd.getPropertyDefs();
+        for (QPropertyDefinition pd : pda) {
             /**
              * sanity check:
              * make sure declaring node type matches name of node type definition
@@ -1557,10 +1518,10 @@
              * check default values:
              * make sure type of value is consistent with required property type
              */
-            InternalValue[] defVals = pd.getDefaultValues();
+            QValue[] defVals = pd.getDefaultValues();
             if (defVals != null && defVals.length != 0) {
                 int reqType = pd.getRequiredType();
-                for (InternalValue defVal : defVals) {
+                for (QValue defVal : defVals) {
                     if (reqType == PropertyType.UNDEFINED) {
                         reqType = defVal.getType();
                     } else {
@@ -1590,7 +1551,7 @@
             if (constraints != null && constraints.length > 0) {
                 if (defVals != null && defVals.length > 0) {
                     // check value constraints on every value
-                    for (InternalValue defVal : defVals) {
+                    for (QValue defVal : defVals) {
                         // constraints are OR-ed together
                         boolean satisfied = false;
                         ConstraintViolationException cve = null;
@@ -1638,8 +1599,8 @@
         }
 
         // validate child-node definitions
-        NodeDef[] cnda = ntd.getChildNodeDefs();
-        for (NodeDef cnd : cnda) {
+        QNodeDefinition[] cnda = ntd.getChildNodeDefs();
+        for (QNodeDefinition cnd : cnda) {
             /**
              * sanity check:
              * make sure declaring node type matches name of node type definition
@@ -1816,8 +1777,8 @@
         return ent;
     }
 
-    private static NodeDef createRootNodeDef() {
-        NodeDefImpl def = new NodeDefImpl();
+    private static QNodeDefinition createRootNodeDef() {
+        QNodeDefinitionBuilder def = new QNodeDefinitionBuilder();
 
         // FIXME need a fake declaring node type:
         // rep:root is not quite correct but better than a non-existing node type
@@ -1829,7 +1790,7 @@
         def.setOnParentVersion(OnParentVersionAction.VERSION);
         def.setAllowsSameNameSiblings(false);
         def.setAutoCreated(true);
-        return def;
+        return def.build();
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDefId.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDefId.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDefId.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDefId.java Wed Oct 21 11:38:31 2009
@@ -18,14 +18,16 @@
 
 import java.io.Serializable;
 
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+
 /**
- * <code>PropDefId</code> serves as identifier for a given <code>PropDef</code>.
+ * <code>PropDefId</code> serves as identifier for a given <code>QPropertyDefinition</code>.
  *
  *
- * uniquely identifies a <code>PropDef</code> in the
+ * uniquely identifies a <code>QPropertyDefinition</code> in the
  * node type registry.
  */
-public class PropDefId implements Serializable {
+class PropDefId implements Serializable {
 
     /**
      * Serialization UID of this class.
@@ -34,20 +36,20 @@
 
     /**
      * The internal id is computed based on the characteristics of the
-     * <code>PropDef</code> that this <code>PropDefId</code> identifies.
+     * <code>QPropertyDefinition</code> that this <code>PropDefId</code> identifies.
      */
     private final int id;
 
     /**
      * Creates a new <code>PropDefId</code> that serves as identifier for
-     * the given <code>PropDef</code>. An internal id is computed based on
-     * the characteristics of the <code>PropDef</code> that it identifies.
+     * the given <code>QPropertyDefinition</code>. An internal id is computed based on
+     * the characteristics of the <code>QPropertyDefinition</code> that it identifies.
      *
-     * @param def <code>PropDef</code> to create identifier for
+     * @param def <code>QPropertyDefinition</code> to create identifier for
      */
-    PropDefId(PropDef def) {
+    public PropDefId(QPropertyDefinition def) {
         if (def == null) {
-            throw new IllegalArgumentException("PropDef argument can not be null");
+            throw new IllegalArgumentException("QPropertyDefinition argument can not be null");
         }
         // build key (format: <declaringNodeType>/<name>/<requiredType>/<multiple>)
         StringBuffer sb = new StringBuffer();

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java Wed Oct 21 11:38:31 2009
@@ -25,11 +25,7 @@
 import javax.jcr.version.OnParentVersionAction;
 
 import org.apache.jackrabbit.core.id.NodeId;
-import org.apache.jackrabbit.core.nodetype.NodeDef;
-import org.apache.jackrabbit.core.nodetype.NodeDefId;
-import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
-import org.apache.jackrabbit.core.nodetype.PropDef;
 import org.apache.jackrabbit.core.state.ChangeLog;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
@@ -38,6 +34,9 @@
 import org.apache.jackrabbit.core.virtual.VirtualNodeState;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 
 /**
@@ -74,12 +73,9 @@
      */
     protected VirtualNodeState createRootNodeState() throws RepositoryException {
         VirtualNodeState root = new VirtualNodeState(this, parentId, rootNodeId, NameConstants.REP_NODETYPES, null);
-        NodeDefId id = ntReg.getEffectiveNodeType(NameConstants.REP_SYSTEM).getApplicableChildNodeDef(
-                NameConstants.JCR_NODETYPES, NameConstants.REP_NODETYPES, ntReg).getId();
-        root.setDefinitionId(id);
         Name[] ntNames = ntReg.getRegisteredNodeTypes();
         for (int i = 0; i < ntNames.length; i++) {
-            NodeTypeDef ntDef = ntReg.getNodeTypeDef(ntNames[i]);
+            QNodeTypeDefinition ntDef = ntReg.getNodeTypeDef(ntNames[i]);
             VirtualNodeState ntState = createNodeTypeState(root, ntDef);
             root.addChildNodeEntry(ntNames[i], ntState.getNodeId());
             // add as hard reference
@@ -108,7 +104,7 @@
     public void onNodeTypeAdded(Name ntName) throws RepositoryException {
         try {
             VirtualNodeState root = (VirtualNodeState) getRootState();
-            NodeTypeDef ntDef = ntReg.getNodeTypeDef(ntName);
+            QNodeTypeDefinition ntDef = ntReg.getNodeTypeDef(ntName);
             VirtualNodeState ntState = createNodeTypeState(root, ntDef);
             root.addChildNodeEntry(ntName, ntState.getNodeId());
 
@@ -153,7 +149,7 @@
      * @throws RepositoryException
      */
     private VirtualNodeState createNodeTypeState(VirtualNodeState parent,
-                                                 NodeTypeDef ntDef)
+                                                 QNodeTypeDefinition ntDef)
             throws RepositoryException {
         NodeId id = calculateStableId(ntDef.getName().toString());
         VirtualNodeState ntState = createNodeState(parent, ntDef.getName(), id, NameConstants.NT_NODETYPE);
@@ -168,7 +164,7 @@
         }
 
         // add property defs
-        PropDef[] propDefs = ntDef.getPropertyDefs();
+        QPropertyDefinition[] propDefs = ntDef.getPropertyDefs();
         for (int i = 0; i < propDefs.length; i++) {
             VirtualNodeState pdState = createPropertyDefState(ntState, propDefs[i], ntDef, i);
             ntState.addChildNodeEntry(NameConstants.JCR_PROPERTYDEFINITION, pdState.getNodeId());
@@ -177,7 +173,7 @@
         }
 
         // add child node defs
-        NodeDef[] cnDefs = ntDef.getChildNodeDefs();
+        QNodeDefinition[] cnDefs = ntDef.getChildNodeDefs();
         for (int i = 0; i < cnDefs.length; i++) {
             VirtualNodeState cnState = createChildNodeDefState(ntState, cnDefs[i], ntDef, i);
             ntState.addChildNodeEntry(NameConstants.JCR_CHILDNODEDEFINITION, cnState.getNodeId());
@@ -197,8 +193,8 @@
      * @throws RepositoryException
      */
     private VirtualNodeState createPropertyDefState(VirtualNodeState parent,
-                                                    PropDef propDef,
-                                                    NodeTypeDef ntDef, int n)
+                                                    QPropertyDefinition propDef,
+                                                    QNodeTypeDefinition ntDef, int n)
             throws RepositoryException {
         NodeId id = calculateStableId(
                 ntDef.getName().toString() + "/" + NameConstants.JCR_PROPERTYDEFINITION.toString() + "/" + n);
@@ -218,7 +214,7 @@
         pState.setPropertyValue(
                 NameConstants.JCR_REQUIREDTYPE,
                 InternalValue.create(PropertyType.nameFromValue(propDef.getRequiredType()).toUpperCase()));
-        InternalValue[] defVals = propDef.getDefaultValues();
+        InternalValue[] defVals = InternalValue.create(propDef.getDefaultValues());
         // retrieve the property type from the first default value present with
         // the property definition. in case no default values are defined,
         // fallback to PropertyType.STRING in order to avoid creating a property
@@ -227,7 +223,9 @@
         if (defVals != null && defVals.length > 0) {
             defValsType = defVals[0].getType();
         }
-        pState.setPropertyValues(NameConstants.JCR_DEFAULTVALUES, defValsType, defVals);
+        if (defVals != null) {
+            pState.setPropertyValues(NameConstants.JCR_DEFAULTVALUES, defValsType, defVals);
+        }
         QValueConstraint[] vc = propDef.getValueConstraints();
         InternalValue[] vals = new InternalValue[vc.length];
         for (int i = 0; i < vc.length; i++) {
@@ -246,8 +244,8 @@
      * @throws RepositoryException
      */
     private VirtualNodeState createChildNodeDefState(VirtualNodeState parent,
-                                                     NodeDef cnDef,
-                                                     NodeTypeDef ntDef, int n)
+                                                     QNodeDefinition cnDef,
+                                                     QNodeTypeDefinition ntDef, int n)
             throws RepositoryException {
         NodeId id = calculateStableId(
                 ntDef.getName().toString() + "/" + NameConstants.JCR_CHILDNODEDEFINITION.toString() + "/" + n);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java Wed Oct 21 11:38:31 2009
@@ -17,12 +17,6 @@
 package org.apache.jackrabbit.core.nodetype.xml;
 
 import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
-import org.apache.jackrabbit.core.nodetype.ItemDef;
-import org.apache.jackrabbit.core.nodetype.NodeDef;
-import org.apache.jackrabbit.core.nodetype.NodeDefImpl;
-import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
-import org.apache.jackrabbit.core.nodetype.PropDef;
-import org.apache.jackrabbit.core.nodetype.PropDefImpl;
 import org.apache.jackrabbit.core.util.DOMWalker;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.core.value.InternalValueFactory;
@@ -34,9 +28,16 @@
 import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
 import org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException;
+import org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder;
+import org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder;
+import org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.value.ValueHelper;
 
 import javax.jcr.PropertyType;
@@ -70,7 +71,7 @@
      * @throws InvalidNodeTypeDefException if the node type definition
      *                                     format is invalid
      */
-    public static NodeTypeDef[] read(InputStream xml)
+    public static QNodeTypeDefinition[] read(InputStream xml)
             throws IOException, InvalidNodeTypeDefException {
         try {
             NodeTypeReader reader = new NodeTypeReader(xml);
@@ -130,13 +131,13 @@
      *                                     illegal name
      * @throws NamespaceException if a namespace is not defined
      */
-    public NodeTypeDef[] getNodeTypeDefs()
+    public QNodeTypeDefinition[] getNodeTypeDefs()
             throws InvalidNodeTypeDefException, NameException, NamespaceException {
-        List<NodeTypeDef> defs = new ArrayList<NodeTypeDef>();
+        List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>();
         while (walker.iterateElements(Constants.NODETYPE_ELEMENT)) {
             defs.add(getNodeTypeDef());
         }
-        return defs.toArray(new NodeTypeDef[defs.size()]);
+        return defs.toArray(new QNodeTypeDefinition[defs.size()]);
     }
 
     /**
@@ -148,9 +149,9 @@
      *                                     illegal name
      * @throws NamespaceException if a namespace is not defined
      */
-    private NodeTypeDef getNodeTypeDef()
+    private QNodeTypeDefinition getNodeTypeDef()
             throws InvalidNodeTypeDefException, NameException, NamespaceException {
-        NodeTypeDef type = new NodeTypeDef();
+        QNodeTypeDefinitionBuilder type = new QNodeTypeDefinitionBuilder();
 
         type.setName(resolver.getQName(
                 walker.getAttribute(Constants.NAME_ATTRIBUTE)));
@@ -183,24 +184,24 @@
         }
 
         // property definitions
-        List<PropDef> properties = new ArrayList<PropDef>();
+        List<QPropertyDefinition> properties = new ArrayList<QPropertyDefinition>();
         while (walker.iterateElements(Constants.PROPERTYDEFINITION_ELEMENT)) {
-            PropDefImpl def = getPropDef();
+            QPropertyDefinitionBuilder def = getPropDef();
             def.setDeclaringNodeType(type.getName());
-            properties.add(def);
+            properties.add(def.build());
         }
-        type.setPropertyDefs(properties.toArray(new PropDef[properties.size()]));
+        type.setPropertyDefs(properties.toArray(new QPropertyDefinition[properties.size()]));
 
         // child node definitions
-        List<NodeDef> nodes = new ArrayList<NodeDef>();
+        List<QNodeDefinition> nodes = new ArrayList<QNodeDefinition>();
         while (walker.iterateElements(Constants.CHILDNODEDEFINITION_ELEMENT)) {
-            NodeDefImpl def = getChildNodeDef();
+            QNodeDefinitionBuilder def = getChildNodeDef();
             def.setDeclaringNodeType(type.getName());
-            nodes.add(def);
+            nodes.add(def.build());
         }
-        type.setChildNodeDefs(nodes.toArray(new NodeDef[nodes.size()]));
+        type.setChildNodeDefs(nodes.toArray(new QNodeDefinition[nodes.size()]));
 
-        return type;
+        return type.build();
     }
 
     /**
@@ -212,26 +213,23 @@
      *                                     illegal name
      * @throws NamespaceException if a namespace is not defined
      */
-    private PropDefImpl getPropDef()
+    private QPropertyDefinitionBuilder getPropDef()
             throws InvalidNodeTypeDefException, NameException, NamespaceException {
-        PropDefImpl def = new PropDefImpl();
+        QPropertyDefinitionBuilder def = new QPropertyDefinitionBuilder();
         String name = walker.getAttribute(Constants.NAME_ATTRIBUTE);
         if (name.equals("*")) {
-            def.setName(ItemDef.ANY_NAME);
+            def.setName(NameConstants.ANY_NAME);
         } else {
             def.setName(resolver.getQName(name));
         }
 
         // simple attributes
         def.setAutoCreated(Boolean.valueOf(
-                walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE)));
         def.setMandatory(Boolean.valueOf(
-                walker.getAttribute(Constants.MANDATORY_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.MANDATORY_ATTRIBUTE)));
         def.setProtected(Boolean.valueOf(
-                walker.getAttribute(Constants.PROTECTED_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.PROTECTED_ATTRIBUTE)));
         def.setOnParentVersion(OnParentVersionAction.valueFromName(
                 walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
         def.setMultiple(Boolean.valueOf(
@@ -320,25 +318,22 @@
      * @throws NameException if the definition contains an illegal name
      * @throws NamespaceException if a namespace is not defined
      */
-    private NodeDefImpl getChildNodeDef() throws NameException, NamespaceException {
-        NodeDefImpl def = new NodeDefImpl();
+    private QNodeDefinitionBuilder getChildNodeDef() throws NameException, NamespaceException {
+        QNodeDefinitionBuilder def = new QNodeDefinitionBuilder();
         String name = walker.getAttribute(Constants.NAME_ATTRIBUTE);
         if (name.equals("*")) {
-            def.setName(ItemDef.ANY_NAME);
+            def.setName(NameConstants.ANY_NAME);
         } else {
             def.setName(resolver.getQName(name));
         }
 
         // simple attributes
         def.setAutoCreated(Boolean.valueOf(
-                walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE)));
         def.setMandatory(Boolean.valueOf(
-                walker.getAttribute(Constants.MANDATORY_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.MANDATORY_ATTRIBUTE)));
         def.setProtected(Boolean.valueOf(
-                walker.getAttribute(Constants.PROTECTED_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.PROTECTED_ATTRIBUTE)));
         def.setOnParentVersion(OnParentVersionAction.valueFromName(
                 walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
         def.setAllowsSameNameSiblings(Boolean.valueOf(

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java Wed Oct 21 11:38:31 2009
@@ -16,32 +16,33 @@
  */
 package org.apache.jackrabbit.core.nodetype.xml;
 
-import org.apache.jackrabbit.core.nodetype.NodeDef;
-import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
-import org.apache.jackrabbit.core.nodetype.PropDef;
-import org.apache.jackrabbit.core.util.DOMBuilder;
-import org.apache.jackrabbit.core.value.InternalValue;
-import org.apache.jackrabbit.core.value.InternalValueFactory;
-import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
-import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
-import org.apache.jackrabbit.spi.commons.query.qom.Operator;
-import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
-import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.QValueConstraint;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.List;
 
+import javax.jcr.NamespaceException;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.NamespaceException;
 import javax.jcr.query.qom.QueryObjectModelConstants;
 import javax.jcr.version.OnParentVersionAction;
 import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.List;
-import java.util.Arrays;
+
+import org.apache.jackrabbit.commons.query.qom.Operator;
+import org.apache.jackrabbit.core.util.DOMBuilder;
+import org.apache.jackrabbit.core.value.InternalValueFactory;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
+import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
 
 /**
  * Node type definition writer. This class is used to write the
@@ -63,11 +64,11 @@
      * @throws RepositoryException on repository errors
      */
     public static void write(
-            OutputStream xml, NodeTypeDef[] types, NamespaceRegistry registry)
+            OutputStream xml, QNodeTypeDefinition[] types, NamespaceRegistry registry)
             throws IOException, RepositoryException {
         try {
             NodeTypeWriter writer = new NodeTypeWriter(registry);
-            for (NodeTypeDef type : types) {
+            for (QNodeTypeDefinition type : types) {
                 writer.addNodeTypeDef(type);
             }
             writer.write(xml);
@@ -125,7 +126,7 @@
      * @throws NamespaceException if the node type definition contains
      *                                   invalid namespace references
      */
-    private void addNodeTypeDef(NodeTypeDef def)
+    private void addNodeTypeDef(QNodeTypeDefinition def)
             throws NamespaceException, RepositoryException {
         builder.startElement(Constants.NODETYPE_ELEMENT);
 
@@ -165,14 +166,14 @@
         }
 
         // property definitions
-        PropDef[] properties = def.getPropertyDefs();
-        for (PropDef property : properties) {
+        QPropertyDefinition[] properties = def.getPropertyDefs();
+        for (QPropertyDefinition property : properties) {
             addPropDef(property);
         }
 
         // child node definitions
-        NodeDef[] nodes = def.getChildNodeDefs();
-        for (NodeDef node : nodes) {
+        QNodeDefinition[] nodes = def.getChildNodeDefs();
+        for (QNodeDefinition node : nodes) {
             addChildNodeDef(node);
         }
 
@@ -188,7 +189,7 @@
      * @throws NamespaceException if the property definition contains
      *                                   invalid namespace references
      */
-    private void addPropDef(PropDef def)
+    private void addPropDef(QPropertyDefinition def)
             throws NamespaceException, RepositoryException {
         builder.startElement(Constants.PROPERTYDEFINITION_ELEMENT);
 
@@ -261,10 +262,10 @@
         }
 
         // default values
-        InternalValue[] defaults = def.getDefaultValues();
+        QValue[] defaults = def.getDefaultValues();
         if (defaults != null && defaults.length > 0) {
             builder.startElement(Constants.DEFAULTVALUES_ELEMENT);
-            for (InternalValue v : defaults) {
+            for (QValue v : defaults) {
                 builder.addContentElement(
                         Constants.DEFAULTVALUE_ELEMENT,
                         factory.createValue(v).getString());
@@ -282,7 +283,7 @@
      * @throws NamespaceException if the child node definition contains
      *                                   invalid namespace references
      */
-    private void addChildNodeDef(NodeDef def)
+    private void addChildNodeDef(QNodeDefinition def)
             throws NamespaceException {
         builder.startElement(Constants.CHILDNODEDEFINITION_ELEMENT);
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java Wed Oct 21 11:38:31 2009
@@ -132,7 +132,6 @@
             // Copy the node state
             NodeState targetNode = target.createNew(sourceNode.getNodeId());
             targetNode.setParentId(sourceNode.getParentId());
-            targetNode.setDefinitionId(sourceNode.getDefinitionId());
             targetNode.setNodeTypeName(sourceNode.getNodeTypeName());
             targetNode.setMixinTypeNames(sourceNode.getMixinTypeNames());
             targetNode.setPropertyNames(sourceNode.getPropertyNames());
@@ -148,7 +147,6 @@
                 PropertyId id = new PropertyId(sourceNode.getNodeId(), name);
                 PropertyState sourceState = source.load(id);
                 PropertyState targetState = target.createNew(id);
-                targetState.setDefinitionId(sourceState.getDefinitionId());
                 targetState.setType(sourceState.getType());
                 targetState.setMultiValued(sourceState.isMultiValued());
                 InternalValue[] values = sourceState.getValues();

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java Wed Oct 21 11:38:31 2009
@@ -30,7 +30,6 @@
 import org.apache.jackrabbit.core.id.ItemId;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.id.PropertyId;
-import org.apache.jackrabbit.core.nodetype.PropDefId;
 import org.apache.jackrabbit.core.persistence.IterablePersistenceManager;
 import org.apache.jackrabbit.core.persistence.PMContext;
 import org.apache.jackrabbit.core.persistence.PersistenceManager;
@@ -109,15 +108,6 @@
     /** the cache of non-existent bundles */
     private LRUNodeIdCache missing;
 
-    /** definition id of the jcr:uuid property */
-    private PropDefId idJcrUUID;
-
-    /** definition id of the jcr:primaryType property */
-    private PropDefId idJcrPrimaryType;
-
-    /** definition id of the jcr:mixinTypes property */
-    private PropDefId idJcrMixinTypes;
-
     /** the persistence manager context */
     protected PMContext context;
 
@@ -397,18 +387,6 @@
         // init bundle cache
         bundles = new BundleCache(bundleCacheSize);
         missing = new LRUNodeIdCache();
-
-        // init property definitions
-        if (context.getNodeTypeRegistry() != null) {
-            idJcrUUID = context.getNodeTypeRegistry()
-                .getEffectiveNodeType(NameConstants.MIX_REFERENCEABLE)
-                .getApplicablePropertyDef(NameConstants.JCR_UUID, PropertyType.STRING, false)
-                .getId();
-            idJcrPrimaryType = context.getNodeTypeRegistry().getEffectiveNodeType(NameConstants.NT_BASE).getApplicablePropertyDef(
-                    NameConstants.JCR_PRIMARYTYPE, PropertyType.NAME, false).getId();
-            idJcrMixinTypes = context.getNodeTypeRegistry().getEffectiveNodeType(NameConstants.NT_BASE).getApplicablePropertyDef(
-                    NameConstants.JCR_MIXINTYPES, PropertyType.NAME, true).getId();
-        }
     }
     
     /**
@@ -451,22 +429,19 @@
             if (id.getName().equals(NameConstants.JCR_UUID)) {
                 state = createNew(id);
                 state.setType(PropertyType.STRING);
-                state.setDefinitionId(idJcrUUID);
                 state.setMultiValued(false);
                 state.setValues(new InternalValue[]{InternalValue.create(id.getParentId().toString())});
             } else if (id.getName().equals(NameConstants.JCR_PRIMARYTYPE)) {
                 state = createNew(id);
                 state.setType(PropertyType.NAME);
-                state.setDefinitionId(idJcrPrimaryType);
                 state.setMultiValued(false);
                 state.setValues(new InternalValue[]{InternalValue.create(bundle.getNodeTypeName())});
             } else if (id.getName().equals(NameConstants.JCR_MIXINTYPES)) {
                 Set<Name> mixins = bundle.getMixinTypeNames();
                 state = createNew(id);
                 state.setType(PropertyType.NAME);
-                state.setDefinitionId(idJcrMixinTypes);
                 state.setMultiValued(true);
-                state.setValues(InternalValue.create((Name[]) mixins.toArray(new Name[mixins.size()])));
+                state.setValues(InternalValue.create(mixins.toArray(new Name[mixins.size()])));
             } else {
                 throw new NoSuchItemStateException(id.toString());
             }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java Wed Oct 21 11:38:31 2009
@@ -26,8 +26,6 @@
 import org.apache.jackrabbit.core.util.StringIndex;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.core.data.DataStore;
-import org.apache.jackrabbit.core.nodetype.NodeDefId;
-import org.apache.jackrabbit.core.nodetype.PropDefId;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
@@ -100,7 +98,7 @@
         bundle.setParentId(readID(in));
 
         // definitionId
-        bundle.setNodeDefId(NodeDefId.valueOf(in.readUTF()));
+        in.readUTF();
 
         // mixin types
         Set<Name> mixinTypeNames = new HashSet<Name>();
@@ -273,7 +271,7 @@
         writeID(out, bundle.getParentId());
 
         // definitionId
-        out.writeUTF(bundle.getNodeDefId().toString());
+        out.writeUTF("");
 
         // mixin types
         for (Name name : bundle.getMixinTypeNames()) {
@@ -342,7 +340,7 @@
         // multiValued
         entry.setMultiValued(in.readBoolean());
         // definitionId
-        entry.setPropDefId(PropDefId.valueOf(in.readUTF()));
+        in.readUTF();
         // values
         int count = in.readInt();   // count
         InternalValue[] values = new InternalValue[count];
@@ -598,7 +596,7 @@
         // multiValued
         out.writeBoolean(state.isMultiValued());
         // definitionId
-        out.writeUTF(state.getPropDefId().toString());
+        out.writeUTF("");
         // values
         InternalValue[] values = state.getValues();
         out.writeInt(values.length); // count
@@ -736,7 +734,7 @@
      * Write a small binary value and return the data.
      *
      * @param out the output stream to write
-     * @param blobVal the binary value
+     * @param value the binary value
      * @param state the property state (for error messages)
      * @param i the index (for error messages)
      * @return the data

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java Wed Oct 21 11:38:31 2009
@@ -24,7 +24,6 @@
 import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.data.DataStore;
-import org.apache.jackrabbit.core.nodetype.NodeDefId;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 
@@ -158,7 +157,7 @@
         // parentUUID
         state.setParentId(readID(in));
         // definitionId
-        state.setDefinitionId(NodeDefId.valueOf(in.readUTF()));
+        in.readUTF();
 
         // mixin types
         int count = in.readInt();   // count
@@ -210,7 +209,7 @@
         // parentUUID
         writeID(out, state.getParentId());
         // definitionId
-        out.writeUTF(state.getDefinitionId().toString());
+        out.writeUTF("");
         // mixin types
         Collection<Name> c = state.getMixinTypeNames();
         out.writeInt(c.size()); // count
@@ -261,7 +260,7 @@
     /**
      * Serializes a node identifier
      * @param out the output stream
-     * @param uuid the node id
+     * @param id the node id
      * @throws IOException in an I/O error occurs.
      */
     public void writeNodeId(DataOutputStream out, String id) throws IOException {