jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r169206 - /incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session /incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype /incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state /incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype
Date Mon, 09 May 2005 01:06:57 GMT
Author: jukka
Date: Sun May  8 18:06:55 2005
New Revision: 169206

URL: http://svn.apache.org/viewcvs?rev=169206&view=rev
Log:
JCR-EXT: Migrating node type implementation code to Subversion.

Added:
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/
    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/SessionNamespaceRegistry.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/
    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
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/ItemDefinitionState.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeDefinitionState.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeManagerState.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeState.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/PropertyDefinitionState.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/package.html

Added: 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=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionHelper.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionHelper.java Sun May  8 18:06:55 2005
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.session;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.jackrabbit.name.Name;
+
+/**
+ * Helper class for accessing the namespaces and node types associated
+ * with a JCR Session.
+ */
+public class SessionHelper {
+
+    /** The session to which this frontend instance is bound. */
+    private final Session session;
+
+    /**
+     * Creates a helper for accessing the given session.
+     *
+     * @param session current session
+     */
+    public SessionHelper(Session session) {
+        this.session = session;
+    }
+
+    /**
+     * Returns the prefixed JCR name that represents the given
+     * qualified name.
+     *
+     * @param name qualified name
+     * @return prefixed JCR name
+     * @throws IllegalStateException if the namespace does not exist
+     * @throws RuntimeException if a repository error occurs
+     */
+    public String getName(Name name)
+            throws IllegalStateException, RuntimeException {
+        try {
+            String prefix = session.getNamespacePrefix(name.getNamespaceURI());
+            if (prefix.length() > 0) {
+                return prefix + ":" + name.getLocalPart();
+            } else {
+                return name.getLocalPart();
+            }
+        } catch (NamespaceException e) {
+            throw new IllegalStateException("Expected namespace not found", e);
+        } catch (RepositoryException e) {
+            throw new RuntimeException("Unexpected repository error", e);
+        }
+    }
+
+    /**
+     * Returns the named node type. This method is used to convert
+     * qualified node type names to actual NodeType objects of the current
+     * node type manager. The returned node type is acquired using the standard
+     * JCR API starting with <code>getWorkspace().getNodeTypeManager()</code>
+     * from the current session.
+     *
+     * @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
+     */
+    public NodeType getNodeType(Name name)
+            throws IllegalStateException, RuntimeException {
+        return getNodeType(getName(name));
+    }
+
+    /**
+     * Returns the named node type. This method is used to convert
+     * node type names to actual NodeType objects of the current node
+     * type manager. The returned node type is acquired using the standard
+     * JCR API starting with <code>getWorkspace().getNodeTypeManager()</code>
+     * from the current session.
+     *
+     * @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
+     */
+    public NodeType getNodeType(String name)
+            throws IllegalStateException, RuntimeException {
+        try {
+            return
+                session.getWorkspace().getNodeTypeManager().getNodeType(name);
+        } catch (NoSuchNodeTypeException e) {
+            throw new IllegalStateException("Expected node type not found", e);
+        } catch (RepositoryException e) {
+            throw new RuntimeException("Unexpected repository error", e);
+        }
+    }
+
+}

