jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r785777 [1/4] - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/com...
Date Wed, 17 Jun 2009 20:22:09 GMT
Author: tripod
Date: Wed Jun 17 20:21:54 2009
New Revision: 785777

URL: http://svn.apache.org/viewvc?rev=785777&view=rev
Log:
JCR-2064 Add new JSR283 features to CND reader/writer
JCR-2153 Introduce QValueConstraint and change return type of QPropertyDefinition.getValueConstraints()
JCR-2158 Consolidate CND related classes from SPI and Core

Added:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefinitionFactory.java   (with props)
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValueConstraint.java   (with props)
Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/InvalidConstraintException.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/compact/
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/InvalidNodeTypeDefException.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDef.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDefImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QItemDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QPropertyDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/namespace/NamespaceMapping.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeTemplateImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefReader.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/Lexer.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/ParseException.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilder.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilderImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/constraint/BooleanConstraint.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/constraint/DateConstraint.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/constraint/NameConstraint.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/constraint/NumericConstraint.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/constraint/PathConstraint.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/constraint/ReferenceConstraint.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/constraint/StringConstraint.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/constraint/ValueConstraint.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefTest.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/constraint/ValueConstraintTest.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/cnd-reader-test-input.cnd
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QPropertyDefinition.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QPropertyDefinitionImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java Wed Jun 17 20:21:54 2009
@@ -16,30 +16,32 @@
  */
 package org.apache.jackrabbit.core.journal;
 
-import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
-import org.apache.jackrabbit.spi.commons.conversion.NameException;
-import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Collection;
+
+import javax.jcr.NamespaceException;
+
+import org.apache.commons.collections.BidiMap;
+import org.apache.commons.collections.bidimap.DualHashBidiMap;
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
-import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
-import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefWriter;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
+import org.apache.jackrabbit.spi.commons.conversion.NameException;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.uuid.Constants;
 import org.apache.jackrabbit.uuid.UUID;
