jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r816551 [2/2] - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/ jackrabbit-c...
Date Fri, 18 Sep 2009 09:15:11 GMT
Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/CyclicNodeTypeRegistrationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/CyclicNodeTypeRegistrationTest.java?rev=816551&r1=816550&r2=816551&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/CyclicNodeTypeRegistrationTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/CyclicNodeTypeRegistrationTest.java
Fri Sep 18 09:15:07 2009
@@ -20,11 +20,13 @@
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 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.test.AbstractJCRTest;
 import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -58,7 +60,7 @@
     /**
      * The cyclic dependent node type definitions we use for the tests
      */
-    private Collection ntDefCollection;
+    private Collection<QNodeTypeDefinition> ntDefCollection;
 
     /**
      * The name factory
@@ -114,11 +116,11 @@
          * [bar]
          * + myFooInBar (foo)
          */
-        final NodeTypeDef foo = new NodeTypeDef();
+        final QNodeTypeDefinitionBuilder foo = new QNodeTypeDefinitionBuilder();
         foo.setName(nameFactory.create("", "foo"));
         foo.setSupertypes(new Name[]{NameConstants.NT_BASE});
 
-        final NodeTypeDef bar = new NodeTypeDef();
+        final QNodeTypeDefinitionBuilder bar = new QNodeTypeDefinitionBuilder();
         bar.setName(nameFactory.create("", "bar"));
         bar.setSupertypes(new Name[]{NameConstants.NT_BASE});
 
@@ -134,9 +136,9 @@
 
         foo.setChildNodeDefs(new QNodeDefinition[]{myBarInFoo.build()});
         bar.setChildNodeDefs(new QNodeDefinition[]{myFooInBar.build()});