Added: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionNamespaceRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionNamespaceRegistry.java?rev=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionNamespaceRegistry.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/SessionNamespaceRegistry.java Sun May  8 18:06:55 2005
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.session;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+
+import org.apache.xerces.util.XMLChar;
+
+public final class SessionNamespaceRegistry implements NamespaceRegistry {
+
+    /** The underlying global namespace registry. */
+    private final NamespaceRegistry registry;
+
+    /** Local prefix to namespace URI mappings. */
+    private final Properties prefixToURI;
+
+    /** Local namespace URI to prefix mappings. */
+    private final Properties uriToPrefix;
+
+    /** The global prefixes hidden by local mappings. */
+    private final Set hiddenPrefixes;
+
+    /**
+     * Creates a local namespace registry based on the given global
+     * namespace registry. The local namespace mappings are initially empty.
+     *
+     * @param registry global namespace registry
+     */
+    public SessionNamespaceRegistry(NamespaceRegistry registry) {
+        this.registry = registry;
+        this.prefixToURI = new Properties();
+        this.uriToPrefix = new Properties();
+        this.hiddenPrefixes = new HashSet();
+    }
+
+    /**
+     * Creates a local namespace mapping. See the JCR specification
+     * for the details of this rather complex operation.
+     * <p>
+     * This method implements the specified semantics of the
+     * Session.setNamespacePrefix method. Session implementations can use
+     * this method as follows:
+     * <pre>
+     *     NamespaceRegistry registry = new SessionNamespaceRegistry(
+     *             getWorkspace().getNamespaceRegistry());
+     *
+     *     public void setNamespacePrefix(String prefix, String uri)
+     *             throws NamespaceException, RepositoryException {
+     *         return registry.registerNamespace(prefix, uri);
+     *     }
+     * </pre>
+     *
+     * @param prefix namespace prefix
+     * @param uri    namespace URI
+     * @throws NamespaceException  if the given namespace mapping is invalid
+     * @throws RepositoryException on repository errors
+     * @see NamespaceRegistry#registerNamespace(String, String)
+     * @see javax.jcr.Session#setNamespacePrefix(String, String)
+     */
+    public void registerNamespace(String prefix, String uri)
+            throws NamespaceException, RepositoryException {
+        if (prefix.length() == 0) {
+            throw new NamespaceException("The empty prefix is reserved");
+        } else if (uri.length() == 0) {
+            throw new NamespaceException("The empty namespace URI is reserved");
+        } else if (prefix.toLowerCase().startsWith("xml")) {
+            throw new NamespaceException("The xml* prefixes are reserved");
+        } else if (!XMLChar.isValidNCName(prefix)) {
+            throw new NamespaceException("Invalid prefix format");
+        }
+
+        // Note: throws a NamespaceException if the URI is not registered
+        String oldPrefix = getPrefix(uri);
+
+        String oldURI;
+        try {
+            oldURI = getURI(prefix);
+        } catch (NamespaceException e) {
+            oldURI = null;
+        }
+        if (oldURI == null) {
+            hiddenPrefixes.add(oldPrefix);
+            prefixToURI.remove(oldPrefix);
+            prefixToURI.setProperty(prefix, uri);
+            uriToPrefix.setProperty(uri, prefix);
+        } else if (!uri.equals(oldURI)) {
+            throw new NamespaceException(
+                    "Cannot hide an existing namespace mapping");
+        }
+    }
+
+    public void unregisterNamespace(String prefix)
+            throws UnsupportedRepositoryOperationException {
+        throw new UnsupportedRepositoryOperationException();
+    }
+
+    /**
+     * Returns the currently mapped namespace prefixes. The returned set
+     * contains all locally mapped prefixes and those global prefixes that
+     * have not been hidden by local mappings.
+     * <p>
+     * This method implements the specified semantics of the
+     * Session.getNamespacePrefixes method. Session implementations can use
+     * this method as follows:
+     * <pre>
+     *     NamespaceRegistry registry = new SessionNamespaceRegistry(
+     *             getWorkspace().getNamespaceRegistry());
+     *
+     *     public String getNamespacePrefixes() throws RepositoryException {
+     *         return registry.getPrefixes();
+     *     }
+     * </pre>
+     *
+     * @return namespace prefixes
+     * @throws RepositoryException on repository errors
+     * @see NamespaceRegistry#getPrefixes()
+     * @see javax.jcr.Session#getNamespacePrefixes()
+     */
+    public String[] getPrefixes() throws RepositoryException {
+        HashSet prefixes = new HashSet();
+        prefixes.addAll(Arrays.asList(registry.getPrefixes()));
+        prefixes.removeAll(hiddenPrefixes);
+        prefixes.addAll(prefixToURI.keySet());
+        return (String[]) prefixes.toArray(new String[prefixes.size()]);
+    }
+
+    /**
+     * Returns the registered namespace URIs. This method call is simply
+     * forwarded to the underlying global namespace registry as it is not
+     * possible to locally add new namespace URIs.
+     *
+     * @return namespace URIs
+     * @throws RepositoryException on repository errors
+     * @see NamespaceRegistry#getURIs()
+     */
+    public String[] getURIs() throws RepositoryException {
+        return registry.getURIs();
+    }
+
+    /**
+     * Returns the namespace URI that is mapped to the given prefix.
+     * Returns the local namespace mapping if the prefix is locally
+     * mapped, otherwise falls back to the underlying global namespace
+     * registry unless the prefix has been hidden by local namespace
+     * mappings.
+     * <p>
+     * This method implements the specified semantics of the
+     * Session.getNamespaceURI method. Session implementations can use
+     * this method as follows:
+     * <pre>
+     *     NamespaceRegistry registry = new SessionNamespaceRegistry(
+     *             getWorkspace().getNamespaceRegistry());
+     *
+     *     public String getNamespaceURI(String prefix)
+     *             throws NamespaceException, RepositoryException {
+     *         return registry.getURI(prefix);
+     *     }
+     * </pre>
+     *
+     * @param prefix namespace prefix
+     * @return namespace URI
+     * @throws NamespaceException  if the prefix is not registered or
+     *                             currently visible
+     * @throws RepositoryException on repository errors
+     * @see NamespaceRegistry#getURI(String)
+     * @see javax.jcr.Session#getNamespaceURI(String)
+     */
+    public String getURI(String prefix)
+            throws NamespaceException, RepositoryException {
+        String uri = prefixToURI.getProperty(prefix);
+        if (uri != null) {
+            return uri;
+        } else if (!hiddenPrefixes.contains(prefix)) {
+            return registry.getURI(prefix);
+        } else {
+            throw new NamespaceException(
+                    "Namespace mapping not found for prefix " + prefix);
+        }
+    }
+
+    /**
+     * Returns the prefix that is mapped to the given namespace URI.
+     * Returns the local prefix if the namespace URI is locally mapped,
+     * otherwise falls back to the underlying global namespace registry.
+     * <p>
+     * This method implements the specified semantics of the
+     * Session.getNamespacePrefix method. Session implementations can use
+     * this method as follows:
+     * <pre>
+     *     NamespaceRegistry registry = new SessionNamespaceRegistry(
+     *             getWorkspace().getNamespaceRegistry());
+     *
+     *     public String getNamespacePrefix(String uri)
+     *             throws NamespaceException, RepositoryException {
+     *         return registry.getPrefix(uri);
+     *     }
+     * </pre>
+     *
+     * @param uri namespace URI
+     * @return namespace prefix
+     * @throws NamespaceException  if the namespace URI is not registered
+     * @throws RepositoryException on repository errors
+     * @see NamespaceRegistry#getPrefix(String)
+     * @see javax.jcr.Session#getNamespacePrefix(String)
+     */
+    public String getPrefix(String uri)
+            throws NamespaceException, RepositoryException {
+        String prefix = uriToPrefix.getProperty(uri);
+        if (prefix != null) {
+            return prefix;
+        } else {
+            return registry.getPrefix(uri);
+        }
+    }
+
+}

