jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r732872 - in /jackrabbit/sandbox/jackrabbit-ngp: ./ src/main/java/org/apache/jackrabbit/ngp/ src/main/java/org/apache/jackrabbit/ngp/nodetype/ src/test/java/org/apache/jackrabbit/ngp/
Date Thu, 08 Jan 2009 23:38:13 GMT
Author: jukka
Date: Thu Jan  8 15:38:12 2009
New Revision: 732872

URL: http://svn.apache.org/viewvc?rev=732872&view=rev
Log:
ngp: Implemented simple node type support based on actual nt:nodeType nodes stored in the
repository.

Work in progress...

Added:
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/AbstractNodeBasedDefinition.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/ItemDefinitionImpl.java
Modified:
    jackrabbit/sandbox/jackrabbit-ngp/pom.xml
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/NodeImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/PropertyImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeDefinitionImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeManagerImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/PropertyDefinitionImpl.java
    jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/NodeTest.java
    jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/RepositoryTest.java
    jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/SessionTest.java

Modified: jackrabbit/sandbox/jackrabbit-ngp/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/pom.xml?rev=732872&r1=732871&r2=732872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/pom.xml (original)
+++ jackrabbit/sandbox/jackrabbit-ngp/pom.xml Thu Jan  8 15:38:12 2009
@@ -39,7 +39,7 @@
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-jcr-commons</artifactId>
-      <version>1.5-SNAPSHOT</version>
+      <version>1.6-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>commons-collections</groupId>
@@ -59,13 +59,19 @@
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-jcr-tests</artifactId>
-      <version>1.5-SNAPSHOT</version>
+      <version>1.6-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>4.4</version>
+      <version>4.5</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>1.5.3</version>
       <scope>test</scope>
     </dependency>
   </dependencies>

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/NodeImpl.java?rev=732872&r1=732871&r2=732872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/NodeImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/NodeImpl.java
Thu Jan  8 15:38:12 2009
@@ -39,7 +39,6 @@
 import org.apache.jackrabbit.commons.AbstractNode;
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
 import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
-import org.apache.jackrabbit.ngp.nodetype.NodeDefinitionImpl;
 import org.apache.jackrabbit.ngp.state.MultiValuedPropertyState;
 import org.apache.jackrabbit.ngp.state.NodeState;
 import org.apache.jackrabbit.ngp.state.PersistentNodeState;

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/PropertyImpl.java?rev=732872&r1=732871&r2=732872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/PropertyImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/PropertyImpl.java
Thu Jan  8 15:38:12 2009
@@ -24,7 +24,6 @@
 import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.jackrabbit.commons.AbstractProperty;
