jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r814610 [1/2] - 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/test/java/org/apache/jackrabbit/core/data/ jackra...
Date Mon, 14 Sep 2009 12:30:37 GMT
Author: mduerig
Date: Mon Sep 14 12:30:36 2009
New Revision: 814610

URL: http://svn.apache.org/viewvc?rev=814610&view=rev
Log:
JCR-2301: CND support in jackrabbit-jcr-commons

Added:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/AbstractItemTypeDefinitionsBuilder.java
      - copied, changed from r808006, jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilder.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/CndImporter.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/CompactNodeTypeDefReader.java
      - copied, changed from r812902, jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefReader.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/ItemTemplatesBuilder.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/Lexer.java
      - copied, changed from r808006, jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/Lexer.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/ParseException.java
      - copied, changed from r808006, 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/QItemDefinitionsBuilder.java
      - copied, changed from r808006, jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilderImpl.java
Removed:
    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/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
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/NodeTypeDefStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/MixinTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.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/AbstractRepositoryService.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefTest.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=814610&r1=814609&r2=814610&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 Mon Sep 14 12:30:36 2009
@@ -25,6 +25,8 @@
 
 import org.apache.commons.collections.BidiMap;
 import org.apache.commons.collections.bidimap.DualHashBidiMap;
+import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.commons.cnd.ParseException;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
@@ -37,9 +39,8 @@
 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.QItemDefinitionsBuilder;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter;