Added: 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=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionItemDefinition.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionItemDefinition.java Sun May  8 18:06:55 2005
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.session.nodetype;
+
+import javax.jcr.nodetype.ItemDefinition;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.jackrabbit.session.SessionHelper;
+import org.apache.jackrabbit.state.nodetype.ItemDefinitionState;
+
+/**
+ * Immutable and session-bound item definition frontend. An instance
+ * of this class presents the underlying item definition state using
+ * the JCR ItemDef 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 {
+
+    /** Helper for accessing the current session. */
+    private final SessionHelper helper;
+
+    /** The node type that contains this item definition. */
+    private final NodeType type;
+
+    /** The underlying item definitions state. */
+    private final ItemDefinitionState state;
+
+    /**
+     * Creates an item definition frontend that is bound to the
+     * given node type, session, and underlying item definition state.
+     *
+     * @param helper helper for accessing the current session
+     * @param type declaring node type
+     * @param state underlying item definition state
+     */
+    protected SessionItemDefinition(
+            SessionHelper helper, NodeType type, ItemDefinitionState state) {
+        this.helper = helper;
+        this.type = type;
+        this.state = state;
+    }
+
+    /**
+     * Returns the node type that contains this item definition.
+     *
+     * @return declaring node type
+     * @see ItemDefinition#getDeclaringNodeType()
+     */
+    public NodeType getDeclaringNodeType() {
+        return type;
+    }
+
+    /**
+     * Returns the prefixed JCR name of this item definition. The underlying
+     * qualified name is mapped to a prefixed JCR name using the namespace
+     * mappings of the current session.
+     *
+     * @return prefixed JCR name
+     * @see ItemDefinition#getName()
+     */
+    public String getName() {
+        return helper.getName(state.getName());
+    }
+
+    /**
+     * Returns the value of the AutoCreated item definition property.
+     * The returned value is retrieved from the underlying item
+     * definition state.
+     *
+     * @return AutoCreated property value
+     * @see ItemDefinition#isAutoCreated()
+     */
+    public boolean isAutoCreated() {
+        return state.isAutoCreated();
+    }
+
+    /**
+     * Returns the value of the Mandatory item definition property.
+     * The returned value is retrieved from the underlying item
+     * definition state.
+     *
+     * @return Mandatory property value
+     * @see ItemDefinition#isMandatory()
+     */
+    public boolean isMandatory() {
+        return state.isMandatory();
+    }
+
+    /**
+     * Returns the value of the OnParentVersion item definition property.
+     * The returned value is retrieved from the underlying item
+     * definition state.
+     *
+     * @return OnParentVersion property value
+     * @see ItemDefinition#getOnParentVersion()
+     */
+    public int getOnParentVersion() {
+        return state.getOnParentVersion();
+    }
+
+    /**
+     * Returns the value of the Protected item definition property.
+     * The returned value is retrieved from the underlying item
+     * definition state.
+     *
+     * @return Protected property value
+     * @see ItemDefinition#isProtected()
+     */
+    public boolean isProtected() {
+        return state.isProtected();
+    }
+
+}