-import org.apache.commons.collections.BidiMap;
-import org.apache.commons.collections.bidimap.DualHashBidiMap;
-
-import javax.jcr.NamespaceException;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.List;
 
 /**
  * Base implementation for a record.
@@ -73,6 +75,8 @@
 
     /**
      * Create a new instance of this class.
+     * @param nsResolver the namespace resolver
+     * @param resolver the name-path resolver
      */
     public AbstractRecord(NamespaceResolver nsResolver, NamePathResolver resolver) {
         this.nsResolver = nsResolver;
@@ -145,7 +149,7 @@
         try {
             StringWriter sw = new StringWriter();
             CompactNodeTypeDefWriter writer = new CompactNodeTypeDefWriter(sw, nsResolver, resolver);
-            writer.write(ntd);
+            writer.write(ntd.getQNodeTypeDefinition());
             writer.close();
 
             writeString(sw.toString());
@@ -219,13 +223,13 @@
             if (index == -1) {
                 return null;
             } else {
-                return (NodeId) nodeIdIndex.getKey(new Integer(index));
+                return (NodeId) nodeIdIndex.getKey(index);
             }
         } else if (uuidType == UUID_LITERAL) {
             byte[] b = new byte[Constants.UUID_BYTE_LENGTH];
             readFully(b);
             NodeId nodeId = new NodeId(new UUID(b));
-            nodeIdIndex.put(nodeId, new Integer(nodeIdIndex.size()));
+            nodeIdIndex.put(nodeId, nodeIdIndex.size());
             return nodeId;
         } else {
             String msg = "Unknown UUID type found: " + uuidType;
@@ -246,14 +250,13 @@
     public NodeTypeDef readNodeTypeDef() throws JournalException {
         try {
             StringReader sr = new StringReader(readString());
-
             CompactNodeTypeDefReader reader = new CompactNodeTypeDefReader(
                     sr, "(internal)", new NamespaceMapping(nsResolver));
-            List ntds = reader.getNodeTypeDefs();
+            Collection<QNodeTypeDefinition> ntds = reader.getNodeTypeDefinitions();
             if (ntds.size() != 1) {
                 throw new JournalException("Expected one node type definition: got " + ntds.size());
             }
-            return (NodeTypeDef) ntds.get(0);
+            return new NodeTypeDef(ntds.iterator().next());
         } catch (ParseException e) {
             String msg = "Parse error while reading node type definition.";
             throw new JournalException(msg, e);
@@ -269,10 +272,10 @@
     private int getOrCreateIndex(NodeId nodeId) {
         Integer index = (Integer) nodeIdIndex.get(nodeId);
         if (index == null) {
-            nodeIdIndex.put(nodeId, new Integer(nodeIdIndex.size()));
+            nodeIdIndex.put(nodeId, nodeIdIndex.size());
             return -1;
         } else {
-            return index.intValue();
+            return index;
         }
     }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java Wed Jun 17 20:21:54 2009
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QValueConstraint;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -646,7 +647,7 @@
             throw new ConstraintViolationException("the property is not multi-valued");
         }
 
-        ValueConstraint[] constraints = pd.getValueConstraints();
+        QValueConstraint[] constraints = pd.getValueConstraints();
         if (constraints == null || constraints.length == 0) {
             // no constraints to check
             return;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefImpl.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefImpl.java Wed Jun 17 20:21:54 2009
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.nodetype;
 
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QItemDefinition;
 
 import javax.jcr.version.OnParentVersionAction;
 
@@ -63,6 +64,15 @@
     public ItemDefImpl() {
     }
 
+    public ItemDefImpl(QItemDefinition def) {
+        name = def.getName();
+        declaringNodeType = def.getDeclaringNodeType();
+        autoCreated = def.isAutoCreated();
+        onParentVersion = def.getOnParentVersion();
+        writeProtected = def.isProtected();
+        mandatory = def.isMandatory();
+    }
+    
     /**
      * Sets the name of declaring node type.
      *

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefImpl.java Wed Jun 17 20:21:54 2009
@@ -17,10 +17,13 @@
 package org.apache.jackrabbit.core.nodetype;
 
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.QNodeDefinitionImpl;
 
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.Set;
 
 /**
  * This class implements the <code>NodeDef</code> interface and additionally
@@ -36,7 +39,7 @@
     /**
      * The names of the required primary types.
      */
-    private HashSet requiredPrimaryTypes;
+    private Set<Name> requiredPrimaryTypes;
 
     /**
      * The 'allowsSameNameSiblings' flag.
@@ -55,12 +58,38 @@
      */
     public NodeDefImpl() {
         defaultPrimaryType = null;
-        requiredPrimaryTypes = new HashSet();
+        requiredPrimaryTypes = new HashSet<Name>();
         requiredPrimaryTypes.add(NameConstants.NT_BASE);
         allowsSameNameSiblings = false;
         id = null;
     }
 
+    public NodeDefImpl(QNodeDefinition nd) {
+        super(nd);
+        defaultPrimaryType = nd.getDefaultPrimaryType();
+        requiredPrimaryTypes = new HashSet<Name>(Arrays.asList(nd.getRequiredPrimaryTypes()));
+        allowsSameNameSiblings = nd.allowsSameNameSiblings();
+        id = null;
+    }
+
+    /**
+     * Returns the QNodeDefinition for this NodeDef
+     * @return the QNodeDefinition
+     */
+    public QNodeDefinition getQNodeDefinition() {
+        return new QNodeDefinitionImpl(
+                getName(),
+                getDeclaringNodeType(),
+                isAutoCreated(),
+                isMandatory(),
+                getOnParentVersion(),
+                isProtected(),
+                getDefaultPrimaryType(),
+                getRequiredPrimaryTypes(),
+                allowsSameNameSiblings()
+        );
+    }
+
     /**
      * Sets the name of default primary type.
      *
@@ -183,7 +212,7 @@
         if (requiredPrimaryTypes.isEmpty()) {
             return Name.EMPTY_ARRAY;
         }
-        return (Name[]) requiredPrimaryTypes.toArray(
+        return requiredPrimaryTypes.toArray(
                 new Name[requiredPrimaryTypes.size()]);
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java Wed Jun 17 20:21:54 2009
@@ -16,18 +16,24 @@
  */
 package org.apache.jackrabbit.core.nodetype;
 
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
-
-import javax.jcr.PropertyType;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
-import java.util.Iterator;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import javax.jcr.PropertyType;
+
+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.QValueConstraint;
+import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+
 /**
  * A <code>NodeTypeDef</code> holds the definition of a node type.
  */
@@ -48,9 +54,9 @@
     private boolean abstractStatus;
     private Name primaryItemName;
 
-    private HashSet propDefs;
-    private HashSet nodeDefs;
-    private Set dependencies;
+    private Set<PropDef> propDefs;
+    private Set<NodeDef> nodeDefs;
+    private Set<Name> dependencies;
 
     /**
      * Default constructor.
@@ -59,13 +65,65 @@
         dependencies = null;
         name = null;
         primaryItemName = null;
-        nodeDefs = new HashSet();
-        propDefs = new HashSet();
         supertypes = Name.EMPTY_ARRAY;
         mixin = false;
         orderableChildNodes = false;
         abstractStatus = false;
         queryable = true;
+        nodeDefs = new HashSet<NodeDef>();
+        propDefs = new HashSet<PropDef>();
+    }
+
+    /**
+     * Creates a node type def from a spi QNodeTypeDefinition
+     * @param def definition
+     */
+    public NodeTypeDef(QNodeTypeDefinition def) {
+        name = def.getName();
+        primaryItemName = def.getPrimaryItemName();
+        supertypes = def.getSupertypes();
+        mixin = def.isMixin();
+        orderableChildNodes = def.hasOrderableChildNodes();
+        abstractStatus = def.isAbstract();
+        queryable = def.isQueryable();
+        nodeDefs = new HashSet<NodeDef>();
+        for (QNodeDefinition nd: def.getChildNodeDefs()) {
+            nodeDefs.add(new NodeDefImpl(nd));
+        }
+        propDefs = new HashSet<PropDef>();
+        for (QPropertyDefinition pd: def.getPropertyDefs()) {
+            propDefs.add(new PropDefImpl(pd));
+        }
+    }
+
+    /**
+     * Returns the QNodeTypeDefintion for this NodeTypeDef
+     * @return the QNodeTypeDefintion
+     */
+    public QNodeTypeDefinition getQNodeTypeDefinition() {
+        QNodeDefinition[] qNodeDefs = new QNodeDefinition[nodeDefs.size()];
+        int i=0;
+        for (NodeDef nd: nodeDefs) {
+            qNodeDefs[i++] = ((NodeDefImpl) nd).getQNodeDefinition();
+        }
+        QPropertyDefinition[] qPropDefs = new QPropertyDefinition[nodeDefs.size()];
+        i=0;
+        for (PropDef pd: propDefs) {
+            qPropDefs[i++] = ((PropDefImpl) pd).getQPropertyDefinition();
+        }
+
+        return new QNodeTypeDefinitionImpl(
+                getName(),
+                getSupertypes(),
+                null,
+                isMixin(),
+                isAbstract(),
+                isQueryable(),
+                hasOrderableChildNodes(),
+                getPrimaryItemName(),
+                qPropDefs,
+                qNodeDefs
+        );
     }
 
     /**
@@ -82,12 +140,11 @@
      */
     public Collection getDependencies() {
         if (dependencies == null) {
-            dependencies = new HashSet();
+            dependencies = new HashSet<Name>();
             // supertypes
             dependencies.addAll(Arrays.asList(supertypes));
             // child node definitions
-            for (Iterator iter = nodeDefs.iterator(); iter.hasNext();) {
-                NodeDef nd = (NodeDef) iter.next();
+            for (NodeDef nd: nodeDefs) {
                 // default primary type
                 Name ntName = nd.getDefaultPrimaryType();
                 if (ntName != null && !name.equals(ntName)) {
@@ -95,24 +152,23 @@
                 }
                 // required primary type
                 Name[] ntNames = nd.getRequiredPrimaryTypes();
-                for (int j = 0; j < ntNames.length; j++) {
-                    if (ntNames[j] != null && !name.equals(ntNames[j])) {
-                        dependencies.add(ntNames[j]);
+                for (Name ntName1 : ntNames) {
+                    if (ntName1 != null && !name.equals(ntName1)) {
+                        dependencies.add(ntName1);
                     }
                 }
             }
             // property definitions
-            for (Iterator iter = propDefs.iterator(); iter.hasNext();) {
-                PropDef pd = (PropDef) iter.next();
+            for (PropDef pd : propDefs) {
                 // [WEAK]REFERENCE value constraints
                 if (pd.getRequiredType() == PropertyType.REFERENCE
                         || pd.getRequiredType() == PropertyType.WEAKREFERENCE) {
-                    ValueConstraint[] ca = pd.getValueConstraints();
+                    QValueConstraint[] ca = pd.getValueConstraints();
                     if (ca != null) {
-                        for (int j = 0; j < ca.length; j++) {
-                            ReferenceConstraint rc = (ReferenceConstraint) ca[j];
-                            if (!name.equals(rc.getNodeTypeName())) {
-                                dependencies.add(rc.getNodeTypeName());
+                        for (QValueConstraint aCa : ca) {
+                            Name rcName = NameFactoryImpl.getInstance().create(aCa.getString());
+                            if (!name.equals(rcName)) {
+                                dependencies.add(rcName);
                             }
                         }
                     }
@@ -150,9 +206,9 @@
             supertypes = new Name[] { names[0] };
         } else {
             // Sort and remove duplicates
-            SortedSet types = new TreeSet();
+            SortedSet<Name> types = new TreeSet<Name>();
             types.addAll(Arrays.asList(names));
-            supertypes = (Name[]) types.toArray(new Name[types.size()]);
+            supertypes = types.toArray(new Name[types.size()]);
         }
     }
 
@@ -310,7 +366,7 @@
         if (propDefs.isEmpty()) {
             return PropDef.EMPTY_ARRAY;
         }
-        return (PropDef[]) propDefs.toArray(new PropDef[propDefs.size()]);
+        return propDefs.toArray(new PropDef[propDefs.size()]);
     }
 
     /**
@@ -324,7 +380,7 @@
         if (nodeDefs.isEmpty()) {
             return NodeDef.EMPTY_ARRAY;
         }
-        return (NodeDef[]) nodeDefs.toArray(new NodeDef[nodeDefs.size()]);
+        return nodeDefs.toArray(new NodeDef[nodeDefs.size()]);
     }
 
     //-------------------------------------------< java.lang.Object overrides >
@@ -337,8 +393,10 @@
         clone.orderableChildNodes = orderableChildNodes;
         clone.abstractStatus = abstractStatus;
         clone.queryable = queryable;
-        clone.nodeDefs = (HashSet) nodeDefs.clone();
-        clone.propDefs = (HashSet) propDefs.clone();
+        clone.nodeDefs = new HashSet<NodeDef>();
+        // todo: itemdefs should be cloned as well, since mutable
+        clone.nodeDefs = new HashSet<NodeDef>(nodeDefs);
+        clone.propDefs = new HashSet<PropDef>(propDefs);
         return clone;
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefDiff.java Wed Jun 17 20:21:54 2009
@@ -26,6 +26,8 @@
 
 import javax.jcr.PropertyType;
 
+import org.apache.jackrabbit.spi.QValueConstraint;
+
 /**
  * A <code>NodeTypeDefDiff</code> represents the result of the comparison of
  * two node type definitions.
@@ -529,15 +531,15 @@
                  * check if valueConstraints were made more restrictive
                  * (constraints are ORed)
                  */
-                ValueConstraint[] vca1 = getOldDef().getValueConstraints();
+                QValueConstraint[] vca1 = getOldDef().getValueConstraints();
                 HashSet set1 = new HashSet();
                 for (int i = 0; i < vca1.length; i++) {
-                    set1.add(vca1[i].getDefinition());
+                    set1.add(vca1[i].getString());
                 }
-                ValueConstraint[] vca2 = getNewDef().getValueConstraints();
+                QValueConstraint[] vca2 = getNewDef().getValueConstraints();
                 HashSet set2 = new HashSet();
                 for (int i = 0; i < vca2.length; i++) {
-                    set2.add(vca2[i].getDefinition());
+                    set2.add(vca2[i].getString());
                 }
 
                 if (set1.isEmpty() && !set2.isEmpty()) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java Wed Jun 17 20:21:54 2009
@@ -16,14 +16,6 @@
  */
 package org.apache.jackrabbit.core.nodetype;
 
-import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
-import org.apache.jackrabbit.core.nodetype.xml.NodeTypeWriter;
-import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
-import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException;
-import org.apache.jackrabbit.spi.Name;
-
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.RepositoryException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -31,7 +23,18 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.Map;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
+import org.apache.jackrabbit.core.nodetype.xml.NodeTypeWriter;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+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.compact.QNodeTypeDefinitionsBuilderImpl;
 
 /**
  * <code>NodeTypeDefStore</code> ...
@@ -39,13 +42,13 @@
 public class NodeTypeDefStore {
 
     /** Map of node type names to node type definitions. */
-    private final HashMap ntDefs;
+    private final Map<Name, NodeTypeDef> ntDefs;
 
     /**
      * Empty default constructor.
      */
     public NodeTypeDefStore() throws RepositoryException {
-        ntDefs = new HashMap();
+        ntDefs = new HashMap<Name, NodeTypeDef>();
     }
 
     /**
@@ -57,8 +60,8 @@
             throws IOException, InvalidNodeTypeDefException,
             RepositoryException {
         NodeTypeDef[] types = NodeTypeReader.read(in);
-        for (int i = 0; i < types.length; i++) {
-            add(types[i]);
+        for (NodeTypeDef type : types) {
+            add(type);
         }
     }
 
@@ -75,9 +78,8 @@
             throws IOException, InvalidNodeTypeDefException {
         try {
             CompactNodeTypeDefReader r = new CompactNodeTypeDefReader(in, systemId);
-            Iterator iter = r.getNodeTypeDefs().iterator();
-            while (iter.hasNext()) {
-                add((NodeTypeDef) iter.next());
+            for (QNodeTypeDefinition qdef: r.getNodeTypeDefinitions()) {
+                add(new NodeTypeDef(qdef));
             }
         } catch (ParseException e) {
             throw new InvalidNodeTypeDefException("Unable to parse CND stream.", e);
@@ -92,8 +94,7 @@
      */
     public void store(OutputStream out, NamespaceRegistry registry)
             throws IOException, RepositoryException {
-        NodeTypeDef[] types = (NodeTypeDef[])
-            ntDefs.values().toArray(new NodeTypeDef[ntDefs.size()]);
+        NodeTypeDef[] types = ntDefs.values().toArray(new NodeTypeDef[ntDefs.size()]);
         NodeTypeWriter.write(out, types, registry);
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java Wed Jun 17 20:21:54 2009
@@ -16,40 +16,6 @@
  */
 package org.apache.jackrabbit.core.nodetype;
 
-import org.apache.commons.collections.map.ReferenceMap;
-import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
-import javax.jcr.nodetype.InvalidNodeTypeDefinitionException;
-import org.apache.jackrabbit.commons.NamespaceHelper;
-import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
-import org.apache.jackrabbit.spi.commons.conversion.NameException;
-import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException;
-import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.data.DataStore;
-import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
-
-import javax.jcr.nodetype.NodeTypeDefinition;
-import javax.jcr.nodetype.NodeTypeExistsException;
-
-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.commons.namespace.NamespaceMapping;
-import org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeTypeManager;
-import org.apache.jackrabbit.spi.Name;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.jcr.NamespaceException;
-import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
-import javax.jcr.ValueFactory;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.nodetype.NodeDefinition;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.nodetype.NodeTypeIterator;
-import javax.jcr.nodetype.PropertyDefinition;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -66,6 +32,43 @@
 import java.util.Properties;
 import java.util.Set;
 
+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.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.commons.conversion.NameException;
+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.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
 /**
  * A <code>NodeTypeManagerImpl</code> implements a session dependant
  * NodeTypeManager.
@@ -97,19 +100,19 @@
      * A cache for <code>NodeType</code> instances created by this
      * <code>NodeTypeManager</code>
      */
-    private final Map ntCache;
+    private final Map<Name, NodeTypeImpl> ntCache;
 
     /**
      * A cache for <code>PropertyDefinition</code> instances created by this
      * <code>NodeTypeManager</code>
      */
-    private final Map pdCache;
+    private final Map<PropDefId, PropertyDefinitionImpl> pdCache;
 
     /**
      * A cache for <code>NodeDefinition</code> instances created by this
      * <code>NodeTypeManager</code>
      */
-    private final Map ndCache;
+    private final Map<NodeDefId, NodeDefinitionImpl> ndCache;
 
     private final DataStore store;
 
@@ -118,8 +121,10 @@
      *
      * @param ntReg      node type registry
      * @param session    current session
+     * @param store      the data store
      * @throws RepositoryException If an error occurs.
      */
+    @SuppressWarnings("unchecked")
     public NodeTypeManagerImpl(
             NodeTypeRegistry ntReg, SessionImpl session, DataStore store)
             throws RepositoryException {
@@ -148,12 +153,12 @@
     }
 
     /**
-     * @param id
+     * @param id node def id
      * @return the node definition
      */
     public NodeDefinitionImpl getNodeDefinition(NodeDefId id) {
         synchronized (ndCache) {
-            NodeDefinitionImpl ndi = (NodeDefinitionImpl) ndCache.get(id);
+            NodeDefinitionImpl ndi = ndCache.get(id);
             if (ndi == null) {
                 NodeDef nd = ntReg.getNodeDef(id);
                 if (nd != null) {
@@ -166,12 +171,12 @@
     }
 
     /**
-     * @param id
+     * @param id prop def id
      * @return the property definition
      */
     public PropertyDefinitionImpl getPropertyDefinition(PropDefId id) {
         synchronized (pdCache) {
-            PropertyDefinitionImpl pdi = (PropertyDefinitionImpl) pdCache.get(id);
+            PropertyDefinitionImpl pdi = pdCache.get(id);
             if (pdi == null) {
                 PropDef pd = ntReg.getPropDef(id);
                 if (pd != null) {
@@ -184,13 +189,13 @@
     }
 
     /**
-     * @param name
-     * @return
-     * @throws NoSuchNodeTypeException
+     * @param name node type name
+     * @return node type
+     * @throws NoSuchNodeTypeException if the nodetype does not exit
      */
     public NodeTypeImpl getNodeType(Name name) throws NoSuchNodeTypeException {
         synchronized (ntCache) {
-            NodeTypeImpl nt = (NodeTypeImpl) ntCache.get(name);
+            NodeTypeImpl nt = ntCache.get(name);
             if (nt == null) {
                 EffectiveNodeType ent = ntReg.getEffectiveNodeType(name);
                 NodeTypeDef def = ntReg.getNodeTypeDef(name);
@@ -228,8 +233,8 @@
             throws IOException, RepositoryException {
 
         try {
-            Map namespaceMap = new HashMap();
-            List nodeTypeDefs = new ArrayList();
+            Map<String, String> namespaceMap = new HashMap<String, String>();
+            List<NodeTypeDef> nodeTypeDefs = new ArrayList<NodeTypeDef>();
 
             if (contentType.equalsIgnoreCase(TEXT_XML)
                     || contentType.equalsIgnoreCase(APPLICATION_XML)) {
@@ -258,8 +263,9 @@
                             new InputStreamReader(in), "cnd input stream", mapping);
 
                     namespaceMap.putAll(mapping.getPrefixToURIMapping());
-
-                    nodeTypeDefs.addAll(reader.getNodeTypeDefs());
+                    for (QNodeTypeDefinition ntDef: reader.getNodeTypeDefinitions()) {
+                        nodeTypeDefs.add(new NodeTypeDef(ntDef));
+                    }
                 } catch (ParseException e) {
                     IOException e2 = new IOException(e.getMessage());
                     e2.initCause(e);
@@ -276,10 +282,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 newNodeTypeDefs = new ArrayList();
-                List registeredNodeTypeDefs = new ArrayList();
-                for (Iterator iter = nodeTypeDefs.iterator(); iter.hasNext();) {
-                    NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next();
+                List<NodeTypeDef> newNodeTypeDefs = new ArrayList<NodeTypeDef>();
+                List<NodeTypeDef> registeredNodeTypeDefs = new ArrayList<NodeTypeDef>();
+                for (NodeTypeDef nodeTypeDef: nodeTypeDefs) {
                     if (ntReg.isRegistered(nodeTypeDef.getName())) {
                         registeredNodeTypeDefs.add(nodeTypeDef);
                     } else {
@@ -287,21 +292,20 @@
                     }
                 }
 
-                ArrayList nodeTypes = new ArrayList();
+                ArrayList<NodeType> nodeTypes = new ArrayList<NodeType>();
 
                 // register new node types
                 nodeTypes.addAll(registerNodeTypes(newNodeTypeDefs));
 
-                // reregister already existing node types
-                for (Iterator iter = registeredNodeTypeDefs.iterator(); iter.hasNext();) {
-                    NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next();
+                // re-register already existing node types
+                for (NodeTypeDef nodeTypeDef: registeredNodeTypeDefs) {
                     ntReg.reregisterNodeType(nodeTypeDef);
                     nodeTypes.add(getNodeType(nodeTypeDef.getName()));
                 }
-                return (NodeType[]) nodeTypes.toArray(new NodeType[nodeTypes.size()]);
+                return nodeTypes.toArray(new NodeType[nodeTypes.size()]);
             } else {
-                Collection types = registerNodeTypes(nodeTypeDefs);
-                return (NodeType[]) types.toArray(new NodeType[types.size()]);
+                Collection<NodeType> types = registerNodeTypes(nodeTypeDefs);
+                return types.toArray(new NodeType[types.size()]);
             }
 
         } catch (InvalidNodeTypeDefException e) {
@@ -375,9 +379,9 @@
      */
     public NodeTypeIterator getAllNodeTypes() throws RepositoryException {
         Name[] ntNames = ntReg.getRegisteredNodeTypes();
-        ArrayList list = new ArrayList(ntNames.length);
-        for (int i = 0; i < ntNames.length; i++) {
-            list.add(getNodeType(ntNames[i]));
+        ArrayList<NodeType> list = new ArrayList<NodeType>(ntNames.length);
+        for (Name ntName : ntNames) {
+            list.add(getNodeType(ntName));
         }
         return new NodeTypeIteratorAdapter(list);
     }
@@ -387,9 +391,9 @@
      */
     public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException {
         Name[] ntNames = ntReg.getRegisteredNodeTypes();
-        ArrayList list = new ArrayList(ntNames.length);
-        for (int i = 0; i < ntNames.length; i++) {
-            NodeType nt = getNodeType(ntNames[i]);
+        ArrayList<NodeType> list = new ArrayList<NodeType>(ntNames.length);
+        for (Name ntName : ntNames) {
+            NodeType nt = getNodeType(ntName);
             if (!nt.isMixin()) {
                 list.add(nt);
             }
@@ -402,9 +406,9 @@
      */
     public NodeTypeIterator getMixinNodeTypes() throws RepositoryException {
         Name[] ntNames = ntReg.getRegisteredNodeTypes();
-        ArrayList list = new ArrayList(ntNames.length);
-        for (int i = 0; i < ntNames.length; i++) {
-            NodeType nt = getNodeType(ntNames[i]);
+        ArrayList<NodeType> list = new ArrayList<NodeType>(ntNames.length);
+        for (Name ntName : ntNames) {
+            NodeType nt = getNodeType(ntName);
             if (nt.isMixin()) {
                 list.add(nt);
             }
@@ -433,19 +437,17 @@
      * Returns a collection containing the registered node types.
      *
      * @param defs a collection of <code>NodeTypeDef<code> objects
-     * @returns registered node types
-     * @throws InvalidNodeTypeDefException
-     * @throws RepositoryException
+     * @return registered node types
+     * @throws InvalidNodeTypeDefException if a nodetype is invalid
+     * @throws RepositoryException if an error occurs
      */
-    private Collection registerNodeTypes(List defs)
+    private Collection<NodeType> registerNodeTypes(List<NodeTypeDef> defs)
             throws InvalidNodeTypeDefException, RepositoryException {
         ntReg.registerNodeTypes(defs);
 
-        Set types = new HashSet();
-        Iterator iterator = defs.iterator();
-        while (iterator.hasNext()) {
+        Set<NodeType> types = new HashSet<NodeType>();
+        for (NodeTypeDef def : defs) {
             try {
-                NodeTypeDef def = (NodeTypeDef) iterator.next();
                 types.add(getNodeType(def.getName()));
             } catch (NoSuchNodeTypeException e) {
                 // ignore
@@ -553,8 +555,8 @@
         // 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 addedDefs = new ArrayList();
-        List modifiedDefs = new ArrayList();
+        List<NodeTypeDef> addedDefs = new ArrayList<NodeTypeDef>();
+        List<NodeTypeDef> modifiedDefs = new ArrayList<NodeTypeDef>();
         for (NodeTypeDefinition definition : definitions) {
             // convert to NodeTypeDef
             NodeTypeDef def = toNodeTypeDef(definition);
@@ -570,14 +572,13 @@
         }
 
         try {
-            ArrayList result = new ArrayList();
+            ArrayList<NodeType> result = new ArrayList<NodeType>();
 
             // register new node types
             result.addAll(registerNodeTypes(addedDefs));
 
-            // reregister already existing node types
-            for (Iterator iter = modifiedDefs.iterator(); iter.hasNext();) {
-                NodeTypeDef nodeTypeDef = (NodeTypeDef) iter.next();
+            // re-register already existing node types
+            for (NodeTypeDef nodeTypeDef: modifiedDefs) {
                 ntReg.reregisterNodeType(nodeTypeDef);
                 result.add(getNodeType(nodeTypeDef.getName()));
             }
@@ -605,14 +606,14 @@
     public void unregisterNodeTypes(String[] names)
             throws UnsupportedRepositoryOperationException,
             NoSuchNodeTypeException, RepositoryException {
-        HashSet ntNames = new HashSet();
-        for (int i = 0; i < names.length; i++) {
+        Set<Name> ntNames = new HashSet<Name>();
+        for (String name : names) {
             try {
-                ntNames.add(session.getQName(names[i]));
+                ntNames.add(session.getQName(name));
             } catch (NamespaceException e) {
-                throw new RepositoryException("Invalid name: " + names[i], e);
+                throw new RepositoryException("Invalid name: " + name, e);
             } catch (NameException e) {
-                throw new RepositoryException("Invalid name: " + names[i], e);
+                throw new RepositoryException("Invalid name: " + name, e);
             }
         }
         getNodeTypeRegistry().unregisterNodeTypes(ntNames);
@@ -623,10 +624,10 @@
      * (using prefixed JCR names) to a <code>NodeTypeDef</code> (using
      * namespace-qualified names).
      *
-     * @param definition
+     * @param definition the definition
      * @return a <code>NodeTypeDef</code>
-     * @throws InvalidNodeTypeDefinitionException
-     * @throws RepositoryException
+     * @throws InvalidNodeTypeDefinitionException if the definiton is invalid
+     * @throws RepositoryException if a repository error occurs
      */
     private NodeTypeDef toNodeTypeDef(NodeTypeDefinition definition)
             throws InvalidNodeTypeDefinitionException, RepositoryException {
@@ -770,7 +771,7 @@
                 // value constraints
                 String[] constraints = pdefs[i].getValueConstraints();
                 if (constraints != null) {
-                    ValueConstraint[] qconstraints = new ValueConstraint[constraints.length];
+                    QValueConstraint[] qconstraints = new QValueConstraint[constraints.length];
                     for (int j = 0; j < constraints.length; j++) {
                         try {
                             qconstraints[j] = ValueConstraint.create(type, constraints[j], session);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java Wed Jun 17 20:21:54 2009
@@ -27,7 +27,9 @@
 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.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -623,7 +625,7 @@
                 ps.println("\t\tName\t\t" + (pd[i].definesResidual() ? "*" : pd[i].getName().toString()));
                 String type = pd[i].getRequiredType() == 0 ? "null" : PropertyType.nameFromValue(pd[i].getRequiredType());
                 ps.println("\t\tRequiredType\t" + type);
-                ValueConstraint[] vca = pd[i].getValueConstraints();
+                QValueConstraint[] vca = pd[i].getValueConstraints();
                 StringBuffer constraints = new StringBuffer();
                 if (vca == null) {
                     constraints.append("<null>");
@@ -632,7 +634,7 @@
                         if (constraints.length() > 0) {
                             constraints.append(", ");
                         }
-                        constraints.append(vca[n].getDefinition());
+                        constraints.append(vca[n].getString());
                     }
                 }
                 ps.println("\t\tValueConstraints\t" + constraints.toString());
@@ -1551,7 +1553,7 @@
             }
 
             // check that default values satisfy value constraints
-            ValueConstraint[] constraints = pd.getValueConstraints();
+            QValueConstraint[] constraints = pd.getValueConstraints();
             if (constraints != null && constraints.length > 0) {
                 if (defVals != null && defVals.length > 0) {
                     // check value constraints on every value
@@ -1587,13 +1589,12 @@
                  */
                 if (pd.getRequiredType() == PropertyType.REFERENCE
                         || pd.getRequiredType() == PropertyType.WEAKREFERENCE) {
-                    for (int j = 0; j < constraints.length; j++) {
-                        ReferenceConstraint rc = (ReferenceConstraint) constraints[j];
-                        Name ntName = rc.getNodeTypeName();
+                    for (QValueConstraint constraint : constraints) {
+                        Name ntName = NameFactoryImpl.getInstance().create(constraint.getString());
                         if (!name.equals(ntName) && !ntdCache.containsKey(ntName)) {
                             String msg = "[" + name + "#" + pd.getName()
                                     + "] invalid "
-                                    + (pd.getRequiredType() == PropertyType.REFERENCE ? "REFERENCE" : "WEAKREFERENCE") 
+                                    + (pd.getRequiredType() == PropertyType.REFERENCE ? "REFERENCE" : "WEAKREFERENCE")
                                     + " value constraint '"
                                     + ntName + "' (unknown node type)";
                             log.debug(msg);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDef.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDef.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDef.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDef.java Wed Jun 17 20:21:54 2009
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.nodetype;
 
 import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.spi.QValueConstraint;
 
 /**
  * <code>PropDef</code> is the internal representation of
@@ -48,7 +49,7 @@
      *
      * @return the array of value constraints.
      */
-    ValueConstraint[] getValueConstraints();
+    QValueConstraint[] getValueConstraints();
 
     /**
      * Returns the array of default values.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDefImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDefImpl.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDefImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropDefImpl.java Wed Jun 17 20:21:54 2009
@@ -18,9 +18,15 @@
 
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+import org.apache.jackrabbit.spi.commons.QPropertyDefinitionImpl;
 
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+
 import java.util.Arrays;
 
 /**
@@ -37,7 +43,7 @@
     /**
      * The value constraints.
      */
-    private ValueConstraint[] valueConstraints = ValueConstraint.EMPTY_ARRAY;
+    private QValueConstraint[] valueConstraints = QValueConstraint.EMPTY_ARRAY;
 
     /**
      * The default values.
@@ -78,6 +84,49 @@
     public PropDefImpl() {
     }
 
+    public PropDefImpl(QPropertyDefinition pd) {
+        super(pd);
+        requiredType = pd.getRequiredType();
+        valueConstraints = pd.getValueConstraints();
+        QValue[] vs = pd.getDefaultValues();
+        if (vs != null) {
+            defaultValues = new InternalValue[vs.length];
+            for (int i=0; i<vs.length; i++) {
+                try {
+                    defaultValues[i] = InternalValue.create(vs[i]);
+                } catch (RepositoryException e) {
+                    throw new IllegalStateException("Error while converting default values.", e);
+                }
+            }
+        }
+        multiple = pd.isMultiple();
+        fullTextSearchable = pd.isFullTextSearchable();
+        queryOrderable = pd.isQueryOrderable();
+        queryOperators = pd.getAvailableQueryOperators();
+    }
+
+    /**
+     * Returns the QPropertyDefinition of this PropDef
+     * @return the QPropertyDefinition
+     */
+    public QPropertyDefinition getQPropertyDefinition() {
+        return new QPropertyDefinitionImpl(
+                getName(),
+                getDeclaringNodeType(),
+                isAutoCreated(),
+                isMandatory(),
+                getOnParentVersion(),
+                isProtected(),
+                getDefaultValues(),
+                isMultiple(),
+                getRequiredType(),
+                getValueConstraints(),
+                getAvailableQueryOperators(),
+                isFullTextSearchable(),
+                isQueryOrderable()
+        );
+    }
+
     /**
      * Sets the required type
      *
@@ -94,13 +143,13 @@
      *
      * @param valueConstraints
      */
-    public void setValueConstraints(ValueConstraint[] valueConstraints) {
+    public void setValueConstraints(QValueConstraint[] valueConstraints) {
         // reset id field in order to force lazy recomputation of identifier
         id = null;
         if (valueConstraints != null) {
             this.valueConstraints = valueConstraints;
         } else {
-            this.valueConstraints = ValueConstraint.EMPTY_ARRAY;
+            this.valueConstraints = QValueConstraint.EMPTY_ARRAY;
         }
     }
 
@@ -248,7 +297,7 @@
     /**
      * {@inheritDoc}
      */
-    public ValueConstraint[] getValueConstraints() {
+    public QValueConstraint[] getValueConstraints() {
         return valueConstraints;
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java Wed Jun 17 20:21:54 2009
@@ -22,8 +22,11 @@
 import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.spi.QValueConstraint;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,7 +52,7 @@
      * @param propDef    property definition
      * @param ntMgr      node type manager
      * @param resolver   name resolver
-     * @param valueFactory
+     * @param valueFactory the value factory
      */
     PropertyDefinitionImpl(PropDef propDef, NodeTypeManagerImpl ntMgr,
                            NamePathResolver resolver, ValueFactory valueFactory) {
@@ -102,13 +105,19 @@
      * {@inheritDoc}
      */
     public String[] getValueConstraints() {
-        ValueConstraint[] constraints = ((PropDef) itemDef).getValueConstraints();
+        QValueConstraint[] constraints = ((PropDef) itemDef).getValueConstraints();
         if (constraints == null || constraints.length == 0) {
             return new String[0];
         }
         String[] vca = new String[constraints.length];
         for (int i = 0; i < constraints.length; i++) {
-            vca[i] = constraints[i].getDefinition(resolver);
+            try {
+                ValueConstraint vc = ValueConstraint.create(((PropDef) itemDef).getRequiredType(), constraints[i].getString());
+                vca[i] = vc.getDefinition(resolver);
+            } catch (InvalidConstraintException e) {
+                log.warn("Error during conversion of value constraint.", e);
+                vca[i] = constraints[i].getString();
+            }
         }
         return vca;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateProvider.java Wed Jun 17 20:21:54 2009
@@ -30,7 +30,6 @@
 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.nodetype.ValueConstraint;
 import org.apache.jackrabbit.core.state.ChangeLog;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
@@ -38,6 +37,7 @@
 import org.apache.jackrabbit.core.virtual.AbstractVISProvider;
 import org.apache.jackrabbit.core.virtual.VirtualNodeState;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QValueConstraint;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.uuid.UUID;
 
@@ -229,10 +229,10 @@
             defValsType = defVals[0].getType();
         }
         pState.setPropertyValues(NameConstants.JCR_DEFAULTVALUES, defValsType, defVals);
-        ValueConstraint[] vc = propDef.getValueConstraints();
+        QValueConstraint[] vc = propDef.getValueConstraints();
         InternalValue[] vals = new InternalValue[vc.length];
         for (int i = 0; i < vc.length; i++) {
-            vals[i] = InternalValue.create(vc[i].getDefinition());
+            vals[i] = InternalValue.create(vc[i].getString());
         }
         pState.setPropertyValues(NameConstants.JCR_VALUECONSTRAINTS, PropertyType.STRING, vals);
         return pState;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java Wed Jun 17 20:21:54 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.core.nodetype.xml;
 
-import org.apache.jackrabbit.core.nodetype.InvalidConstraintException;
 import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
 import org.apache.jackrabbit.core.nodetype.ItemDef;
 import org.apache.jackrabbit.core.nodetype.NodeDef;
@@ -24,7 +23,6 @@
 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.nodetype.ValueConstraint;
 import org.apache.jackrabbit.core.util.DOMWalker;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.core.value.InternalValueFactory;
@@ -34,8 +32,11 @@
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
 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.Name;
 import org.apache.jackrabbit.spi.QValueFactory;
+import org.apache.jackrabbit.spi.QValueConstraint;
 import org.apache.jackrabbit.value.ValueHelper;
 
 import javax.jcr.PropertyType;
@@ -113,6 +114,7 @@
     /**
      * Returns the namespaces declared in the node type definition
      * file.
+     * @return the namespaces
      */
     public Properties getNamespaces() {
         return namespaces;
@@ -126,14 +128,15 @@
      * @throws InvalidNodeTypeDefException if a definition is invalid
      * @throws NameException               if a definition contains an
      *                                     illegal name
+     * @throws NamespaceException if a namespace is not defined
      */
     public NodeTypeDef[] getNodeTypeDefs()
             throws InvalidNodeTypeDefException, NameException, NamespaceException {
-        List defs = new ArrayList();
+        List<NodeTypeDef> defs = new ArrayList<NodeTypeDef>();
         while (walker.iterateElements(Constants.NODETYPE_ELEMENT)) {
             defs.add(getNodeTypeDef());
         }
-        return (NodeTypeDef[]) defs.toArray(new NodeTypeDef[defs.size()]);
+        return defs.toArray(new NodeTypeDef[defs.size()]);
     }
 
     /**
@@ -143,6 +146,7 @@
      * @throws InvalidNodeTypeDefException if the definition is invalid
      * @throws NameException               if the definition contains an
      *                                     illegal name
+     * @throws NamespaceException if a namespace is not defined
      */
     private NodeTypeDef getNodeTypeDef()
             throws InvalidNodeTypeDefException, NameException, NamespaceException {
@@ -151,17 +155,15 @@
         type.setName(resolver.getQName(
                 walker.getAttribute(Constants.NAME_ATTRIBUTE)));
         type.setMixin(Boolean.valueOf(
-                walker.getAttribute(Constants.ISMIXIN_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.ISMIXIN_ATTRIBUTE)));
         type.setOrderableChildNodes(Boolean.valueOf(
-                walker.getAttribute(Constants.HASORDERABLECHILDNODES_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.HASORDERABLECHILDNODES_ATTRIBUTE)));
         type.setAbstract(Boolean.valueOf(
-                walker.getAttribute(Constants.ISABSTRACT_ATTRIBUTE))
-                .booleanValue());
-        type.setQueryable(Boolean.valueOf(
-                walker.getAttribute(Constants.ISQUERYABLE_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.ISABSTRACT_ATTRIBUTE)));
+        if (walker.getAttribute(Constants.ISQUERYABLE_ATTRIBUTE) != null) {
+            type.setQueryable(Boolean.valueOf(
+                    walker.getAttribute(Constants.ISQUERYABLE_ATTRIBUTE)));
+        }
         String primaryItemName =
             walker.getAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE);
         if (primaryItemName != null && primaryItemName.length() > 0) {
@@ -171,35 +173,32 @@
 
         // supertype declarations
         if (walker.enterElement(Constants.SUPERTYPES_ELEMENT)) {
-            List supertypes = new ArrayList();
+            List<Name> supertypes = new ArrayList<Name>();
             while (walker.iterateElements(Constants.SUPERTYPE_ELEMENT)) {
                 supertypes.add(
                         resolver.getQName(walker.getContent()));
             }
-            type.setSupertypes((Name[])
-                    supertypes.toArray(new Name[supertypes.size()]));
+            type.setSupertypes(supertypes.toArray(new Name[supertypes.size()]));
             walker.leaveElement();
         }
 
         // property definitions
-        List properties = new ArrayList();
+        List<PropDef> properties = new ArrayList<PropDef>();
         while (walker.iterateElements(Constants.PROPERTYDEFINITION_ELEMENT)) {
             PropDefImpl def = getPropDef();
             def.setDeclaringNodeType(type.getName());
             properties.add(def);
         }
-        type.setPropertyDefs((PropDef[])
-                properties.toArray(new PropDef[properties.size()]));
+        type.setPropertyDefs(properties.toArray(new PropDef[properties.size()]));
 
         // child node definitions
-        List nodes = new ArrayList();
+        List<NodeDef> nodes = new ArrayList<NodeDef>();
         while (walker.iterateElements(Constants.CHILDNODEDEFINITION_ELEMENT)) {
             NodeDefImpl def = getChildNodeDef();
             def.setDeclaringNodeType(type.getName());
             nodes.add(def);
         }
-        type.setChildNodeDefs((NodeDef[])
-                nodes.toArray(new NodeDef[nodes.size()]));
+        type.setChildNodeDefs(nodes.toArray(new NodeDef[nodes.size()]));
 
         return type;
     }
@@ -211,6 +210,7 @@
      * @throws InvalidNodeTypeDefException if the definition is invalid
      * @throws NameException               if the definition contains an
      *                                     illegal name
+     * @throws NamespaceException if a namespace is not defined
      */
     private PropDefImpl getPropDef()
             throws InvalidNodeTypeDefException, NameException, NamespaceException {
@@ -235,20 +235,17 @@
         def.setOnParentVersion(OnParentVersionAction.valueFromName(
                 walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
         def.setMultiple(Boolean.valueOf(
-                walker.getAttribute(Constants.MULTIPLE_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.MULTIPLE_ATTRIBUTE)));
         def.setFullTextSearchable(Boolean.valueOf(
-                walker.getAttribute(Constants.ISFULLTEXTSEARCHABLE_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.ISFULLTEXTSEARCHABLE_ATTRIBUTE)));
         def.setQueryOrderable(Boolean.valueOf(
-                walker.getAttribute(Constants.ISQUERYORDERABLE_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.ISQUERYORDERABLE_ATTRIBUTE)));
         String s = walker.getAttribute(Constants.AVAILABLEQUERYOPERATORS_ATTRIBUTE);
         if (s != null && s.length() > 0) {
             String[] ops = s.split(" ");
-            List queryOps = new ArrayList();
-            for (int i = 0; i < ops.length; i++) {
-                String op = ops[i].trim();
+            List<String> queryOps = new ArrayList<String>();
+            for (String op1 : ops) {
+                String op = op1.trim();
                 if (op.equals(Constants.EQ_ENTITY)) {
                     queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO);
                 } else if (op.equals(Constants.NE_ENTITY)) {
@@ -267,7 +264,7 @@
                     throw new InvalidNodeTypeDefException("'" + op + "' is not a valid query operator");
                 }
             }
-            def.setAvailableQueryOperators((String[]) queryOps.toArray(new String[queryOps.size()]));
+            def.setAvailableQueryOperators(queryOps.toArray(new String[queryOps.size()]));
 
         }
         def.setRequiredType(PropertyType.valueFromName(
@@ -275,7 +272,7 @@
 
         // value constraints
         if (walker.enterElement(Constants.VALUECONSTRAINTS_ELEMENT)) {
-            List constraints = new ArrayList();
+            List<QValueConstraint> constraints = new ArrayList<QValueConstraint>();
             int type = def.getRequiredType();
             while (walker.iterateElements(Constants.VALUECONSTRAINT_ELEMENT)) {
                 String constraint = walker.getContent();
@@ -287,14 +284,14 @@
                             "Invalid value constraint " + constraint, e);
                 }
             }
-            def.setValueConstraints((ValueConstraint[]) constraints.toArray(
-                    new ValueConstraint[constraints.size()]));
+            def.setValueConstraints(constraints.toArray(
+                    new QValueConstraint[constraints.size()]));
             walker.leaveElement();
         }
 
         // default values
         if (walker.enterElement(Constants.DEFAULTVALUES_ELEMENT)) {
-            List<InternalValue> values = new ArrayList();
+            List<InternalValue> values = new ArrayList<InternalValue>();
             int type = def.getRequiredType();
             if (type == PropertyType.UNDEFINED) {
                 type = PropertyType.STRING;
@@ -309,8 +306,7 @@
                             "Unable to create default value: " + value, e);
                 }
             }
-            def.setDefaultValues((InternalValue[])
-                    values.toArray(new InternalValue[values.size()]));
+            def.setDefaultValues(values.toArray(new InternalValue[values.size()]));
             walker.leaveElement();
         }
 
@@ -322,6 +318,7 @@
      *
      * @return child node definition
      * @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();
@@ -345,8 +342,7 @@
         def.setOnParentVersion(OnParentVersionAction.valueFromName(
                 walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
         def.setAllowsSameNameSiblings(Boolean.valueOf(
-                walker.getAttribute(Constants.SAMENAMESIBLINGS_ATTRIBUTE))
-                .booleanValue());
+                walker.getAttribute(Constants.SAMENAMESIBLINGS_ATTRIBUTE)));
 
         // default primary type
         String type =
@@ -357,12 +353,11 @@
 
         // required primary types
         if (walker.enterElement(Constants.REQUIREDPRIMARYTYPES_ELEMENT)) {
-            List types = new ArrayList();
+            List<Name> types = new ArrayList<Name>();
             while (walker.iterateElements(Constants.REQUIREDPRIMARYTYPE_ELEMENT)) {
                 types.add(resolver.getQName(walker.getContent()));
             }
-            def.setRequiredPrimaryTypes(
-                    (Name[]) types.toArray(new Name[types.size()]));
+            def.setRequiredPrimaryTypes(types.toArray(new Name[types.size()]));
             walker.leaveElement();
         } else {
             /* Default to nt:base?

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java Wed Jun 17 20:21:54 2009
@@ -19,7 +19,6 @@
 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.nodetype.ValueConstraint;
 import org.apache.jackrabbit.core.util.DOMBuilder;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.core.value.InternalValueFactory;
@@ -28,7 +27,9 @@
 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 javax.jcr.NamespaceRegistry;
 import javax.jcr.PropertyType;
@@ -66,8 +67,8 @@
             throws IOException, RepositoryException {
         try {
             NodeTypeWriter writer = new NodeTypeWriter(registry);
-            for (int i = 0; i < types.length; i++) {
-                writer.addNodeTypeDef(types[i]);
+            for (NodeTypeDef type : types) {
+                writer.addNodeTypeDef(type);
             }
             writer.write(xml);
         } catch (ParserConfigurationException e) {
@@ -103,10 +104,10 @@
         builder = new DOMBuilder(Constants.NODETYPES_ELEMENT);
 
         String[] prefixes = registry.getPrefixes();
-        for (int i = 0; i < prefixes.length; i++) {
-            if (!"".equals(prefixes[i])) {
-                String uri = registry.getURI(prefixes[i]);
-                builder.setAttribute("xmlns:" + prefixes[i], uri);
+        for (String prefix : prefixes) {
+            if (!"".equals(prefix)) {
+                String uri = registry.getURI(prefix);
+                builder.setAttribute("xmlns:" + prefix, uri);
             }
         }
 
@@ -155,24 +156,24 @@
         Name[] supertypes = def.getSupertypes();
         if (supertypes.length > 0) {
             builder.startElement(Constants.SUPERTYPES_ELEMENT);
-            for (int i = 0; i < supertypes.length; i++) {
+            for (Name supertype : supertypes) {
                 builder.addContentElement(
                         Constants.SUPERTYPE_ELEMENT,
-                        resolver.getJCRName(supertypes[i]));
+                        resolver.getJCRName(supertype));
             }
             builder.endElement();
         }
 
         // property definitions
         PropDef[] properties = def.getPropertyDefs();
-        for (int i = 0; i < properties.length; i++) {
-            addPropDef(properties[i]);
+        for (PropDef property : properties) {
+            addPropDef(property);
         }
 
         // child node definitions
         NodeDef[] nodes = def.getChildNodeDefs();
-        for (int i = 0; i < nodes.length; i++) {
-            addChildNodeDef(nodes[i]);
+        for (NodeDef node : nodes) {
+            addChildNodeDef(node);
         }
 
         builder.endElement();
@@ -246,13 +247,15 @@
                 PropertyType.nameFromValue(def.getRequiredType()));
 
         // value constraints
-        ValueConstraint[] constraints = def.getValueConstraints();
+        QValueConstraint[] constraints = def.getValueConstraints();
         if (constraints != null && constraints.length > 0) {
             builder.startElement(Constants.VALUECONSTRAINTS_ELEMENT);
-            for (int i = 0; i < constraints.length; i++) {
+            for (QValueConstraint constraint : constraints) {
+                ValueConstraint vc = ValueConstraint.create(
+                        def.getRequiredType(), constraint.getString());
                 builder.addContentElement(
                         Constants.VALUECONSTRAINT_ELEMENT,
-                        constraints[i].getDefinition(resolver));
+                        vc.getDefinition(resolver));
             }
             builder.endElement();
         }
@@ -261,8 +264,7 @@
         InternalValue[] defaults = def.getDefaultValues();
         if (defaults != null && defaults.length > 0) {
             builder.startElement(Constants.DEFAULTVALUES_ELEMENT);
-            for (int i = 0; i < defaults.length; i++) {
-                InternalValue v = defaults[i];
+            for (InternalValue v : defaults) {
                 builder.addContentElement(
                         Constants.DEFAULTVALUE_ELEMENT,
                         factory.createValue(v).getString());
@@ -312,10 +314,10 @@
         // required primary types
         Name[] requiredTypes = def.getRequiredPrimaryTypes();
         builder.startElement(Constants.REQUIREDPRIMARYTYPES_ELEMENT);
-        for (int i = 0; i < requiredTypes.length; i++) {
+        for (Name requiredType : requiredTypes) {
             builder.addContentElement(
                     Constants.REQUIREDPRIMARYTYPE_ELEMENT,
-                    resolver.getJCRName(requiredTypes[i]));
+                    resolver.getJCRName(requiredType));
         }
         builder.endElement();
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=785777&r1=785776&r2=785777&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java Wed Jun 17 20:21:54 2009
@@ -16,38 +16,39 @@
  */
 package org.apache.jackrabbit.core.value;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.SequenceInputStream;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Calendar;
+
+import javax.jcr.Binary;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+
 import org.apache.jackrabbit.core.data.DataIdentifier;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.data.DataStoreException;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.Path;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.util.ISO8601;
-import org.apache.jackrabbit.uuid.UUID;
-import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi.commons.value.AbstractQValue;
+import org.apache.jackrabbit.spi.commons.value.AbstractQValueFactory;
 import org.apache.jackrabbit.spi.commons.value.QValueValue;
-
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
-import javax.jcr.Binary;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.SequenceInputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Calendar;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.math.BigDecimal;
+import org.apache.jackrabbit.util.ISO8601;
+import org.apache.jackrabbit.uuid.UUID;
 
 /**
  * <code>InternalValue</code> represents the internal format of a property value.
@@ -91,6 +92,8 @@
      * @param value the JCR value
      * @param resolver
      * @return the created internal value
+     * @throws RepositoryException
+     * @throws ValueFormatException
      */
     public static InternalValue create(Value value, NamePathResolver resolver)
             throws ValueFormatException, RepositoryException {
@@ -105,6 +108,8 @@
      * @param resolver
      * @param store the data store
      * @return the created internal value
+     * @throws RepositoryException
+     * @throws ValueFormatException
      */
     public static InternalValue create(Value value, NamePathResolver resolver, DataStore store)
             throws ValueFormatException, RepositoryException {
@@ -187,6 +192,42 @@
         }
     }
 
+    public static InternalValue create(QValue value)
+            throws RepositoryException {
+        switch (value.getType()) {
+            case PropertyType.BINARY:
+                try {
+                    return create(value.getString().getBytes(AbstractQValueFactory.DEFAULT_ENCODING));
+                } catch (UnsupportedEncodingException e) {
+                    throw new InternalError(AbstractQValueFactory.DEFAULT_ENCODING + " not supported");
+                }
+            case PropertyType.BOOLEAN:
+                return new InternalValue(value.getBoolean());
+            case PropertyType.DATE:
+                return new InternalValue(value.getCalendar());
+            case PropertyType.DOUBLE:
+                return new InternalValue(value.getDouble());
+            case PropertyType.DECIMAL:
+                return new InternalValue(value.getDecimal());
+            case PropertyType.LONG:
+                return new InternalValue(value.getLong());
+            case PropertyType.REFERENCE:
+                return create(new UUID(value.getString()));
+            case PropertyType.WEAKREFERENCE:
+                return create(new UUID(value.getString()), true);
+            case PropertyType.URI:
+                return new InternalValue(value.getURI());
+            case PropertyType.NAME:
+                return new InternalValue(value.getName());
+            case PropertyType.PATH:
+                return new InternalValue(value.getPath());
+            case PropertyType.STRING:
+                return new InternalValue(value.getString());
+            default:
+                throw new IllegalArgumentException("illegal value");
+        }
+    }
+
     static InternalValue getInternalValue(DataIdentifier identifier, DataStore store) throws DataStoreException {
         // access the record to ensure it is not garbage collected
         if (store.getRecordIfStored(identifier) != null) {
@@ -268,6 +309,7 @@
      *
      * @param value the stream
      * @return the internal value
+     * @throws RepositoryException
      */
     public static InternalValue createTemporary(InputStream value) throws RepositoryException {
         return new InternalValue(getBLOBFileValue(null, value, true));
@@ -277,7 +319,9 @@
      * Create an internal value that is stored in the data store (if enabled).
      *
      * @param value the input stream
+     * @param store
      * @return the internal value
+     * @throws RepositoryException
      */
     static InternalValue create(InputStream value, DataStore store) throws RepositoryException {
         return new InternalValue(getBLOBFileValue(store, value, false));
@@ -287,6 +331,7 @@
      * @param value
      * @return
      * @throws IOException
+     * @throws RepositoryException
      */
     public static InternalValue create(InputStream value) throws RepositoryException {
         return new InternalValue(getBLOBFileValue(null, value, false));
@@ -421,7 +466,7 @@
     public static InternalValue valueOf(String s, int type) {
         switch (type) {
             case PropertyType.BOOLEAN:
-                return create(Boolean.valueOf(s).booleanValue());
+                return create(Boolean.valueOf(s));
             case PropertyType.DATE:
                 return create(ISO8601.parse(s));
             case PropertyType.DOUBLE:
@@ -476,11 +521,11 @@
     }
 
     private InternalValue(long value) {
-        super(Long.valueOf(value));
+        super(value);
     }
 
     private InternalValue(double value) {
-        super(Double.valueOf(value));
+        super(value);
     }
 
     private InternalValue(Calendar value) {
@@ -488,7 +533,7 @@
     }
 
     private InternalValue(boolean value) {
-        super(Boolean.valueOf(value));
+        super(value);
     }
 
     private InternalValue(URI value) {
@@ -519,6 +564,7 @@
      * @param in the input stream
      * @param temporary if the file should be deleted when discard is called (ignored if a data store is used)
      * @return the value
+     * @throws RepositoryException
      */
     private static BLOBFileValue getBLOBFileValue(DataStore store, InputStream in, boolean temporary) throws RepositoryException {
         int maxMemorySize;



Mime
View raw message