jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r797410 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/no...
Date Fri, 24 Jul 2009 10:32:23 GMT
Author: angela
Date: Fri Jul 24 10:32:23 2009
New Revision: 797410

URL: http://svn.apache.org/viewvc?rev=797410&view=rev
Log:
JCR-2192: Handling of expanded-form jcr names by node type *Template classes

Added:
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeDefinitionTemplateImplTest.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionTemplateImplTest.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeCreationTest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractItemDefinitionTemplate.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractNodeTypeManager.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeDefinitionTemplateImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeTemplateImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionTemplateImpl.java

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=797410&r1=797409&r2=797410&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 Fri Jul 24 10:32:23 2009
@@ -60,6 +60,7 @@
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QValueConstraint;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping;
 import org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeTypeManager;
 import org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException;
@@ -207,6 +208,13 @@
     }
 
     /**
+     * @see org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeTypeManager#getNamePathResolver() 
+     */
+    public NamePathResolver getNamePathResolver() {
+        return session;
+    }
+
+    /**
      * @return the node type registry
      */
     public NodeTypeRegistry getNodeTypeRegistry() {

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeCreationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeCreationTest.java?rev=797410&r1=797409&r2=797410&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeCreationTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeCreationTest.java Fri Jul 24 10:32:23 2009
@@ -21,9 +21,12 @@
 import javax.jcr.PropertyType;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
+import javax.jcr.nodetype.NodeDefinitionTemplate;
+import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.query.qom.QueryObjectModelConstants;
 import javax.jcr.version.OnParentVersionAction;
 
@@ -39,9 +42,9 @@
  */
 public class NodeTypeCreationTest extends AbstractJCRTest {
 
-    private static String ns = "http://example.org/jcr-tck/";
-    private static String propname = "{" + ns + "}" + "boolean";
-    
+    private String expandedPropName;
+    private String jcrPropName;
+
     private NodeTypeManager ntm;
     
     /**
@@ -51,6 +54,9 @@
         super.setUp();
         ntm = superuser.getWorkspace().getNodeTypeManager();
         super.checkSupportedOption(Repository.OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED);
+
+        expandedPropName = "{" + NS_JCR_URI + "}" + "boolean";
+        jcrPropName = superuser.getNamespacePrefix(NS_JCR_URI) + ":boolean";
     }
 
     /**
@@ -60,28 +66,138 @@
         super.tearDown();
     }
 
+    public void testEmptyNodeTypeTemplate() throws Exception {
+
+        NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
+        assertNull(ntt.getName());
+
+        assertFalse(ntt.isMixin());
+        assertFalse(ntt.isAbstract());
+        assertFalse(ntt.hasOrderableChildNodes());
+        // TODO: see https://jsr-283.dev.java.net/issues/show_bug.cgi?id=798
+        assertTrue(ntt.isQueryable());
+
+        // TODO see https://jsr-283.dev.java.net/issues/show_bug.cgi?id=797        
+        assertNotNull(ntt.getDeclaredSupertypeNames());
+        assertEquals(0, ntt.getDeclaredSupertypeNames().length);
+
+        assertNull(ntt.getPrimaryItemName());
+
+        assertNull(ntt.getDeclaredChildNodeDefinitions());
+        assertNull(ntt.getDeclaredPropertyDefinitions());
+
+        assertNotNull(ntt.getNodeDefinitionTemplates());
+        assertTrue(ntt.getNodeDefinitionTemplates().isEmpty());
+
+        assertNotNull(ntt.getPropertyDefinitionTemplates());
+        assertTrue(ntt.getPropertyDefinitionTemplates().isEmpty());
+    }
+    
     public void testNewNodeTypeTemplate() throws Exception {
         
-        String ntname = "{" + ns + "}" + "littlemixin";
+        String expandedName = "{" + NS_MIX_URI + "}" + "littlemixin";
+        String jcrName = superuser.getNamespacePrefix(NS_MIX_URI) + ":littlemixin";
         
         NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
-        
-        ntt.setName(ntname);
+
+        ntt.setName(expandedName);
+        assertEquals(jcrName, ntt.getName());
+        ntt.setName(jcrName);
+        assertEquals(jcrName, ntt.getName());
+
         ntt.setAbstract(false);
-        ntt.setDeclaredSuperTypeNames(null);
+        assertFalse(ntt.isAbstract());
+
+        try {
+            ntt.setDeclaredSuperTypeNames(null);
+            fail("null isn't a valid array of jcr name");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+        assertNotNull(ntt.getDeclaredSupertypeNames());
+        assertEquals(0, ntt.getDeclaredSupertypeNames().length);
+
+        ntt.setDeclaredSuperTypeNames(new String[] {mixReferenceable});
+        assertNotNull(ntt.getDeclaredSupertypeNames());
+        assertEquals(1, ntt.getDeclaredSupertypeNames().length);
+        assertEquals(mixReferenceable, ntt.getDeclaredSupertypeNames()[0]);
+
         ntt.setMixin(true);
-        ntt.setOrderableChildNodes(false);
+        assertTrue(ntt.isMixin());
+
+        ntt.setOrderableChildNodes(true);
+        assertTrue(ntt.hasOrderableChildNodes());
+
         ntt.setQueryable(false);
+        assertFalse(ntt.isQueryable());
+
         ntt.setPrimaryItemName(null);
-        
+        assertNull(ntt.getPrimaryItemName());
+
+        ntt.setPrimaryItemName(jcrPrimaryType);
+        assertEquals(jcrPrimaryType, ntt.getPrimaryItemName());
+
+        PropertyDefinitionTemplate pdTemplate = createBooleanPropTemplate();
+
         List pdefs = ntt.getPropertyDefinitionTemplates();
-        pdefs.add(createBooleanPropTemplate());
+        pdefs.add(pdTemplate);
+
+        assertNotNull(ntt.getDeclaredPropertyDefinitions());
+        assertEquals(1, ntt.getDeclaredPropertyDefinitions().length);
+        assertEquals(pdTemplate, ntt.getDeclaredPropertyDefinitions()[0]);
+
+        pdefs = ntt.getPropertyDefinitionTemplates();
+        assertEquals(1, pdefs.size());
+        assertEquals(pdTemplate, pdefs.get(0));
+
+        NodeDefinitionTemplate ndTemplate = ntm.createNodeDefinitionTemplate();
+
+        List ndefs = ntt.getNodeDefinitionTemplates();
+        ndefs.add(ndTemplate);
+
+        assertNotNull(ntt.getDeclaredChildNodeDefinitions());
+        assertEquals(1, ntt.getDeclaredChildNodeDefinitions().length);
+        assertEquals(ndTemplate, ntt.getDeclaredChildNodeDefinitions()[0]);
+
+        ndefs = ntt.getNodeDefinitionTemplates();
+        assertEquals(1, ndefs.size());
+        assertEquals(ndTemplate, ndefs.get(0));
+    }
+
+    public void testEmptyPropertyDefinitionTemplate() throws Exception {
+        PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
+
+        assertNull(pdt.getName());
+        assertFalse(pdt.isAutoCreated());
+        assertFalse(pdt.isMandatory());
+        assertFalse(pdt.isProtected());
+        assertEquals(OnParentVersionAction.COPY, pdt.getOnParentVersion());
+        assertNull(pdt.getDeclaringNodeType());
+
+        assertEquals(PropertyType.STRING, pdt.getRequiredType());
+        assertFalse(pdt.isMultiple());
+        assertNull(pdt.getValueConstraints());
+        assertNull(pdt.getDefaultValues());
+
+        // TODO: add tests for default values of (missing definition in API)
+        // getAvailableQueryOperators
+        // isFullTextSearchable
+        // isQueryOrderable
+
     }
 
     public void testPropertyDefinitionTemplate() throws Exception {
         PropertyDefinitionTemplate pdt = createBooleanPropTemplate();
-        
-        assertEquals(propname, pdt.getName());
+
+        assertEquals(jcrPropName, pdt.getName());
+        try {
+            pdt.setName(null);
+            fail("null isn't a valid JCR name");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+
+
         assertEquals(false, pdt.isAutoCreated());
         assertEquals(false, pdt.isMandatory());
         assertEquals(OnParentVersionAction.IGNORE, pdt.getOnParentVersion());
@@ -96,11 +212,177 @@
         assertEquals(false, pdt.isFullTextSearchable());
         assertEquals(false, pdt.isQueryOrderable());
     }
-    
-    
+
+    public void testSetDefaultValues() throws Exception {
+
+        PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
+        pdt.setRequiredType(PropertyType.LONG);
+
+        pdt.setDefaultValues(null);
+        assertNull(pdt.getDefaultValues());
+
+        pdt.setDefaultValues(new Value[0]);
+        assertNotNull(pdt.getDefaultValues());
+        assertEquals(0, pdt.getDefaultValues().length);
+
+        pdt.setDefaultValues(new Value[] { superuser.getValueFactory().createValue(24)});
+        assertNotNull(pdt.getDefaultValues());
+        assertEquals(1, pdt.getDefaultValues().length);
+        assertEquals(24, pdt.getDefaultValues()[0].getLong());
+        assertEquals(PropertyType.LONG, pdt.getDefaultValues()[0].getType());
+    }
+
+    public void testSetValueConstraints() throws Exception {
+
+        // TODO: PropertyDefinitionTemplate: test setting value constraints
+        // TODO: PropertyDefinitionTemplate: test setting name/path constraints
+        // see  https://jsr-283.dev.java.net/issues/show_bug.cgi?id=794
+    }
+
+    public void testEmptyNodeDefinitionTemplate() throws Exception {
+        NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
+
+        assertNull(ndt.getName());
+        assertFalse(ndt.isAutoCreated());
+        assertFalse(ndt.isMandatory());
+        assertFalse(ndt.isProtected());
+        assertEquals(OnParentVersionAction.COPY, ndt.getOnParentVersion());
+        assertNull(ndt.getDeclaringNodeType());
+
+        assertNull(ndt.getRequiredPrimaryTypes());
+        assertNull(ndt.getRequiredPrimaryTypeNames());
+        assertNull(ndt.getDefaultPrimaryType());
+        assertNull(ndt.getDefaultPrimaryTypeName());
+        assertFalse(ndt.allowsSameNameSiblings());
+    }
+
+    public void testNodeDefinitionTemplate() throws Exception {
+        NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
+
+        try {
+            ndt.setName(null);
+            fail("null isn't a valid JCR name");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+
+        String expandedName = "{" + NS_JCR_URI + "}" + "content";
+        String jcrName = superuser.getNamespacePrefix(NS_JCR_URI) + ":content";
+        ndt.setName(expandedName);
+        assertEquals(jcrName, ndt.getName());
+        ndt.setName(jcrName);
+        assertEquals(jcrName, ndt.getName());
+
+        ndt.setSameNameSiblings(true);
+        assertTrue(ndt.allowsSameNameSiblings());
+
+        ndt.setAutoCreated(true);
+        assertTrue(ndt.isAutoCreated());
+
+        ndt.setMandatory(true);
+        assertTrue(ndt.isMandatory());
+
+        ndt.setProtected(true);
+        assertTrue(ndt.isProtected());
+
+        ndt.setOnParentVersion(OnParentVersionAction.VERSION);
+        assertEquals(OnParentVersionAction.VERSION, ndt.getOnParentVersion());
+
+        expandedName = "{" + NS_NT_URI + "}" + "folder";
+        jcrName = superuser.getNamespacePrefix(NS_NT_URI) + ":folder";
+        ndt.setDefaultPrimaryTypeName(expandedName);
+        assertEquals(jcrName, ndt.getDefaultPrimaryTypeName());
+
+        try {
+            ndt.setDefaultPrimaryTypeName(null);
+            fail("null isn't a valid jcr name");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+
+        ndt.setRequiredPrimaryTypeNames(new String[] {expandedName});
+        assertNotNull(ndt.getRequiredPrimaryTypeNames());
+        assertEquals(1, ndt.getRequiredPrimaryTypeNames().length);
+        assertEquals(jcrName, ndt.getRequiredPrimaryTypeNames()[0]);
+
+        try {
+            ndt.setRequiredPrimaryTypeNames(null);
+            fail("null isn't a valid array of jcr name");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+    }
+
+    public void testResidualNames() throws Exception {
+        String residualName = "*";
+
+        NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
+        ndt.setName(residualName);
+        assertEquals(residualName, ndt.getName());
+
+        PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
+        pdt.setName(residualName);
+        assertEquals(residualName, pdt.getName());
+    }
+
+    public void testInvalidJCRNames() throws Exception {
+        String invalidName = ":ab[2]";
+
+        // invalid name(s) passed to NT-template methods
+        NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
+        try {
+            ntt.setName(invalidName);
+            fail("ConstraintViolationException expected. Nt-name is invalid");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+        try {
+            ntt.setDeclaredSuperTypeNames(new String[] {"{" + NS_MIX_URI + "}" + "littlemixin", invalidName});
+            fail("ConstraintViolationException expected. One of the super type names is invalid");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+        try {
+            ntt.setPrimaryItemName(invalidName);
+            fail("ConstraintViolationException expected. Primary item name is invalid");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+
+        // invalid name(s) passed to NodeDefinitionTemplate
+        NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
+        try {
+            ndt.setName(invalidName);
+            fail("ConstraintViolationException expected. Name is invalid");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+        try {
+            ndt.setRequiredPrimaryTypeNames(new String[] {"{" + NS_MIX_URI + "}" + "littlemixin", invalidName});
+            fail("ConstraintViolationException expected. One of the required primary type names is invalid");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+        try {
+            ndt.setDefaultPrimaryTypeName(invalidName);
+            fail("ConstraintViolationException expected. Default primary type name is invalid");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+
+        // invalid name(s) passed to PropertyDefinitionTemplate
+        PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
+        try {
+            pdt.setName(invalidName);
+            fail("ConstraintViolationException expected. Name is invalid");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+    }
+
     private PropertyDefinitionTemplate createBooleanPropTemplate() throws RepositoryException {
         PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
-        pdt.setName(propname);
+        pdt.setName(expandedPropName);
         pdt.setAutoCreated(false);
         pdt.setMandatory(false);
         pdt.setOnParentVersion(OnParentVersionAction.IGNORE);
@@ -114,6 +396,5 @@
         pdt.setQueryOrderable(false);
 
         return pdt;
-    }
-    
+    }    
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java?rev=797410&r1=797409&r2=797410&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java Fri Jul 24 10:32:23 2009
@@ -124,19 +124,13 @@
         return mgrProvider.getNamespaceResolver();
     }
 
-    private NamePathResolver resolver() {
-        return mgrProvider.getNamePathResolver();
-    }
-
     private EffectiveNodeTypeProvider entProvider() {
         return mgrProvider.getEffectiveNodeTypeProvider();
     }
 
     //--------------------------------------------------------------------------
     /**
-     * @param name
-     * @return
-     * @throws NoSuchNodeTypeException
+     * @see AbstractNodeTypeManager#getNodeType(org.apache.jackrabbit.spi.Name)
      */
     public NodeTypeImpl getNodeType(Name name) throws NoSuchNodeTypeException {
         synchronized (ntCache) {
@@ -152,6 +146,13 @@
     }
 
     /**
+     * @see org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeTypeManager#getNamePathResolver() 
+     */
+    public NamePathResolver getNamePathResolver() {
+        return mgrProvider.getNamePathResolver();
+    }
+
+    /**
      *
      * @param nodeTypeName
      * @return
@@ -175,7 +176,7 @@
         synchronized (ndCache) {
             NodeDefinition ndi = (NodeDefinition) ndCache.get(def);
             if (ndi == null) {
-                ndi = new NodeDefinitionImpl(def, this, resolver());
+                ndi = new NodeDefinitionImpl(def, this, getNamePathResolver());
                 ndCache.put(def, ndi);
             }
             return ndi;
@@ -193,7 +194,7 @@
         synchronized (pdCache) {
             PropertyDefinition pdi = (PropertyDefinition) pdCache.get(def);
             if (pdi == null) {
-                pdi = new PropertyDefinitionImpl(def, this, resolver(), valueFactory);
+                pdi = new PropertyDefinitionImpl(def, this, getNamePathResolver(), valueFactory);
                 pdCache.put(def, pdi);
             }
             return pdi;
@@ -231,7 +232,7 @@
         // flush all affected cache entries
         ntCache.remove(ntName);
         try {
-            String name = resolver().getJCRName(ntName);
+            String name = getNamePathResolver().getJCRName(ntName);
             synchronized (pdCache) {
                 Iterator iter = pdCache.values().iterator();
                 while (iter.hasNext()) {
@@ -268,7 +269,7 @@
         // flush all affected cache entries
         ntCache.remove(ntName);
         try {
-            String name = resolver().getJCRName(ntName);
+            String name = getNamePathResolver().getJCRName(ntName);
             synchronized (pdCache) {
                 Iterator iter = pdCache.values().iterator();
                 while (iter.hasNext()) {
@@ -347,7 +348,7 @@
     public NodeType getNodeType(String nodeTypeName)
             throws NoSuchNodeTypeException {
         try {
-            Name qName = resolver().getQName(nodeTypeName);
+            Name qName = getNamePathResolver().getQName(nodeTypeName);
             return getNodeType(qName);
         } catch (NamespaceException e) {
             throw new NoSuchNodeTypeException(nodeTypeName, e);
@@ -361,7 +362,7 @@
      */
     public boolean hasNodeType(String name) throws RepositoryException {
         try {
-            Name qName = resolver().getQName(name);
+            Name qName = getNamePathResolver().getQName(name);
             return hasNodeType(qName);
         } catch (NamespaceException e) {
             return false;
@@ -377,7 +378,7 @@
             throws RepositoryException {
         List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>(ntds.length);
         for (NodeTypeDefinition definition : ntds) {
-            QNodeTypeDefinition qdef = new QNodeTypeDefinitionImpl(definition, resolver(), mgrProvider.getQValueFactory());
+            QNodeTypeDefinition qdef = new QNodeTypeDefinitionImpl(definition, getNamePathResolver(), mgrProvider.getQValueFactory());
             if (!allowUpdate && hasNodeType(qdef.getName())) {
                 throw new NodeTypeExistsException("NodeType " + definition.getName() + " already exists.");
             }
@@ -400,7 +401,7 @@
     public void unregisterNodeTypes(String[] names) throws RepositoryException {
         HashSet ntNames = new HashSet();
         for (String name : names) {
-            ntNames.add(resolver().getQName(name));
+            ntNames.add(getNamePathResolver().getQName(name));
         }
         getNodeTypeRegistry().unregisterNodeTypes(ntNames);
     }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractItemDefinitionTemplate.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractItemDefinitionTemplate.java?rev=797410&r1=797409&r2=797410&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractItemDefinitionTemplate.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractItemDefinitionTemplate.java Fri Jul 24 10:32:23 2009
@@ -16,8 +16,18 @@
  */
 package org.apache.jackrabbit.spi.commons.nodetype;
 
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.Name;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import javax.jcr.nodetype.ItemDefinition;
 import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.RepositoryException;
+import javax.jcr.NamespaceException;
+import javax.jcr.version.OnParentVersionAction;
 
 /**
  * <code>AbstractItemDefinitionTemplate</code> serves as base class for
@@ -26,25 +36,40 @@
  */
 abstract class AbstractItemDefinitionTemplate implements ItemDefinition {
 
-    private String name;
+    private static final Logger log = LoggerFactory.getLogger(AbstractItemDefinitionTemplate.class);
+
+    private Name name;
     private boolean autoCreated;
     private boolean mandatory;
-    private int opv;
+    private int opv = OnParentVersionAction.COPY;
     private boolean protectedStatus;
 
+    protected final NamePathResolver resolver;
+
     /**
      * Package private constructor
+     *
+     * @param resolver
      */
-    AbstractItemDefinitionTemplate() {
+    AbstractItemDefinitionTemplate(NamePathResolver resolver) {
+        this.resolver = resolver;
     }
 
     /**
      * Package private constructor
      *
      * @param def
+     * @param resolver
+     * @throws javax.jcr.nodetype.ConstraintViolationException
      */
-    AbstractItemDefinitionTemplate(ItemDefinition def) {
-        name = def.getName();
+    AbstractItemDefinitionTemplate(ItemDefinition def, NamePathResolver resolver) throws ConstraintViolationException {
+        this.resolver = resolver;
+
+        if (def instanceof ItemDefinitionImpl) {
+            name = ((ItemDefinitionImpl) def).itemDef.getName();
+        } else {
+            setName(def.getName());
+        }
         autoCreated = def.isAutoCreated();
         mandatory = def.isMandatory();
         opv = def.getOnParentVersion();
@@ -56,9 +81,20 @@
      * Sets the name of the child item.
      *
      * @param name a <code>String</code>.
+     * @throws ConstraintViolationException
      */
-    public void setName(String name) {
-        this.name = name;
+    public void setName(String name) throws ConstraintViolationException {
+        if (ItemDefinitionImpl.ANY_NAME.equals(name)) {
+            // handle the * special case that isn't a valid JCR name but a valid
+            // name for a ItemDefinition (residual).
+            this.name = NameConstants.ANY_NAME;
+        } else {
+            try {
+                this.name = resolver.getQName(name);
+            } catch (RepositoryException e) {
+                throw new ConstraintViolationException(e);
+            }
+        }
     }
 
     /**
@@ -83,8 +119,11 @@
      * Sets the on-parent-version status of the child item.
      *
      * @param opv an <code>int</code> constant member of <code>OnParentVersionAction</code>.
+     * @throws IllegalArgumentException If the given <code>opv</code> flag isn't valid.
      */
     public void setOnParentVersion(int opv) {
+        // validate the given opv-action
+        OnParentVersionAction.nameFromValue(opv);
         this.opv = opv;
     }
 
@@ -102,7 +141,17 @@
      * {@inheritDoc}
      */
     public String getName() {
-        return name;
+        if (name == null) {
+            return null;
+        } else {
+            try {
+                return resolver.getJCRName(name);
+            } catch (NamespaceException e) {
+                // should never get here
+                log.error("encountered unregistered namespace in item definition name", e);
+                return name.toString();
+            }
+        }
     }
 
     /**
@@ -139,5 +188,4 @@
     public boolean isProtected() {
         return protectedStatus;
     }
-
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractNodeTypeManager.java?rev=797410&r1=797409&r2=797410&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractNodeTypeManager.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/AbstractNodeTypeManager.java Fri Jul 24 10:32:23 2009
@@ -19,6 +19,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeTemplate;
@@ -50,13 +51,22 @@
      */
     public abstract NodeType getNodeType(Name ntName) throws NoSuchNodeTypeException;
 
+    /**
+     * Returns the NamePathResolver used to validate JCR names.
+     *
+     * @return the NamePathResolver used to convert JCR names/paths to internal
+     * onces and vice versa. The resolver may also be used to validate names
+     * passed to the various templates.
+     */
+    public abstract NamePathResolver getNamePathResolver();
+
     //----------------------------------------------------< NodeTypeManager >---
     /**
      * @see javax.jcr.nodetype.NodeTypeManager#createNodeTypeTemplate()
      */
     public NodeTypeTemplate createNodeTypeTemplate()
             throws UnsupportedRepositoryOperationException, RepositoryException {
-        return new NodeTypeTemplateImpl();
+        return new NodeTypeTemplateImpl(getNamePathResolver());
     }
 
     /**
@@ -64,7 +74,7 @@
      */
     public NodeTypeTemplate createNodeTypeTemplate(NodeTypeDefinition ntd)
             throws UnsupportedRepositoryOperationException, RepositoryException {
-        return new NodeTypeTemplateImpl(ntd);
+        return new NodeTypeTemplateImpl(ntd, getNamePathResolver());
     }
 
     /**
@@ -72,7 +82,7 @@
      */
     public NodeDefinitionTemplate createNodeDefinitionTemplate()
             throws UnsupportedRepositoryOperationException, RepositoryException {
-        return new NodeDefinitionTemplateImpl(getNodeType(NodeType.NT_BASE));
+        return new NodeDefinitionTemplateImpl(getNamePathResolver());
     }
 
     /**
@@ -80,7 +90,7 @@
      */
     public PropertyDefinitionTemplate createPropertyDefinitionTemplate()
             throws UnsupportedRepositoryOperationException, RepositoryException {
-        return new PropertyDefinitionTemplateImpl();
+        return new PropertyDefinitionTemplateImpl(getNamePathResolver());
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeDefinitionTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeDefinitionTemplateImpl.java?rev=797410&r1=797409&r2=797410&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeDefinitionTemplateImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeDefinitionTemplateImpl.java Fri Jul 24 10:32:23 2009
@@ -16,11 +16,19 @@
  */
 package org.apache.jackrabbit.spi.commons.nodetype;
 
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import javax.jcr.nodetype.NodeDefinitionTemplate;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.NamespaceException;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.ConstraintViolationException;
 
 /**
  * A <code>NodeDefinitionTemplateImpl</code> ...
@@ -29,53 +37,75 @@
         extends AbstractItemDefinitionTemplate
         implements NodeDefinitionTemplate {
 
+    private static final Logger log = LoggerFactory.getLogger(NodeDefinitionTemplateImpl.class);
+
     private NodeType[] requiredPrimaryTypes;
-    private String[] requiredPrimaryTypeNames;
-    private String defaultPrimaryTypeName;
+    private Name[] requiredPrimaryTypeNames;
+    private Name defaultPrimaryTypeName;
     private boolean allowSameNameSiblings;
 
     /**
      * Package private constructor
      *
-     * @param ntBase
+     * @param resolver
      * @throws RepositoryException
      */
-    NodeDefinitionTemplateImpl(NodeType ntBase) throws RepositoryException {
-        requiredPrimaryTypes = new NodeType[] {ntBase};
-        requiredPrimaryTypeNames = new String[] {requiredPrimaryTypes[0].getName()};
+    NodeDefinitionTemplateImpl(NamePathResolver resolver) throws RepositoryException {
+        super(resolver);
+        requiredPrimaryTypes = null;
+        requiredPrimaryTypeNames = null;
     }
 
     /**
      * Package private constructor
      *
      * @param def
+     * @param resolver
+     * @throws javax.jcr.nodetype.ConstraintViolationException
      */
-    NodeDefinitionTemplateImpl(NodeDefinition def) {
-        super(def);
+    NodeDefinitionTemplateImpl(NodeDefinition def, NamePathResolver resolver) throws ConstraintViolationException {
+        super(def, resolver);
         requiredPrimaryTypes = def.getRequiredPrimaryTypes();
-        // FIXME temporary workaround until JSR 283 has been finalized
-        requiredPrimaryTypeNames = new String[requiredPrimaryTypes.length];
-        for (int i = 0; i < requiredPrimaryTypes.length; i++) {
-            requiredPrimaryTypeNames[i] = requiredPrimaryTypes[i].getName();
-        }
-        defaultPrimaryTypeName =
-                def.getDefaultPrimaryType() == null ? null : def.getDefaultPrimaryType().getName();
         allowSameNameSiblings = def.allowsSameNameSiblings();
+
+        if (def instanceof NodeDefinitionImpl) {
+            QNodeDefinition qDef = (QNodeDefinition) ((NodeDefinitionImpl) def).itemDef;
+            requiredPrimaryTypeNames = qDef.getRequiredPrimaryTypes();
+            defaultPrimaryTypeName = qDef.getDefaultPrimaryType();
+        } else {
+            setRequiredPrimaryTypeNames(def.getRequiredPrimaryTypeNames());
+            setDefaultPrimaryTypeName(def.getDefaultPrimaryTypeName());
+        }        
     }
 
     //-----------------------------------------------< NodeDefinitionTemplate >
     /**
      * {@inheritDoc}
      */
-    public void setRequiredPrimaryTypeNames(String[] requiredPrimaryTypeNames) {
-        this.requiredPrimaryTypeNames = requiredPrimaryTypeNames;
+    public void setRequiredPrimaryTypeNames(String[] requiredPrimaryTypeNames) throws ConstraintViolationException {
+        if (requiredPrimaryTypeNames == null) {
+            throw new ConstraintViolationException("null isn't a valid array of JCR names.");
+        } else {
+            this.requiredPrimaryTypeNames = new Name[requiredPrimaryTypeNames.length];
+            for (int i = 0; i < requiredPrimaryTypeNames.length; i++) {
+                try {
+                    this.requiredPrimaryTypeNames[i] = resolver.getQName(requiredPrimaryTypeNames[i]);
+                } catch (RepositoryException e) {
+                    throw new ConstraintViolationException(e);
+                }
+            }
+        }
     }
 
     /**
      * {@inheritDoc}
      */
-    public void setDefaultPrimaryTypeName(String defaultPrimaryType) {
-        this.defaultPrimaryTypeName = defaultPrimaryType;
+    public void setDefaultPrimaryTypeName(String defaultPrimaryType) throws ConstraintViolationException {
+        try {
+            this.defaultPrimaryTypeName = resolver.getQName(defaultPrimaryType);
+        } catch (RepositoryException e) {
+            throw new ConstraintViolationException(e);
+        }
     }
 
     /**
@@ -97,7 +127,21 @@
      * {@inheritDoc}
      */
     public String[] getRequiredPrimaryTypeNames() {
-        return requiredPrimaryTypeNames;
+        if (requiredPrimaryTypeNames == null) {
+            return null;
+        } else {
+            String[] rptNames = new String[requiredPrimaryTypeNames.length];
+            for (int i = 0; i < requiredPrimaryTypeNames.length; i++) {
+                try {
+                    rptNames[i] = resolver.getJCRName(requiredPrimaryTypeNames[i]);
+                } catch (NamespaceException e) {
+                    // should never get here
+                    log.error("invalid node type name: " + requiredPrimaryTypeNames[i], e);
+                    rptNames[i] = requiredPrimaryTypeNames[i].toString();
+                }
+            }
+            return rptNames;
+        }
     }
 
     /**
@@ -111,7 +155,17 @@
      * {@inheritDoc}
      */
     public String getDefaultPrimaryTypeName() {
-        return defaultPrimaryTypeName;
+        if (defaultPrimaryTypeName == null) {
+            return null;
+        } else {
+            try {
+                return resolver.getJCRName(defaultPrimaryTypeName);
+            } catch (NamespaceException e) {
+                // should never get here
+                log.error("encountered unregistered namespace in default primary type name", e);
+                return defaultPrimaryTypeName.toString();
+            }
+        }
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefinitionImpl.java?rev=797410&r1=797409&r2=797410&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefinitionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefinitionImpl.java Fri Jul 24 10:32:23 2009
@@ -40,7 +40,7 @@
      */
     private static final Logger log = LoggerFactory.getLogger(NodeTypeDefinitionImpl.class);
 
-    private final QNodeTypeDefinition ntd;
+    protected final QNodeTypeDefinition ntd;
     private final NamePathResolver resolver;
     private final ValueFactory valueFactory;
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeTemplateImpl.java?rev=797410&r1=797409&r2=797410&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeTemplateImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeTemplateImpl.java Fri Jul 24 10:32:23 2009
@@ -16,24 +16,35 @@
  */
 package org.apache.jackrabbit.spi.commons.nodetype;
 
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.util.LinkedList;
 import java.util.List;
 
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeDefinitionTemplate;
-import javax.jcr.nodetype.NodeTypeDefinition;
 import javax.jcr.nodetype.NodeTypeTemplate;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NodeTypeDefinition;
+import javax.jcr.NamespaceException;
+import javax.jcr.RepositoryException;
 
 /**
  * A <code>NodeTypeTemplateImpl</code> ...
  */
 public class NodeTypeTemplateImpl implements NodeTypeTemplate {
 
-    private String name;
-    private String[] superTypeNames;
-    private String primaryItemName;
+    private static final Logger log = LoggerFactory.getLogger(NodeTypeTemplateImpl.class);
+
+    private Name name;
+    private Name[] superTypeNames;
+    private Name primaryItemName;
     private boolean abstractStatus;
     private boolean queryable;
     private boolean mixin;
@@ -41,38 +52,58 @@
     private List<NodeDefinitionTemplate> nodeDefinitionTemplates;
     private List<PropertyDefinitionTemplate> propertyDefinitionTemplates;
 
+    private final NamePathResolver resolver;
+
     /**
      * Package private constructor
+     *
+     * @param resolver
      */
-    NodeTypeTemplateImpl() {
+    NodeTypeTemplateImpl(NamePathResolver resolver) {
+        // TODO: see https://jsr-283.dev.java.net/issues/show_bug.cgi?id=798
         queryable = true;
+        // TODO see https://jsr-283.dev.java.net/issues/show_bug.cgi?id=797
+        superTypeNames = new Name[0];
+        this.resolver = resolver;
     }
 
     /**
      * Package private constructor
      *
      * @param def
+     * @param resolver
      */
-    NodeTypeTemplateImpl(NodeTypeDefinition def) {
-        name = def.getName();
-        superTypeNames = def.getDeclaredSupertypeNames();
-        primaryItemName = def.getPrimaryItemName();
+    NodeTypeTemplateImpl(NodeTypeDefinition def, NamePathResolver resolver) throws RepositoryException {
+        this.resolver = resolver;
+        
+        if (def instanceof NodeTypeDefinitionImpl) {
+            QNodeTypeDefinition qDef = ((NodeTypeDefinitionImpl) def).ntd;
+            name = qDef.getName();
+            superTypeNames = qDef.getSupertypes();
+            primaryItemName = qDef.getPrimaryItemName();
+        } else {
+            setName(def.getName());
+            setDeclaredSuperTypeNames(def.getDeclaredSupertypeNames());
+            setPrimaryItemName(def.getPrimaryItemName());
+        }
+
         abstractStatus = def.isAbstract();
         mixin = def.isMixin();
         queryable = def.isQueryable();
         orderableChildNodes = def.hasOrderableChildNodes();
+
         NodeDefinition[] nodeDefs = def.getDeclaredChildNodeDefinitions();
         if (nodeDefs != null) {
             List list = getNodeDefinitionTemplates();
             for (NodeDefinition nodeDef : nodeDefs) {
-                list.add(new NodeDefinitionTemplateImpl(nodeDef));
+                list.add(new NodeDefinitionTemplateImpl(nodeDef, resolver));
             }
         }
         PropertyDefinition[] propDefs = def.getDeclaredPropertyDefinitions();
         if (propDefs != null) {
             List list = getPropertyDefinitionTemplates();
             for (PropertyDefinition propDef : propDefs) {
-                list.add(new PropertyDefinitionTemplateImpl(propDef));
+                list.add(new PropertyDefinitionTemplateImpl(propDef, resolver));
             }
         }
     }
@@ -81,15 +112,31 @@
     /**
      * {@inheritDoc}
      */
-    public void setName(String name) {
-        this.name = name;
+    public void setName(String name) throws ConstraintViolationException {
+        try {
+            this.name = resolver.getQName(name);
+        } catch (RepositoryException e) {
+            throw new ConstraintViolationException(e);
+        }
     }
 
     /**
      * {@inheritDoc}
      */
-    public void setDeclaredSuperTypeNames(String[] names) {
-        superTypeNames = names;
+    public void setDeclaredSuperTypeNames(String[] names) throws ConstraintViolationException {
+        // TODO see https://jsr-283.dev.java.net/issues/show_bug.cgi?id=797
+        if (names == null) {
+            throw new ConstraintViolationException("null isn't a valid array of JCR names.");            
+        } else {
+            superTypeNames = new Name[names.length];
+            for (int i = 0; i < names.length; i++) {
+                try {
+                    superTypeNames[i] = resolver.getQName(names[i]);
+                } catch (RepositoryException e) {
+                    throw new ConstraintViolationException(e);
+                }
+            }
+        }
     }
 
     /**
@@ -116,8 +163,16 @@
     /**
      * {@inheritDoc}
      */
-    public void setPrimaryItemName(String name) {
-        primaryItemName = name;
+    public void setPrimaryItemName(String name) throws ConstraintViolationException {
+        if (name == null) {
+            primaryItemName = null;
+        } else {
+            try {
+                primaryItemName = resolver.getQName(name);
+            } catch (RepositoryException e) {
+                throw new ConstraintViolationException(e);
+            }
+        }
     }
 
     /**
@@ -152,14 +207,34 @@
      * {@inheritDoc}
      */
     public String getName() {
-        return name;
+        if (name == null) {
+            return null;
+        } else {
+            try {
+                return resolver.getJCRName(name);
+            } catch (NamespaceException e) {
+                // should never get here
+                log.error("encountered unregistered namespace in node type name", e);
+                return name.toString();
+            }
+        }
     }
 
     /**
      * {@inheritDoc}
      */
     public String[] getDeclaredSupertypeNames() {
-        return superTypeNames;
+        String[] names = new String[superTypeNames.length];
+        for (int i = 0; i < superTypeNames.length; i++) {
+            try {
+                names[i] = resolver.getJCRName(superTypeNames[i]);
+            } catch (NamespaceException e) {
+                // should never get here
+                log.error("encountered unregistered namespace in super type name", e);
+                names[i] = superTypeNames[i].toString();
+            }
+        }
+        return names;
     }
 
     /**
@@ -191,7 +266,17 @@
      * {@inheritDoc}
      */
     public String getPrimaryItemName() {
-        return primaryItemName;
+        if (primaryItemName == null) {
+            return null;
+        } else {
+            try {
+                return resolver.getJCRName(primaryItemName);
+            } catch (NamespaceException e) {
+                // should never get here
+                log.error("encountered unregistered namespace in primary type name", e);
+                return primaryItemName.toString();
+            }
+        }
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionTemplateImpl.java?rev=797410&r1=797409&r2=797410&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionTemplateImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionTemplateImpl.java Fri Jul 24 10:32:23 2009
@@ -17,11 +17,13 @@
 package org.apache.jackrabbit.spi.commons.nodetype;
 
 import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 
 import javax.jcr.PropertyType;
 import javax.jcr.Value;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.nodetype.PropertyDefinitionTemplate;
+import javax.jcr.nodetype.ConstraintViolationException;
 
 /**
  * A <code>PropertyDefinitionTemplateImpl</code> ...
@@ -40,8 +42,11 @@
 
     /**
      * Package private constructor
+     *
+     * @param resolver
      */
-    PropertyDefinitionTemplateImpl() {
+    PropertyDefinitionTemplateImpl(NamePathResolver resolver) {
+        super(resolver);
         type = PropertyType.STRING;
         fullTextSearchable = true;
         queryOrderable = true;
@@ -52,23 +57,29 @@
      * Package private constructor
      *
      * @param def
+     * @param resolver
+     * @throws javax.jcr.nodetype.ConstraintViolationException
      */
-    PropertyDefinitionTemplateImpl(PropertyDefinition def) {
-        super(def);
+    PropertyDefinitionTemplateImpl(PropertyDefinition def, NamePathResolver resolver) throws ConstraintViolationException {
+        super(def, resolver);
         type = def.getRequiredType();
-        constraints = def.getValueConstraints();
         defaultValues = def.getDefaultValues();
         multiple = def.isMultiple();
         fullTextSearchable = def.isFullTextSearchable();
         queryOrderable = def.isQueryOrderable();
         queryOperators = def.getAvailableQueryOperators();
+        setValueConstraints(def.getValueConstraints());
     }
 
     //-------------------------------------------< PropertyDefinitionTemplate >
     /**
      * {@inheritDoc}
+     *
+     * @throws IllegalArgumentException If an invalid type is passed.
      */
     public void setRequiredType(int type) {
+        // validate
+        PropertyType.nameFromValue(type);
         this.type = type;
     }
 
@@ -76,6 +87,7 @@
      * {@inheritDoc}
      */
     public void setValueConstraints(String[] constraints) {
+        // TODO: see https://jsr-283.dev.java.net/issues/show_bug.cgi?id=794
         this.constraints = constraints;
     }
 
@@ -126,6 +138,7 @@
      * {@inheritDoc}
      */
     public String[] getValueConstraints() {
+        // TODO: see https://jsr-283.dev.java.net/issues/show_bug.cgi?id=794
         return constraints;
     }
 

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeDefinitionTemplateImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeDefinitionTemplateImplTest.java?rev=797410&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeDefinitionTemplateImplTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NodeDefinitionTemplateImplTest.java Fri Jul 24 10:32:23 2009
@@ -0,0 +1,58 @@
+/*
+ * 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 org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.DummyNamespaceResolver;
+
+import javax.jcr.nodetype.NodeDefinitionTemplate;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>NodeDefinitionTemplateImplTest</code>...
+ */
+public class NodeDefinitionTemplateImplTest extends TestCase {
+
+    private NodeDefinitionTemplate tmpl;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        NamePathResolver resolver = new DefaultNamePathResolver(new DummyNamespaceResolver());
+        tmpl = new NodeDefinitionTemplateImpl(resolver);
+    }
+
+    public void testInvalidOPVFlag() {
+        try {
+            tmpl.setOnParentVersion(-1);
+            fail("-1 isn't a valid OPV flag.");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+        try {
+            tmpl.setOnParentVersion(Integer.MAX_VALUE);
+            fail(Integer.MAX_VALUE + " isn't a valid OPV flag.");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+    }
+
+    // TODO: add tests for default values on empty template NOT specified by the specification
+}
\ No newline at end of file

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionTemplateImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionTemplateImplTest.java?rev=797410&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionTemplateImplTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PropertyDefinitionTemplateImplTest.java Fri Jul 24 10:32:23 2009
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.DummyNamespaceResolver;
+
+import javax.jcr.nodetype.PropertyDefinitionTemplate;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>PropertyDefinitionTemplateImplTest</code>...
+ */
+public class PropertyDefinitionTemplateImplTest extends TestCase {
+
+    private PropertyDefinitionTemplate tmpl;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        NamePathResolver resolver = new DefaultNamePathResolver(new DummyNamespaceResolver());
+        tmpl = new PropertyDefinitionTemplateImpl(resolver);
+    }
+
+    public void testInvalidPropertyType() {
+        try {
+            tmpl.setRequiredType(-1);
+            fail("-1 isn't a valid property type.");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+        try {
+            tmpl.setRequiredType(Integer.MAX_VALUE);
+            fail(Integer.MAX_VALUE + " isn't a valid property type.");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+    }
+
+    public void testInvalidOPVFlag() {
+        try {
+            tmpl.setOnParentVersion(-1);
+            fail("-1 isn't a valid OPV flag.");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+        try {
+            tmpl.setOnParentVersion(Integer.MAX_VALUE);
+            fail(Integer.MAX_VALUE + " isn't a valid OPV flag.");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+    }
+
+    // TODO: add tests for default values on empty template NOT specified by the specification
+    
+}
\ No newline at end of file

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java?rev=797410&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java Fri Jul 24 10:32:23 2009
@@ -0,0 +1,40 @@
+/*
+ * 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 junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all testcases for package org.apache.jackrabbit.spi.commons.nodetype.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("org.apache.jackrabbit.spi.commons.nodetype tests");
+
+        suite.addTestSuite(NodeDefinitionTemplateImplTest.class);
+        suite.addTestSuite(PropertyDefinitionTemplateImplTest.class);
+
+        return suite;
+    }
+}



Mime
View raw message