Added: 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=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeDefinition.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeDefinition.java Sun May  8 18:06:55 2005
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.session.nodetype;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.jackrabbit.session.SessionHelper;
+import org.apache.jackrabbit.name.Name;
+import org.apache.jackrabbit.state.nodetype.NodeDefinitionState;
+
+/**
+ * Immutable and session-bound node definition frontend. An instance
+ * of this class presents the underlying node definition state using
+ * the JCR NodeDef 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
+ * node definition information.
+ */
+public class SessionNodeDefinition extends SessionItemDefinition
+        implements NodeDefinition {
+
+    /** Helper for accessing the current session. */
+    private final SessionHelper helper;
+
+    /** 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.
+     *
+     * @param helper helper for accessing the current session
+     * @param type declaring node type
+     * @param state underlying node definition state
+     */
+    public SessionNodeDefinition(
+            SessionHelper helper, NodeType type, NodeDefinitionState state) {
+        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;
+    }
+
+    /**
+     * Returns the required primary types of the defined node. The returned
+     * node types are retrieved from the node type manager of the current
+     * session using the node type names stored in the underlying state.
+     * <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;
+        }
+        return (NodeType[]) requiredPrimaryTypes.toArray(
+                new NodeType[requiredPrimaryTypes.size()]);
+    }
+
+    /**
+     * Returns the value of the AllowsSameNameSiblings node definition property.
+     * The returned value is retrieved from the underlying node definition
+     * state.
+     *
+     * @return AlloswSameNameSiblings property value
+     * @see NodeDefinition#allowsSameNameSiblings()
+     */
+    public boolean allowsSameNameSiblings() {
+        return state.isAllowsSameNameSiblings();
+    }
+
+}

Added: 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=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeType.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeType.java Sun May  8 18:06:55 2005
@@ -0,0 +1,543 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.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.name.Name;
+import org.apache.jackrabbit.state.nodetype.NodeDefinitionState;
+import org.apache.jackrabbit.state.nodetype.NodeTypeState;
+import org.apache.jackrabbit.state.nodetype.PropertyDefinitionState;
+
+/**
+ * Immutable and session-bound node type frontend. An instance
+ * of this class presents the underlying node type state using
+ * the JCR NodeType interface. This class also contains simple
+ * implementations of the higher-order methods defined by the
+ * NodeType 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
+ * node type information.
+ */
+public class SessionNodeType implements NodeType {
+
+    /** The wildcard item definition name. */
+    private static final String WILDCARD = "*";
+
+    /** Helper for accessing the current session. */
+    private final SessionHelper helper;
+
+    /** 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.
+     *
+     * @param helper helper for accessing the current session
+     * @param state underlying node type state
+     */
+    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();
+    }
+
+    /**
+     * Returns the name of the node type. The returned name is retrieved
+     * from the underlying node type state and converted into a prefixed
+     * JCR name using the namespace mappings of the current session.
+     *
+     * @return node type name
+     * @see NodeType#getName()
+     */
+    public String getName() {
+        return helper.getName(state.getName());
+    }
+
+    /**
+     * Returns the value of the Mixin node type property. The returned
+     * value is retrieved from the underlying node type state.
+     *
+     * @return Mixin property value
+     * @see NodeType#isMixin()
+     */
+    public boolean isMixin() {
+        return state.isMixin();
+    }
+
+    /**
+     * Returns the value of the HasOrderableChildNodes node type property.
+     * The returned value is retrieved from the underlying node type state.
+     *
+     * @return HasOrderableChildNodes property value
+     * @see NodeType#hasOrderableChildNodes()
+     */
+    public boolean hasOrderableChildNodes() {
+        return state.isHasOrderableChildNodes();
+    }
+
+    /**
+     * Returns the name of the primary item of this node type.
+     * The returned name is retrieved from the underlying node type state
+     * and converted into a prefixed JCR name using the namespace mappings
+     * of the current session.
+     *
+     * @return primary item name, or <code>null</code> if not specified
+     * @see NodeType#getPrimaryItemName()
+     */
+    public String getPrimaryItemName() {
+        Name name = state.getPrimaryItemName();
+        if (name != null) {
+            return helper.getName(name);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Returns the declared supertypes of this node type. The returned
+     * node types are retrieved from the node type manager of the current
+     * session using the supertype names stored in the underlying state.
+     * <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()]);
+        }
+        return (NodeType[]) declaredSupertypes.clone();
+    }
+
+    /**
+     * Returns the declared child node definitions of this node type.
+     * The returned child node definitions are SessionNodeDefs instantiated
+     * using the node definition states returned by the underlying node type
+     * state.
+     * <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()]);
+        }
+        return (NodeDefinition[]) declaredChildNodeDefinitions.clone();
+    }
+
+    /**
+     * Returns the declared property definitions of this node type.
+     * The returned property definitions are SessionPropertyDefs instantiated
+     * using the property definition states returned by the underlying
+     * node type state.
+     * <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;
+        }
+    }
+
+    /**
+     * 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.
+     * <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.
+     *
+     * @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,
+     *         <code>false</code> otherwise
+     * @see NodeType#canAddChildNode(String, String)
+     */
+    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;
+                }
+            }
+            return true;
+        } 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.
+     *
+     * @param name item name
+     * @return <code>true</code> if the item can be removed,
+     *         <code>false</code> otherwise
+     * @see NodeType#canRemoveItem(String)
+     */
+    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;
+    }
+
+}