-import org.apache.jackrabbit.ngp.nodetype.PropertyDefinitionImpl;
 import org.apache.jackrabbit.ngp.state.PropertyState;
 
 public class PropertyImpl extends AbstractProperty {

Added: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/AbstractNodeBasedDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/AbstractNodeBasedDefinition.java?rev=732872&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/AbstractNodeBasedDefinition.java
(added)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/AbstractNodeBasedDefinition.java
Thu Jan  8 15:38:12 2009
@@ -0,0 +1,167 @@
+/*
+ * 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.ngp.nodetype;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+/**
+ * Abstract base class for the type classes in this package. Subclasses
+ * represents some type-related information that is stored in a given node
+ * or subtree. This purpose of this base class is to reduce duplicate code
+ * and to make it easier for subclasses to access the information in the
+ * underlying nodes.
+ * <p>
+ * This class provides protected convenience methods for accessing information
+ * from the underlying nodes. These methods replace any thrown
+ * {@link RepositoryException}s with {@link IllegalStateException}s with
+ * appropriate exception messages to better match the method signatures in
+ * the JCR type interfaces.
+ * <p>
+ * It is assumed that all the names that a subclass uses to access properties
+ * and child nodes are statically prefixed with "jcr:" and use the standard
+ * "http://www.jcp.org/jcr/1.0" namespace. The methods in this class will
+ * automatically map such names to whatever namespace prefix is currently
+ * active in the associated JCR session.
+ */
+abstract class AbstractNodeBasedDefinition {
+
+    private static final String JCR_NAMESPACE = "http://www.jcp.org/jcr/1.0";
+
+    private final Node node;
+
+    protected AbstractNodeBasedDefinition(Node node) {
+        this.node = node;
+    }
+
+    protected boolean hasProperty(String name) {
+        try {
+            return node.hasProperty(mapName(name));
+        } catch (RepositoryException e) {
+            throw new IllegalStateException(
+                    "Failed to test for the existence of property "
+                    + name + " in "+ this, e);
+        }
+    }
+
+    protected String getString(String name) {
+        try {
+            return node.getProperty(mapName(name)).getString();
+        } catch (RepositoryException e) {
+            throw new IllegalStateException(
+                    "Failed to access the string value of property "
+                    + name + " of "+ this, e);
+        }
+    }
+
+    public boolean getBoolean(String name) {
+        try {
+            return node.getProperty(mapName(name)).getBoolean();
+        } catch (RepositoryException e) {
+            throw new IllegalStateException(
+                    "Failed to access the boolean value of property "
+                    + name + " of "+ this, e);
+        }
+    }
+
+    protected Value[] getValues(String name) {
+        try {
+            return node.getProperty(mapName(name)).getValues();
+        } catch (RepositoryException e) {
+            throw new IllegalStateException(
+                    "Failed to access the values of property "
+                    + name + " of "+ this, e);
+        }
+    }
+
+    protected String[] getStrings(String name) {
+        Value[] values = getValues(name);
+        String[] strings = new String[values.length];
+        for (int i = 0; i < values.length; i++) {
+            try {
+                strings[i] = values[i].getString();
+            } catch (RepositoryException e) {
+                throw new IllegalStateException(
+                        "Failed to get the string representation of value "
+                        + values[i] + " of property " + name + " in "+ this, e);
+            }
+        }
+        return strings;
+    }
+
+    public NodeIterator getNodes(String name) {
+        try {
+            return node.getNodes(mapName(name));
+        } catch (RepositoryException e) {
+            throw new IllegalStateException(
+                    "Failed to access " + name + " children of " + this, e);
+        }
+    }
+
+    //-------------------------------------------------------------< private >
+
+    private String mapName(String name) throws RepositoryException {
+        if (name.startsWith("jcr:")) {
+            String prefix = node.getSession().getNamespacePrefix(JCR_NAMESPACE);
+            if (prefix.equals("jcr")) {
+                return name;
+            } else {
+                return prefix + name.substring("jcr".length());
+            }
+        } else {
+            throw new IllegalArgumentException(
+                    "Unexpected namespace prefix in name " + name);
+        }
+    }
+
+    //--------------------------------------------------------------< Object >
+
+    /**
+     * Returns "node /path/to/node". Subclasses should override this method
+     * with something like "property definition " + super.toString() to
+     * produce a string like "property definition node /path/to/node" for
+     * use in potential exception messages.
+     */
+    public String toString() {
+        return node.toString();
+    }
+
+    public boolean equals(Object that) {
+        if (that instanceof AbstractNodeBasedDefinition) {
+            try {
+                return node.isSame(((AbstractNodeBasedDefinition) that).node);
+            } catch (RepositoryException e) {
+                throw new IllegalStateException(
+                        "Failed to compare " + this + " to " + that, e);
+            }
+        } else {
+            return false;
+        }
+    }
+
+    public int hashCode() {
+        try {
+            return node.getPath().hashCode();
+        } catch (RepositoryException e) {
+            throw new IllegalStateException(
+                    "Failed to compute hash code of " + this, e);
+        }
+    }
+
+}

Added: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/ItemDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/ItemDefinitionImpl.java?rev=732872&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/ItemDefinitionImpl.java
(added)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/ItemDefinitionImpl.java
Thu Jan  8 15:38:12 2009
@@ -0,0 +1,73 @@
+/*
+ * 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.ngp.nodetype;
+
+import javax.jcr.Node;
+import javax.jcr.nodetype.ItemDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.version.OnParentVersionAction;
+
+abstract class ItemDefinitionImpl extends AbstractNodeBasedDefinition
+        implements ItemDefinition {
+
+    /**
+     * Declaring node type.
+     */
+    private final NodeType type;
+
+    ItemDefinitionImpl(NodeType type, Node node) {
+        super(node);
+        this.type = type;
+    }
+
+    //------------------------------------------------------< ItemDefinition >
+
+    public NodeType getDeclaringNodeType() {
+        return type;
+    }
+
+    public String getName() {
+        if (hasProperty("jcr:name")) {
+            return getString("jcr:name");
+        } else {
+            return "*";
+        }
+    }
+
+    public boolean isAutoCreated() {
+        return getBoolean("jcr:autoCreated");
+    }
+
+    public boolean isMandatory() {
+        return getBoolean("jcr:mandatory");
+    }
+
+    public boolean isProtected() {
+        return getBoolean("jcr:protected");
+    }
+
+    public int getOnParentVersion() {
+        String opv = getString("jcr:onParentVersion");
+        try {
+            return OnParentVersionAction.valueFromName(opv);
+        } catch (IllegalArgumentException e) {
+            throw new IllegalStateException(
+                    "Unexpected OnParentVersion " + opv + " in " + this, e);
+        }
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeDefinitionImpl.java?rev=732872&r1=732871&r2=732872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeDefinitionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeDefinitionImpl.java
Thu Jan  8 15:38:12 2009
@@ -16,47 +16,74 @@
  */
 package org.apache.jackrabbit.ngp.nodetype;
 
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
-import javax.jcr.version.OnParentVersionAction;
+import javax.jcr.nodetype.NodeTypeManager;
 
+class NodeDefinitionImpl extends ItemDefinitionImpl implements NodeDefinition {
 
-public class NodeDefinitionImpl implements NodeDefinition {
+    private final NodeTypeManager manager;
 
-    public boolean allowsSameNameSiblings() {
-        return false;
-    }
-
-    public NodeType getDefaultPrimaryType() {
-        return new NodeTypeImpl();
+    /**
+     *
+     * @param type declaring node type
+     * @param node node definition node
+     */
+    NodeDefinitionImpl(NodeTypeManager manager, NodeType type, Node node) {
+        super(type, node);
+        this.manager = manager;
     }
 
     public NodeType[] getRequiredPrimaryTypes() {
-        return new NodeType[] {new NodeTypeImpl() };
-    }
-
-    public NodeType getDeclaringNodeType() {
-        return new NodeTypeImpl();
+        String[] names = getStrings("jcr:requiredPrimaryTypes");
+        NodeType[] types = new NodeType[names.length];
+        for (int i = 0; i < names.length; i++) {
+            try {
+                types[i] = manager.getNodeType(names[i]);
+            } catch (NoSuchNodeTypeException e) {
+                throw new IllegalStateException(
+                        "Unknown required node type "
+                        + names[i] + " in node definition " + this, e);
+            } catch (RepositoryException e) {
+                throw new IllegalStateException(
+                        "Failed to access the required node type "
+                        + names[i] + " of node definition "+ this, e);
+            }
+        }
+        return types;
     }
 
-    public String getName() {
-        return "*";
-    }
-
-    public int getOnParentVersion() {
-        return OnParentVersionAction.COPY;
+    public NodeType getDefaultPrimaryType() {
+        if (hasProperty("jcr:defaultPrimaryType")) {
+            String name = getString("jcr:defaultPrimaryType");
+            try {
+                return manager.getNodeType(name);
+            } catch (NoSuchNodeTypeException e) {
+                throw new IllegalStateException(
+                        "Unknown default type " + name + " in " + this, e);
+            } catch (RepositoryException e) {
+                throw new IllegalStateException(
+                        "Failed to get default type " + name + " of "+ this, e);
+            }
+        } else {
+            return null;
+        }
     }
 
-    public boolean isAutoCreated() {
-        return false;
+    public boolean allowsSameNameSiblings() {
+        return getBoolean("jcr:sameNameSiblings");
     }
 
-    public boolean isMandatory() {
-        return false;
-    }
+    //--------------------------------------------------------------< Object >
 
-    public boolean isProtected() {
-        return false;
+    /**
+     * Returns "node definition node /path/to/node"
+     */
+    public String toString() {
+        return "node definition " + super.toString();
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeImpl.java?rev=732872&r1=732871&r2=732872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeImpl.java
Thu Jan  8 15:38:12 2009
@@ -16,83 +16,260 @@
  */
 package org.apache.jackrabbit.ngp.nodetype;
 
-import javax.jcr.PropertyType;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
 import javax.jcr.Value;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.PropertyDefinition;
 
+class NodeTypeImpl extends AbstractNodeBasedDefinition implements NodeType {
 
-public class NodeTypeImpl implements NodeType {
+    private final NodeTypeManager manager;
 
-    public boolean canAddChildNode(String childNodeName) {
-        return true;
-    }
-
-    public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
-        return true;
+    NodeTypeImpl(NodeTypeManager manager, Node node) {
+        super(node);
+        this.manager = manager;
     }
 
-    public boolean canRemoveItem(String itemName) {
-        return !itemName.equals("jcr:primaryType");
+    public String getName() {
+        return getString("jcr:nodeTypeName");
     }
 
-    public boolean canSetProperty(String propertyName, Value value) {
-        return !propertyName.equals("jcr:primaryType");
+    public NodeType[] getDeclaredSupertypes() {
+        if (hasProperty("jcr:supertypes")) {
+            String[] names = getStrings("jcr:supertypes");
+            NodeType[] types = new NodeType[names.length];
+            for (int i = 0; i < names.length; i++) {
+                try {
+                    types[i] = manager.getNodeType(names[i]);
+                } catch (NoSuchNodeTypeException e) {
+                    throw new IllegalStateException(
+                            "Unknown declared supertype "
+                            + names[i] + " in " + this, e);
+                } catch (RepositoryException e) {
+                    throw new IllegalStateException(
+                            "Failed to access the declared supertype "
+                            + names[i] + " of "+ this, e);
+                }
+            }
+            return types;
+        } else {
+            return new NodeType[0];
+        }
     }
 
-    public boolean canSetProperty(String propertyName, Value[] values) {
-        return false;
+    public boolean isMixin() {
+        return getBoolean("jcr:isMixin");
     }
 
-    public NodeDefinition[] getChildNodeDefinitions() {
-        return new NodeDefinition[] { new NodeDefinitionImpl() };
+    public boolean hasOrderableChildNodes() {
+        return getBoolean("jcr:hasOrderableChildNodes");
     }
 
-    public NodeDefinition[] getDeclaredChildNodeDefinitions() {
-        return new NodeDefinition[] { new NodeDefinitionImpl() };
+    public String getPrimaryItemName() {
+        if (hasProperty("jcr:primaryItemName")) {
+            return getString("jcr:primaryItemName");
+        } else {
+            return null;
+        }
     }
 
     public PropertyDefinition[] getDeclaredPropertyDefinitions() {
-        return new PropertyDefinition[] {
-                new PropertyDefinitionImpl(PropertyType.UNDEFINED, true),
-                new PropertyDefinitionImpl(PropertyType.UNDEFINED, false)
-        };
+        List<PropertyDefinition> defs = new ArrayList<PropertyDefinition>();

+        NodeIterator iterator = getNodes("jcr:propertyDefinition");
+        while (iterator.hasNext()) {
+            defs.add(new PropertyDefinitionImpl(this, iterator.nextNode()));
+        }
+        return defs.toArray(new PropertyDefinition[defs.size()]);
     }
 
-    public NodeType[] getDeclaredSupertypes() {
-        return new NodeType[0];
+    public NodeDefinition[] getDeclaredChildNodeDefinitions() {
+        List<NodeDefinition> defs = new ArrayList<NodeDefinition>(); 
+        NodeIterator iterator = getNodes("jcr:childNodeDefinition");
+        while (iterator.hasNext()) {
+            defs.add(new NodeDefinitionImpl(
+                    manager, this, iterator.nextNode()));
+        }
+        return defs.toArray(new NodeDefinition[defs.size()]);
     }
 
-    public String getName() {
-        return "nt:unstructured";
-    }
+    //-----------------------------------------------------< derived methods >
 
-    public String getPrimaryItemName() {
-        return null;
+    public boolean canAddChildNode(String childNodeName) {
+        for (NodeDefinition definition : getChildNodeDefinitions()) {
+            String name = definition.getName();
+            if (name == null || name.equals(childNodeName)) {
+                if (definition.getDefaultPrimaryType() != null) {
+                    return true;
+                }
+            }
+        }
+        return false;
     }
 
-    public PropertyDefinition[] getPropertyDefinitions() {
-        return new PropertyDefinition[] {
-                new PropertyDefinitionImpl(PropertyType.UNDEFINED, true),
-                new PropertyDefinitionImpl(PropertyType.UNDEFINED, false)
-        };
+    public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
+        try {
+            NodeType type = manager.getNodeType(nodeTypeName);
+            for (NodeDefinition def : getChildNodeDefinitions()) {
+                String name = def.getName();
+                if (name == null || name.equals(childNodeName)) {
+                    boolean match = true;
+                    for (NodeType required : def.getRequiredPrimaryTypes()) {
+                        match = match && type.isNodeType(required.getName());
+                    }
+                    if (match) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        } catch (NoSuchNodeTypeException e) {
+            throw new IllegalArgumentException(
+                    "Node type " + nodeTypeName + " not found");
+            // ... or should we return false for this case?
+        } catch (RepositoryException e) {
+            throw new IllegalStateException(
+                    "Failed to access node type " + nodeTypeName, e);
+        }
     }
 
-    public NodeType[] getSupertypes() {
-        return new NodeType[0];
+    public boolean canRemoveItem(String itemName) {
+        // named property definitions
+        for (PropertyDefinition def : getPropertyDefinitions()) {
+            String name = def.getName();
+            if (name != null && name.equals(itemName)) {
+                return !def.isMandatory() && !def.isProtected();
+            }
+        }
+
+        // named child node definitions
+        for (NodeDefinition def : getChildNodeDefinitions()) {
+            String name = def.getName();
+            if (name != null && name.equals(itemName)) {
+                return !def.isMandatory() && !def.isProtected();
+            }
+        }
+
+        // residual property definitions
+        for (PropertyDefinition def : getPropertyDefinitions()) {
+            if (def.getName() == null) {
+                return true; // can't be mandatory or protected
+            }
+        }
+
+        // residual child node definitions
+        for (NodeDefinition def : getChildNodeDefinitions()) {
+            if (def.getName() == null) {
+                return true; // can't be mandatory or protected
+            }
+        }
+
+        return false;
     }
 
-    public boolean hasOrderableChildNodes() {
+    public boolean canSetProperty(String propertyName, Value value) {
+        // named property definitions
+        for (PropertyDefinition def : getPropertyDefinitions()) {
+            String name = def.getName();
+            if (name != null && name.equals(propertyName)
+                    && !def.isMultiple()) {
+                return !def.isProtected(); // TODO: check value constraints
+            }
+        }
+
+        // residual property definitions
+        for (PropertyDefinition def : getPropertyDefinitions()) {
+            if (def.getName() == null && !def.isMultiple()) {
+                // can't be protected
+                return true; // TODO: check value constraints
+            }
+        }
+
         return false;
     }
 
-    public boolean isMixin() {
+    public boolean canSetProperty(String propertyName, Value[] values) {
+        // named property definitions
+        for (PropertyDefinition def : getPropertyDefinitions()) {
+            String name = def.getName();
+            if (name != null && name.equals(propertyName) && def.isMultiple())
{
+                return !def.isProtected(); // TODO: check value constraints
+            }
+        }
+
+        // residual property definitions
+        for (PropertyDefinition def : getPropertyDefinitions()) {
+            if (def.getName() == null && def.isMultiple()) {
+                // can't be protected
+                return true; // TODO: check value constraints
+            }
+        }
+
         return false;
     }
 
-    public boolean isNodeType(String nodeTypeName) {
-        return getName().equals(nodeTypeName);
+    public NodeType[] getSupertypes() {
+        List<NodeType> types = new ArrayList<NodeType>();
+        Queue<NodeType> queue = new LinkedList<NodeType>();
+        queue.addAll(Arrays.asList(getDeclaredSupertypes()));
+        while (!queue.isEmpty()) {
+            NodeType type = queue.remove();
+            if (!types.contains(type)) {
+                types.add(type);
+                queue.addAll(Arrays.asList(type.getDeclaredSupertypes()));
+            }
+        }
+        return types.toArray(new NodeType[types.size()]);
+    }
+
+    public PropertyDefinition[] getPropertyDefinitions() {
+        List<PropertyDefinition> defs = new ArrayList<PropertyDefinition>();
+        defs.addAll(Arrays.asList(getDeclaredPropertyDefinitions()));
+        for (NodeType type : getSupertypes()) {
+            defs.addAll(Arrays.asList(type.getDeclaredPropertyDefinitions()));
+        }
+        return defs.toArray(new PropertyDefinition[defs.size()]);
+    }
+
+    public NodeDefinition[] getChildNodeDefinitions() {
+        List<NodeDefinition> defs = new ArrayList<NodeDefinition>();
+        defs.addAll(Arrays.asList(getDeclaredChildNodeDefinitions()));
+        for (NodeType type : getSupertypes()) {
+            defs.addAll(Arrays.asList(type.getDeclaredChildNodeDefinitions()));
+        }
+        return defs.toArray(new NodeDefinition[defs.size()]);
+    }
+
+    public boolean isNodeType(String name) {
+        if (getName().equals(name)) {
+            return true;
+        } else {
+            for (NodeType type : getSupertypes()) {
+                if (type.getName().equals(name)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    //--------------------------------------------------------------< Object >
+
+    /**
+     * Returns "node type node /path/to/node"
+     */
+    public String toString() {
+        return "node type " + super.toString();
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeManagerImpl.java?rev=732872&r1=732871&r2=732872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeManagerImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/NodeTypeManagerImpl.java
Thu Jan  8 15:38:12 2009
@@ -16,8 +16,11 @@
  */
 package org.apache.jackrabbit.ngp.nodetype;
 
-import java.util.Collections;
+import java.util.ArrayList;
+import java.util.List;
 
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeType;
@@ -26,27 +29,60 @@
 
 import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
 
-public class NodeTypeManagerImpl implements NodeTypeManager {
+class NodeTypeManagerImpl implements NodeTypeManager {
+
+    private final Node node;
+
+    NodeTypeManagerImpl(Node node) {
+        this.node = node;
+    }
 
     public NodeTypeIterator getAllNodeTypes() throws RepositoryException {
-        return new NodeTypeIteratorAdapter(Collections.singleton(new NodeTypeImpl()));
+        List<NodeType> types = new ArrayList<NodeType>();
+        NodeIterator iterator = node.getNodes();
+        while (iterator.hasNext()) {
+            types.add(new NodeTypeImpl(this, iterator.nextNode()));
+        }
+        return new NodeTypeIteratorAdapter(types);
     }
 
+    //-----------------------------------------------------< derived methods >
+
     public NodeTypeIterator getMixinNodeTypes() throws RepositoryException {
-        return new NodeTypeIteratorAdapter(Collections.EMPTY_LIST);
+        List<NodeType> types = new ArrayList<NodeType>();
+        NodeTypeIterator iterator = getAllNodeTypes();
+        while (iterator.hasNext()) {
+            NodeType type = iterator.nextNodeType();
+            if (type.isMixin()) {
+                types.add(type);
+            }
+        }
+        return new NodeTypeIteratorAdapter(types);
     }
 
     public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException {
-        return new NodeTypeIteratorAdapter(Collections.singleton(new NodeTypeImpl()));
+        List<NodeType> types = new ArrayList<NodeType>();
+        NodeTypeIterator iterator = getAllNodeTypes();
+        while (iterator.hasNext()) {
+            NodeType type = iterator.nextNodeType();
+            if (!type.isMixin()) {
+                types.add(type);
+            }
+        }
+        return new NodeTypeIteratorAdapter(types);
     }
 
     public NodeType getNodeType(String nodeTypeName)
             throws NoSuchNodeTypeException, RepositoryException {
-        if (nodeTypeName.equals("nt:unstructured")) {
-            return new NodeTypeImpl();
-        } else {
-            throw new NoSuchNodeTypeException(nodeTypeName);
+        NodeTypeIterator iterator = getAllNodeTypes();
+        while (iterator.hasNext()) {
+            NodeType type = iterator.nextNodeType();
+            if (type.getName().equals(nodeTypeName)) {
+                return type;
+            }
         }
+        throw new NoSuchNodeTypeException(
+                "Node type " + nodeTypeName + " not found");
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/PropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/PropertyDefinitionImpl.java?rev=732872&r1=732871&r2=732872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/PropertyDefinitionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/main/java/org/apache/jackrabbit/ngp/nodetype/PropertyDefinitionImpl.java
Thu Jan  8 15:38:12 2009
@@ -16,60 +16,56 @@
  */
 package org.apache.jackrabbit.ngp.nodetype;
 
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
 import javax.jcr.Value;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
-import javax.jcr.version.OnParentVersionAction;
 
-public class PropertyDefinitionImpl implements PropertyDefinition {
+class PropertyDefinitionImpl extends ItemDefinitionImpl
+        implements PropertyDefinition {
 
-    private int type;
-
-    private boolean multiple;
-
-    public PropertyDefinitionImpl(int type, boolean multiple) {
-        this.type = type;
-        this.multiple = multiple;
-    }
-
-    public Value[] getDefaultValues() {
-        return null;
+    PropertyDefinitionImpl(NodeType type, Node node) {
+        super(type, node);
     }
 
     public int getRequiredType() {
-        return type;
+        String type = getString("jcr:requiredType");
+        try {
+            return PropertyType.valueFromName(type);
+        } catch (IllegalArgumentException e) {
+            throw new IllegalStateException(
+                    "Unexpected required type " + type + " in " + this, e);
+        }
     }
 
     public String[] getValueConstraints() {
-        return null;
-    }
-
-    public boolean isMultiple() {
-        return multiple;
+        if (hasProperty("jcr:valueConstraints")) {
+            return getStrings("jcr:valueConstraints");
+        } else {
+            return null;
+        }
     }
 
-    public NodeType getDeclaringNodeType() {
-        return null;
-    }
-
-    public String getName() {
-        return "*";
-    }
-
-    public int getOnParentVersion() {
-        return OnParentVersionAction.COPY;
+    public Value[] getDefaultValues() {
+        if (hasProperty("jcr:defaultValues")) {
+            return getValues("jcr:defaultValues");
+        } else {
+            return null;
+        }
     }
 
-    public boolean isAutoCreated() {
-        return false;
+    public boolean isMultiple() {
+        return getBoolean("jcr:multiple");
     }
 
-    public boolean isMandatory() {
-        return false;
-    }
+    //--------------------------------------------------------------< Object >
 
-    public boolean isProtected() {
-        return false;
+    /**
+     * Returns "property definition node /path/to/node"
+     */
+    public String toString() {
+        return "property definition " + super.toString();
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/NodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/NodeTest.java?rev=732872&r1=732871&r2=732872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/NodeTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/NodeTest.java
Thu Jan  8 15:38:12 2009
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.ngp;
 
 import static org.junit.Assert.*;
-import static org.junit.matchers.IsCollectionContaining.*;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -40,8 +39,8 @@
     @Test
     public void testGetAttributeNames() {
         Collection<String> names = Arrays.asList(session.getAttributeNames());
-        assertThat(names, hasItem(Credentials.class.getName()));
-        assertThat(names, hasItem(Workspace.class.getName()));
+        assertTrue(names.contains(Credentials.class.getName()));
+        assertTrue(names.contains(Workspace.class.getName()));
     }
 
     @Test

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/RepositoryTest.java?rev=732872&r1=732871&r2=732872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/RepositoryTest.java
Thu Jan  8 15:38:12 2009
@@ -18,7 +18,6 @@
 
 import static javax.jcr.Repository.*;
 import static org.junit.Assert.*;
-import static org.junit.matchers.IsCollectionContaining.*;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -33,14 +32,14 @@
     @Test
     public void testGetDescriptorKeys() {
         Collection<String> keys = Arrays.asList(repository.getDescriptorKeys());
-        assertThat(keys, hasItem(SPEC_NAME_DESC));
-        assertThat(keys, hasItem(SPEC_VERSION_DESC));
+        assertTrue(keys.contains(SPEC_NAME_DESC));
+        assertTrue(keys.contains(SPEC_VERSION_DESC));
 
-        assertThat(keys, hasItem(REP_NAME_DESC));
-        assertThat(keys, hasItem(REP_VERSION_DESC));
+        assertTrue(keys.contains(REP_NAME_DESC));
+        assertTrue(keys.contains(REP_VERSION_DESC));
 
-        assertThat(keys, hasItem(REP_VENDOR_DESC));
-        assertThat(keys, hasItem(REP_VENDOR_URL_DESC));
+        assertTrue(keys.contains(REP_VENDOR_DESC));
+        assertTrue(keys.contains(REP_VENDOR_URL_DESC));
 
         // assertThat(keys, hasItem(LEVEL_1_SUPPORTED));
         // assertThat(keys, hasItem(LEVEL_2_SUPPORTED));

Modified: jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/SessionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/SessionTest.java?rev=732872&r1=732871&r2=732872&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/SessionTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-ngp/src/test/java/org/apache/jackrabbit/ngp/SessionTest.java
Thu Jan  8 15:38:12 2009
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.ngp;
 
 import static org.junit.Assert.*;
-import static org.junit.matchers.IsCollectionContaining.*;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -40,8 +39,8 @@
     @Test
     public void testGetAttributeNames() {
         Collection<String> names = Arrays.asList(session.getAttributeNames());
-        assertThat(names, hasItem(Credentials.class.getName()));
-        assertThat(names, hasItem(Workspace.class.getName()));
+        assertTrue(names.contains(Credentials.class.getName()));
+        assertTrue(names.contains(Workspace.class.getName()));
     }
 
     @Test



Mime
View raw message