-import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException;
 
 /**
  * Base implementation for a record.
@@ -248,8 +249,12 @@
     public NodeTypeDef readNodeTypeDef() throws JournalException {
         try {
             StringReader sr = new StringReader(readString());
-            CompactNodeTypeDefReader reader = new CompactNodeTypeDefReader(
-                    sr, "(internal)", new NamespaceMapping(nsResolver));
+
+            CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping> reader =
+                new CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping>(
+                    sr, "(internal)", new NamespaceMapping(nsResolver),
+                    new QItemDefinitionsBuilder());
+
             Collection<QNodeTypeDefinition> ntds = reader.getNodeTypeDefinitions();
             if (ntds.size() != 1) {
                 throw new JournalException("Expected one node type definition: got " + ntds.size());

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=814610&r1=814609&r2=814610&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 Mon Sep 14 12:30:36 2009
@@ -28,12 +28,14 @@
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
 
+import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.commons.cnd.ParseException;
 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.namespace.NamespaceMapping;
+import org.apache.jackrabbit.spi.commons.nodetype.QItemDefinitionsBuilder;
 
 /**
  * <code>NodeTypeDefStore</code> ...
@@ -66,7 +68,7 @@
 
     /**
      * Loads node types from a CND stream.
-     * 
+     *
      * @param in reader containing the nodetype definitions
      * @param systemId optional name of the stream
      *
@@ -76,7 +78,10 @@
     public void loadCND(Reader in, String systemId)
             throws IOException, InvalidNodeTypeDefException {
         try {
-            CompactNodeTypeDefReader r = new CompactNodeTypeDefReader(in, systemId);
+            CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping> r =
+                new CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping>(
+                    in, systemId, new QItemDefinitionsBuilder());
+
             for (QNodeTypeDefinition qdef: r.getNodeTypeDefinitions()) {
                 add(new NodeTypeDef(qdef));
             }

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=814610&r1=814609&r2=814610&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 Mon Sep 14 12:30:36 2009
@@ -50,6 +50,8 @@
 import org.apache.commons.collections.map.ReferenceMap;
 import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
 import org.apache.jackrabbit.commons.NamespaceHelper;
+import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.commons.cnd.ParseException;
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.data.DataStore;
@@ -64,8 +66,7 @@
 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.QItemDefinitionsBuilder;
 import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -208,7 +209,7 @@
     }
 
     /**
-     * @see org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeTypeManager#getNamePathResolver() 
+     * @see org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeTypeManager#getNamePathResolver()
      */
     public NamePathResolver getNamePathResolver() {
         return session;
@@ -267,8 +268,11 @@
             } else if (contentType.equalsIgnoreCase(TEXT_X_JCR_CND)) {
                 try {
                     NamespaceMapping mapping = new NamespaceMapping(session);
-                    CompactNodeTypeDefReader reader = new CompactNodeTypeDefReader(
-                            new InputStreamReader(in), "cnd input stream", mapping);
+
+                    CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping> reader =
+                        new CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping>(
+                            new InputStreamReader(in), "cnd input stream", mapping,
+                            new QItemDefinitionsBuilder());
 
                     namespaceMap.putAll(mapping.getPrefixToURIMapping());
                     for (QNodeTypeDefinition ntDef: reader.getNodeTypeDefinitions()) {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java?rev=814610&r1=814609&r2=814610&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java Mon Sep 14 12:30:36 2009
@@ -16,17 +16,21 @@
  */
 package org.apache.jackrabbit.core.data;
 
-import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
-import org.apache.jackrabbit.test.AbstractJCRTest;
-
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
 
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 
+import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
+import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.apache.jackrabbit.commons.cnd.ParseException;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
 /**
  * Test node types with binary default values.
  */
@@ -35,16 +39,18 @@
     /**
      * Test a node type with a binary default value
      * @throws RepositoryException
+     * @throws ParseException
      */
     public void testNodeTypesWithBinaryDefaultValue()
-            throws RepositoryException, IOException {
+            throws RepositoryException, IOException, ParseException {
+
         doTestNodeTypesWithBinaryDefaultValue(0);
         doTestNodeTypesWithBinaryDefaultValue(10);
         doTestNodeTypesWithBinaryDefaultValue(10000);
     }
 
     public void doTestNodeTypesWithBinaryDefaultValue(int len)
-            throws RepositoryException, IOException {
+            throws RepositoryException, IOException, ParseException {
         char[] chars = new char[len];
         for (int i = 0; i < chars.length; i++) {
             chars[i] = 'a';
@@ -58,9 +64,8 @@
         JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager)
             superuser.getWorkspace().getNodeTypeManager();
         if (!manager.hasNodeType(type)) {
-            manager.registerNodeTypes(
-                    new ByteArrayInputStream(cnd.getBytes("UTF-8")),
-                    JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+            Reader cndReader = new InputStreamReader(new ByteArrayInputStream(cnd.getBytes("UTF-8")));
+            CndImporter.registerNodeTypes(cndReader, superuser);
         }
 
         Node root = superuser.getRootNode();

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=814610&r1=814609&r2=814610&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 Mon Sep 14 12:30:36 2009
@@ -16,35 +16,39 @@
  */
 package org.apache.jackrabbit.core.nodetype.xml;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Arrays;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.OnParentVersionAction;
+
 import junit.framework.AssertionFailedError;
 
 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.NodeDef;
 import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
 import org.apache.jackrabbit.core.nodetype.PropDef;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.core.value.InternalValueFactory;
-import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 
-import javax.jcr.NamespaceException;
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.version.OnParentVersionAction;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-
 /**
  * Test cases for reading and writing node type definition files.
  */
@@ -284,11 +288,9 @@
             superuser.getNamespacePrefix("test-namespace3");
             // Ignore test case, node type and namespace already registered
         } catch (NamespaceException e1) {
-            JackrabbitNodeTypeManager ntm = (JackrabbitNodeTypeManager)
-                superuser.getWorkspace().getNodeTypeManager();
-            ntm.registerNodeTypes(
-                    TestAll.class.getResourceAsStream(TEST_NS_CND_NODETYPES),
-                    JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+            Reader cnd = new InputStreamReader(TestAll.class.getResourceAsStream(TEST_NS_CND_NODETYPES));
+            CndImporter.registerNodeTypes(cnd, superuser);
+            cnd.close();
             try {
                 superuser.getNamespacePrefix("test-namespace3");
             } catch (NamespaceException e2) {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/MixinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/MixinTest.java?rev=814610&r1=814609&r2=814610&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/MixinTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/MixinTest.java Mon Sep 14 12:30:36 2009
@@ -16,19 +16,23 @@
  */
 package org.apache.jackrabbit.core.query;
 
-import javax.jcr.RepositoryException;
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Calendar;
+
 import javax.jcr.Node;
+import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
-
-import java.io.ByteArrayInputStream;
-import java.util.Calendar;
+import org.apache.jackrabbit.commons.cnd.CndImporter;
 
 /**
  * Tests if mixin types are queried correctly when using element test: element()
  */
 public class MixinTest extends AbstractQueryTest {
 
+    @Override
     protected void setUp() throws Exception {
         super.setUp();
 
@@ -38,9 +42,9 @@
             String cnd =
                 "<test='http://www.apache.org/jackrabbit/test'>\n"
                 + "[test:mimeType] > mix:mimeType mixin";
-            manager.registerNodeTypes(
-                    new ByteArrayInputStream(cnd.getBytes()),
-                    JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+
+            Reader cndReader = new InputStreamReader(new ByteArrayInputStream(cnd.getBytes()));
+            CndImporter.registerNodeTypes(cndReader, superuser);
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java?rev=814610&r1=814609&r2=814610&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java Mon Sep 14 12:30:36 2009
@@ -19,6 +19,8 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 
 import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.Node;
@@ -28,6 +30,7 @@
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 
 import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
+import org.apache.jackrabbit.commons.cnd.CndImporter;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 
 /**
@@ -43,6 +46,7 @@
      *
      * @throws Exception if an unexpected error occurs
      */
+    @Override
     protected void setUp() throws Exception {
         super.setUp();
         JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager)
@@ -51,9 +55,8 @@
             manager.getNodeType("DocViewMultiValueTest");
         } catch (NoSuchNodeTypeException e) {
             String cnd = "[DocViewMultiValueTest] - test (boolean) multiple";
-            manager.registerNodeTypes(
-                    new ByteArrayInputStream(cnd.getBytes("UTF-8")),
-                    JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+            Reader cndReader = new InputStreamReader(new ByteArrayInputStream(cnd.getBytes("UTF-8")));
+            CndImporter.registerNodeTypes(cndReader, superuser);
         }
     }
 
@@ -62,6 +65,7 @@
      *
      * @throws Exception if an unexpected error occurs
      */
+    @Override
     protected void tearDown() throws Exception {
         // TODO: Unregister the MultiValueTestType node type once Jackrabbit
         // supports node type removal.

Copied: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/AbstractItemTypeDefinitionsBuilder.java (from r808006, jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilder.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/AbstractItemTypeDefinitionsBuilder.java?p2=jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/AbstractItemTypeDefinitionsBuilder.java&p1=jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilder.java&r1=808006&r2=814610&rev=814610&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilder.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/AbstractItemTypeDefinitionsBuilder.java Mon Sep 14 12:30:36 2009
@@ -14,581 +14,377 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.spi.commons.nodetype.compact;
+package org.apache.jackrabbit.commons.cnd;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.ValueFormatException;
-import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.nodetype.ItemDefinition;
 import javax.jcr.nodetype.NodeTypeDefinition;
-
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.QItemDefinition;
-import org.apache.jackrabbit.spi.QNodeDefinition;
-import org.apache.jackrabbit.spi.QNodeTypeDefinition;
-import org.apache.jackrabbit.spi.QPropertyDefinition;
-import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.spi.QValueConstraint;
-import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException;
-import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+import javax.jcr.nodetype.PropertyDefinition;
 
 /**
- * A builder for {@link QNodeTypeDefinition}s
+ * Builder for node type definitions, node definitions and property definitions.
+ * @param <T>  type of the node type definition
+ * @param <N>  type of the namespace mapping
  */
-public abstract class QNodeTypeDefinitionsBuilder {
+public abstract class AbstractItemTypeDefinitionsBuilder<T, N> {
+
+    /**
+     * Create a new instance of a {@link AbstractNodeTypeDefinitionBuilder}
+     * @return
+     * @throws RepositoryException
+     */
+    public abstract AbstractNodeTypeDefinitionBuilder<T> newNodeTypeDefinitionBuilder()
+            throws RepositoryException;
 
     /**
-     * @return a new instance of a builder for a {@link QNodeTypeDefinition}
+     * Set the namespace mapping to use for the node type definition being built
+     * @param nsMapping
      */
-    public abstract QNodeTypeDefinitionBuilder newQNodeTypeDefinition();
+    public abstract void setNamespaceMapping(N nsMapping);
 
     /**
-     * Returns a <code>Name</code> with the given namespace URI and
-     * local part and validates the given parameters.
-     *
-     * @param namespaceURI namespace uri
-     * @param localName local part
-     * @return the created name
-     * @throws IllegalArgumentException if <code>namespaceURI</code> or
-     * <code>localName</code> is invalid.
+     * @return  the namespace mapping used for the node type definition being built
      */
-    public abstract Name createName(String namespaceURI, String localName)
-            throws IllegalArgumentException;
+    public abstract N getNamespaceMapping();
 
     /**
-     * A builder for a {@link QNodeTypeDefinition}
+     * Add a mapping to the namespace map
+     * @param prefix
+     * @param uri
+     * @throws RepositoryException
      */
-    public abstract class QNodeTypeDefinitionBuilder {
-        private Name name;
-        private Name[] supertypes;
-        private boolean isMixin;
-        private boolean isOrderable;
-        private Name primaryItemName;
-        private QPropertyDefinition[] propertyDefinitions;
-        private QNodeDefinition[] childNodeDefinitions;
-        private boolean isAbstract;
-        private boolean isQueryable = true;
+    public abstract void setNamespace(String prefix, String uri) throws RepositoryException;
+
+    /**
+     * Builder for a node type definition of type T.
+     * @param <T>
+     */
+    public static abstract class AbstractNodeTypeDefinitionBuilder<T> {
+
+        /** See {@link #setName(String)} */
+        protected String name;
+
+        /** See {@link #setMixin(boolean)} */
+        protected boolean isMixin;
+
+        /** See {@link #setOrderableChildNodes(boolean)} */
+        protected boolean isOrderable;
+
+        /** See {@link #setAbstract(boolean)} */
+        protected boolean isAbstract;
+
+        /** See {@link #setQueryable(boolean)} */
+        protected boolean queryable;
 
         /**
          * Set the name of the node type definition being built
-         * @param name the name
+         * @param name
+         * @throws RepositoryException  if the name is not valid
          * @see NodeTypeDefinition#getName()
          */
-        public void setName(Name name) {
+        public void setName(String name) throws RepositoryException {
             this.name = name;
         }
 
         /**
-         * @return the name of the node type definition being built or
-         * <code>null</code> if not set.
-         * @see NodeTypeDefinition#getName()
+         * Returns the name of the node type definition being built
+         * @return
          */
-        public Name getName() {
+        public String 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 = supertypes;
-        }
-
-        /**
-         * Returns an array containing the names of the supertypes of the node
-         * type definition being built.
-         *
-         * @return an array of supertype names
+         * Add the given name to the set of supertypes of the node type definition
+         * being built
+         * @param name  name of the the supertype
+         * @throws RepositoryException  if the name is not valid
          * @see NodeTypeDefinition#getDeclaredSupertypeNames()
          */
-        public Name[] getSuperTypes() {
-            return supertypes;
-        }
+        public abstract void addSupertype(String name) throws RepositoryException;
 
         /**
          * @param isMixin <code>true</code> if building a mixin node type
          * definition; <code>false</code> otherwise.
+         * @throws RepositoryException
          * @see NodeTypeDefinition#isMixin()
          */
-        public void setMixin(boolean isMixin) {
+        public void setMixin(boolean isMixin) throws RepositoryException {
             this.isMixin = isMixin;
         }
 
         /**
-         * @return <code>true</code> if building a mixin node type definition;
-         * <code>false</code> otherwise.
-         * @see NodeTypeDefinition#isMixin()
-         */
-        public boolean getMixin() {
-            return isMixin;
-        }
-
-        /**
          * @param isOrderable <code>true</code> if building a node type having
          * orderable child nodes; <code>false</code> otherwise.
+         * @throws RepositoryException
          * @see NodeTypeDefinition#hasOrderableChildNodes()
          */
-        public void setOrderableChildNodes(boolean isOrderable) {
+        public void setOrderableChildNodes(boolean isOrderable) throws RepositoryException {
             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 getOrderableChildNodes() {
-            return isOrderable;
-        }
-
-        /**
-         * @param primaryItemName the name of the primary item or
-         * <code>null</code> if not set.
+         * @param name  the name of the primary item.
+         * @throws RepositoryException
          * @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 getAbstract() {
-            return isAbstract;
-        }
+        public abstract void setPrimaryItemName(String name) throws RepositoryException;
 
         /**
          * @param isAbstract <code>true</code> if building a node type that is abstract.
+         * @throws RepositoryException
          * @see NodeTypeDefinition#isAbstract()
          */
-        public void setAbstract(boolean isAbstract) {
+        public void setAbstract(boolean isAbstract) throws RepositoryException {
             this.isAbstract = isAbstract;
         }
 
         /**
-         * @return <code>true</code> if the node type is queryable
-         * @see NodeTypeDefinition#isQueryable()
-         */
-        public boolean getQueryable() {
-            return isQueryable;
-        }
-
-        /**
          * @param queryable <code>true</code> if building a node type that is queryable
+         * @throws RepositoryException
          * @see NodeTypeDefinition#isQueryable()
          */
-        public void setQueryable(boolean queryable) {
-            isQueryable = queryable;
+        public void setQueryable(boolean queryable) throws RepositoryException {
+            this.queryable = queryable;
         }
 
         /**
-         * @param propDefs an array containing the property definitions of the node type definition
-         *                being built.
-         * @see NodeTypeDefinition#getDeclaredPropertyDefinitions()
+         * Create a new instance of a {@link AbstractItemTypeDefinitionsBuilder.AbstractPropertyDefinitionBuilder}
+         * which can be used to add property definitions to the node type definition being built.
+         * @return
+         * @throws RepositoryException
          */
-        public void setPropertyDefs(QPropertyDefinition[] propDefs) {
-            propertyDefinitions = propDefs;
-        }
+        public abstract AbstractPropertyDefinitionBuilder<T> newPropertyDefinitionBuilder()
+                throws RepositoryException;
 
         /**
-         * @return an array containing the property definitions of the node type definition being
-         *         built or <code>null</code> if not set.
-         * @see NodeTypeDefinition#getDeclaredPropertyDefinitions()
+         * Create a new instance fo a {@link AbstractItemTypeDefinitionsBuilder.AbstractNodeDefinitionBuilder}
+         * which can be used to add child node definitions to the node type definition being built.
+         * @return
+         * @throws RepositoryException
          */
-        public QPropertyDefinition[] getPropertyDefs() {
-            return propertyDefinitions;
-        }
+        public abstract AbstractNodeDefinitionBuilder<T> newNodeDefinitionBuilder() throws RepositoryException;
 
         /**
-         * @param childDefs an array containing the child node definitions of the node type
-         *                definition being.
-         * @see NodeTypeDefinition#getDeclaredChildNodeDefinitions()
+         * Build this node type definition
+         * @return
+         * @throws RepositoryException
          */
-        public void setChildNodeDefs(QNodeDefinition[] childDefs) {
-            childNodeDefinitions = childDefs;
-        }
+        public abstract T build() throws RepositoryException;
+    }
 
-        /**
-         * @return an array containing the child node definitions of the node type definition being
-         *         built or <code>null</code> if not set.
-         * @see NodeTypeDefinition#getDeclaredChildNodeDefinitions()
-         */
-        public QNodeDefinition[] getChildNodeDefs() {
-            return childNodeDefinitions;
-        }
+    /**
+     * Builder for item definitions of type <code>T</code>
+     * @param <T>
+     */
+    public static abstract class AbstractItemDefinitionBuilder<T> {
 
-        /**
-         * @return  a new instance of a builder for a {@link QNodeDefinition}.
-         */
-        public abstract QPropertyDefinitionBuilder newQPropertyDefinition();
+        /** See {@link #setName(String)} */
+        protected String name;
 
-        /**
-         * @return  a new instance of a builder for a {@link QNodeDefinition}.
-         */
-        public abstract QNodeDefinitionBuilder newQNodeDefinitionBuilder();
+        /** See {@link #setAutoCreated(boolean)} */
+        protected boolean autocreate;
 
-        /**
-         * 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 abstract QNodeTypeDefinition build() throws IllegalStateException;
-    }
+        /** See {@link #setOnParentVersion(int)} */
+        protected int onParent;
 
-    /**
-     * A builder for a {@link QItemDefinition}
-     */
-    abstract class QItemDefinitionBuilder {
-        private Name name;
-        private Name declaringType;
-        private boolean isAutocreated;
-        private int onParentVersion;
-        private boolean isProtected;
-        private boolean isMandatory;
+        /** See {@link #setProtected(boolean)} */
+        protected boolean isProtected;
+
+        /** See {@link #setMandatory(boolean)} */
+        protected boolean isMandatory;
 
         /**
          * @param name  the name of the child item definition being build
+         * @throws RepositoryException
          * @see ItemDefinition#getName()
          */
-        public void setName(Name name) {
+        public void setName(String name) throws RepositoryException {
             this.name = name;
         }
 
         /**
-         * @return the name of the child item definition being build.
-         * @see ItemDefinition#getName()
+         * Name of the child item definition being built
+         * @return
          */
-        public Name getName() {
+        public String getName() {
             return name;
         }
 
         /**
-         * @param type  the name of the declaring node type.
+         * @param name the name of the declaring node type.
+         * @throws RepositoryException
          * @see ItemDefinition#getDeclaringNodeType()
          */
-        public void setDeclaringNodeType(Name type) {
-            declaringType = type;
-        }
+        public abstract void setDeclaringNodeType(String name) throws RepositoryException;
 
         /**
-         * @return the name of the declaring node type.
-         * @see ItemDefinition#getDeclaringNodeType()
-         */
-        public Name getDeclaringNodeType() {
-            return declaringType;
-        }
-
-        /**
-         * @param autocreate <code>true</code> if building a 'autocreate' child item 
+         * @param autocreate <code>true</code> if building a 'autocreate' child item
          * definition, false otherwise.
+         * @throws RepositoryException
          * @see ItemDefinition#isAutoCreated()
          */
-        public void setAutoCreated(boolean autocreate) {
-            isAutocreated = autocreate;
-        }
-
-        /**
-         * @return <code>true</code> if building a 'autocreate' child item
-         * definition, false otherwise.
-         * @see ItemDefinition#isAutoCreated()
-         */
-        public boolean getAutoCreated() {
-            return isAutocreated;
+        public void setAutoCreated(boolean autocreate) throws RepositoryException {
+            this.autocreate = autocreate;
         }
 
         /**
          * @param onParent the 'onParentVersion' attribute of the child item definition being built
+         * @throws RepositoryException
          * @see ItemDefinition#getOnParentVersion()
          */
-        public void setOnParentVersion(int onParent) {
-            onParentVersion = onParent;
-        }
-
-        /**
-         * @return the 'onParentVersion' attribute of the child item definition being built
-         * @see ItemDefinition#getOnParentVersion()
-         */
-        public int getOnParentVersion() {
-            return onParentVersion;
+        public void setOnParentVersion(int onParent) throws RepositoryException {
+            this.onParent = onParent;
         }
 
         /**
          * @param isProtected <code>true</code> if building a 'protected' child
          * item definition, false otherwise.
+         * @throws RepositoryException
          * @see ItemDefinition#isProtected()
          */
-        public void setProtected(boolean isProtected) {
+        public void setProtected(boolean isProtected) throws RepositoryException {
             this.isProtected = isProtected;
         }
 
         /**
-         * @return <code>true</code> if building a 'protected' child item
-         * definition, false otherwise.
-         * @see ItemDefinition#isProtected()
-         */
-        public boolean getProtected() {
-            return isProtected;
-        }
-
-        /**
          * @param isMandatory <code>true</code> if building a 'mandatory' child
          * item definition, false otherwise.
-         * @see ItemDefinition#isMandatory()
+         * @throws RepositoryException
          */
-        public void setMandatory(boolean isMandatory) {
+        public void setMandatory(boolean isMandatory) throws RepositoryException {
             this.isMandatory = isMandatory;
         }
 
         /**
-         * @return <code>true</code> if building a 'mandatory' child item
-         * definition, false otherwise.
-         * @see ItemDefinition#isMandatory()
+         * Build this item definition an add it to its parent node type definition
+         * @throws RepositoryException
          */
-        public boolean getMandatory() {
-            return isMandatory;
-        }
+        public abstract void build() throws RepositoryException;
     }
 
     /**
-     * A builder for a {@link QPropertyDefinition}
-     * @see PropertyDefinition
+     * Builder for property definitions of type <code>T</code>
+     * @param <T>
      */
-    public abstract class QPropertyDefinitionBuilder extends QItemDefinitionBuilder {
+    public static abstract class AbstractPropertyDefinitionBuilder<T> extends AbstractItemDefinitionBuilder<T> {
+
+        /** See {@link #setRequiredType(int)} */
+        protected int requiredType;
+
+        /** See {@link #setMultiple(boolean)} */
+        protected boolean isMultiple;
+
+        /** See {@link #setFullTextSearchable(boolean)} */
+        protected boolean fullTextSearchable;
 
-        private int requiredType;
-        private QValueConstraint[] valueConstraints;
-        private QValue[] defaultValues;
-        private boolean isMultiple;
-        private boolean fullTextSearchable = true;
-        private boolean queryOrderable = true;
-        private String[] queryOperators = Operator.getAllQueryOperators();
+        /** See {@link #setQueryOrderable(boolean)} */
+        protected boolean queryOrderable;
+
+        /** See {@link #setAvailableQueryOperators(String[])} */
+        protected String[] queryOperators;
 
         /**
          * @param type the required type of the property definition being built.
+         * @throws RepositoryException
          * @see PropertyDefinition#getRequiredType()
          */
-        public void setRequiredType(int type) {
-            requiredType = type;
+        public void setRequiredType(int type) throws RepositoryException {
+            this.requiredType = type;
         }
 
         /**
-         * @return the required type of the property definition being built.
-         * @see PropertyDefinition#getRequiredType()
+         * The required type of the property definition being built.
+         * @return
          */
         public int getRequiredType() {
             return requiredType;
         }
 
         /**
-         * @param constraints array of value constraints of the property definition being built.
-         * @see PropertyDefinition#getValueConstraints()
-         */
-        public void setValueConstraints(QValueConstraint[] constraints) {
-            valueConstraints = constraints;
-        }
-
-        /**
-         * @return array of value constraints of the property definition being built.
+         * @param constraint  add a value constraint to the list of value constraints of the property
+         * definition being built.
+         * @throws RepositoryException
          * @see PropertyDefinition#getValueConstraints()
          */
-        public QValueConstraint[] getValueConstraints() {
-            return valueConstraints;
-        }
+        public abstract void addValueConstraint(String constraint) throws RepositoryException;
 
         /**
-         * @param values array of default values of the property definition being built.
+         * @param value  add a default value to the list of default values of the property definition
+         * being built.
+         * @throws RepositoryException
          * @see PropertyDefinition#getDefaultValues()
          */
-        public void setDefaultValues(QValue[] values) {
-            defaultValues = values;
-        }
+        public abstract void addDefaultValues(String value) throws RepositoryException;
 
-        /**
-         * @return array of default values of the property definition being built or
-         *         <code>null</code> if no default values are defined.
-         * @see PropertyDefinition#getDefaultValues()
-         */
-        public QValue[] getDefaultValues() {
-            return defaultValues;
-        }
-
-        /**
+         /**
          * @param isMultiple true if building a 'multiple' property definition.
+         * @throws RepositoryException
          * @see PropertyDefinition#isMultiple()
          */
-        public void setMultiple(boolean isMultiple) {
+        public void setMultiple(boolean isMultiple) throws RepositoryException {
             this.isMultiple = isMultiple;
         }
 
         /**
-         * @return true if building a 'multiple' property definition.
-         * @see PropertyDefinition#isMultiple()
-         */
-        public boolean getMultiple() {
-            return isMultiple;
-        }
-
-        /**
-         * @return <code>true</code> if the property is fulltext searchable
-         * @see PropertyDefinition#isFullTextSearchable()
-         */
-        public boolean getFullTextSearchable() {
-            return fullTextSearchable;
-        }
-
-        /**
          * @param fullTextSearchable <code>true</code> if building a
          * 'fulltext searchable' property definition
+         * @throws RepositoryException
          * @see PropertyDefinition#isFullTextSearchable()
          */
-        public void setFullTextSearchable(boolean fullTextSearchable) {
+        public void setFullTextSearchable(boolean fullTextSearchable) throws RepositoryException {
             this.fullTextSearchable = fullTextSearchable;
         }
 
         /**
-         * @return <code>true</code> if the property is orderable in a query
+         * @param queryOrderable <code>true</code> if the property is orderable in a query
+         * @throws RepositoryException
          * @see PropertyDefinition#isQueryOrderable()
          */
-        public boolean getQueryOrderable() {
-            return queryOrderable;
-        }
-
-        /**
-         * @param queryOrderable <code>true</code> if the property is orderable
-         *        in a query
-         * @see PropertyDefinition#isQueryOrderable()
-         */
-        public void setQueryOrderable(boolean queryOrderable) {
+        public void setQueryOrderable(boolean queryOrderable) throws RepositoryException {
             this.queryOrderable = queryOrderable;
         }
 
         /**
-         * @return the query operators of the property
-         * @see PropertyDefinition#getAvailableQueryOperators()
-         */
-        public String[] getAvailableQueryOperators() {
-            return queryOperators;
-        }
-
-        /**
          * @param queryOperators the query operators of the property
+         * @throws RepositoryException
          * @see PropertyDefinition#getAvailableQueryOperators()
          */
-        public void setAvailableQueryOperators(String[] queryOperators) {
+        public void setAvailableQueryOperators(String[] queryOperators) throws RepositoryException {
             this.queryOperators = queryOperators;
         }
-
-        /**
-         * Validate the given <code>constraint</code> and resolve any prefixes.
-         *
-         * @param constraint the contraint
-         * @param resolver the resolver
-         * @return A syntactically valid value constrained which refers to
-         * internal names and paths representations only.
-         * @throws InvalidConstraintException if <code>constraint</code> cannot
-         * be converted to a valid value constrained.
-         */
-        public abstract QValueConstraint createValueConstraint(String constraint, NamePathResolver resolver)
-                throws InvalidConstraintException;
-
-        /**
-         * Create a new <code>QValue</code> for <code>value</code> of the type this instance
-         * represents using the given <code>resolver</code>.
-         *
-         * @param value the value
-         * @param resolver the resolver
-         * @return a new <code>QValue</code>.
-         * @throws ValueFormatException If the given <code>value</code> cannot be converted to the
-         *                 specified <code>type</code>.
-         * @throws RepositoryException If another error occurs.
-         */
-        public abstract QValue createValue(String value, NamePathResolver resolver)
-                throws ValueFormatException, RepositoryException;
-
-        /**
-         * Creates a new {@link QPropertyDefinition} instance based on the state of this builder.
-         *
-         * @return a new {@link QPropertyDefinition} instance.
-         * @throws IllegalStateException if the instance has not the necessary information to build
-         *                 the QPropertyDefinition instance.
-         */
-        public abstract QPropertyDefinition build() throws IllegalStateException;
     }
 
     /**
-     * A builder for a {@link QNodeDefinition}
+     * Builder for child node definitions of type <code>T</code>
+     * @param <T>
      */
-    public abstract class QNodeDefinitionBuilder extends QItemDefinitionBuilder {
-        private Name defaultPrimaryType;
-        private Name[] requiredPrimaryTypes;
-        private boolean allowsSameNameSiblings;
+    public static abstract class AbstractNodeDefinitionBuilder<T> extends AbstractItemDefinitionBuilder<T> {
+        protected boolean allowSns;
 
         /**
          * @param name the name of the default primary type of the node definition being built.
+         * @throws RepositoryException
          */
-        public void setDefaultPrimaryType(Name name) {
-            defaultPrimaryType = name;
-        }
-
-        /**
-         * @return the name of the default primary type of the node definition being built.
-         */
-        public Name getDefaultPrimaryType() {
-            return defaultPrimaryType;
-        }
-
-        /**
-         * @param names array of names of the required primary types of the node definition being
-         *                built.
-         */
-        public void setRequiredPrimaryTypes(Name[] names) {
-            requiredPrimaryTypes = names;
-        }
+        public abstract void setDefaultPrimaryType(String name) throws RepositoryException;
 
         /**
-         * @return array of names of the required primary types of the node definition being built.
+         * @param name  add a required primary type to the list of names of the required primary types of
+         * the node definition being built.
+         * @throws RepositoryException
          */
-        public Name[] getRequiredPrimaryTypes() {
-            return requiredPrimaryTypes;
-        }
-
-        /**
-         * @param allowSns true if building a node definition with same name siblings, false
-         *                otherwise.
-         */
-        public void setAllowsSameNameSiblings(boolean allowSns) {
-            allowsSameNameSiblings = allowSns;
-        }
+        public abstract void addRequiredPrimaryType(String name) throws RepositoryException;
 
         /**
-         * @return true if building a node definition with same name siblings, false otherwise.
+         * @param allowSns true if building a node definition with same name siblings, false otherwise.
+         * @throws RepositoryException
          */
-        public boolean getAllowsSameNameSiblings() {
-            return allowsSameNameSiblings;
+        public void setAllowsSameNameSiblings(boolean allowSns) throws RepositoryException {
+            this.allowSns = allowSns;
         }
 
-        /**
-         * Creates a new {@link QNodeDefinition} instance based on the state of this builder.
-         *
-         * @return a new {@link QNodeDefinition} instance.
-         * @throws IllegalStateException if the instance has not the necessary information to build
-         *                 the QNodeDefinition instance.
-         */
-        public abstract QNodeDefinition build() throws IllegalStateException;
     }
 
 }
+
+

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/CndImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/CndImporter.java?rev=814610&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/CndImporter.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/CndImporter.java Mon Sep 14 12:30:36 2009
@@ -0,0 +1,149 @@
+/*
+ * 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.commons.cnd;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.ValueFactory;
+import javax.jcr.Workspace;
+import javax.jcr.nodetype.InvalidNodeTypeDefinitionException;
+import javax.jcr.nodetype.NodeDefinitionTemplate;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeExistsException;
+import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeTypeTemplate;
+import javax.jcr.nodetype.PropertyDefinitionTemplate;
+
+/**
+ * Utility class for importing compact node type definitions.
+ * @see CompactNodeTypeDefReader
+ * @see ItemTemplatesBuilder
+ */
+public final class CndImporter {
+
+    private CndImporter() {
+        super();
+    }
+
+    /**
+     * Shortcut for
+     * <pre>
+     *   registerNodeTypes(cnd, "cnd input stream", wsp.getNodeTypeManager(),
+     *          wsp.getNamespaceRegistry(), session.getValueFactory(), false);
+     * </pre>
+     * where <code>wsp</code> is the workspace of the <code>session</code> passed.
+     * @see #registerNodeTypes(Reader, String, NodeTypeManager, NamespaceRegistry, ValueFactory, boolean)
+     * @param cnd
+     * @param session  the session to use for registering the node types
+     * @return  the registered node types
+     *
+     * @throws InvalidNodeTypeDefinitionException
+     * @throws NodeTypeExistsException
+     * @throws UnsupportedRepositoryOperationException
+     * @throws ParseException
+     * @throws RepositoryException
+     * @throws IOException
+     */
+    public static NodeType[] registerNodeTypes(Reader cnd, Session session)
+            throws InvalidNodeTypeDefinitionException, NodeTypeExistsException,
+            UnsupportedRepositoryOperationException, ParseException, RepositoryException, IOException {
+
+        Workspace wsp = session.getWorkspace();
+        return registerNodeTypes(cnd, "cnd input stream", wsp.getNodeTypeManager(), wsp.getNamespaceRegistry(),
+                session.getValueFactory(), false);
+    }
+
+    /**
+     * Registers nodetypes in <code>cnd</code> format.
+     * @param cnd  a reader to the cnd. The reader is closed on return.
+     * @param systemId  a informative id of the given cnd input.
+     * @param nodeTypeManager  the {@link NodeTypeManager} used for creating and registering the
+     *     {@link NodeTypeTemplate}s, {@link NodeDefinitionTemplate}s and {@link PropertyDefinitionTemplate}s
+     *     defined in the cnd.
+     * @param namespaceRegistry  the {@link NamespaceRegistry} used for registering namespaces defined in
+     *     the cnd.
+     * @param valueFactory  the {@link ValueFactory} used to create
+     *     {@link PropertyDefinitionTemplate#setDefaultValues(javax.jcr.Value[]) default value(s)}.
+     * @param reregisterExisting  <code>true</code> if existing node types should be re-registered
+     *     with those present in the cnd. <code>false</code> otherwise.
+     * @return  the registered node types
+     *
+     * @throws ParseException  if the cnd cannot be parsed
+     * @throws InvalidNodeTypeDefinitionException  if a <code>NodeTypeDefinition</code> is invalid.
+     * @throws NodeTypeExistsException  if <code>reregisterExisting</code> is <code>false</code> and a
+     *     <code>NodeTypeDefinition</code> specifies a node type name that is already registered.
+     * @throws UnsupportedRepositoryOperationException  if the <code>NodeTypeManager</code> does not
+     *     support node type registration.
+     * @throws IOException  if closing the cnd reader fails
+     * @throws RepositoryException  if another error occurs.
+     */
+    public static NodeType[] registerNodeTypes(Reader cnd, String systemId, NodeTypeManager nodeTypeManager,
+            NamespaceRegistry namespaceRegistry, ValueFactory valueFactory, boolean reregisterExisting)
+        throws ParseException, InvalidNodeTypeDefinitionException, NodeTypeExistsException,
+            UnsupportedRepositoryOperationException, RepositoryException, IOException {
+
+        try {
+            AbstractItemTypeDefinitionsBuilder<NodeTypeTemplate, NamespaceRegistry> builder =
+                    new ItemTemplatesBuilder(nodeTypeManager, valueFactory, namespaceRegistry);
+
+            CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry> cndReader =
+                new CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry>(cnd, systemId, builder);
+
+            List<NodeTypeTemplate> ntts = cndReader.getNodeTypeDefinitions();
+
+            NodeTypeIterator registered;
+            if (reregisterExisting) {
+                registered = nodeTypeManager.registerNodeTypes(ntts.toArray(new NodeTypeTemplate[ntts.size()]), true);
+            } else {
+                List<NodeTypeTemplate> toRegister = new ArrayList<NodeTypeTemplate>(ntts.size());
+                for (NodeTypeTemplate ntt : ntts) {
+                    if (!nodeTypeManager.hasNodeType(ntt.getName())) {
+                        toRegister.add(ntt);
+                    }
+                }
+
+                registered = nodeTypeManager.registerNodeTypes(toRegister.toArray(new NodeTypeTemplate[toRegister.size()]), true);
+            }
+
+            return toArray(registered);
+        }
+        finally {
+            cnd.close();
+        }
+    }
+
+    // -----------------------------------------------------< private >---
+
+    private static NodeType[] toArray(NodeTypeIterator nodeTypes) {
+        ArrayList<NodeType> nts = new ArrayList<NodeType>();
+
+        while (nodeTypes.hasNext()) {
+            nts.add(nodeTypes.nextNodeType());
+        }
+
+        return nts.toArray(new NodeType[nts.size()]);
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/CndImporter.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message