Added: 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=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeTypeManager.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionNodeTypeManager.java Sun May  8 18:06:55 2005
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.session.nodetype;
+
+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.iterator.ArrayNodeTypeIterator;
+import org.apache.jackrabbit.session.SessionHelper;
+import org.apache.jackrabbit.state.nodetype.NodeTypeManagerState;
+import org.apache.jackrabbit.state.nodetype.NodeTypeState;
+
+/**
+ * Immutable and session-bound node type manager frontend. An instance
+ * of this class presents the underlying node type manager state using
+ * the JCR NodeTypeManager 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
+ * node type information.
+ */
+public class SessionNodeTypeManager implements NodeTypeManager {
+
+    /** Helper for accessing the current session. */
+    private final SessionHelper helper;
+
+    /** 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.
+     *
+     * @param helper helper for accessing the current session
+     * @param state underlying node type manager state
+     */
+    public SessionNodeTypeManager(
+            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()
+     */
+    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()]);
+        }
+        return new ArrayNodeTypeIterator(allTypes);
+    }
+
+    /**
+     * Returns all primary node types. This method is implemented by
+     * listing all available node types and selecting only the primary
+     * node types.
+     * <p>
+     * The set of primary node types is memorized to improve performance,
+     * and will therefore not change even if the underlying state changes!
+     *
+     * @return primary node types
+     * @see NodeTypeManager#getPrimaryNodeTypes()
+     */
+    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()]);
+        }
+        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!
+     *
+     * @return mixin node types
+     * @see NodeTypeManager#getMixinNodeTypes()
+     */
+    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);
+    }
+
+}

Added: 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=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionPropertyDefinition.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/SessionPropertyDefinition.java Sun May  8 18:06:55 2005
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.session.nodetype;
+
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+
+import org.apache.jackrabbit.session.SessionHelper;
+import org.apache.jackrabbit.state.nodetype.PropertyDefinitionState;
+
+/**
+ * Immutable and session-bound property definition frontend. An instance
+ * of this class presents the underlying property definition state using
+ * the JCR PropertyDef 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
+ * property definition information.
+ */
+public class SessionPropertyDefinition extends SessionItemDefinition
+        implements PropertyDefinition {
+
+    /** The underlying property definition state. */
+    private final PropertyDefinitionState state;
+
+    /**
+     * Creates a property definition frontend that is bound to the
+     * given node type, session, and underlying property definition state.
+     *
+     * @param helper helper for accessing the current session
+     * @param type declaring node type
+     * @param state underlying property definition state
+     */
+    public SessionPropertyDefinition(
+            SessionHelper helper, NodeType type, PropertyDefinitionState state) {
+        super(helper, type, state);
+        this.state = state;
+    }
+
+    /**
+     * Returns the required type of the defined property. The returned value
+     * is retrieved from the underlying property definition state.
+     *
+     * @return required property type
+     * @see PropertyDef#getRequiredType()
+     */
+    public int getRequiredType() {
+        return state.getRequiredType();
+    }
+
+    /**
+     * Returns the constraint strings that specify the value constraint
+     * of the defined property. The returned string array is retrieved
+     * from the underlying property definition state, but is not by itself
+     * a part of the state and can thus be modified freely.
+     *
+     * @return value constraint strings
+     * @see PropertyDef#getValueConstraints()
+     */
+    public String[] getValueConstraints() {
+        return state.getValueConstraints();
+    }
+
+    /**
+     * Returns the value of the Multiple property definition property.
+     * The returned value is retrieved from the underlying property
+     * definition state.
+     *
+     * @return Multiple property value
+     * @see PropertyDef#isMultiple()
+     */
+    public boolean isMultiple() {
+        return state.isMultiple();
+    }
+    
+    /**
+     * Not implemented.
+     */
+    public Value[] getDefaultValues() {
+        return null;
+    }
+}

Added: 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=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/package.html Sun May  8 18:06:55 2005
@@ -0,0 +1,9 @@
+<body>
+Immutable and session-bound frontend to node type information.
+<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.
+</body>