-        ntDefCollection = new LinkedList();
-        ntDefCollection.add(foo);
-        ntDefCollection.add(bar);
+        ntDefCollection = new LinkedList<QNodeTypeDefinition>();
+        ntDefCollection.add(foo.build());
+        ntDefCollection.add(bar.build());
 
         try {
             ntreg.registerNodeTypes(ntDefCollection);
@@ -162,7 +164,7 @@
          * + myNTInFoo (I_am_an_invalid_required_primary_type)
          *
          */
-        final NodeTypeDef foo = new NodeTypeDef();
+        final QNodeTypeDefinitionBuilder foo = new QNodeTypeDefinitionBuilder();
         foo.setName(nameFactory.create("", "foo"));
         foo.setSupertypes(new Name[]{NameConstants.NT_BASE});
 
@@ -173,8 +175,8 @@
         myBarInFoo.setDeclaringNodeType(foo.getName());
 
         foo.setChildNodeDefs(new QNodeDefinition[]{myBarInFoo.build()});
-        ntDefCollection = new LinkedList();
-        ntDefCollection.add(foo);
+        ntDefCollection = new LinkedList<QNodeTypeDefinition>();
+        ntDefCollection.add(foo.build());
 
         try {
             ntreg.registerNodeTypes(ntDefCollection);
@@ -206,10 +208,10 @@
          *
          */
 
-        final NodeTypeDef folder = new NodeTypeDef();
+        final QNodeTypeDefinitionBuilder folder = new QNodeTypeDefinitionBuilder();
         folder.setName(nameFactory.create("", "Folder"));
 
-        final NodeTypeDef cmsObject = new NodeTypeDef();
+        final QNodeTypeDefinitionBuilder cmsObject = new QNodeTypeDefinitionBuilder();
         cmsObject.setName(nameFactory.create("", "CmsObject"));
         cmsObject.setSupertypes(new Name[]{NameConstants.NT_BASE});
 
@@ -220,7 +222,7 @@
         cmsObject.setChildNodeDefs(new QNodeDefinition[]{parentFolder.build()});
 
 
-        final NodeTypeDef document = new NodeTypeDef();
+        final QNodeTypeDefinitionBuilder document = new QNodeTypeDefinitionBuilder();
         document.setName(nameFactory.create("", "Document"));
         document.setSupertypes(new Name[]{cmsObject.getName()});
         QPropertyDefinitionBuilder sizeProp = new QPropertyDefinitionBuilder();
@@ -244,10 +246,10 @@
 
         folder.setChildNodeDefs(new QNodeDefinition[]{
                 folders.build(), documents.build()});
-        ntDefCollection = new LinkedList();
-        ntDefCollection.add(folder);
-        ntDefCollection.add(document);
-        ntDefCollection.add(cmsObject);
+        ntDefCollection = new LinkedList<QNodeTypeDefinition>();
+        ntDefCollection.add(folder.build());
+        ntDefCollection.add(document.build());
+        ntDefCollection.add(cmsObject.build());
 
         try {
             ntreg.registerNodeTypes(ntDefCollection);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java?rev=816551&r1=816550&r2=816551&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/NodeTypesInContentTest.java
Fri Sep 18 09:15:07 2009
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
 import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 
 import javax.jcr.ItemVisitor;
 import javax.jcr.Property;
@@ -45,7 +46,7 @@
         super.setUp();
         
         InputStream xml = getClass().getClassLoader().getResourceAsStream(TEST_NODETYPES);
-        NodeTypeDef[] ntDefs = NodeTypeReader.read(xml);
+        QNodeTypeDefinition[] ntDefs = NodeTypeReader.read(xml);
         NodeTypeRegistry ntReg = ((SessionImpl) superuser).getNodeTypeManager().getNodeTypeRegistry();
         if (!ntReg.isRegistered(ntDefs[0].getName())) {
             ntReg.registerNodeTypes(Arrays.asList(ntDefs));

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java?rev=816551&r1=816550&r2=816551&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
Fri Sep 18 09:15:07 2009
@@ -35,13 +35,13 @@
 import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
 import org.apache.jackrabbit.commons.cnd.CndImporter;
 import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
-import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
 import org.apache.jackrabbit.core.value.InternalValueFactory;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
 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.conversion.DefaultNamePathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
@@ -81,7 +81,7 @@
     private static final NameFactory FACTORY = NameFactoryImpl.getInstance();
 
     /** Test node types definitions. */
-    private NodeTypeDef[] types;
+    private QNodeTypeDefinition[] types;
 
     /** Registry for the test namespaces. */
     private NamespaceRegistry registry;
@@ -109,7 +109,7 @@
      * @param name node type name
      * @return node type definition
      */
-    private NodeTypeDef getNodeType(String name) {
+    private QNodeTypeDefinition getNodeType(String name) {
         Name qname = FACTORY.create(TEST_NAMESPACE, name);
         for (int i = 0; i < types.length; i++) {
             if (qname.equals(types[i].getName())) {
@@ -139,7 +139,7 @@
             name = NameConstants.ANY_NAME;
         }
 
-        NodeTypeDef def = getNodeType(typeName);
+        QNodeTypeDefinition def = getNodeType(typeName);
         QPropertyDefinition[] defs = def.getPropertyDefs();
         for (int i = 0; i < defs.length; i++) {
             if (name.equals(defs[i].getName())) {
@@ -182,7 +182,7 @@
     private QNodeDefinition getChildNode(String typeName, String nodeName) {
         Name name = FACTORY.create(TEST_NAMESPACE, nodeName);
 
-        NodeTypeDef def = getNodeType(typeName);
+        QNodeTypeDefinition def = getNodeType(typeName);
         QNodeDefinition[] defs = def.getChildNodeDefs();
         for (int i = 0; i < defs.length; i++) {
             if (name.equals(defs[i].getName())) {
@@ -205,7 +205,7 @@
 
     /** Test for the empty node type. */
     public void testEmptyNodeType() {
-        NodeTypeDef def = getNodeType("emptyNodeType");
+        QNodeTypeDefinition def = getNodeType("emptyNodeType");
         assertNotNull("emptyNodeType exists", def);
         assertEquals("emptyNodeType mixin",
                 false, def.isMixin());
@@ -221,21 +221,21 @@
 
     /** Test for the <code>mixin</code> node type attribute. */
     public void testMixinNodeType() {
-        NodeTypeDef def = getNodeType("mixinNodeType");
+        QNodeTypeDefinition def = getNodeType("mixinNodeType");
         assertEquals("mixinNodeType mixin",
                 true, def.isMixin());
     }
 
     /** Test for the <code>hasOrderableChildNodes</code> node type attribute.
*/
     public void testOrderedNodeType() {
-        NodeTypeDef def = getNodeType("orderedNodeType");
+        QNodeTypeDefinition def = getNodeType("orderedNodeType");
         assertEquals("orderedNodeType hasOrderableChildNodes",
                 true, def.hasOrderableChildNodes());
     }
 
     /** Test for node type item definitions. */
     public void testItemNodeType() {
-        NodeTypeDef def = getNodeType("itemNodeType");
+        QNodeTypeDefinition def = getNodeType("itemNodeType");
         assertEquals("itemNodeType primaryItemName",
                 FACTORY.create(TEST_NAMESPACE, "emptyItem"),
                 def.getPrimaryItemName());
@@ -389,7 +389,7 @@
 
     /** Test for node type property definitions. */
     public void testPropertyNodeType() {
-        NodeTypeDef def = getNodeType("propertyNodeType");
+        QNodeTypeDefinition def = getNodeType("propertyNodeType");
         assertEquals("propertyNodeType propertyDefs",
                 13, def.getPropertyDefs().length);
     }
@@ -590,7 +590,7 @@
 
     /** Test for node type child node definitions. */
     public void testChildNodeType() {
-        NodeTypeDef def = getNodeType("childNodeType");
+        QNodeTypeDefinition def = getNodeType("childNodeType");
         assertEquals("childNodeType childNodeDefs",
                 4, def.getChildNodeDefs().length);
     }
@@ -646,7 +646,7 @@
             ByteArrayOutputStream xml = new ByteArrayOutputStream();
             NodeTypeWriter.write(xml, types, registry);
             byte[] bytes = xml.toByteArray();
-            NodeTypeDef[] output =
+            QNodeTypeDefinition[] output =
                 NodeTypeReader.read(new ByteArrayInputStream(bytes));
             assertTrue("write output", Arrays.equals(types, output));
         } catch (InvalidNodeTypeDefException e) {

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/DefinitionBuilderFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/DefinitionBuilderFactory.java?rev=816551&r1=816550&r2=816551&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/DefinitionBuilderFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/DefinitionBuilderFactory.java
Fri Sep 18 09:15:07 2009
@@ -17,6 +17,8 @@
 package org.apache.jackrabbit.commons.cnd;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
+import javax.jcr.query.qom.QueryObjectModelConstants;
 import javax.jcr.nodetype.ItemDefinition;
 import javax.jcr.nodetype.NodeTypeDefinition;
 import javax.jcr.nodetype.PropertyDefinition;
@@ -269,20 +271,30 @@
      */
     public static abstract class AbstractPropertyDefinitionBuilder<T> extends AbstractItemDefinitionBuilder<T>
{
 
+        private static final String[] ALL_OPERATORS = new String[]{
+                QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
+                QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN,
+                QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO,
+                QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN,
+                QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO,
+                QueryObjectModelConstants.JCR_OPERATOR_LIKE,
+                QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO
+        };
+
         /** See {@link #setRequiredType(int)} */
-        protected int requiredType;
+        protected int requiredType = PropertyType.UNDEFINED;
 
         /** See {@link #setMultiple(boolean)} */
-        protected boolean isMultiple;
+        protected boolean isMultiple = false;
 
         /** See {@link #setFullTextSearchable(boolean)} */
-        protected boolean fullTextSearchable;
+        protected boolean fullTextSearchable = true;
 
         /** See {@link #setQueryOrderable(boolean)} */
-        protected boolean queryOrderable;
+        protected boolean queryOrderable = true;
 
         /** See {@link #setAvailableQueryOperators(String[])} */
-        protected String[] queryOperators;
+        protected String[] queryOperators = ALL_OPERATORS;
 
         /**
          * @param type the required type of the property definition being built.
@@ -351,6 +363,9 @@
          * @see PropertyDefinition#getAvailableQueryOperators()
          */
         public void setAvailableQueryOperators(String[] queryOperators) throws RepositoryException
{
+            if (queryOperators == null) {
+                throw new NullPointerException("queryOperators");
+            }
             this.queryOperators = queryOperators;
         }
     }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeDefinitionImpl.java?rev=816551&r1=816550&r2=816551&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeDefinitionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeDefinitionImpl.java
Fri Sep 18 09:15:07 2009
@@ -18,22 +18,30 @@
 
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.conversion.NameException;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
 
 import java.util.Arrays;
 import java.util.TreeSet;
 import java.util.Set;
 import java.util.HashSet;
 
+import javax.jcr.NamespaceException;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+
 /**
  * <code>QNodeDefinitionImpl</code> implements a <code>QNodeDefinition</code>.
  */
 public class QNodeDefinitionImpl extends QItemDefinitionImpl implements QNodeDefinition {
 
+    private static final long serialVersionUID = -3671882394577685657L;
+
     /**
      * The name of the default primary type.
      */
     private final Name defaultPrimaryType;
-
     /**
      * The names of the required primary types.
      */
@@ -82,7 +90,32 @@
         this.allowsSameNameSiblings = allowsSameNameSiblings;
     }
 
+    /**
+     * Creates a new node definition based on a JCR <code>NodeDefinition</code>.
+     *
+     * @param nodeDef  the node definition.
+     * @param resolver the name/path resolver of the session that provided the
+     *                 node definition
+     * @throws NameException      if <code>nodeDef</code> contains an illegal
+     *                            name.
+     * @throws NamespaceException if <code>nodeDef</code> contains a name with
+     *                            an namespace prefix that is unknown to
+     *                            <code>resolver</code>.
+     */
+    public QNodeDefinitionImpl(NodeDefinition nodeDef,
+                               NamePathResolver resolver)
+            throws NameException, NamespaceException {
+        this(nodeDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME
: resolver.getQName(nodeDef.getName()),
+                nodeDef.getDeclaringNodeType() != null ? resolver.getQName(nodeDef.getDeclaringNodeType().getName())
: null,
+                nodeDef.isAutoCreated(), nodeDef.isMandatory(),
+                nodeDef.getOnParentVersion(), nodeDef.isProtected(),
+                nodeDef.getDefaultPrimaryType() != null ? resolver.getQName(nodeDef.getDefaultPrimaryType().getName())
: null,
+                getNodeTypeNames(nodeDef.getRequiredPrimaryTypes(), resolver),
+                nodeDef.allowsSameNameSiblings());
+    }
+
     //-------------------------------------------------------< QNodeDefinition >
+
     /**
      * {@inheritDoc}
      */
@@ -171,4 +204,29 @@
         }
         return hashCode;
     }
+
+    //-----------------------------< internal >---------------------------------
+
+    /**
+     * Returns the names of the passed node types using the namespace resolver
+     * to parse the names.
+     *
+     * @param nt       the node types
+     * @param resolver the name/path resolver of the session that provided
+     *                 <code>nt</code>.
+     * @return the names of the node types.
+     * @throws NameException      if a node type returns an illegal name.
+     * @throws NamespaceException if the name of a node type contains a prefix
+     *                            that is not known to <code>resolver</code>.
+     */
+    private static Name[] getNodeTypeNames(NodeType[] nt,
+                                           NamePathResolver resolver)
+            throws NameException, NamespaceException {
+        Name[] names = new Name[nt.length];
+        for (int i = 0; i < nt.length; i++) {
+            Name ntName = resolver.getQName(nt[i].getName());
+            names[i] = ntName;
+        }
+        return names;
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java?rev=816551&r1=816550&r2=816551&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java
Fri Sep 18 09:15:07 2009
@@ -50,19 +50,19 @@
  * <code>QNodeTypeDefinitionImpl</code> implements a serializable SPI node
  * type definition.
  */
-public class QNodeTypeDefinitionImpl implements QNodeTypeDefinition, Serializable, Cloneable
{
+public class QNodeTypeDefinitionImpl implements QNodeTypeDefinition, Serializable {
 
     private static final long serialVersionUID = -4065300714874671511L;
 
     /**
      * The name of the node definition.
      */
-    private Name name;
+    private final Name name;
 
     /**
      * The names of the declared super types of this node type definition.
      */
-    private Name[] supertypes;
+    private final Name[] supertypes;
 
     /**
      * The names of the supported mixins on this node type (or <code>null</code>)
@@ -72,27 +72,27 @@
     /**
      * Indicates whether this is a mixin node type definition.
      */
-    private boolean isMixin;
+    private final boolean isMixin;
 
     /**
      * Indicates whether this is an abstract node type definition.
      */
-    private boolean isAbstract;
+    private final boolean isAbstract;
 
     /**
      * Indicates whether this is a queryable node type definition.
      */
-    private boolean isQueryable;
+    private final boolean isQueryable;
 
     /**
      * Indicates whether this node type definition has orderable child nodes.
      */
-    private boolean hasOrderableChildNodes;
+    private final boolean hasOrderableChildNodes;
 
     /**
      * The name of the primary item or <code>null</code> if none is defined.
      */
-    private Name primaryItemName;
+    private final Name primaryItemName;
 
     /**
      * The list of child node definitions.
@@ -103,11 +103,14 @@
      * The list of property definitions.
      */
     private final Set<QNodeDefinition> childNodeDefs;
+
     /**
      * Unmodifiable collection of dependent node type <code>Name</code>s.
+     * Calculated on demand.
+     *
      * @see #getDependencies()
      */
-    private transient Collection<Name> dependencies;
+    private transient volatile Collection<Name> dependencies;
 
     /**
      * Default constructor.
@@ -164,7 +167,10 @@
         this.primaryItemName = primaryItemName;
         this.propertyDefs = getSerializablePropertyDefs(declaredPropDefs);
         this.childNodeDefs = getSerializableNodeDefs(declaredNodeDefs);
-        setSupertypes(supertypes); // make sure supertypes are sorted
+        // make sure supertypes are sorted
+        SortedSet<Name> types = new TreeSet<Name>();
+        types.addAll(Arrays.asList(supertypes));
+        this.supertypes = types.toArray(new Name[types.size()]);
     }
 
     /**
@@ -207,103 +213,6 @@
                 createQNodeDefinitions(name, def.getDeclaredChildNodeDefinitions(), resolver));
     }
 
-    /**
-     * Sets the name of the node type being defined.
-     *
-     * @param name The name of the node type.
-     */
-    public void setName(Name name) {
-        this.name = name;
-    }
-
-    /**
-     * Sets the supertypes.
-     *
-     * @param names the names of the supertypes.
-     */
-    public void setSupertypes(Name[] names) {
-        resetDependencies();
-        // Optimize common cases (zero or one supertypes)
-        if (names.length == 0) {
-            supertypes = Name.EMPTY_ARRAY;
-        } else if (names.length == 1) {
-            supertypes = new Name[] { names[0] };
-        } else {
-            // Sort and remove duplicates
-            SortedSet<Name> types = new TreeSet<Name>();
-            types.addAll(Arrays.asList(names));
-            supertypes = types.toArray(new Name[types.size()]);
-        }
-    }
-
-    /**
-     * Sets the mixin flag.
-     *
-     * @param mixin flag
-     */
-    public void setMixin(boolean mixin) {
-        this.isMixin = mixin;
-    }
-
-    /**
-     * Sets the orderableChildNodes flag.
-     *
-     * @param orderableChildNodes flag
-     */
-    public void setOrderableChildNodes(boolean orderableChildNodes) {
-        this.hasOrderableChildNodes = orderableChildNodes;
-    }
-
-    /**
-     * Sets the 'abstract' flag.
-     *
-     * @param abstractStatus flag
-     */
-    public void setAbstract(boolean abstractStatus) {
-        this.isAbstract = abstractStatus;
-    }
-
-    /**
-     * Sets the 'queryable' flag.
-     *
-     * @param queryable flag
-     */
-    public void setQueryable(boolean queryable) {
-        this.isQueryable = queryable;
-    }
-
-    /**
-     * Sets the name of the primary item (one of the child items of the node's
-     * of this node type)
-     *
-     * @param primaryItemName The name of the primary item.
-     */
-    public void setPrimaryItemName(Name primaryItemName) {
-        this.primaryItemName = primaryItemName;
-    }
-
-    /**
-     * Sets the property definitions.
-     *
-     * @param defs An array of <code>QPropertyDefinition</code> objects.
-     */
-    public void setPropertyDefs(QPropertyDefinition[] defs) {
-        resetDependencies();
-        propertyDefs.clear();
-        propertyDefs.addAll(Arrays.asList(defs));
-    }
-
-    /**
-     * Sets the child node definitions.
-     *
-     * @param defs An array of <code>QNodeDefinition</code> objects
-     */
-    public void setChildNodeDefs(QNodeDefinition[] defs) {
-        resetDependencies();
-        childNodeDefs.clear();
-        childNodeDefs.addAll(Arrays.asList(defs));
-    }
-
     //------------------------------------------------< QNodeTypeDefinition >---
 
     /**
@@ -419,6 +328,9 @@
         return dependencies;
     }
     
+    /**
+     * {@inheritDoc}
+     */
     public Name[] getSupportedMixinTypes() {
         if (supportedMixins == null) {
             return null;
@@ -432,16 +344,6 @@
     
     //-------------------------------------------< java.lang.Object overrides >
 
-    public QNodeTypeDefinitionImpl clone() {
-        try {
-            // todo: itemdefs should be cloned as well, since mutable
-            return (QNodeTypeDefinitionImpl) super.clone();
-        } catch (CloneNotSupportedException e) {
-            // does not happen, this class is cloneable
-            throw new InternalError();
-        }
-    }
-
     public boolean equals(Object obj) {
         if (this == obj) {
             return true;
@@ -474,10 +376,6 @@
 
     //-------------------------------< internal >-------------------------------
 
-    private void resetDependencies() {
-        dependencies = null;
-    }
-
     /**
      * Returns a set of serializable property definitions for
      * <code>propDefs</code>.

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QPropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QPropertyDefinitionImpl.java?rev=816551&r1=816550&r2=816551&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QPropertyDefinitionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QPropertyDefinitionImpl.java
Fri Sep 18 09:15:07 2009
@@ -20,11 +20,20 @@
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.QValueFactory;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.nodetype.PropertyDefinition;
+
 /**
  * <code>QPropertyDefinitionImpl</code> implements SPI property
  * definition interface.
@@ -32,6 +41,8 @@
 public class QPropertyDefinitionImpl extends QItemDefinitionImpl
         implements QPropertyDefinition {
 
+    private static final long serialVersionUID = 1064686456661663541L;
+
     /**
      * The required type.
      */
@@ -61,7 +72,6 @@
      * The 'fullTextSearcheable' flag
      */
     private final boolean fullTextSearchable;
-
     /**
      * The 'queryOrderable' flag
      */
@@ -101,7 +111,8 @@
      * @param availableQueryOperators the available query operators
      * @param isFullTextSearchable if this is fulltext searchable
      * @param isQueryOrderable   if this is queryable
-     * @throws NullPointerException if <code>valueConstraints</code> is
+     * @throws NullPointerException if <code>valueConstraints</code> or
+     *                              <code>availableQueryOperators</code> is
      *                              <code>null</code>.
      * @since JCR 2.0
      */
@@ -119,6 +130,9 @@
         if (valueConstraints == null) {
             throw new NullPointerException("valueConstraints");
         }
+        if (availableQueryOperators == null) {
+            throw new NullPointerException("availableQueryOperators");
+        }
         this.defaultValues = defaultValues;
         this.multiple = isMultiple;
         this.requiredType = requiredType;
@@ -128,6 +142,31 @@
         this.queryOrderable = isQueryOrderable;
     }
 
+    /**
+     * Creates a new property definition based on <code>propDef</code>.
+     *
+     * @param propDef       the JCR property definition.
+     * @param resolver      the name/path resolver of the session that provided
+     *                      the property definition.
+     * @param qValueFactory the QValue factory.
+     * @throws RepositoryException if an error occurs while reading from
+     *                             <code>propDef</code>.
+     */
+    public QPropertyDefinitionImpl(PropertyDefinition propDef,
+                                   NamePathResolver resolver,
+                                   QValueFactory qValueFactory)
+            throws RepositoryException {
+        this(propDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME
: resolver.getQName(propDef.getName()),
+                resolver.getQName(propDef.getDeclaringNodeType().getName()),
+                propDef.isAutoCreated(), propDef.isMandatory(),
+                propDef.getOnParentVersion(), propDef.isProtected(),
+                convertValues(propDef.getDefaultValues(), resolver, qValueFactory),
+                propDef.isMultiple(), propDef.getRequiredType(),
+                ValueConstraint.create(propDef.getRequiredType(), propDef.getValueConstraints(),
resolver),
+                propDef.getAvailableQueryOperators(),
+                propDef.isFullTextSearchable(), propDef.isQueryOrderable());
+    }
+
     //------------------------------------------------< QPropertyDefinition >---
     /**
      * {@inheritDoc}
@@ -251,4 +290,31 @@
         }
         return hashCode;
     }
+
+    //-------------------------------< internal >-------------------------------
+
+    /**
+     * Convers JCR {@link Value}s to {@link QValue}s.
+     *
+     * @param values   the JCR values.
+     * @param resolver the name/path resolver of the session that provided the
+     *                 values.
+     * @param factory  the QValue factory.
+     * @return the converted values.
+     * @throws RepositoryException if an error occurs while converting the
+     *                             values.
+     */
+    private static QValue[] convertValues(Value[] values,
+                                          NamePathResolver resolver,
+                                          QValueFactory factory)
+            throws RepositoryException {
+        QValue[] defaultValues = null;
+        if (values != null) {
+            defaultValues = new QValue[values.length];
+            for (int i = 0; i < values.length; i++) {
+                defaultValues[i] = ValueFormat.getQValue(values[i], resolver, factory);
+            }
+        }
+        return defaultValues;
+    }
 }

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/QNodeTypeDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/QNodeTypeDefinitionBuilder.java?rev=816551&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/QNodeTypeDefinitionBuilder.java
(added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/QNodeTypeDefinitionBuilder.java
Fri Sep 18 09:15:07 2009
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.commons.nodetype;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import javax.jcr.nodetype.NodeTypeDefinition;
+
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
+
+/**
+ * A builder for {@link QNodeTypeDefinition}.
+ */
+public class QNodeTypeDefinitionBuilder {
+
+    private Name name = null;
+    private List<Name> supertypes = new ArrayList<Name>();
+    private boolean isMixin = false;
+    private boolean isOrderable = false;
+    private Name primaryItemName = null;
+    private List<QPropertyDefinition> propertyDefinitions = new ArrayList<QPropertyDefinition>();
+    private List<QNodeDefinition> childNodeDefinitions = new ArrayList<QNodeDefinition>();
+    private boolean isAbstract = false;
+    private boolean isQueryable = true;
+    private List<Name> supportedMixins = null;
+
+
+    /**
+     * Set the name of the node type definition being built
+     * @param name the name
+     * @see NodeTypeDefinition#getName()
+     */
+    public void setName(Name name) {
+        this.name = name;
+    }
+
+    /**
+     * @return the name of the node type definition being built or
+     * <code>null</code> if not set.
+     * @see NodeTypeDefinition#getName()
+     */
+    public Name getName() {
+        return name;
+    }
+
+    /**
+     * Specifies the supertypes of the node type definition being built
+     * @param supertypes the supertypes
+     * @see NodeTypeDefinition#getDeclaredSupertypeNames()
+     */
+    public void setSupertypes(Name[] supertypes) {
+        this.supertypes.clear();
+        this.supertypes.addAll(Arrays.asList(supertypes));
+    }
+
+    /**
+     * Returns an array containing the names of the supertypes of the node
+     * type definition being built.
+     *
+     * @return an array of supertype names
+     * @see NodeTypeDefinition#getDeclaredSupertypeNames()
+     */
+    public Name[] getSuperTypes() {
+        if (supertypes.size() > 0
+                || isMixin() || NameConstants.NT_BASE.equals(getName())) {
+            return supertypes.toArray(new Name[supertypes.size()]);
+        } else {
+            return new Name[] { NameConstants.NT_BASE };
+        }
+    }
+
+    /**
+     * @param isMixin <code>true</code> if building a mixin node type
+     * definition; <code>false</code> otherwise.
+     * @see NodeTypeDefinition#isMixin()
+     */
+    public void setMixin(boolean isMixin) {
+        this.isMixin = isMixin;
+    }
+
+    /**
+     * @return <code>true</code> if building a mixin node type definition;
+     * <code>false</code> otherwise.
+     * @see NodeTypeDefinition#isMixin()
+     */
+    public boolean isMixin() {
+        return isMixin;
+    }
+
+    /**
+     * Sets the names of additional mixin types supported on this node type.
+     *
+     * @param names an array of mixin type names, or <code>null</code> when
+     *              there are no known constraints
+     */
+    public void setSupportedMixinTypes(Name[] names) {
+        if (names == null) {
+            supportedMixins = null;
+        } else {
+            supportedMixins = new ArrayList<Name>(Arrays.asList(names));
+        }
+    }
+
+    /**
+     * Returns an array containing the names of additional mixin types supported
+     * on this node type.
+     *
+     * @return an array of mixin type names, or <code>null</code> when there
are
+     *         no known constraints.
+     */
+    public Name[] getSupportedMixinTypes() {
+        if (supportedMixins == null) {
+            return null;
+        } else {
+            return supportedMixins.toArray(new Name[supportedMixins.size()]);
+        }
+    }
+
+    /**
+     * @param isOrderable <code>true</code> if building a node type having
+     * orderable child nodes; <code>false</code> otherwise.
+     * @see NodeTypeDefinition#hasOrderableChildNodes()
+     */
+    public void setOrderableChildNodes(boolean isOrderable) {
+        this.isOrderable = isOrderable;
+    }
+
+    /**
+     * @return <code>true</code> if building a node type having orderable
+     * child nodes; <code>false</code> otherwise.
+     * @see NodeTypeDefinition#hasOrderableChildNodes()
+     */
+    public boolean hasOrderableChildNodes() {
+        return isOrderable;
+    }
+
+    /**
+     * @param primaryItemName the name of the primary item or
+     * <code>null</code> if not set.
+     * @see NodeTypeDefinition#getPrimaryItemName()
+     */
+    public void setPrimaryItemName(Name primaryItemName) {
+        this.primaryItemName = primaryItemName;
+    }
+
+    /**
+     * @return the name of the primary item or <code>null</code> if not set.
+     * @see NodeTypeDefinition#getPrimaryItemName()
+     */
+    public Name getPrimaryItemName() {
+        return primaryItemName;
+    }
+
+    /**
+     * @return <code>true</code> if the node type is abstract.
+     * @see NodeTypeDefinition#isAbstract()
+     */
+    public boolean isAbstract() {
+        return isAbstract;
+    }
+
+    /**
+     * @param isAbstract <code>true</code> if building a node type that is abstract.
+     * @see NodeTypeDefinition#isAbstract()
+     */
+    public void setAbstract(boolean isAbstract) {
+        this.isAbstract = isAbstract;
+    }
+
+    /**
+     * @return <code>true</code> if the node type is queryable
+     * @see NodeTypeDefinition#isQueryable()
+     */
+    public boolean isQueryable() {
+        return isQueryable;
+    }
+
+    /**
+     * @param queryable <code>true</code> if building a node type that is queryable
+     * @see NodeTypeDefinition#isQueryable()
+     */
+    public void setQueryable(boolean queryable) {
+        isQueryable = queryable;
+    }
+
+    /**
+     * @param propDefs an array containing the property definitions of the node type definition
+     *                being built.
+     * @see NodeTypeDefinition#getDeclaredPropertyDefinitions()
+     */
+    public void setPropertyDefs(QPropertyDefinition[] propDefs) {
+        propertyDefinitions.clear();
+        propertyDefinitions.addAll(Arrays.asList(propDefs));
+    }
+
+    /**
+     * @return an array containing the property definitions of the node type
+     *         definition being built.
+     * @see NodeTypeDefinition#getDeclaredPropertyDefinitions()
+     */
+    public QPropertyDefinition[] getPropertyDefs() {
+        return propertyDefinitions.toArray(new QPropertyDefinition[propertyDefinitions.size()]);
+    }
+
+    /**
+     * @param childDefs an array containing the child node definitions of the node type
+     *                definition being.
+     * @see NodeTypeDefinition#getDeclaredChildNodeDefinitions()
+     */
+    public void setChildNodeDefs(QNodeDefinition[] childDefs) {
+        childNodeDefinitions.clear();
+        childNodeDefinitions.addAll(Arrays.asList(childDefs));
+    }
+
+    /**
+     * @return an array containing the child node definitions of the node type
+     *         definition being built.
+     * @see NodeTypeDefinition#getDeclaredChildNodeDefinitions()
+     */
+    public QNodeDefinition[] getChildNodeDefs() {
+        return childNodeDefinitions.toArray(new QNodeDefinition[childNodeDefinitions.size()]);
+    }
+
+    /**
+     * Creates a new {@link QNodeTypeDefinition} instance based on the state of this builder.
+     *
+     * @return a new {@link QNodeTypeDefinition} instance.
+     * @throws IllegalStateException if the instance has not the necessary information to
build
+     *                 the QNodeTypeDefinition instance.
+     */
+    public QNodeTypeDefinition build() throws IllegalStateException {
+        return new QNodeTypeDefinitionImpl(getName(), getSuperTypes(),
+                getSupportedMixinTypes(), isMixin(), isAbstract(),
+                isQueryable(), hasOrderableChildNodes(), getPrimaryItemName(),
+                getPropertyDefs(), getChildNodeDefs());
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/QNodeTypeDefinitionBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?rev=816551&r1=816550&r2=816551&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Fri Sep 18 09:15:07 2009
@@ -42,6 +42,9 @@
 import org.apache.jackrabbit.spi.Event;
 import org.apache.jackrabbit.spi.commons.EventFilterImpl;
 import org.apache.jackrabbit.spi.commons.EventBundleImpl;
+import org.apache.jackrabbit.spi.commons.QPropertyDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.QNodeDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
@@ -1229,10 +1232,10 @@
     /**
      * {@inheritDoc}
      */
-    public Iterator getQNodeTypeDefinitions(SessionInfo sessionInfo) throws RepositoryException
{
+    public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo)
throws RepositoryException {
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
         NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
-        List nodeTypes = new ArrayList();
+        List<QNodeTypeDefinition> nodeTypes = new ArrayList<QNodeTypeDefinition>();
         try {
             for (NodeTypeIterator it = ntMgr.getAllNodeTypes(); it.hasNext(); ) {
                 NodeType nt = it.nextNodeType();
@@ -1248,20 +1251,22 @@
     /**
      * {@inheritDoc}
      */
-    public Iterator getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames)
throws RepositoryException {
+    public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo,
Name[] nodetypeNames) throws RepositoryException {
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
         NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
-        List defs = new ArrayList();
-        for (int i = 0; i < nodetypeNames.length; i++) {
+        List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>();
+        for (Name nodetypeName : nodetypeNames) {
             try {
-                String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeNames[i]);
+                String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName);
                 NodeType nt = ntMgr.getNodeType(ntName);
-                defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
+                defs.add(new QNodeTypeDefinitionImpl(nt, 
+                        sInfo.getNamePathResolver(), getQValueFactory()));
 
                 // in addition pack all supertypes into the return value
                 NodeType[] supertypes = nt.getSupertypes();
-                for (int st = 0; st < supertypes.length; st++) {
-                    defs.add(new QNodeTypeDefinitionImpl(supertypes[i], sInfo.getNamePathResolver(),
getQValueFactory()));
+                for (NodeType supertype : supertypes) {
+                    defs.add(new QNodeTypeDefinitionImpl(supertype,
+                            sInfo.getNamePathResolver(), getQValueFactory()));
                 }
             } catch (NameException e) {
                 throw new RepositoryException(e);



Mime
View raw message