jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r657073 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype: ./ compact/
Date Fri, 16 May 2008 14:13:10 GMT
Author: stefan
Date: Fri May 16 07:13:09 2008
New Revision: 657073

URL: http://svn.apache.org/viewvc?rev=657073&view=rev
Log:
JCR-1591: JSR 283: NodeType Management

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefinitionImpl.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeTemplateImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java?rev=657073&r1=657072&r2=657073&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ItemDefinitionImpl.java
Fri May 16 07:13:09 2008
@@ -64,7 +64,7 @@
      *
      * @param itemDef    item definition
      * @param ntMgr      node type manager
-     * @param resolver
+     * @param resolver   name resolver
      */
     ItemDefinitionImpl(ItemDef itemDef, NodeTypeManagerImpl ntMgr,
                        NamePathResolver resolver) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java?rev=657073&r1=657072&r2=657073&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeDefinitionImpl.java
Fri May 16 07:13:09 2008
@@ -45,7 +45,7 @@
      *
      * @param nodeDef    child node definition
      * @param ntMgr      node type manager
-     * @param resolver
+     * @param resolver   name resolver
      */
     NodeDefinitionImpl(NodeDef nodeDef, NodeTypeManagerImpl ntMgr,
                        NamePathResolver resolver) {
@@ -70,6 +70,9 @@
         if (ntName == null) {
             return null;
         }
+        if (ntMgr == null) {
+            return null;
+        }
         try {
             return ntMgr.getNodeType(ntName);
         } catch (NoSuchNodeTypeException e) {
@@ -83,6 +86,9 @@
      * {@inheritDoc}
      */
     public NodeType[] getRequiredPrimaryTypes() {
+        if (ntMgr == null) {
+            return null;
+        }
         Name[] ntNames = ((NodeDef) itemDef).getRequiredPrimaryTypes();
         try {
             if (ntNames == null || ntNames.length == 0) {

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefinitionImpl.java?rev=657073&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefinitionImpl.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefinitionImpl.java
Fri May 16 07:13:09 2008
@@ -0,0 +1,164 @@
+/*
+ * 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.core.nodetype;
+
+import org.apache.jackrabbit.api.jsr283.nodetype.NodeTypeDefinition;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.PropertyDefinition;
+
+/**
+ * This class implements the <code>NodeTypeDefinition</code> interface.
+ * All method calls are delegated to the wrapped {@link NodeTypeDef},
+ * performing the translation from <code>Name</code>s to JCR names
+ * (and vice versa) where necessary.
+ */
+public class NodeTypeDefinitionImpl implements NodeTypeDefinition {
+
+    private static Logger log = LoggerFactory.getLogger(NodeTypeDefinitionImpl.class);
+
+    private final NodeTypeDef ntd;
+    // resolver used to translate qualified names to JCR names
+    private final NamePathResolver resolver;
+
+    public NodeTypeDefinitionImpl(NodeTypeDef ntd, NamePathResolver resolver) {
+        this.ntd = ntd;
+        this.resolver = resolver;
+    }
+
+    //---------------------------------------------------< NodeTypeDefinition >
+    /**
+     * {@inheritDoc}
+     */
+    public String getName() {
+        try {
+            return resolver.getJCRName(ntd.getName());
+        } catch (NamespaceException e) {
+            // should never get here
+            log.error("encountered unregistered namespace in node type name", e);
+            return ntd.getName().toString();
+        }
+    }
+
+    /**
+     * Returns the names of the supertypes actually declared in this node type.
+     * <p/>
+     * In implementations that support node type registration, if this
+     * <code>NodeTypeDefinition</code> object is actually a newly-created empty
+     * <code>NodeTypeTemplate</code>, then this method will return an array
+     * containing a single string indicating the node type
+     * <code>nt:base</code>.
+     *
+     * @return an array of <code>String</code>s
+     * @since JCR 2.0
+     */
+    public String[] getDeclaredSupertypeNames() {
+        Name[] ntNames = ntd.getSupertypes();
+        String[] supertypes = new String[ntNames.length];
+        for (int i = 0; i < ntNames.length; i++) {
+            try {
+                supertypes[i] = resolver.getJCRName(ntd.getName());
+            } catch (NamespaceException e) {
+                // should never get here
+                log.error("encountered unregistered namespace in node type name", e);
+                supertypes[i] = ntd.getName().toString();
+            }
+        }
+        return supertypes;
+    }
+
+    /**
+     * Returns <code>true</code> if this is an abstract node type; returns
+     * <code>false</code> otherwise.
+     * <p/>
+     * An abstract node type is one that cannot be assigned as the primary or
+     * mixin type of a node but can be used in the definitions of other node
+     * types as a superclass.
+     * <p/>
+     * In implementations that support node type registration, if this
+     * <code>NodeTypeDefinition</code> object is actually a newly-created empty
+     * <code>NodeTypeTemplate</code>, then this method will return
+     * <code>false</code>.
+     *
+     * @return a <code>boolean</code>
+     * @since JCR 2.0
+     */
+    public boolean isAbstract() {
+        return ntd.isAbstract();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isMixin() {
+        return ntd.isMixin();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasOrderableChildNodes() {
+        return ntd.hasOrderableChildNodes();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getPrimaryItemName() {
+        try {
+            Name piName = ntd.getPrimaryItemName();
+            if (piName != null) {
+                return resolver.getJCRName(piName);
+            } else {
+                return null;
+            }
+        } catch (NamespaceException e) {
+            // should never get here
+            log.error("encountered unregistered namespace in name of primary item", e);
+            return ntd.getName().toString();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NodeDefinition[] getDeclaredChildNodeDefinitions() {
+        NodeDef[] cnda = ntd.getChildNodeDefs();
+        NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length];
+        for (int i = 0; i < cnda.length; i++) {
+            nodeDefs[i] = new NodeDefinitionImpl(cnda[i], null, resolver);
+        }
+        return nodeDefs;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public PropertyDefinition[] getDeclaredPropertyDefinitions() {
+        PropDef[] pda = ntd.getPropertyDefs();
+        PropertyDefinition[] propDefs = new PropertyDefinition[pda.length];
+        for (int i = 0; i < pda.length; i++) {
+            propDefs[i] = new PropertyDefinitionImpl(pda[i], null, resolver);
+        }
+        return propDefs;
+    }
+}

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeTemplateImpl.java?rev=657073&r1=657072&r2=657073&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeTemplateImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeTemplateImpl.java
Fri May 16 07:13:09 2008
@@ -17,9 +17,9 @@
 package org.apache.jackrabbit.core.nodetype;
 
 import org.apache.commons.collections.list.TypedList;
-import org.apache.jackrabbit.api.jsr283.nodetype.NodeDefinitionTemplate;
-import org.apache.jackrabbit.api.jsr283.nodetype.NodeTypeDefinition;
 import org.apache.jackrabbit.api.jsr283.nodetype.NodeTypeTemplate;
+import org.apache.jackrabbit.api.jsr283.nodetype.NodeTypeDefinition;
+import org.apache.jackrabbit.api.jsr283.nodetype.NodeDefinitionTemplate;
 import org.apache.jackrabbit.api.jsr283.nodetype.PropertyDefinitionTemplate;
 
 import javax.jcr.nodetype.NodeDefinition;
@@ -45,10 +45,6 @@
      * Package private constructor
      */
     NodeTypeTemplateImpl() {
-        nodeDefinitionTemplates = TypedList.decorate(
-                new ArrayList(), NodeDefinitionTemplate.class);
-        propertyDefinitionTemplates = TypedList.decorate(
-                new ArrayList(), PropertyDefinitionTemplate.class);
     }
 
     /**
@@ -64,12 +60,18 @@
         mixin = def.isMixin();
         orderableChildNodes = def.hasOrderableChildNodes();
         NodeDefinition[] nodeDefs = def.getDeclaredChildNodeDefinitions();
-        for (int i = 0; i < nodeDefs.length; i++) {
-            nodeDefinitionTemplates.add(new NodeDefinitionTemplateImpl(nodeDefs[i]));
+        if (nodeDefs != null) {
+            List list = getNodeDefinitionTemplates();
+            for (int i = 0; i < nodeDefs.length; i++) {
+                list.add(new NodeDefinitionTemplateImpl(nodeDefs[i]));
+            }
         }
         PropertyDefinition[] propDefs = def.getDeclaredPropertyDefinitions();
-        for (int i = 0; i < propDefs.length; i++) {
-            propertyDefinitionTemplates.add(new PropertyDefinitionTemplateImpl(propDefs[i]));
+        if (propDefs != null) {
+            List list = getPropertyDefinitionTemplates();
+            for (int i = 0; i < propDefs.length; i++) {
+                list.add(new PropertyDefinitionTemplateImpl(propDefs[i]));
+            }
         }
     }
 
@@ -120,6 +122,10 @@
      * {@inheritDoc}
      */
     public List getPropertyDefinitionTemplates() {
+        if (propertyDefinitionTemplates == null) {
+            propertyDefinitionTemplates = TypedList.decorate(
+                    new ArrayList(), PropertyDefinitionTemplate.class);
+        }
         return propertyDefinitionTemplates;
     }
 
@@ -127,6 +133,10 @@
      * {@inheritDoc}
      */
     public List getNodeDefinitionTemplates() {
+        if (nodeDefinitionTemplates == null) {
+            nodeDefinitionTemplates = TypedList.decorate(
+                    new ArrayList(), NodeDefinitionTemplate.class);
+        }
         return nodeDefinitionTemplates;
     }
 
@@ -177,15 +187,23 @@
      * {@inheritDoc}
      */
     public PropertyDefinition[] getDeclaredPropertyDefinitions() {
-        return (PropertyDefinition[]) propertyDefinitionTemplates.toArray(
-                new PropertyDefinition[propertyDefinitionTemplates.size()]);
+        if (propertyDefinitionTemplates == null) {
+            return null;
+        } else {
+            return (PropertyDefinition[]) propertyDefinitionTemplates.toArray(
+                    new PropertyDefinition[propertyDefinitionTemplates.size()]);
+        }
     }
 
     /**
      * {@inheritDoc}
      */
     public NodeDefinition[] getDeclaredChildNodeDefinitions() {
-        return (NodeDefinition[]) nodeDefinitionTemplates.toArray(
-                new NodeDefinition[nodeDefinitionTemplates.size()]);
+        if (nodeDefinitionTemplates == null) {
+            return null;
+        } else {
+            return (NodeDefinition[]) nodeDefinitionTemplates.toArray(
+                    new NodeDefinition[nodeDefinitionTemplates.size()]);
+        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java?rev=657073&r1=657072&r2=657073&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java
Fri May 16 07:13:09 2008
@@ -44,7 +44,7 @@
      *
      * @param propDef    property definition
      * @param ntMgr      node type manager
-     * @param resolver
+     * @param resolver   name resolver
      */
     PropertyDefinitionImpl(PropDef propDef, NodeTypeManagerImpl ntMgr,
                            NamePathResolver resolver) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java?rev=657073&r1=657072&r2=657073&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
Fri May 16 07:13:09 2008
@@ -24,10 +24,12 @@
 import org.apache.jackrabbit.core.nodetype.PropDef;
 import org.apache.jackrabbit.core.nodetype.PropDefImpl;
 import org.apache.jackrabbit.core.nodetype.ValueConstraint;
+import org.apache.jackrabbit.core.nodetype.NodeTypeDefinitionImpl;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
@@ -46,6 +48,7 @@
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Iterator;
 
 /**
  * CompactNodeTypeDefReader. Parses node type definitions written in the compact
@@ -188,6 +191,20 @@
     }
 
     /**
+     * Returns the list of parsed node type definitions.
+     *
+     * @param resolver name resolver
+     * @return a List of NodeTypeDefinitions objects
+     */
+    public List getNodeTypeDefinitions(NamePathResolver resolver) {
+        List l = new ArrayList(nodeTypeDefs.size());
+        for (Iterator iter = nodeTypeDefs.iterator(); iter.hasNext();) {
+            l.add(new NodeTypeDefinitionImpl((NodeTypeDef) iter.next(), resolver));
+        }
+        return l;
+    }
+
+    /**
      * Returns the namespace mapping.
      *
      * @return a NamespaceMapping object.



Mime
View raw message