Added: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/ItemDefinitionState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/ItemDefinitionState.java?rev=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/ItemDefinitionState.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/ItemDefinitionState.java Sun May  8 18:06:55 2005
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.state.nodetype;
+
+import javax.jcr.version.OnParentVersionAction;
+
+import org.apache.jackrabbit.name.Name;
+
+/**
+ * Item definition state. This base class contains the common
+ * state properties used by both property and node definitions.
+ */
+public class ItemDefinitionState {
+
+    /** The qualified name of the defined item. */
+    private Name name;
+
+    /** The AutoCreated item definition property. */
+    private boolean autoCreated;
+
+    /** The Mandatory item definition property. */
+    private boolean mandatory;
+
+    /** The OnParentVersion item definition property. */
+    private int onParentVersion;
+
+    /** The Protected item definition property. */
+    private boolean isProtected; // avoid the reserved word "protected"
+
+    /** Creates an empty item definition state instance. */
+    protected ItemDefinitionState() {
+        name = null;
+        autoCreated = false;
+        mandatory = false;
+        onParentVersion = OnParentVersionAction.IGNORE;
+        isProtected = false;
+    }
+
+    /**
+     * Returns the qualified name of the defined item.
+     *
+     * @return qualified name
+     */
+    public Name getName() {
+        return name;
+    }
+
+    /**
+     * Sets the qualified name of the defined item.
+     *
+     * @param name new qualified name
+     */
+    public void setName(Name name) {
+        this.name = name;
+    }
+
+    /**
+     * Returns the value of the AutoCreated item definition property.
+     *
+     * @return AutoCreated property value
+     */
+    public boolean isAutoCreated() {
+        return autoCreated;
+    }
+
+    /**
+     * Sets the value of the AutoCreated item definition property.
+     *
+     * @param autoCreated new AutoCreated property value
+     */
+    public void setAutoCreated(boolean autoCreated) {
+        this.autoCreated = autoCreated;
+    }
+
+    /**
+     * Returns the value of the Mandatory item definition property.
+     *
+     * @return Mandatory property value
+     */
+    public boolean isMandatory() {
+        return mandatory;
+    }
+
+    /**
+     * Sets the value of the Mandatory item definition property.
+     *
+     * @param mandatory new Mandatory property value
+     */
+    public void setMandatory(boolean mandatory) {
+        this.mandatory = mandatory;
+    }
+
+    /**
+     * Returns the value of the OnParentVerson item definition property.
+     *
+     * @return OnParentVersion property value
+     */
+    public int getOnParentVersion() {
+        return onParentVersion;
+    }
+
+    /**
+     * Sets the value of the OnParentVersion item definition property.
+     *
+     * @param onParentVersion new OnParentVersion property value
+     */
+    public void setOnParentVersion(int onParentVersion) {
+        this.onParentVersion = onParentVersion;
+    }
+
+    /**
+     * Returns the value of the Protected item definition property.
+     *
+     * @return Protected property value
+     */
+    public boolean isProtected() {
+        return isProtected;
+    }
+
+    /**
+     * Sets the value of the Protected item definition property.
+     *
+     * @param isProtected new Protected property value
+     */
+    public void setProtected(boolean isProtected) {
+        this.isProtected = isProtected;
+    }
+
+}

Added: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeDefinitionState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeDefinitionState.java?rev=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeDefinitionState.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeDefinitionState.java Sun May  8 18:06:55 2005
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.state.nodetype;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.jackrabbit.name.Name;
+
+/**
+ * Node definition state. Instances of this class are used to hold
+ * and manage the internal state of node definitions.
+ */
+public class NodeDefinitionState extends ItemDefinitionState {
+
+    /** Name of the default primary type of the defined node. */
+    private Name defaultPrimaryTypeName;
+
+    /** Names of the required primary types of the defined node. */
+    private Set requiredPrimaryTypeNames;
+
+    /** The AllowsSameNameSiblings node definition property. */
+    private boolean allowsSameNameSiblings;
+
+    /** Creates an empty node definition state instance. */
+    public NodeDefinitionState() {
+        super();
+        defaultPrimaryTypeName = null;
+        requiredPrimaryTypeNames = new HashSet();
+        allowsSameNameSiblings = false;
+    }
+
+    /**
+     * Returns the name of the default primary type of the defined node.
+     *
+     * @return default primary type name
+     */
+    public Name getDefaultPrimaryTypeName() {
+        return defaultPrimaryTypeName;
+    }
+
+    /**
+     * Sets the name of the default primary type of the defined node.
+     *
+     * @param defaultPrimaryType new default primary type name
+     */
+    public void setDefaultPrimaryTypeName(Name defaultPrimaryType) {
+        this.defaultPrimaryTypeName = defaultPrimaryType;
+    }
+
+    /**
+     * Returns the names of the required primary types of the defined node.
+     *
+     * @return type names
+     */
+    public Name[] getRequiredPrimaryTypeNames() {
+        return (Name[]) requiredPrimaryTypeNames.toArray(
+                new Name[requiredPrimaryTypeNames.size()]);
+    }
+
+    /**
+     * Adds a type name to the list of required primary types.
+     *
+     * @param requiredPrimaryTypeName type name
+     */
+    public void addRequiredPrimaryTypeNames(Name requiredPrimaryTypeName) {
+        requiredPrimaryTypeNames.add(requiredPrimaryTypeName);
+    }
+
+    /**
+     * Returns the value of the AllowsSameNameSiblings node definition property.
+     *
+     * @return AllowsSameNameSiblings property value
+     */
+    public boolean isAllowsSameNameSiblings() {
+        return allowsSameNameSiblings;
+    }
+
+    /**
+     * Sets the value of the AllowsSameNameSiblings node definition property.
+     *
+     * @param allowsSameNameSiblings new AllowsSameNameSiblings property value
+     */
+    public void setAllowsSameNameSiblings(boolean allowsSameNameSiblings) {
+        this.allowsSameNameSiblings = allowsSameNameSiblings;
+    }
+
+}

