jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r169256 - in /incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session: SessionHelper.java nodetype/SessionItemDefinition.java nodetype/SessionNodeDefinition.java nodetype/SessionNodeType.java nodetype/SessionNodeTypeManager.java nodetype/SessionPropertyDefinition.java nodetype/package.html
Date Mon, 09 May 2005 08:50:28 GMT
Author: jukka
Date: Mon May  9 01:50:27 2005
New Revision: 169256

URL: http://svn.apache.org/viewcvs?rev=169256&view=rev
Log:
JCR-EXT: Improvements in node type handling.
	* SessionHelper.java: Added proper equals and hashCode implementations.
	* SessionItemDefinition.java: Added proper equals and hashCode implementations.
	* SessionNodeType.java: Added proper equals and hashCode implementations.
	* SessionNodeTypeManager.java: Added proper equals and hashCode implementations.
	* package.html: Removed note about state caching.
	* Switched to using the generic node type base classes for general functionality.
	* Protected and finalized implementation classes.

Modified:
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionHelper.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionItemDefinition.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeDefinition.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeType.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeTypeManager.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionPropertyDefinition.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/package.html

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionHelper.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionHelper.java?rev=169256&r1=169255&r2=169256&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionHelper.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionHelper.java
Mon May  9 01:50:27 2005
@@ -28,7 +28,7 @@
  * Helper class for accessing the namespaces and node types associated
  * with a JCR Session.
  */
