jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r586058 [3/4] - in /jackrabbit/trunk/jackrabbit-spi-commons: ./ src/main/java/org/apache/jackrabbit/conversion/ src/main/java/org/apache/jackrabbit/identifier/ src/main/java/org/apache/jackrabbit/lock/ src/main/java/org/apache/jackrabbit/na...
Date Thu, 18 Oct 2007 18:35:01 GMT
Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/name/PathMap.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/name/PathMap.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/name/PathMap.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/name/PathMap.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,654 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.name;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.conversion.MalformedPathException;
+
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+
+/**
+ * Generic path map that associates information with the individual path elements
+ * of a path.
+ */
+public class PathMap {
+
+    private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
+
+    /**
+     * Root element
+     */
+    private final Element root = new Element(PATH_FACTORY.getRootPath().getNameElement());
+
+    /**
+     * Map a path to a child. If <code>exact</code> is <code>false</code>,
+     * returns the last available item along the path that is stored in the map.
+     * @param path path to map
+     * @param exact flag indicating whether an exact match is required
+     * @return child, maybe <code>null</code> if <code>exact</code> is
+     *         <code>true</code>
+     */
+    public Element map(Path path, boolean exact) {
+        Path.Element[] elements = path.getElements();
+        Element current = root;
+
+        for (int i = 1; i < elements.length; i++) {
+            Element next = current.getChild(elements[i]);
+            if (next == null) {
+                if (exact) {
+                    return null;
+                }
+                break;
+            }
+            current = next;
+        }
+        return current;
+    }
+
+    /**
+     * Create an element given by its path. The path map will create any necessary
+     * intermediate elements.
+     * @param path path to child
+     * @param obj object to store at destination
+     */
+    public Element put(Path path, Object obj) {
+        Element element = put(path);
+        element.obj = obj;
+        return element;
+    }
+
+    /**
+     * Put an element given by its path. The path map will create any necessary
+     * intermediate elements.
+     * @param path path to child
+     * @param element element to store at destination
+     */
+    public void put(Path path, Element element) {
+        Path.Element[] elements = path.getElements();
+        Element current = root;
+
+        for (int i = 1; i < elements.length - 1; i++) {
+            Element next = current.getChild(elements[i]);
+            if (next == null) {
+                next = current.createChild(elements[i]);
+            }
+            current = next;
+        }
+        current.put(path.getNameElement(), element);
+    }
+
+    /**
+     * Create an empty child given by its path.
+     * @param path path to child
+     */
+    public Element put(Path path) {
+        Path.Element[] elements = path.getElements();
+        Element current = root;
+
+        for (int i = 1; i < elements.length; i++) {
+            Element next = current.getChild(elements[i]);
+            if (next == null) {
+                next = current.createChild(elements[i]);
+            }
+            current = next;
+        }
+        return current;
+    }
+
+    /**
+     * Traverse the path map and call back requester. This method visits the root
+     * first, then its children.
+     * @param includeEmpty if <code>true</code> invoke call back on every child
+     *                     regardless, whether the associated object is empty
+     *                     or not; otherwise call back on non-empty children
+     *                     only
+     */
+    public void traverse(ElementVisitor visitor, boolean includeEmpty) {
+        root.traverse(visitor, includeEmpty);
+    }
+
+    /**
+     * Internal class holding the object associated with a certain
+     * path element.
+     */
+    public static class Element {
+
+        /**
+         * Parent element
+         */
+        private Element parent;
+
+        /**
+         * Map of immediate children
+         */
+        private Map children;
+
+        /**
+         * Number of non-empty children
+         */
+        private int childrenCount;
+
+        /**
+         * Object associated with this element
+         */
+        private Object obj;
+
+        /**
+         * Name associated with this element
+         */
+        private Name name;
+
+        /**
+         * 1-based index associated with this element where index=0 is
+         * equivalent to index=1.
+         */
+        private int index;
+
+        /**
+         * Create a new instance of this class with a path element.
+         * @param nameIndex path element of this child
+         */
+        private Element(Path.Element nameIndex) {
+            this.name = nameIndex.getName();
+            this.index = nameIndex.getIndex();
+        }
+
+        /**
+         * Create a child of this node inside the path map.
+         * @param nameIndex position where child is created
+         * @return child
+         */
+        private Element createChild(Path.Element nameIndex) {
+            Element element = new Element(nameIndex);
+            put(nameIndex, element);
+            return element;
+        }
+
+        /**
+         * Insert an empty child. Will shift all children having an index
+         * greater than or equal to the child inserted to the right.
+         * @param nameIndex position where child is inserted
+         */
+        public void insert(Path.Element nameIndex) {
+            // convert 1-based index value to 0-base value
+            int index = getZeroBasedIndex(nameIndex);
+            if (children != null) {
+                ArrayList list = (ArrayList) children.get(nameIndex.getName());
+                if (list != null && list.size() > index) {
+                    for (int i = index; i < list.size(); i++) {
+                        Element element = (Element) list.get(i);
+                        if (element != null) {
+                            element.index = element.getNormalizedIndex() + 1;
+                        }
+                    }
+                    list.add(index, null);
+                }
+            }
+        }
+
+        /**
+         * Return an element matching a name and index.
+         * @param nameIndex position where child is located
+         * @return element matching <code>nameIndex</code> or <code>null</code> if
+         *         none exists.
+         */
+        private Element getChild(Path.Element nameIndex) {
+            // convert 1-based index value to 0-base value
+            int index = getZeroBasedIndex(nameIndex);
+            Element element = null;
+
+            if (children != null) {
+                ArrayList list = (ArrayList) children.get(nameIndex.getName());
+                if (list != null && list.size() > index) {
+                    element = (Element) list.get(index);
+                }
+            }
+            return element;
+        }
+
+        /**
+         * Link a child of this node. Position is given by <code>nameIndex</code>.
+         * @param nameIndex position where child should be located
+         * @param element element to add
+         */
+        public void put(Path.Element nameIndex, Element element) {
+            // convert 1-based index value to 0-base value
+            int index = getZeroBasedIndex(nameIndex);
+            if (children == null) {
+                children = new HashMap();
+            }
+            ArrayList list = (ArrayList) children.get(nameIndex.getName());
+            if (list == null) {
+                list = new ArrayList();
+                children.put(nameIndex.getName(), list);
+            }
+            while (list.size() < index) {
+                list.add(null);
+            }
+            if (list.size() == index) {
+                list.add(element);
+            } else {
+                list.set(index, element);
+            }
+
+            element.parent = this;
+            element.name = nameIndex.getName();
+            element.index = nameIndex.getIndex();
+
+            childrenCount++;
+        }
+
+        /**
+         * Remove a child. Will shift all children having an index greater than
+         * the child removed to the left. If there are no more children left in
+         * this element and no object is associated with this element, the
+         * element itself gets removed.
+         *
+         * @param nameIndex child's path element
+         * @return removed child, may be <code>null</code>
+         */
+        public Element remove(Path.Element nameIndex) {
+            return remove(nameIndex, true, true);
+        }
+
+        /**
+         * Remove a child. If <code>shift</code> is set to <code>true</code>,
+         * will shift all children having an index greater than the child
+         * removed to the left. If <code>removeIfEmpty</code> is set to
+         * <code>true</code> and there are no more children left in
+         * this element and no object is associated with this element, the
+         * element itself gets removed.
+         *
+         * @param nameIndex child's path element
+         * @param shift whether to shift same name siblings having a greater
+         *              index to the left
+         * @param removeIfEmpty remove this element itself if it contains
+         *                      no more children and is not associated to
+         *                      an element
+         * @return removed child, may be <code>null</code>
+         */
+        private Element remove(Path.Element nameIndex, boolean shift,
+                               boolean removeIfEmpty) {
+
+            // convert 1-based index value to 0-base value
+            int index = getZeroBasedIndex(nameIndex);
+            if (children == null) {
+                return null;
+            }
+            ArrayList list = (ArrayList) children.get(nameIndex.getName());
+            if (list == null || list.size() <= index) {
+                return null;
+            }
+            Element element = (Element) list.set(index, null);
+            if (shift) {
+                for (int i = index + 1; i < list.size(); i++) {
+                    Element sibling = (Element) list.get(i);
+                    if (sibling != null) {
+                        sibling.index--;
+                    }
+                }
+                list.remove(index);
+            }
+            if (element != null) {
+                element.parent = null;
+                childrenCount--;
+            }
+            if (removeIfEmpty && childrenCount == 0 && obj == null && parent != null) {
+                parent.remove(getPathElement(), shift, true);
+            }
+            return element;
+        }
+
+        /**
+         * Remove this element. Delegates the call to the parent item.
+         * Index of same name siblings will be shifted!
+         */
+        public void remove() {
+            remove(true);
+        }
+
+        /**
+         * Remove this element. Delegates the call to the parent item.
+         * @param shift if index of same name siblings will be shifted.
+         */
+        public void remove(boolean shift) {
+            if (parent != null) {
+                parent.remove(getPathElement(), shift, true);
+            } else {
+                // Removing the root node is not possible: if it has become
+                // invalid, remove all its children and the associated object
+                children = null;
+                childrenCount = 0;
+                obj = null;
+            }
+        }
+
+        /**
+         * Remove all children of this element. Removes this element itself
+         * if this element does not contain associated information.
+         */
+        public void removeAll() {
+            children = null;
+            childrenCount = 0;
+
+            if (obj == null && parent != null) {
+                parent.remove(getPathElement(), false, true);
+            }
+        }
+
+        /**
+         * Sets a new list of children of this element.
+         *
+         * @param children map of children; keys are of type
+         *                 <code>Path.PathElement</code> and values
+         *                 are of type <code>Element</code>
+         */
+        public void setChildren(Map children) {
+            // Remove all children without removing the element itself
+            this.children = null;
+            childrenCount = 0;
+
+            // Now add back all items
+            Iterator entries = children.entrySet().iterator();
+            while (entries.hasNext()) {
+                Map.Entry entry = (Map.Entry) entries.next();
+
+                Path.Element nameIndex = (Path.Element) entry.getKey();
+                Element element = (Element) entry.getValue();
+                put(nameIndex, element);
+            }
+
+            // Special case: if map was empty, handle like removeAll()
+            if (childrenCount == 0 && obj == null && parent != null) {
+                parent.remove(getPathElement(), false, true);
+            }
+        }
+
+        /**
+         * Return the object associated with this element
+         * @return object associated with this element
+         */
+        public Object get() {
+            return obj;
+        }
+
+        /**
+         * Set the object associated with this element
+         * @param obj object associated with this element
+         */
+        public void set(Object obj) {
+            this.obj = obj;
+
+            if (obj == null && childrenCount == 0 && parent != null) {
+                parent.remove(getPathElement(), false, true);
+            }
+        }
+
+        /**
+         * Return the name of this element
+         * @return name
+         */
+        public Name getName() {
+            return name;
+        }
+
+        /**
+         * Return the non-normalized 1-based index of this element. Note that
+         * this method can return a value of 0 which should be treated as 1.
+         * @return index
+         * @see #getNormalizedIndex()
+         */
+        public int getIndex() {
+            return index;
+        }
+
+        /**
+         * Return the 1-based index of this element.
+         * Same as {@link #getIndex()} except that an {@link Path#INDEX_UNDEFINED
+         * undefined index} value is automatically converted to the
+         * {@link Path#INDEX_DEFAULT default index} value.
+         * @return 1-based index
+         */
+        public int getNormalizedIndex() {
+            if (index == Path.INDEX_UNDEFINED) {
+                return Path.INDEX_DEFAULT;
+            } else {
+                return index;
+            }
+        }
+
+        /**
+         * Return a path element pointing to this element
+         * @return path element
+         */
+        public Path.Element getPathElement() {
+            if (index < Path.INDEX_DEFAULT) {
+                return PATH_FACTORY.create(name).getNameElement();
+            } else {
+                return PATH_FACTORY.create(name, index).getNameElement();
+            }
+        }
+
+        /**
+         * Return the path of this element.
+         * @return path
+         * @throws MalformedPathException if building the path fails
+         */
+        public Path getPath() throws MalformedPathException {
+            if (parent == null) {
+                return PATH_FACTORY.getRootPath();
+            }
+
+            PathBuilder builder = new PathBuilder();
+            getPath(builder);
+            return builder.getPath();
+        }
+
+        /**
+         * Internal implementation of {@link #getPath()} that populates entries
+         * in a builder. On exit, <code>builder</code> contains the path
+         * of this element
+         */
+        private void getPath(PathBuilder builder) {
+            if (parent == null) {
+                builder.addRoot();
+                return;
+            }
+            parent.getPath(builder);
+            if (index == Path.INDEX_UNDEFINED || index == Path.INDEX_DEFAULT) {
+                builder.addLast(name);
+            } else {
+                builder.addLast(name, index);
+            }
+        }
+
+        /**
+         * Checks whether this element has the specified path. Introduced to
+         * avoid catching a <code>MalformedPathException</code> for simple
+         * path comparisons.
+         * @param path path to compare to
+         * @return <code>true</code> if this child has the path
+         *         <code>path</code>, <code>false</code> otherwise
+         */
+        public boolean hasPath(Path path) {
+            return hasPath(path.getElements(), path.getLength());
+        }
+
+        /**
+         * Checks whether this element has the specified path, given by
+         * path elements.
+         * @param elements path elements to compare to
+         * @param len number of elements to compare to
+         * @return <code>true</code> if this element has the path given;
+         *         otherwise <code>false</code>
+         */
+        private boolean hasPath(Path.Element[] elements, int len) {
+            if (getPathElement().equals(elements[len - 1])) {
+                if (parent != null) {
+                    return parent.hasPath(elements, len - 1);
+                }
+                return true;
+            }
+            return false;
+        }
+
+        /**
+         * Return 0-based index of a path element.
+         */
+        private static int getZeroBasedIndex(Path.Element nameIndex) {
+            return nameIndex.getNormalizedIndex() - 1;
+        }
+
+        /**
+         * Recursively invoked traversal method. This method visits the element
+         * first, then its children.
+         * @param visitor visitor to invoke
+         * @param includeEmpty if <code>true</code> invoke call back on every
+         *        element regardless, whether the associated object is empty
+         *        or not; otherwise call back on non-empty children only
+         */
+        public void traverse(ElementVisitor visitor, boolean includeEmpty) {
+            if (includeEmpty || obj != null) {
+                visitor.elementVisited(this);
+            }
+            if (children != null) {
+                Iterator iter = children.values().iterator();
+                while (iter.hasNext()) {
+                    ArrayList list = (ArrayList) iter.next();
+                    for (int i = 0; i < list.size(); i++) {
+                        Element element = (Element) list.get(i);
+                        if (element != null) {
+                            element.traverse(visitor, includeEmpty);
+                        }
+                    }
+                }
+            }
+        }
+
+        /**
+         * Return the depth of this element. Defined to be <code>0</code> for the
+         * root element and <code>n + 1</code> for some element if the depth of
+         * its parent is <code>n</code>.
+         */
+        public int getDepth() {
+            if (parent != null) {
+                return parent.getDepth() + 1;
+            }
+            // Root
+            return Path.ROOT_DEPTH;
+        }
+
+        /**
+         * Return a flag indicating whether the specified node is a
+         * child of this node.
+         * @param other node to check
+         */
+        public boolean isAncestorOf(Element other) {
+            Element parent = other.parent;
+            while (parent != null) {
+                if (parent == this) {
+                    return true;
+                }
+                parent = parent.parent;
+            }
+            return false;
+        }
+
+        /**
+         * Return the parent of this element
+         * @return parent or <code>null</code> if this is the root element
+         */
+        public Element getParent() {
+            return parent;
+        }
+
+        /**
+         * Return the children count of this element
+         * @return children count
+         */
+        public int getChildrenCount() {
+            return childrenCount;
+        }
+
+        /**
+         * Return an iterator over all of this element's children. Every
+         * element returned by this iterator is of type {@link #Element}.
+         */
+        public Iterator getChildren() {
+            ArrayList result = new ArrayList();
+
+            if (children != null) {
+                Iterator iter = children.values().iterator();
+                while (iter.hasNext()) {
+                    ArrayList list = (ArrayList) iter.next();
+                    for (int i = 0; i < list.size(); i++) {
+                        Element element = (Element) list.get(i);
+                        if (element != null) {
+                            result.add(element);
+                        }
+                    }
+                }
+            }
+            return result.iterator();
+        }
+
+        /**
+         * Map a relPath starting at <code>this</code> Element. If
+         * <code>exact</code> is <code>false</code>, returns the last available
+         * item along the relPath that is stored in the map.
+         *
+         * @param relPath relPath to map
+         * @param exact   flag indicating whether an exact match is required
+         * @return descendant, maybe <code>null</code> if <code>exact</code> is
+         *         <code>true</code>
+         */
+        public Element getDescendant(Path relPath, boolean exact) {
+            Path.Element[] elements = relPath.getElements();
+            Element current = this;
+
+            for (int i = 0; i < elements.length; i++) {
+                Element next = current.getChild(elements[i]);
+                if (next == null) {
+                    if (exact) {
+                        return null;
+                    }
+                    break;
+                }
+                current = next;
+            }
+            return current;
+        }
+    }
+
+    /**
+     * Element visitor used in {@link PathMap#traverse}
+     */
+    public interface ElementVisitor {
+
+        /**
+         * Invoked for every element visited on a tree traversal
+         * @param element element visited
+         */
+        void elementVisited(Element element);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/name/PathMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/name/PathMap.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/AbstractNamespaceResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/AbstractNamespaceResolver.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/AbstractNamespaceResolver.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/AbstractNamespaceResolver.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.namespace;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+
+/**
+ * Provides default implementations for the methods:
+ * <ul>
+ * <li>{@link #addListener(NamespaceListener)}</li>
+ * <li>{@link #removeListener(NamespaceListener)}</li>
+ * </ul>
+ * Subclasses may overwrite those methods with more efficient implementations
+ * e.g. using caching. This class also adds optional support for
+ * {@link NamespaceListener}s. To enable listener support call the constructor
+ * with <code>supportListeners</code> set to <code>true</code>. The default
+ * constructor will not enable listener support and all listener related
+ * methods will throw an {@link UnsupportedOperationException} in that case.
+ */
+public abstract class AbstractNamespaceResolver implements NamespaceResolver {
+
+    private final Set listeners;
+
+    /**
+     * Creates a <code>AbstractNamespaceResolver</code> without listener
+     * support.
+     */
+    public AbstractNamespaceResolver() {
+        this(false);
+    }
+
+    /**
+     * Creates a <code>AbstractNamespaceResolver</code> with listener support if
+     * <code>supportListeners</code> is set to <code>true</code>.
+     *
+     * @param supportListeners if <code>true</code> listener are supported by
+     *                         this instance.
+     */
+    public AbstractNamespaceResolver(boolean supportListeners) {
+        if (supportListeners) {
+            listeners = new HashSet();
+        } else {
+            listeners = null;
+        }
+    }
+
+    //--------------------------------------------< NamespaceListener support >
+
+    /**
+     * Registers <code>listener</code> to get notifications when namespace
+     * mappings change.
+     *
+     * @param listener the listener to register.
+     * @throws UnsupportedOperationException if listener support is not enabled
+     *                                       for this <code>AbstractNamespaceResolver</code>.
+     */
+    public void addListener(NamespaceListener listener) {
+        if (listeners == null) {
+            throw new UnsupportedOperationException("addListener");
+        }
+        synchronized (listeners) {
+            listeners.add(listener);
+        }
+    }
+
+    /**
+     * Removes the <code>listener</code> from this <code>NamespaceRegistery</code>.
+     *
+     * @param listener the listener to remove.
+     * @throws UnsupportedOperationException if listener support is not enabled
+     *                                       for this <code>AbstractNamespaceResolver</code>.
+     */
+    public void removeListener(NamespaceListener listener) {
+        if (listeners == null) {
+            throw new UnsupportedOperationException("removeListener");
+        }
+        synchronized (listeners) {
+            listeners.remove(listener);
+        }
+    }
+
+    /**
+     * Notifies the listeners that a new namespace <code>uri</code> has been
+     * added and mapped to <code>prefix</code>.
+     *
+     * @param prefix the prefix.
+     * @param uri    the namespace uri.
+     */
+    protected void notifyNamespaceAdded(String prefix, String uri) {
+        if (listeners == null) {
+            throw new UnsupportedOperationException("notifyNamespaceAdded");
+        }
+        // addition is infrequent compared to listener registration
+        // -> use copy-on-read
+        NamespaceListener[] currentListeners;
+        synchronized (listeners) {
+            int i = 0;
+            currentListeners = new NamespaceListener[listeners.size()];
+            for (Iterator it = listeners.iterator(); it.hasNext();) {
+                currentListeners[i++] = (NamespaceListener) it.next();
+            }
+        }
+        for (int i = 0; i < currentListeners.length; i++) {
+            currentListeners[i].namespaceAdded(prefix, uri);
+        }
+    }
+
+    /**
+     * Notifies listeners that an existing namespace uri has been remapped
+     * to a new prefix.
+     *
+     * @param oldPrefix the old prefix.
+     * @param newPrefix the new prefix.
+     * @param uri the associated namespace uri.
+     */
+    protected void notifyNamespaceRemapped(String oldPrefix,
+                                           String newPrefix,
+                                           String uri) {
+        if (listeners == null) {
+            throw new UnsupportedOperationException("notifyNamespaceRemapped");
+        }
+        // remapping is infrequent compared to listener registration
+        // -> use copy-on-read
+        NamespaceListener[] currentListeners;
+        synchronized (listeners) {
+            int i = 0;
+            currentListeners = new NamespaceListener[listeners.size()];
+            for (Iterator it = listeners.iterator(); it.hasNext();) {
+                currentListeners[i++] = (NamespaceListener) it.next();
+            }
+        }
+        for (int i = 0; i < currentListeners.length; i++) {
+            currentListeners[i].namespaceRemapped(oldPrefix, newPrefix, uri);
+        }
+    }
+
+    /**
+     * Notifies the listeners that the namespace with the given <code>uri</code>
+     * has been removed from the mapping.
+     *
+     * @param uri the namespace uri.
+     * @see NamespaceListener#namespaceRemoved(String)
+     */
+    protected void notifyNamespaceRemoved(String uri) {
+        if (listeners == null) {
+            throw new UnsupportedOperationException("notifyNamespaceRemapped");
+        }
+        // removal is infrequent compared to listener registration
+        // -> use copy-on-read
+        NamespaceListener[] currentListeners;
+        synchronized (listeners) {
+            int i = 0;
+            currentListeners = new NamespaceListener[listeners.size()];
+            for (Iterator it = listeners.iterator(); it.hasNext();) {
+                currentListeners[i++] = (NamespaceListener) it.next();
+            }
+        }
+        for (int i = 0; i < currentListeners.length; i++) {
+            currentListeners[i].namespaceRemoved(uri);
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/AbstractNamespaceResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/AbstractNamespaceResolver.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceAdder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceAdder.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceAdder.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceAdder.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.namespace;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.NamespaceException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.RepositoryException;
+import java.util.Map;
+import java.util.Iterator;
+
+public class NamespaceAdder {
+
+    private final NamespaceRegistry registry;
+
+    public NamespaceAdder(NamespaceRegistry nsr) {
+        registry = nsr;
+    }
+
+    public void addNamespaces(NamespaceMapping nsm)
+            throws NamespaceException, UnsupportedRepositoryOperationException, RepositoryException {
+        Map m = nsm.getPrefixToURIMapping();
+        for (Iterator i = m.values().iterator(); i.hasNext();) {
+            Map.Entry e = (Map.Entry) i.next();
+            String prefix = (String) e.getKey();
+            String uri = (String) e.getKey();
+            registry.registerNamespace(prefix, uri);
+        }
+    }
+
+    public void addNamespace(String prefix, String uri)
+        throws NamespaceException, UnsupportedRepositoryOperationException, RepositoryException {
+        registry.registerNamespace(prefix, uri);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceAdder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceAdder.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceExtractor.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceExtractor.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceExtractor.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceExtractor.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.namespace;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.XMLReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLReaderFactory;
+import org.xml.sax.helpers.DefaultHandler;
+
+import javax.jcr.NamespaceException;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.FileInputStream;
+
+/**
+ * Extracts namespace mapping information from an XML file.
+ * XML file is parsed and all startPrefixMapping events
+ * are intercepted. Scoping of prefix mapping within the XML file
+ * may result in multiple namespace using the same prefix. This
+ * is handled by mangling the prefix when required.
+ *
+ * The resulting NamespaceMapping implements NamespaceResolver
+ * and can be used by tools (such as o.a.j.tools.nodetype.CompactNodeTypeDefWriter)
+ * to resolve namespaces.
+ */
+public class NamespaceExtractor {
+    private static Logger log = LoggerFactory.getLogger(NamespaceExtractor.class);
+    private final NamespaceMapping mapping = new NamespaceMapping();
+    private final Map basePrefixes = new HashMap();
+    private String defaultBasePrefix;
+
+    /**
+     * Constructor
+     * @param fileName
+     * @param dpb
+     * @throws NamespaceException
+     */
+    public NamespaceExtractor(String fileName, String dpb) throws NamespaceException {
+        defaultBasePrefix = dpb;
+        try{
+            ContentHandler handler = new NamespaceExtractor.NamespaceHandler();
+            XMLReader parser = XMLReaderFactory.createXMLReader();
+            parser.setContentHandler(handler);
+            parser.parse(new InputSource(new FileInputStream(fileName)));
+        } catch(Exception e){
+            throw new NamespaceException();
+        }
+    }
+
+    /**
+     * getNamespaceMapping
+     * @return a NamespaceMapping
+     */
+    public NamespaceMapping getNamespaceMapping(){
+        return mapping;
+    }
+
+    /**
+     * SAX ContentHandler that reacts to namespace mappings in incoming XML.
+     */
+    private class NamespaceHandler extends DefaultHandler {
+        public void startPrefixMapping(String prefix, String uri) throws SAXException {
+            if (uri == null) uri = "";
+
+            //Replace the empty prefix with the defaultBasePrefix
+            if (prefix == null || prefix.equals("")){
+                prefix = defaultBasePrefix;
+            }
+
+            try{
+                // if prefix already used
+                if (mapping.hasPrefix(prefix)){
+                    int c;
+                    Integer co = (Integer) basePrefixes.get(prefix);
+                    if (co == null) {
+                        basePrefixes.put(prefix, new Integer(1));
+                        c = 1;
+                    } else {
+                        c = co.intValue() + 1;
+                        basePrefixes.put(prefix, new Integer(c));
+                    }
+                    prefix = prefix + "_" + c;
+                }
+                mapping.setMapping(prefix, uri);
+            } catch(NamespaceException e){
+                String msg = e.getMessage();
+                log.debug(msg);
+            }
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceExtractor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceExtractor.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceListener.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceListener.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceListener.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.namespace;
+
+/**
+ * Receives notifications when a namespace mapping changes.
+ */
+public interface NamespaceListener {
+
+    /**
+     * Notifies the listeners that an existing namespace <code>uri</code> has
+     * been re-mapped from <code>oldPrefix</code> to <code>newPrefix</code>.
+     *
+     * @param oldPrefix the old prefix.
+     * @param newPrefix the new prefix.
+     * @param uri       the associated namespace uri.
+     */
+    public void namespaceRemapped(String oldPrefix, String newPrefix, String uri);
+
+    /**
+     * Notifies the listeners that a new namespace <code>uri</code> has been
+     * added and mapped to <code>prefix</code>.
+     *
+     * @param prefix the prefix.
+     * @param uri    the namespace uri.
+     */
+    public void namespaceAdded(String prefix, String uri);
+
+    /**
+     * Notifies the listeners that the namespace with the given uri has been
+     * unregistered.
+     *
+     * @param uri    the namespace uri.
+     */
+    public void namespaceRemoved(String uri);
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceListener.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceMapping.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceMapping.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceMapping.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceMapping.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.namespace;
+
+import javax.jcr.NamespaceException;
+import java.util.Properties;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.Iterator;
+
+/**
+ * A Simple Namespace Mapping table. Mappings can be added
+ * and then the object can be used as a NamespaceResolver. Additionally, it can
+ * be based on a underlying NamespaceResolver
+ */
+public class NamespaceMapping extends AbstractNamespaceResolver {
+
+    /** local uris */
+    private final Properties prefixToURI = new Properties();
+
+    /** local prefix */
+    private final Properties URIToPrefix = new Properties();
+
+    /** base */
+    private final NamespaceResolver base;
+
+    public NamespaceMapping() {
+        this.base = null;
+    }
+
+    /**
+     * Constructor
+     */
+    public NamespaceMapping(NamespaceResolver base) {
+        this.base = base;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getPrefix(String uri) throws NamespaceException {
+        if (URIToPrefix.containsKey(uri)) {
+            return URIToPrefix.getProperty(uri);
+        } else if (base == null) {
+            throw new NamespaceException("No prefix for URI '" + uri + "' declared.");
+        } else {
+            return base.getPrefix(uri);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getURI(String prefix) throws NamespaceException {
+        if (prefixToURI.containsKey(prefix)) {
+            return prefixToURI.getProperty(prefix);
+        } else if (base == null) {
+            throw new NamespaceException("No URI for pefix '" + prefix + "' declared.");
+        } else {
+            return base.getURI(prefix);
+        }
+    }
+
+    /**
+     * Returns true if prefix is already mapped to some URI. Returns false otherwise.
+     */
+    public boolean hasPrefix(String prefix) {
+        return prefixToURI.containsKey(prefix);
+    }
+
+    /**
+     * Set a prefix == URI one-to-one mapping
+     *
+     * @param prefix
+     * @param uri
+     * @throws NamespaceException
+     */
+    public void setMapping(String prefix, String uri) throws NamespaceException {
+        if (prefix == null) {
+            throw new NamespaceException("Prefix must not be null");
+        }
+        if (uri == null) {
+            throw new NamespaceException("URI must not be null");
+        }
+        if (URIToPrefix.containsKey(uri)) {
+            // remove mapping
+            prefixToURI.remove(URIToPrefix.remove(uri));
+        }
+        if (prefixToURI.containsKey(prefix)) {
+            // remove mapping
+            URIToPrefix.remove(prefixToURI.remove(prefix));
+        }
+        prefixToURI.put(prefix, uri);
+        URIToPrefix.put(uri, prefix);
+    }
+
+    /**
+     * Return a Map of prefix to URI mappings currently registered.
+     * The returned Map is a copy of the internal Map.
+     * @return Map
+     */
+    public Map getPrefixToURIMapping() {
+        return new HashMap(prefixToURI);
+    }
+
+    /**
+     * Return a Map of URI to prefix mappings currently registered.
+     * The returned Map is a copy of the internal Map.
+     * @return Map
+     */
+    public Map getURIToPrefixMapping() {
+        return new HashMap(URIToPrefix);
+    }
+
+     /**
+     * Override equals()
+      *
+     * @param obj
+     * @return boolean
+     */
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof NamespaceMapping) {
+            NamespaceMapping other = (NamespaceMapping) obj;
+            return this.getPrefixToURIMapping().equals(other.getPrefixToURIMapping())
+                   && this.getURIToPrefixMapping().equals(other.getURIToPrefixMapping());
+        }
+        return false;
+    }
+
+    /**
+     * Override toString()
+     *
+     * @return String
+     */
+    public String toString() {
+        String s = "";
+        Set mapping = prefixToURI.entrySet();
+        for (Iterator i = mapping.iterator(); i.hasNext();) {
+            Map.Entry entry = (Map.Entry) i.next();
+            String prefix = (String) entry.getKey();
+            String uri = (String) entry.getValue();
+            s += "'" + prefix + "' == '" + uri + "'\n";
+        }
+        return s;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceMapping.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceMapping.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceResolver.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceResolver.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceResolver.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.namespace;
+
+import javax.jcr.NamespaceException;
+
+/**
+ * Interface for resolving namespace URIs and prefixes. Unlike the JCR
+ * {@link javax.jcr.NamespaceRegistry} interface, this interface contains
+ * no functionality other than the basic namespace URI and prefix resolution
+ * methods. This interface is therefore used internally in many places where
+ * the full namespace registry is either not available or some other mechanism
+ * is used for resolving namespaces.
+ */
+public interface NamespaceResolver {
+
+    /**
+     * Returns the URI to which the given prefix is mapped.
+     *
+     * @param prefix namespace prefix
+     * @return the namespace URI to which the given prefix is mapped.
+     * @throws NamespaceException if the prefix is unknown.
+     */
+    String getURI(String prefix) throws NamespaceException;
+
+    /**
+     * Returns the prefix which is mapped to the given URI.
+     *
+     * @param uri namespace URI
+     * @return the prefix mapped to the given URI.
+     * @throws NamespaceException if the URI is unknown.
+     */
+    String getPrefix(String uri) throws NamespaceException;
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/NamespaceResolver.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/SessionNamespaceResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/SessionNamespaceResolver.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/SessionNamespaceResolver.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/SessionNamespaceResolver.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.namespace;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * helper class that exposes the <code>NamespaceResolver</code>
+ * interface on a <code>Session</code>.
+ */
+public class SessionNamespaceResolver extends AbstractNamespaceResolver {
+
+    /**
+     * the session for the namespace lookups
+     */
+    private final Session session;
+
+    /**
+     * Creates a new namespace resolver based on a session
+     * @param session
+     */
+    public SessionNamespaceResolver(Session session) {
+        this.session = session;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getPrefix(String uri) throws NamespaceException {
+        try {
+            return session.getNamespacePrefix(uri);
+        } catch (RepositoryException e) {
+            // should never get here...
+            throw new NamespaceException("internal error: failed to resolve namespace uri", e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getURI(String prefix) throws NamespaceException {
+        try {
+            return session.getNamespaceURI(prefix);
+        } catch (RepositoryException e) {
+            // should never get here...
+            throw new NamespaceException("internal error: failed to resolve namespace prefix", e);
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/SessionNamespaceResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/namespace/SessionNamespaceResolver.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidConstraintException.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidConstraintException.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidConstraintException.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidConstraintException.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.nodetype;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * The <code>InvalidConstraintException</code> ...
+ */
+public class InvalidConstraintException extends RepositoryException {
+
+    /**
+     * Constructs a new instance of this class with the specified detail
+     * message.
+     *
+     * @param message the detail message. The detail message is saved for
+     *                later retrieval by the {@link #getMessage()} method.
+     */
+    public InvalidConstraintException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructs a new instance of this class with the specified detail
+     * message and root cause.
+     *
+     * @param message   the detail message. The detail message is saved for
+     *                  later retrieval by the {@link #getMessage()} method.
+     * @param rootCause root failure cause
+     */
+    public InvalidConstraintException(String message, Throwable rootCause) {
+        super(message, rootCause);
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidConstraintException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidConstraintException.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidNodeTypeDefException.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidNodeTypeDefException.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidNodeTypeDefException.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidNodeTypeDefException.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.nodetype;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * The <code>NodeTypeConflictException</code> ...
+ */
+public class InvalidNodeTypeDefException extends RepositoryException {
+
+    /**
+     * Constructs a new instance of this class with the specified detail
+     * message.
+     *
+     * @param message the detail message. The detail message is saved for
+     *                later retrieval by the {@link #getMessage()} method.
+     */
+    public InvalidNodeTypeDefException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructs a new instance of this class with the specified detail
+     * message and root cause.
+     *
+     * @param message   the detail message. The detail message is saved for
+     *                  later retrieval by the {@link #getMessage()} method.
+     * @param rootCause root failure cause
+     */
+    public InvalidNodeTypeDefException(String message, Throwable rootCause) {
+        super(message, rootCause);
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidNodeTypeDefException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/InvalidNodeTypeDefException.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/NodeTypeConflictException.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/NodeTypeConflictException.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/NodeTypeConflictException.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/NodeTypeConflictException.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.nodetype;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * The <code>NodeTypeConflictException</code> ...
+ */
+public class NodeTypeConflictException extends RepositoryException {
+
+    /**
+     * Constructs a new instance of this class with the specified detail
+     * message.
+     *
+     * @param message the detail message. The detail message is saved for
+     *                later retrieval by the {@link #getMessage()} method.
+     */
+    public NodeTypeConflictException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructs a new instance of this class with the specified detail
+     * message and root cause.
+     *
+     * @param message   the detail message. The detail message is saved for
+     *                  later retrieval by the {@link #getMessage()} method.
+     * @param rootCause root failure cause
+     */
+    public NodeTypeConflictException(String message, Throwable rootCause) {
+        super(message, rootCause);
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/NodeTypeConflictException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/nodetype/NodeTypeConflictException.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ChildInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ChildInfoImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ChildInfoImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ChildInfoImpl.java Thu Oct 18 11:34:57 2007
@@ -17,7 +17,7 @@
 package org.apache.jackrabbit.spi.commons;
 
 import org.apache.jackrabbit.spi.ChildInfo;
-import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.Name;
 
 import java.io.Serializable;
 
@@ -29,7 +29,7 @@
     /**
      * The name of this child info.
      */
-    private final QName name;
+    private final Name name;
 
     /**
      * The unique id for this child info or <code>null</code> if it does not
@@ -49,7 +49,7 @@
      * @param uniqueId the unique id of the child node or <code>null</code>.
      * @param index    the index of the child node.
      */
-    public ChildInfoImpl(QName name, String uniqueId, int index) {
+    public ChildInfoImpl(Name name, String uniqueId, int index) {
         this.name = name;
         this.uniqueId = uniqueId;
         this.index = index;
@@ -58,7 +58,7 @@
     /**
      * {@inheritDoc}
      */
-    public QName getName() {
+    public Name getName() {
         return name;
     }
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventFilterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventFilterImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventFilterImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventFilterImpl.java Thu Oct 18 11:34:57 2007
@@ -19,10 +19,9 @@
 import org.apache.jackrabbit.spi.EventFilter;
 import org.apache.jackrabbit.spi.Event;
 import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.MalformedPathException;
+import org.apache.jackrabbit.spi.Path;
 
-import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
 import java.util.Set;
 import java.util.HashSet;
 import java.util.Arrays;
@@ -54,7 +53,7 @@
      * @param absPath       filter events that are below this path.
      * @param isDeep        whether this filter is applied deep.
      * @param uuids         the jcr:uuid of the nodes this filter allows.
-     * @param nodeTypeNames the QNames of the already resolved node types this
+     * @param nodeTypeNames the Names of the already resolved node types this
      *                      filter allows.
      * @param noLocal       whether this filter accepts local events or not.
      */
@@ -120,9 +119,9 @@
             // node where the property belongs to.
             Path eventPath;
             if (type == Event.NODE_ADDED || type == Event.NODE_REMOVED) {
-                eventPath = event.getQPath();
+                eventPath = event.getPath();
             } else {
-                eventPath = event.getQPath().getAncestor(1);
+                eventPath = event.getPath().getAncestor(1);
             }
 
             boolean match = eventPath.equals(absPath);
@@ -130,9 +129,7 @@
                 match = eventPath.isDescendantOf(absPath);
             }
             return match;
-        } catch (MalformedPathException e) {
-            // should never get here
-        } catch (PathNotFoundException e) {
+        } catch (RepositoryException e) {
             // should never get here
         }
         // if we get here an exception occurred while checking for the path

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/EventImpl.java Thu Oct 18 11:34:57 2007
@@ -19,8 +19,8 @@
 import org.apache.jackrabbit.spi.Event;
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
 
 import java.io.Serializable;
 
@@ -54,12 +54,12 @@
     /**
      * The name of the primary node type of the 'associated' node of this event.
      */
-    private final QName primaryNodeTypeName;
+    private final Name primaryNodeTypeName;
 
     /**
      * The names of the mixin types of the 'associated' node of this event.
      */
-    private final QName[] mixinTypeNames;
+    private final Name[] mixinTypeNames;
 
     /**
      * The user ID connected with this event.
@@ -70,7 +70,7 @@
      * Creates a new serializable event.
      */
     public EventImpl(int type, Path path, ItemId itemId, NodeId parentId,
-                     QName primaryNodeTypeName, QName[] mixinTypeNames,
+                     Name primaryNodeTypeName, Name[] mixinTypeNames,
                      String userId) {
         this.type = type;
         this.path = path;
@@ -91,7 +91,7 @@
     /**
      * {@inheritDoc}
      */
-    public Path getQPath() {
+    public Path getPath() {
         return path;
     }
 
@@ -112,15 +112,15 @@
     /**
      * {@inheritDoc}
      */
-    public QName getPrimaryNodeTypeName() {
+    public Name getPrimaryNodeTypeName() {
         return primaryNodeTypeName;
     }
 
     /**
      * {@inheritDoc}
      */
-    public QName[] getMixinTypeNames() {
-        QName[] mixins = new QName[mixinTypeNames.length];
+    public Name[] getMixinTypeNames() {
+        Name[] mixins = new Name[mixinTypeNames.length];
         System.arraycopy(mixinTypeNames, 0, mixins, 0, mixinTypeNames.length);
         return mixins;
     }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoImpl.java Thu Oct 18 11:34:57 2007
@@ -18,8 +18,8 @@
 
 import org.apache.jackrabbit.spi.ItemInfo;
 import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
 
 import java.io.Serializable;
 
@@ -38,7 +38,7 @@
     /**
      * The name of this item info.
      */
-    private final QName name;
+    private final Name name;
 
     /**
      * The path of this item info.
@@ -59,7 +59,7 @@
      * @param path     the path to this item.
      * @param isNode   if this item is a node.
      */
-    public ItemInfoImpl(NodeId parentId, QName name, Path path, boolean isNode) {
+    public ItemInfoImpl(NodeId parentId, Name name, Path path, boolean isNode) {
         this.parentId = parentId;
         this.name = name;
         this.path = path;
@@ -76,7 +76,7 @@
     /**
      * {@inheritDoc}
      */
-    public QName getQName() {
+    public Name getName() {
         return name;
     }
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/NodeInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/NodeInfoImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/NodeInfoImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/NodeInfoImpl.java Thu Oct 18 11:34:57 2007
@@ -20,8 +20,8 @@
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.IdFactory;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.util.IteratorHelper;
 
 import java.util.List;
@@ -48,12 +48,12 @@
     /**
      * The name of the primary node type.
      */
-    private final QName primaryTypeName;
+    private final Name primaryTypeName;
 
     /**
      * The names of assigned mixins.
      */
-    private final QName[] mixinNames;
+    private final Name[] mixinNames;
 
     /**
      * The list of {@link PropertyId}s that reference this node info.
@@ -82,7 +82,7 @@
                 NodeId parentId = refs[i].getParentId();
                 parentId = idFactory.createNodeId(
                         parentId.getUniqueID(), parentId.getPath());
-                serRefs.add(idFactory.createPropertyId(parentId, refs[i].getQName()));
+                serRefs.add(idFactory.createPropertyId(parentId, refs[i].getName()));
             }
             NodeId parentId = null;
             if (nodeInfo.getParentId() != null) {
@@ -92,7 +92,7 @@
             }
             NodeId nodeId = nodeInfo.getId();
             nodeId = idFactory.createNodeId(nodeId.getUniqueID(), nodeId.getPath());
-            return new NodeInfoImpl(parentId, nodeInfo.getQName(),
+            return new NodeInfoImpl(parentId, nodeInfo.getName(),
                     nodeInfo.getPath(), nodeId,
                     nodeInfo.getIndex(), nodeInfo.getNodetype(),
                     nodeInfo.getMixins(), serRefs.iterator(),
@@ -103,7 +103,7 @@
                             idFactory.createNodeId(
                                     parentId.getUniqueID(), parentId.getPath());
                             return idFactory.createPropertyId(
-                                    parentId, propId.getQName());
+                                    parentId, propId.getName());
                         }
                     });
         }
@@ -123,8 +123,8 @@
      * @param references      the references to this node.
      * @param propertyIds     the properties of this node.
      */
-    public NodeInfoImpl(NodeId parentId, QName name, Path path, NodeId id,
-                         int index, QName primaryTypeName, QName[] mixinNames,
+    public NodeInfoImpl(NodeId parentId, Name name, Path path, NodeId id,
+                         int index, Name primaryTypeName, Name[] mixinNames,
                          Iterator references, Iterator propertyIds) {
         super(parentId, name, path, true);
         this.id = id;
@@ -160,15 +160,15 @@
     /**
      * {@inheritDoc}
      */
-    public QName getNodetype() {
+    public Name getNodetype() {
         return primaryTypeName;
     }
 
     /**
      * {@inheritDoc}
      */
-    public QName[] getMixins() {
-        QName[] ret = new QName[mixinNames.length];
+    public Name[] getMixins() {
+        Name[] ret = new Name[mixinNames.length];
         System.arraycopy(mixinNames, 0, ret, 0, mixinNames.length);
         return ret;
     }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/PropertyInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/PropertyInfoImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/PropertyInfoImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/PropertyInfoImpl.java Thu Oct 18 11:34:57 2007
@@ -21,8 +21,8 @@
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.IdFactory;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
 
 import java.io.Serializable;
 
@@ -67,8 +67,8 @@
             parentId = idFactory.createNodeId(
                     parentId.getUniqueID(), parentId.getPath());
             PropertyId propId = idFactory.createPropertyId(
-                    parentId, propertyInfo.getId().getQName());
-            return new PropertyInfoImpl(parentId, propertyInfo.getQName(),
+                    parentId, propertyInfo.getId().getName());
+            return new PropertyInfoImpl(parentId, propertyInfo.getName(),
                     propertyInfo.getPath(), propId, propertyInfo.getType(),
                     propertyInfo.isMultiValued(), propertyInfo.getValues());
         }
@@ -85,7 +85,7 @@
      * @param isMultiValued whether this property is multi-valued.
      * @param values        the values.
      */
-    public PropertyInfoImpl(NodeId parentId, QName name, Path path,
+    public PropertyInfoImpl(NodeId parentId, Name name, Path path,
                             PropertyId id, int type, boolean isMultiValued,
                             QValue[] values) {
         super(parentId, name, path, false);

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QItemDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QItemDefinitionImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QItemDefinitionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QItemDefinitionImpl.java Thu Oct 18 11:34:57 2007
@@ -16,10 +16,11 @@
  */
 package org.apache.jackrabbit.spi.commons;
 
-import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.spi.QItemDefinition;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.name.NameFactoryImpl;
 
 import java.io.Serializable;
 
@@ -32,18 +33,19 @@
 
     /**
      * The special wildcard name used as the name of residual item definitions.
+     * TODO don't rely on specific factory impl
      */
-    public static final QName ANY_NAME = new QName("", "*");
+    public static final Name ANY_NAME = NameFactoryImpl.getInstance().create("", "*");
 
     /**
      * The name of the child item.
      */
-    private final QName name;
+    private final Name name;
 
     /**
      * The name of the declaring node type.
      */
-    private final QName declaringNodeType;
+    private final Name declaringNodeType;
 
     /**
      * The 'autoCreated' flag.
@@ -80,7 +82,7 @@
      * @param onParentVersion   the on parent version behaviour.
      * @param isProtected       if this item is protected.
      */
-    QItemDefinitionImpl(QName name, QName declaringNodeType,
+    QItemDefinitionImpl(Name name, Name declaringNodeType,
                         boolean isAutoCreated, boolean isMandatory,
                         int onParentVersion, boolean isProtected) {
         this.name = name;
@@ -95,14 +97,14 @@
     /**
      * {@inheritDoc}
      */
-    public QName getDeclaringNodeType() {
+    public Name getDeclaringNodeType() {
         return declaringNodeType;
     }
 
     /**
      * {@inheritDoc}
      */
-    public QName getQName() {
+    public Name getName() {
         return name;
     }
 
@@ -138,7 +140,7 @@
      * {@inheritDoc}
      */
     public boolean definesResidual() {
-        return name.equals(ANY_NAME);
+        return Name.NS_DEFAULT_URI.equals(name.getNamespaceURI()) && "*".equals(name.getLocalName());
     }
 
     //-------------------------------------------< java.lang.Object overrides >
@@ -161,7 +163,7 @@
             return (declaringNodeType == null
                     ? other.getDeclaringNodeType() == null
                     : declaringNodeType.equals(other.getDeclaringNodeType()))
-                    && (name == null ? other.getQName() == null : name.equals(other.getQName()))
+                    && (name == null ? other.getName() == null : name.equals(other.getName()))
                     && autoCreated == other.isAutoCreated()
                     && onParentVersion == other.getOnParentVersion()
                     && writeProtected == other.isProtected()

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeDefinitionImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeDefinitionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeDefinitionImpl.java Thu Oct 18 11:34:57 2007
@@ -17,7 +17,7 @@
 package org.apache.jackrabbit.spi.commons;
 
 import org.apache.jackrabbit.spi.QNodeDefinition;
-import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.Name;
 
 import java.util.Arrays;
 import java.util.TreeSet;
@@ -25,19 +25,17 @@
 /**
  * <code>QNodeDefinitionImpl</code> implements a <code>QNodeDefinition</code>.
  */
-public class QNodeDefinitionImpl
-        extends QItemDefinitionImpl
-        implements QNodeDefinition {
+public class QNodeDefinitionImpl extends QItemDefinitionImpl implements QNodeDefinition {
 
     /**
      * The name of the default primary type.
      */
-    private final QName defaultPrimaryType;
+    private final Name defaultPrimaryType;
 
     /**
      * The names of the required primary types.
      */
-    private final QName[] requiredPrimaryTypes;
+    private final Name[] requiredPrimaryTypes;
 
     /**
      * The 'allowsSameNameSiblings' flag.
@@ -50,7 +48,7 @@
      * @param nodeDef some other node definition.
      */
     public QNodeDefinitionImpl(QNodeDefinition nodeDef) {
-        this(nodeDef.getQName(), nodeDef.getDeclaringNodeType(),
+        this(nodeDef.getName(), nodeDef.getDeclaringNodeType(),
                 nodeDef.isAutoCreated(), nodeDef.isMandatory(),
                 nodeDef.getOnParentVersion(), nodeDef.isProtected(),
                 nodeDef.getDefaultPrimaryType(),
@@ -68,11 +66,11 @@
      * @param onParentVersion   the on parent version behaviour.
      * @param isProtected       if this item is protected.
      */
-    public QNodeDefinitionImpl(QName name, QName declaringNodeType,
-                        boolean isAutoCreated, boolean isMandatory,
-                        int onParentVersion, boolean isProtected,
-                        QName defaultPrimaryType, QName[] requiredPrimaryTypes,
-                        boolean allowsSameNameSiblings) {
+    public QNodeDefinitionImpl(Name name, Name declaringNodeType,
+                               boolean isAutoCreated, boolean isMandatory,
+                               int onParentVersion, boolean isProtected,
+                               Name defaultPrimaryType, Name[] requiredPrimaryTypes,
+                               boolean allowsSameNameSiblings) {
         super(name, declaringNodeType, isAutoCreated, isMandatory,
                 onParentVersion, isProtected);
         this.defaultPrimaryType = defaultPrimaryType;
@@ -84,14 +82,14 @@
     /**
      * {@inheritDoc}
      */
-    public QName getDefaultPrimaryType() {
+    public Name getDefaultPrimaryType() {
         return defaultPrimaryType;
     }
 
     /**
      * {@inheritDoc}
      */
-    public QName[] getRequiredPrimaryTypes() {
+    public Name[] getRequiredPrimaryTypes() {
         return requiredPrimaryTypes;
     }
 
@@ -155,12 +153,12 @@
             if (definesResidual()) {
                 sb.append('*');
             } else {
-                sb.append(getQName().toString());
+                sb.append(getName().toString());
             }
             sb.append('/');
             // set of required node type names, sorted in ascending order
             TreeSet set = new TreeSet();
-            QName[] names = getRequiredPrimaryTypes();
+            Name[] names = getRequiredPrimaryTypes();
             for (int i = 0; i < names.length; i++) {
                 set.add(names[i]);
             }



Mime
View raw message