Added: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeManagerState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeManagerState.java?rev=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeManagerState.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeManagerState.java Sun May  8 18:06:55 2005
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.state.nodetype;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Node type manager state. Instances of this class are used to hold
+ * and manage the internal state of node type managers.
+ */
+public class NodeTypeManagerState {
+
+    /** Available node type states. */
+    private final Set types;
+
+    /** Creates an empty node type manager state instance. */
+    public NodeTypeManagerState() {
+        types = new HashSet();
+    }
+
+    /**
+     * Returns all available node type states.
+     *
+     * @return node type states
+     */
+    public NodeTypeState[] getNodeTypeStates() {
+        return (NodeTypeState[]) types.toArray(new NodeTypeState[types.size()]);
+    }
+
+    /**
+     * Adds a node type to the node type manager state.
+     *
+     * @param state node type state
+     */
+    public void addNodeTypeState(NodeTypeState state) {
+        types.add(state);
+    }
+
+}

Added: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeState.java?rev=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeState.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeState.java Sun May  8 18:06:55 2005
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.state.nodetype;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.jackrabbit.name.Name;
+
+/**
+ * Node type state. Instances of this class are used to hold
+ * and manage the internal state of node types.
+ */
+public class NodeTypeState {
+
+    /** Name of the node type. */
+    private Name name;
+
+    /** The Mixin node type property. */
+    private boolean mixin;
+
+    /** The HasOrderableChildNodes node type property. */
+    private boolean hasOrderableChildNodes;
+
+    /** Name of the primary item of the node type. */
+    private Name primaryItemName;
+
+    /** Names of the declared supertypes. */
+    private Set supertypeNames;
+
+    /** Child node definition states. */
+    private Set childNodeDefinitionStates;
+
+    /** Property definition states. */
+    private Set propertyDefinitionStates;
+
+    /** Creates an empty node type state instance. */
+    public NodeTypeState() {
+        name = null;
+        mixin = false;
+        hasOrderableChildNodes = false;
+        primaryItemName = null;
+        supertypeNames = new HashSet();
+        childNodeDefinitionStates = new HashSet();
+        propertyDefinitionStates = new HashSet();
+    }
+
+    /**
+     * Returns the node type name.
+     *
+     * @return qualified name
+     */
+    public Name getName() {
+        return name;
+    }
+
+    /**
+     * Sets the node type name.
+     *
+     * @param name new qualified name
+     */
+    public void setName(Name name) {
+        this.name = name;
+    }
+
+    /**
+     * Returns the value of the Mixin node type property.
+     *
+     * @return Mixin property value
+     */
+    public boolean isMixin() {
+        return mixin;
+    }
+
+    /**
+     * Sets the value of the Mixin node type property.
+     *
+     * @param mixin new Mixin property value
+     */
+    public void setMixin(boolean mixin) {
+        this.mixin = mixin;
+    }
+
+    /**
+     * Returns the value of the HasOrderableChildNodes node type property.
+     *
+     * @return HasOrderableChildNodes property value
+     */
+    public boolean isHasOrderableChildNodes() {
+        return hasOrderableChildNodes;
+    }
+
+    /**
+     * Sets the value of the HasOrderableChildNodes node type property.
+     *
+     * @param hasOrderableChildNodes new HasOrderableChildNodes property value
+     */
+    public void setHasOrderableChildNodes(boolean hasOrderableChildNodes) {
+        this.hasOrderableChildNodes = hasOrderableChildNodes;
+    }
+
+    /**
+     * Returns the name of the primary item of the node type.
+     *
+     * @return primary item name
+     */
+    public Name getPrimaryItemName() {
+        return primaryItemName;
+    }
+
+    /**
+     * Sets the name of the primary item of the node type.
+     *
+     * @param primaryItemName new primary item name
+     */
+    public void setPrimaryItemName(Name primaryItemName) {
+        this.primaryItemName = primaryItemName;
+    }
+
+    /**
+     * Returns the names of the declared supertypes.
+     *
+     * @return supertype names
+     */
+    public Name[] getSupertypeNames() {
+        return (Name[])
+            supertypeNames.toArray(new Name[supertypeNames.size()]);
+    }
+
+    /**
+     * Adds a supertype name to the list of declared supertypes.
+     *
+     * @param name supertype name
+     */
+    public void addSupertypeName(Name name) {
+        supertypeNames.add(name);
+    }
+
+    /**
+     * Returns the child node definition states of the node type.
+     *
+     * @return child node definition states
+     */
+    public NodeDefinitionState[] getChildNodeDefinitionStates() {
+        return (NodeDefinitionState[]) childNodeDefinitionStates.toArray(
+                new NodeDefinitionState[childNodeDefinitionStates.size()]);
+    }
+
+    /**
+     * Adds a node definition state to the list of child node definition
+     * states of the node type.
+     *
+     * @param state child node definition state
+     */
+    public void addChildNodeDefinition(NodeDefinitionState state) {
+        childNodeDefinitionStates.add(state);
+    }
+
+    /**
+     * Returns the property definition states of the node type.
+     *
+     * @return property definition states
+     */
+    public PropertyDefinitionState[] getPropertyDefinitionStates() {
+        return (PropertyDefinitionState[]) propertyDefinitionStates.toArray(
+                new PropertyDefinitionState[propertyDefinitionStates.size()]);
+    }
+
+    /**
+     * Adds a property definition state to the list of property definition
+     * states of the node type.
+     *
+     * @param state property definition state
+     */
+    public void addPropertyDefinitionState(PropertyDefinitionState state) {
+        propertyDefinitionStates.add(state);
+    }
+
+}