-public class SessionHelper {
+public final class SessionHelper {
 
     /** The session to which this frontend instance is bound. */
     private final Session session;
@@ -77,7 +77,7 @@
      * @param name qualified node type name
      * @return named node type
      * @throws IllegalStateException if the named node type does not exist
-     * @throws RuntimeException if a repository error occurs
+     * @throws RuntimeException      if a repository error occurs
      */
     public NodeType getNodeType(Name name)
             throws IllegalStateException, RuntimeException {
@@ -94,7 +94,7 @@
      * @param name node type name
      * @return named node type
      * @throws IllegalStateException if the named node type does not exist
-     * @throws RuntimeException if a repository error occurs
+     * @throws RuntimeException      if a repository error occurs
      */
     public NodeType getNodeType(String name)
             throws IllegalStateException, RuntimeException {
@@ -106,6 +106,36 @@
         } catch (RepositoryException e) {
             throw new RuntimeException("Unexpected repository error", e);
         }
+    }
+
+    /**
+     * Compares session helpers for equality. Two session helpers are equal
+     * if they refer to the same session.
+     *
+     * @param that the object to compare this one to
+     * @return <code>true</code> if the objects are equal,
+     *         <code>false</code> otherwise
+     * @see Object#equals(Object)
+     */
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        } else if (that instanceof SessionHelper) {
+            return session.equals(((SessionHelper) that).session);
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Calculates the session helper hash code. This method simply returns
+     * the hash code of the underlying session.
+     *
+     * @return session hash code
+     * @see Object#hashCode()
+     */
+    public int hashCode() {
+        return session.hashCode();
     }
 
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionItemDefinition.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionItemDefinition.java?rev=169256&r1=169255&r2=169256&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionItemDefinition.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionItemDefinition.java
Mon May  9 01:50:27 2005
@@ -25,13 +25,13 @@
 /**
  * Immutable and session-bound item definition frontend. An instance
  * of this class presents the underlying item definition state using
- * the JCR ItemDef interface.
+ * the JCR ItemDefinition interface.
  * <p>
  * By not exposing the setter methods of the underlying state instance,
  * this class intentionally makes it impossible for a JCR client to modify
  * item definition information.
  */
-public class SessionItemDefinition implements ItemDefinition {
+class SessionItemDefinition implements ItemDefinition {
 
     /** Helper for accessing the current session. */
     private final SessionHelper helper;
@@ -125,6 +125,49 @@
      */
     public boolean isProtected() {
         return state.isProtected();
+    }
+
+    /**
+     * Compares objects for equality. Returns <code>true</code> if the
+     * given object is a SessionItemDefinition with the same underlying item
+     * definition state, session, and declaring node type.
+     * <p>
+     * Note that the item definition state class does not override the equals
+     * method and thus the mutable state instances are compared for
+     * reference equality.
+     *
+     * @param that the object to compare this object with
+     * @return <code>true</code> if the objects are equal,
+     *         <code>false</code> otherwise
+     * @see Object#equals(Object)
+     */
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        } else if (that instanceof SessionItemDefinition) {
+            return state.equals(((SessionItemDefinition) that).state)
+                && helper.equals(((SessionItemDefinition) that).helper)
+                && type.equals(((SessionItemDefinition) that).type);
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Returns a hash code for this object. To satisfy the equality
+     * constraints the returned hash code is a combination of the
+     * hash codes of the underlying node type state, session, and declaring
+     * node type.
+     *
+     * @return hash code
+     * @see Object#hashCode()
+     */
+    public int hashCode() {
+        int code = 17;
+        code = code * 37 + state.hashCode();
+        code = code * 37 + helper.hashCode();
+        code = code * 37 + type.hashCode();
+        return code;
     }
 
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeDefinition.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeDefinition.java?rev=169256&r1=169255&r2=169256&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeDefinition.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeDefinition.java
Mon May  9 01:50:27 2005
@@ -35,7 +35,7 @@
  * this class intentionally makes it impossible for a JCR client to modify
  * node definition information.
  */
-public class SessionNodeDefinition extends SessionItemDefinition
+final class SessionNodeDefinition extends SessionItemDefinition
         implements NodeDefinition {
 
     /** Helper for accessing the current session. */
@@ -44,12 +44,6 @@
     /** The underlying node definition state. */
     private final NodeDefinitionState state;
 
-    /** Memorized default primary node type. Initially <code>null</code>. */
-    private NodeType defaultPrimaryType;
-
-    /** Memorized set of required node types. Initially <code>null</code>. */
-    private Set requiredPrimaryTypes;
-
     /**
      * Creates a node definition frontend that is bound to the
      * given node type, session, and underlying node definition state.
@@ -63,27 +57,18 @@
         super(helper, type, state);
         this.helper = helper;
         this.state = state;
-        this.defaultPrimaryType = null;
-        this.requiredPrimaryTypes = null;
     }
 
     /**
      * Returns the default primary type of the defined node. The returned
      * node type is retrieved from the node type manager of the current
      * session using the node type name stored in the underlying state.
-     * <p>
-     * The return value is memorized to improve performance, and will
-     * therefore not change even if the underlying state changes!
      *
      * @return default primary type
      * @see NodeDefinition#getDefaultPrimaryType()
      */
     public NodeType getDefaultPrimaryType() {
-        if (defaultPrimaryType == null) {
-            defaultPrimaryType =
-                helper.getNodeType(state.getDefaultPrimaryTypeName());
-        }
-        return defaultPrimaryType;
+        return helper.getNodeType(state.getDefaultPrimaryTypeName());
     }
 
     /**
@@ -93,24 +78,17 @@
      * <p>
      * The returned array is freshly instantiated and not a part of the
      * underlying state, so it can be freely modified.
-     * <p>
-     * The set of required primary types is memorized to improve performance,
-     * and will therefore not change even if the underlying state changes!
      *
      * @return required primary types
      * @see NodeDefinition#getRequiredPrimaryTypes()
      */
     public NodeType[] getRequiredPrimaryTypes() {
-        if (requiredPrimaryTypes == null) {
-            Set types = new HashSet();
-            Name[] names = state.getRequiredPrimaryTypeNames();
-            for (int i = 0; i < names.length; i++) {
-                types.add(helper.getNodeType(names[i]));
-            }
-            requiredPrimaryTypes = types;
+        Set types = new HashSet();
+        Name[] names = state.getRequiredPrimaryTypeNames();
+        for (int i = 0; i < names.length; i++) {
+            types.add(helper.getNodeType(names[i]));
         }
-        return (NodeType[]) requiredPrimaryTypes.toArray(
-                new NodeType[requiredPrimaryTypes.size()]);
+        return (NodeType[]) types.toArray(new NodeType[types.size()]);
     }
 
     /**
@@ -118,11 +96,11 @@
      * The returned value is retrieved from the underlying node definition
      * state.
      *
-     * @return AlloswSameNameSiblings property value
+     * @return AllowsSameNameSiblings property value
      * @see NodeDefinition#allowsSameNameSiblings()
      */
     public boolean allowsSameNameSiblings() {
-        return state.isAllowsSameNameSiblings();
+        return state.allowsSameNameSiblings();
     }
 
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeType.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeType.java?rev=169256&r1=169255&r2=169256&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeType.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeType.java
Mon May  9 01:50:27 2005
@@ -16,16 +16,15 @@
  */
 package org.apache.jackrabbit.session.nodetype;
 
-import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
-import javax.jcr.Value;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.jackrabbit.session.SessionHelper;
+import org.apache.jackrabbit.base.nodetype.BaseNodeType;
 import org.apache.jackrabbit.name.Name;
 import org.apache.jackrabbit.state.nodetype.NodeDefinitionState;
 import org.apache.jackrabbit.state.nodetype.NodeTypeState;
@@ -42,7 +41,7 @@
  * this class intentionally makes it impossible for a JCR client to modify
  * node type information.
  */
-public class SessionNodeType implements NodeType {
+final class SessionNodeType extends BaseNodeType implements NodeType {
 
     /** The wildcard item definition name. */
     private static final String WILDCARD = "*";
@@ -53,24 +52,6 @@
     /** The underlying node type state. */
     private final NodeTypeState state;
 
-    /** Memorized set of declared supertypes. Initially <code>null</code>. */
-    private NodeType[] declaredSupertypes;
-
-    /** Memorized set of all supertypes. Initially <code>null</code>. */
-    private NodeType[] supertypes;
-
-    /** Memorized set of declared property defs. Initially <code>null</code>.
*/
-    private PropertyDefinition[] declaredPropertyDefinitions;
-
-    /** Memorized set of all property defs. Initially <code>null</code>. */
-    private PropertyDefinition[] propertyDefinitions;
-
-    /** Memorized set of declared child node defs. Initially <code>null</code>.
*/
-    private NodeDefinition[] declaredChildNodeDefinitions;
-
-    /** Memorized set of all child node defs. Initially <code>null</code>. */
-    private NodeDefinition[] childNodeDefinitions;
-
     /**
      * Creates a node type frontend that is bound to the
      * given session and underlying node type state.
@@ -81,44 +62,6 @@
     public SessionNodeType(SessionHelper helper, NodeTypeState state) {
         this.helper = helper;
         this.state = state;
-        this.declaredSupertypes = null;
-        this.supertypes = null;
-        this.declaredPropertyDefinitions = null;
-        this.propertyDefinitions = null;
-        this.declaredChildNodeDefinitions = null;
-        this.childNodeDefinitions = null;
-    }
-
-    /**
-     * Compares objects for equality. Returns <code>true</code> if the
-     * given object is a SessionNodeType with the same (refrence equality)
-     * underlying node type state.
-     *
-     * @param that the object to compare this object with
-     * @return <code>true</code> if the objects are equal,
-     *         <code>false</code> otherwise
-     * @see Object#equals(Object)
-     */
-    public boolean equals(Object that) {
-        if (this == that) {
-            return true;
-        } else if (that instanceof SessionNodeType) {
-            return state == ((SessionNodeType) that).state;
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * Returns a hash code for this object. To satisfy the equality
-     * constraints the returned hash code is the hash code of the
-     * underlying node type state.
-     *
-     * @return hash code
-     * @see Object#hashCode()
-     */
-    public int hashCode() {
-        return state.hashCode();
     }
 
     /**
@@ -180,24 +123,17 @@
      * <p>
      * The returned array is freshly instantiated and not a part of the
      * underlying state, so it can be freely modified.
-     * <p>
-     * The set of declared supertypes is memorized to improve performance,
-     * and will therefore not change even if the underlying state changes!
      *
      * @return declared supertypes
      * @see NodeType#getDeclaredSupertypes()
      */
     public NodeType[] getDeclaredSupertypes() {
-        if (declaredSupertypes == null) {
-            Set types = new HashSet();
-            Name[] names = state.getSupertypeNames();
-            for (int i = 0; i < names.length; i++) {
-                types.add(helper.getNodeType(names[i]));
-            }
-            declaredSupertypes =
-                (NodeType[]) types.toArray(new NodeType[types.size()]);
+        Set types = new HashSet();
+        Name[] names = state.getSupertypeNames();
+        for (int i = 0; i < names.length; i++) {
+            types.add(helper.getNodeType(names[i]));
         }
-        return (NodeType[]) declaredSupertypes.clone();
+        return (NodeType[]) types.toArray(new NodeType[types.size()]);
     }
 
     /**
@@ -208,25 +144,19 @@
      * <p>
      * The returned array is freshly instantiated and not a part of the
      * underlying state, so it can be freely modified.
-     * <p>
-     * The set of declared child node defs is memorized to improve performance,
-     * and will therefore not change even if the underlying state changes!
      *
      * @return declared child node definitions
      * @see SessionNodeDefinition
      * @see NodeType#getDeclaredChildNodeDefinitions()
      */
     public NodeDefinition[] getDeclaredChildNodeDefinitions() {
-        if (declaredChildNodeDefinitions == null) {
-            Set defs = new HashSet();
-            NodeDefinitionState[] states = state.getChildNodeDefinitionStates();
-            for (int i = 0; i < states.length; i++) {
-                defs.add(new SessionNodeDefinition(helper, this, states[i]));
-            }
-            declaredChildNodeDefinitions = (NodeDefinition[])
-                defs.toArray(new NodeDefinition[defs.size()]);
+        Set definitions = new HashSet();
+        NodeDefinitionState[] states = state.getChildNodeDefinitionStates();
+        for (int i = 0; i < states.length; i++) {
+            definitions.add(new SessionNodeDefinition(helper, this, states[i]));
         }
-        return (NodeDefinition[]) declaredChildNodeDefinitions.clone();
+        return (NodeDefinition[])
+            definitions.toArray(new NodeDefinition[definitions.size()]);
     }
 
     /**
@@ -237,307 +167,61 @@
      * <p>
      * The returned array is freshly instantiated and not a part of the
      * underlying state, so it can be freely modified.
-     * <p>
-     * The set of declared property defs is memorized to improve performance,
-     * and will therefore not change even if the underlying state changes!
      *
      * @return declared child node definitions
      * @see SessionPropertyDefinition
      * @see NodeType#getDeclaredChildNodeDefs()
      */
     public PropertyDefinition[] getDeclaredPropertyDefinitions() {
-        if (declaredPropertyDefinitions == null) {
-            Set defs = new HashSet();
-            PropertyDefinitionState[] states =
-                state.getPropertyDefinitionStates();
-            for (int i = 0; i < states.length; i++) {
-                defs.add(new SessionPropertyDefinition(helper, this, states[i]));
-            }
-            declaredPropertyDefinitions = (PropertyDefinition[])
-                defs.toArray(new PropertyDefinition[defs.size()]);
-        }
-        return (PropertyDefinition[]) declaredPropertyDefinitions.clone();
-    }
-
-    /**
-     * Checks whether this node type is or inherits the named node type.
-     * The check is implemented by first comparing the given name to the name
-     * of this node type and then (if names did not match) recursively checking
-     * all declared supertypes.
-     *
-     * @param name node type name
-     * @return <code>true</code> if this node type is or inherits the given
-     *         node type, <code>false</code> otherwise
-     * @see NodeType#isNodeType(String)
-     */
-    public boolean isNodeType(String name) {
-        if (name.equals(getName())) {
-            return true;
-        } else {
-            NodeType[] types = getDeclaredSupertypes();
-            for (int i = 0; i < types.length; i++) {
-                if (types[i].isNodeType(name)) {
-                    return true;
-                }
-            }
-            return false;
+        Set definitions = new HashSet();
+        PropertyDefinitionState[] states =
+            state.getPropertyDefinitionStates();
+        for (int i = 0; i < states.length; i++) {
+            definitions.add(
+                    new SessionPropertyDefinition(helper, this, states[i]));
         }
+        return (PropertyDefinition[])
+            definitions.toArray(new PropertyDefinition[definitions.size()]);
     }
 
     /**
-     * Returns all supertypes (declared and inherited) of this node type.
-     * Implemented by recursively getting the supertypes of all the declared
-     * supertypes of this node type, and combining all the returned types
-     * into a single set.
-     * <p>
-     * The returned array is freshly instantiated and not a part of the
-     * internal state, so it can be freely modified.
-     * <p>
-     * The set of all supertypes is memorized to improve performance,
-     * and will therefore not change even if the underlying state changes!
-     *
-     * @return all supertypes
-     * @see NodeType#getSupertypes()
-     */
-    public NodeType[] getSupertypes() {
-        if (supertypes == null) {
-            Set types = new HashSet();
-            NodeType[] declaredSupertypes = getDeclaredSupertypes();
-            for (int i = 0; i < declaredSupertypes.length; i++) {
-                types.add(declaredSupertypes[i]);
-                types.addAll(
-                        Arrays.asList(declaredSupertypes[i].getSupertypes()));
-            }
-            supertypes = (NodeType[]) types.toArray(new NodeType[types.size()]);
-        }
-        return (NodeType[]) supertypes.clone();
-    }
-
-    /**
-     * Returns all child node definitions (declared and inherited) of this
-     * node type. Implemented by recursively getting the child node definitions
-     * of all the declared supertypes of this node type, and combining all
-     * the returned definitions into a single set.
-     * <p>
-     * The returned array is freshly instantiated and not a part of the
-     * internal state, so it can be freely modified.
-     * <p>
-     * The set of all child node defs is memorized to improve performance,
-     * and will therefore not change even if the underlying state changes!
-     *
-     * @return all child node definitions
-     * @see NodeType#getChildNodeDefs()
-     */
-    public NodeDefinition[] getChildNodeDefinitions() {
-        if (childNodeDefinitions == null) {
-            Set defs = new HashSet();
-            defs.addAll(Arrays.asList(getDeclaredChildNodeDefinitions()));
-            NodeType[] supertypes = getDeclaredSupertypes();
-            for (int i = 0; i < supertypes.length; i++) {
-                defs.addAll(
-                        Arrays.asList(supertypes[i].getChildNodeDefinitions()));
-            }
-            childNodeDefinitions = (NodeDefinition[])
-                defs.toArray(new NodeDefinition[defs.size()]);
-        }
-        return (NodeDefinition[]) childNodeDefinitions.clone();
-    }
-
-    /**
-     * Returns all property definitions (declared and inherited) of this
-     * node type. Implemented by recursively getting the property definitions
-     * of all the declared supertypes of this node type, and combining all
-     * the returned definitions into a single set.
-     * <p>
-     * The returned array is freshly instantiated and not a part of the
-     * internal state, so it can be freely modified.
+     * Compares objects for equality. Returns <code>true</code> if the
+     * given object is a SessionNodeType with the same underlying node
+     * type state and session.
      * <p>
-     * The set of all property defs is memorized to improve performance,
-     * and will therefore not change even if the underlying state changes!
-     *
-     * @return all property definitions
-     * @see NodeType#getPropertyDefs()
-     */
-    public PropertyDefinition[] getPropertyDefinitions() {
-        if (propertyDefinitions == null) {
-            Set defs = new HashSet();
-            defs.addAll(Arrays.asList(getDeclaredPropertyDefinitions()));
-            NodeType[] supertypes = getDeclaredSupertypes();
-            for (int i = 0; i < supertypes.length; i++) {
-                defs.addAll(
-                        Arrays.asList(supertypes[i].getPropertyDefinitions()));
-            }
-            propertyDefinitions = (PropertyDefinition[])
-                defs.toArray(new PropertyDefinition[defs.size()]);
-        }
-        return (PropertyDefinition[]) propertyDefinitions.clone();
-    }
-
-    /**
-     * Returns the named property definition of this node type.
-     * The property definition is located by iterating over all the
-     * property definitions and selecting the one that matches the
-     * given name (or the wildcard name if no exact match is found).
-     *
-     * @param name property name
-     * @return property definition, or <code>null</code> if not found
-     */
-    private PropertyDefinition getPropertyDefinition(String name) {
-        PropertyDefinition[] defs = getPropertyDefinitions();
-        for (int i = 0; i < defs.length; i++) {
-            if (name.equals(defs[i].getName())) {
-                return defs[i];
-            }
-        }
-        for (int i = 0; i < defs.length; i++) {
-            if (WILDCARD.equals(defs[i].getName())) {
-                return defs[i];
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Returns the named child node definition of this node type.
-     * The node definition is located by iterating over all the
-     * child node definitions and selecting the one that matches the
-     * given name (or the wildcard name if no exact match is found).
-     *
-     * @param name child node name
-     * @return child node definition, or <code>null</code> if not found
-     */
-    private NodeDefinition getChildNodeDefinition(String name) {
-        NodeDefinition[] defs = getChildNodeDefinitions();
-        for (int i = 0; i < defs.length; i++) {
-            if (name.equals(defs[i].getName())) {
-                return defs[i];
-            }
-        }
-        for (int i = 0; i < defs.length; i++) {
-            if (WILDCARD.equals(defs[i].getName())) {
-                return defs[i];
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Checks whether the given property can be set to the given
-     * value in an instance of this node type. The check is implemented
-     * by retrieving a matching property definition and validating
-     * all defined constraints and other settings for the given value.
-     *
-     * @param name property name
-     * @param value property value
-     * @return <code>true</code> if the property can be set,
-     *         <code>false</code> otherwise
-     * @see NodeType#canSetProperty(String, Value)
-     */
-    public boolean canSetProperty(String name, Value value) {
-        PropertyDefinition def = getPropertyDefinition(name);
-        if (def == null || def.isMultiple() || def.isProtected()) {
-            return false;
-        } else {
-            // TODO check type conversion & value constraints
-            return value != null;
-        }
-    }
-
-    /**
-     * Checks whether the given property can be set to the given
-     * multi-value in an instance of this node type. The check is
-     * implemented by retrieving a matching property definition and
-     * validating all defined constraints and other settings for the
-     * given values.
+     * Note that the node type state class does not override the equals
+     * method and thus the mutable state instances are compared for
+     * reference equality.
      *
-     * @param name property name
-     * @param values property values
-     * @return <code>true</code> if the property can be set,
-     *         <code>false</code> otherwise
-     * @see NodeType#canSetProperty(String, Value[])
-     */
-    public boolean canSetProperty(String name, Value[] values) {
-        PropertyDefinition def = getPropertyDefinition(name);
-        if (def == null || !def.isMultiple() || def.isProtected()) {
-            return false;
-        } else {
-            // TODO check type conversion & value constraints
-            for (int i = 0; i < values.length; i++) {
-                if (values[i] == null) {
-                    return false;
-                }
-            }
-            return true;
-        }
-    }
-
-    /**
-     * Checks whether the given child node can be added to an instance
-     * of this node type. The check is implemented by retrieving a
-     * matching child node definition and verifying that the definition
-     * allows the child node to be added.
-     *
-     * @param name child node name
-     * @return <code>true</code> if the child node can be added,
-     *         <code>false</code> otherwise
-     * @see NodeType#canAddChildNode(String)
-     */
-    public boolean canAddChildNode(String name) {
-        NodeDefinition def = getChildNodeDefinition(name);
-        return def != null && !def.isAutoCreated() && !def.isProtected();
-    }
-
-    /**
-     * Checks whether the given child node can be added to an instance
-     * of this node type. The check is implemented by retrieving a
-     * matching child node definition and verifying that the definition
-     * allows the child node to be added with the given node type.
-     *
-     * @param name child node name
-     * @param typeName node type name
-     * @return <code>true</code> if the typed child node can be added,
+     * @param that the object to compare this object with
+     * @return <code>true</code> if the objects are equal,
      *         <code>false</code> otherwise
-     * @see NodeType#canAddChildNode(String, String)
+     * @see Object#equals(Object)
      */
-    public boolean canAddChildNode(String name, String typeName) {
-        NodeDefinition def = getChildNodeDefinition(name);
-        if (def != null && !def.isAutoCreated() && !def.isProtected()) {
-            NodeType type = helper.getNodeType(typeName);
-            NodeType[] types = def.getRequiredPrimaryTypes();
-            for (int i = 0; i < types.length; i++) {
-                if (!type.isNodeType(types[i].getName())) {
-                    return false;
-                }
-            }
+    public boolean equals(Object that) {
+        if (this == that) {
             return true;
+        } else if (that instanceof SessionNodeType) {
+            return state.equals(((SessionNodeType) that).state)
+                && helper.equals(((SessionNodeType) that).helper);
         } else {
             return false;
         }
     }
 
     /**
-     * Checks whether the given item can be removed from an instance
-     * of this node type. The check is implemented by retrieving a
-     * matching item definition and verifying that the item is not
-     * mandatory or protected.
+     * Returns a hash code for this object. To satisfy the equality
+     * constraints the returned hash code is a combination of the
+     * hash codes of the underlying node type state and session.
      *
-     * @param name item name
-     * @return <code>true</code> if the item can be removed,
-     *         <code>false</code> otherwise
-     * @see NodeType#canRemoveItem(String)
+     * @return hash code
+     * @see Object#hashCode()
      */
-    public boolean canRemoveItem(String name) {
-        NodeDefinition nodeDef = getChildNodeDefinition(name);
-        if (nodeDef != null && !WILDCARD.equals(nodeDef.getName())) {
-            return !nodeDef.isMandatory() && !nodeDef.isProtected();
-        }
-
-        PropertyDefinition propertyDef = getPropertyDefinition(name);
-        if (propertyDef != null && !WILDCARD.equals(nodeDef.getName())) {
-            return !propertyDef.isMandatory() && !propertyDef.isProtected();
-        }
-
-        return nodeDef != null || propertyDef != null;
+    public int hashCode() {
+        int code = 17;
+        code = code * 37 + state.hashCode();
+        code = code * 37 + helper.hashCode();
+        return code;
     }
 
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeTypeManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeTypeManager.java?rev=169256&r1=169255&r2=169256&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeTypeManager.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeTypeManager.java
Mon May  9 01:50:27 2005
@@ -19,11 +19,10 @@
 import java.util.HashSet;
 import java.util.Set;
 
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeTypeManager;
 
+import org.apache.jackrabbit.base.nodetype.BaseNodeTypeManager;
 import org.apache.jackrabbit.iterator.ArrayNodeTypeIterator;
 import org.apache.jackrabbit.session.SessionHelper;
 import org.apache.jackrabbit.state.nodetype.NodeTypeManagerState;
@@ -38,7 +37,8 @@
  * this class intentionally makes it impossible for a JCR client to modify
  * node type information.
  */
-public class SessionNodeTypeManager implements NodeTypeManager {
+public final class SessionNodeTypeManager extends BaseNodeTypeManager
+        implements NodeTypeManager {
 
     /** Helper for accessing the current session. */
     private final SessionHelper helper;
@@ -46,15 +46,6 @@
     /** The underlying node type manager state instance. */
     private final NodeTypeManagerState state;
 
-    /** Memorized set of all node types. Initially <code>null</code>. */
-    private NodeType[] allTypes;
-
-    /** Memorized set of primary node types. Initially <code>null</code>. */
-    private NodeType[] primaryTypes;
-
-    /** Memorized set of mixin node types. Initially <code>null</code>. */
-    private NodeType[] mixinTypes;
-
     /**
      * Creates a node type manager frontend that is bound to the
      * given session and underlying node type manager state.
@@ -66,109 +57,65 @@
             SessionHelper helper, NodeTypeManagerState state) {
         this.helper = helper;
         this.state = state;
-        this.allTypes = null;
-        this.primaryTypes = null;
-        this.mixinTypes = null;
-    }
-
-    /**
-     * Returns the named node type. This implementation iterates through
-     * all the available node types and returns the one that matches the
-     * given name. If no matching node type is found, then a
-     * NoSuchNodeTypeException is thrown.
-     *
-     * @param name node type name
-     * @return named node type
-     * @throws NoSuchNodeTypeException if the named node type does not exist
-     * @see NodeTypeManager#getNodeType(String)
-     */
-    public NodeType getNodeType(String name) throws NoSuchNodeTypeException {
-        NodeTypeIterator iterator = getAllNodeTypes();
-        while (iterator.hasNext()) {
-            NodeType type = iterator.nextNodeType();
-            if (name.equals(type.getName())) {
-                return type;
-            }
-        }
-        throw new NoSuchNodeTypeException("Node type " + name + " not found");
     }
 
     /**
      * Returns all available node types. The returned node types are
      * SessionNodeTypes instantiated using the node type states returned
      * by the underlying node type manager state.
-     * <p>
-     * The set of all node types is memorized to improve performance,
-     * and will therefore not change even if the underlying state changes!
      *
      * @return all node types
      * @see SessionNodeType
      * @see NodeTypeManager#getAllNodeTypes()
+     * @see NodeTypeManagerState#getNodeTypeStates()
      */
     public NodeTypeIterator getAllNodeTypes() {
-        if (allTypes == null) {
-            Set types = new HashSet();
-            NodeTypeState[] states = state.getNodeTypeStates();
-            for (int i = 0; i < states.length; i++) {
-                types.add(new SessionNodeType(helper, states[i]));
-            }
-            allTypes = (NodeType[]) types.toArray(new NodeType[types.size()]);
+        Set types = new HashSet();
+        NodeTypeState[] states = state.getNodeTypeStates();
+        for (int i = 0; i < states.length; i++) {
+            types.add(new SessionNodeType(helper, states[i]));
         }
-        return new ArrayNodeTypeIterator(allTypes);
+        return new ArrayNodeTypeIterator(types);
     }
 
     /**
-     * Returns all primary node types. This method is implemented by
-     * listing all available node types and selecting only the primary
-     * node types.
+     * Compares objects for equality. Returns <code>true</code> if the
+     * given object is a SessionNodeTypeManager with the same underlying node
+     * type manager state and session.
      * <p>
-     * The set of primary node types is memorized to improve performance,
-     * and will therefore not change even if the underlying state changes!
+     * Note that the node type manager state class does not override the
+     * equals method and thus the mutable state instances are compared for
+     * reference equality.
      *
-     * @return primary node types
-     * @see NodeTypeManager#getPrimaryNodeTypes()
+     * @param that the object to compare this object with
+     * @return <code>true</code> if the objects are equal,
+     *         <code>false</code> otherwise
+     * @see Object#equals(Object)
      */
-    public NodeTypeIterator getPrimaryNodeTypes() {
-        if (primaryTypes == null) {
-            Set types = new HashSet();
-            NodeTypeIterator iterator = getAllNodeTypes();
-            while (iterator.hasNext()) {
-                NodeType type = iterator.nextNodeType();
-                if (!type.isMixin()) {
-                    types.add(type);
-                }
-            }
-            primaryTypes =
-                (NodeType[]) types.toArray(new NodeType[types.size()]);
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        } else if (that instanceof SessionNodeTypeManager) {
+            return state.equals(((SessionNodeTypeManager) that).state)
+                && helper.equals(((SessionNodeTypeManager) that).helper);
+        } else {
+            return false;
         }
-        return new ArrayNodeTypeIterator(primaryTypes);
     }
 
     /**
-     * Returns all mixin node types. This method is implemented by
-     * listing all available node types and selecting only the mixin
-     * node types.
-     * <p>
-     * The set of mixin node types is memorized to improve performance,
-     * and will therefore not change even if the underlying state changes!
+     * Returns a hash code for this object. To satisfy the equality
+     * constraints the returned hash code is a combination of the
+     * hash codes of the underlying node type manager state and session.
      *
-     * @return mixin node types
-     * @see NodeTypeManager#getMixinNodeTypes()
+     * @return hash code
+     * @see Object#hashCode()
      */
-    public NodeTypeIterator getMixinNodeTypes() {
-        if (mixinTypes == null) {
-            Set types = new HashSet();
-            NodeTypeIterator iterator = getAllNodeTypes();
-            while (iterator.hasNext()) {
-                NodeType type = iterator.nextNodeType();
-                if (type.isMixin()) {
-                    types.add(type);
-                }
-            }
-            mixinTypes =
-                (NodeType[]) types.toArray(new NodeType[types.size()]);
-        }
-        return new ArrayNodeTypeIterator(mixinTypes);
+    public int hashCode() {
+        int code = 17;
+        code = code * 37 + state.hashCode();
+        code = code * 37 + helper.hashCode();
+        return code;
     }
 
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionPropertyDefinition.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionPropertyDefinition.java?rev=169256&r1=169255&r2=169256&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionPropertyDefinition.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionPropertyDefinition.java
Mon May  9 01:50:27 2005
@@ -32,7 +32,7 @@
  * this class intentionally makes it impossible for a JCR client to modify
  * property definition information.
  */
-public class SessionPropertyDefinition extends SessionItemDefinition
+final class SessionPropertyDefinition extends SessionItemDefinition
         implements PropertyDefinition {
 
     /** The underlying property definition state. */
@@ -87,11 +87,9 @@
     public boolean isMultiple() {
         return state.isMultiple();
     }
-    
-    /**
-     * Not implemented.
-     */
+
+    /** Not implemented. */
     public Value[] getDefaultValues() {
-        return null;
+        return null; // TODO
     }
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/package.html?rev=169256&r1=169255&r2=169256&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/package.html
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/package.html
Mon May  9 01:50:27 2005
@@ -3,7 +3,6 @@
 <p>
 The classes in this package implement the
 {@link javax.jcr.nodetype JCR node type interfaces} based on an underlying
-node type state and the current session. The implementation uses aggressive
-caching of node type information, and is therefore not suitable for
-applications where the node types need to be modified within a session.
+node type state and the current session.
+</p>
 </body>



Mime
View raw message