Added: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/PropertyDefinitionState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/PropertyDefinitionState.java?rev=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/PropertyDefinitionState.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/PropertyDefinitionState.java Sun May  8 18:06:55 2005
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.state.nodetype;
+
+import java.util.List;
+import java.util.Vector;
+
+import javax.jcr.PropertyType;
+
+/**
+ * Property definition state. Instances of this class are used to hold
+ * and manage the internal state of property definitions.
+ */
+public class PropertyDefinitionState extends ItemDefinitionState {
+
+    /** Required type of the defined property. */
+    private int requiredType;
+
+    /** List of value constraint strings. */
+    private List valueConstraints;
+
+    /** The Multiple property definition property. */
+    private boolean multiple;
+
+    /** Creates an empty property definition state instance. */
+    public PropertyDefinitionState() {
+        requiredType = PropertyType.UNDEFINED;
+        valueConstraints = new Vector();
+        multiple = false;
+    }
+
+    /**
+     * Returns the required type of the defined property.
+     *
+     * @return required property type
+     */
+    public int getRequiredType() {
+        return requiredType;
+    }
+
+    /**
+     * Sets the required type of the defined property.
+     *
+     * @param requiredType new required property type
+     */
+    public void setRequiredType(int requiredType) {
+        this.requiredType = requiredType;
+    }
+
+    /**
+     * Returns the property value constraint strings. The returned
+     * array can be modified freely as it is freshly instantiated and
+     * not a part of the property definition state.
+     *
+     * @return value constraints
+     */
+    public String[] getValueConstraints() {
+        return (String[])
+            valueConstraints.toArray(new String[valueConstraints.size()]);
+    }
+
+    /**
+     * Adds a constraint string to the list of property value constraints.
+     *
+     * @param constraint constraint string
+     */
+    public void addValueConstraints(String constraint) {
+        valueConstraints.add(constraint);
+    }
+
+    /**
+     * Returns the value of the Multiple property definition property.
+     *
+     * @return Multiple property value
+     */
+    public boolean isMultiple() {
+        return multiple;
+    }
+
+    /**
+     * Sets the value of the Multiple property definition property.
+     *
+     * @param multiple new Multiple property value
+     */
+    public void setMultiple(boolean multiple) {
+        this.multiple = multiple;
+    }
+
+}

Added: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/package.html?rev=169206&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/package.html Sun May  8 18:06:55 2005
@@ -0,0 +1,11 @@
+<body>
+Node type state implementation.
+<p>
+The classes in this package provide a simple and straightforward mechanism
+for holding and managing node type information. The node type information
+managed by this package is mutable and not bound to a specific session.
+The {@link org.apache.jackrabbit.session.nodetype
+org.apache.jackrabbit.session.nodetype} package implements the standard
+{@link javax.jcr.nodetype JCR node type interfaces} based on underlying
+node type state managed by classes from this package.
+</body>



Mime
View raw message