jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r328807 - in /incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base: ./ nodetype/
Date Thu, 27 Oct 2005 06:39:23 GMT
Author: jukka
Date: Wed Oct 26 23:39:12 2005
New Revision: 328807

URL: http://svn.apache.org/viewcvs?rev=328807&view=rev
Log:
JCR-EXT: Various improvements and documentation for the JCR base classes.

Modified:
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseItem.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseNamespaceRegistry.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseNode.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseRepository.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseSession.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseWorkspace.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseItemDefinition.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeDefinition.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeType.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeTypeManager.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BasePropertyDefinition.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/package.html

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseItem.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseItem.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseItem.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseItem.java Wed Oct 26 23:39:12 2005
@@ -16,29 +16,19 @@
  */
 package org.apache.jackrabbit.base;
 
-import javax.jcr.AccessDeniedException;
-import javax.jcr.InvalidItemStateException;
 import javax.jcr.Item;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.ItemVisitor;
 import javax.jcr.Node;
-import javax.jcr.ReferentialIntegrityException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.VersionException;
 
 /**
  * Item base class.
  */
 public class BaseItem implements Item {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BaseItem() {
-    }
-
     /**
      * Implemented by calling <code>getParent().getPath()</code> and
      * appending <code>getName()</code> to the returned parent path.
@@ -73,8 +63,7 @@
      * given depth.
      * {@inheritDoc}
      */
-    public Item getAncestor(int depth) throws ItemNotFoundException,
-            AccessDeniedException, RepositoryException {
+    public Item getAncestor(int depth) throws RepositoryException {
         int thisDepth = getDepth();
         if (thisDepth == depth) {
             return this;
@@ -88,8 +77,7 @@
     }
 
     /** Not implemented. {@inheritDoc} */
-    public Node getParent() throws ItemNotFoundException,
-            AccessDeniedException, RepositoryException {
+    public Node getParent() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
@@ -120,17 +108,21 @@
 
     /** Not implemented. {@inheritDoc} */
     public boolean isNew() {
-        throw new UnsupportedOperationException();
+        return false;
     }
 
     /** Not implemented. {@inheritDoc} */
     public boolean isModified() {
-        throw new UnsupportedOperationException();
+        return false;
     }
 
     /** Not implemented. {@inheritDoc} */
     public boolean isSame(Item otherItem) {
-        throw new UnsupportedOperationException();
+        try {
+            return getPath().equals(otherItem.getPath());
+        } catch (RepositoryException e) {
+            return false;
+        }
     }
 
     /** Does nothing. {@inheritDoc} */
@@ -138,22 +130,17 @@
     }
 
     /** Not implemented. {@inheritDoc} */
-    public void save() throws AccessDeniedException,
-            ConstraintViolationException, InvalidItemStateException,
-            ReferentialIntegrityException, VersionException, LockException,
-            RepositoryException {
+    public void save() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
     /** Not implemented. {@inheritDoc} */
-    public void refresh(boolean keepChanges) throws InvalidItemStateException,
-            RepositoryException {
+    public void refresh(boolean keepChanges) throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
     /** Not implemented. {@inheritDoc} */
-    public void remove() throws VersionException, LockException,
-            RepositoryException {
+    public void remove() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseNamespaceRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseNamespaceRegistry.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseNamespaceRegistry.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseNamespaceRegistry.java Wed Oct 26 23:39:12 2005
@@ -22,68 +22,112 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 
 /**
- * NamespaceRegistry base class.
+ * NamespaceRegistry base class. The dummy namespace registry implemented
+ * by this class only contains the builtin namespaces defined by the JSR 170
+ * specification. Subclasses should override the methods of this class to
+ * include other namespaces or to support namespace management.
  */
 public class BaseNamespaceRegistry implements NamespaceRegistry {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BaseNamespaceRegistry() {
-    }
+    /** The default namespace prefixes. */
+    private static final String[] NAMESPACE_PREFIXES =
+        new String[] { "jcr", "nt", "mix", "xml", "" };
+
+    /** The default namespace URIs. */
+    private static final String[] NAMESPACE_URIS = new String[] {
+            "http://www.jcp.org/jcr/1.0",
+            "http://www.jcp.org/jcr/nt/1.0",
+            "http://www.jcp.org/jcr/mix/1.0",
+            "http://www.w3.org/XML/1998/namespace",
+            ""
+        };
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Unsupported operation. Subclasses should override this method to
+     * allow namespace management.
+     *
+     * @param prefix namespace prefix
+     * @param uri namespace URI
+     * @see NamespaceRegistry#registerNamespace(String, String)
+     */
     public void registerNamespace(String prefix, String uri)
-            throws NamespaceException, UnsupportedRepositoryOperationException,
-            RepositoryException {
+            throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Not implemented. {@inheritDoc} */
-    public void unregisterNamespace(String prefix) throws NamespaceException,
-            UnsupportedRepositoryOperationException, RepositoryException {
+    /**
+     * Unsupported operation. Subclasses should override this method to
+     * allow namespace management.
+     *
+     * @param prefix namespace prefix
+     * @see NamespaceRegistry#unregisterNamespace(String, String)
+     */
+    public void unregisterNamespace(String prefix) throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Returns the builtin namespace prefixes defined by the JSR 170
+     * specification. Subclasses should override this method to return
+     * the actual registered namespace prefixes.
+     *
+     * @return builtin namespace prefixes
+     * @see NamespaceRegistry#getPrefixes()
+     */
     public String[] getPrefixes() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return (String[]) NAMESPACE_PREFIXES.clone();
     }
 
     /**
-     * Implemented by calling <code>getPrefixes()</code> and
-     * mapping all returned prefixes into namespace URIs using
-     * <code>getURI(prefix)</code>.
-     * {@inheritDoc}
+     * Returns the builtin namespace URIs defined by the JSR 170
+     * specification. Subclasses should override this method to return
+     * the actual registered namespace URIs.
+     *
+     * @return builtin namespace prefixes
+     * @see NamespaceRegistry#getURIs()
      */
     public String[] getURIs() throws RepositoryException {
-        String[] prefixes = getPrefixes();
-        String[] uris = new String[prefixes.length];
-        for (int i = 0; i < prefixes.length; i++) {
-            uris[i] = getURI(prefixes[i]);
-        }
-        return uris;
+        return (String[]) NAMESPACE_URIS.clone();
     }
 
-    /** Not implemented. {@inheritDoc} */
-    public String getURI(String prefix) throws NamespaceException,
-            RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+    /**
+     * Returns the builtin namespace URI that is mapped to the given
+     * builtin namespace prefix as defined by the JSR 170 specification.
+     * Subclasses should override this method to support the actual
+     * registered namespaces.
+     *
+     * @param prefix namespace prefix
+     * @return namespace URI
+     * @throws NamespaceException if the namespace prefix was not found
+     * @see NamespaceRegistry#getURI(String)
+     */
+    public String getURI(String prefix) throws RepositoryException {
+        for (int i = 0; i < NAMESPACE_PREFIXES.length; i++) {
+            if (NAMESPACE_PREFIXES[i].equals(prefix)) {
+                return NAMESPACE_URIS[i];
+            }
+        }
+        throw new NamespaceException("Prefix " + prefix + " not found");
     }
 
     /**
-     * Implemented by calling <code>getPrefixes()</code> and iterating
-     * over the returned prefixes to find the prefix for which
-     * <code>getURI(prefix)</code> returns the given namespace URI.
-     * {@inheritDoc}
-     */
-    public String getPrefix(String uri) throws NamespaceException,
-            RepositoryException {
-        String[] prefixes = getPrefixes();
-        for (int i = 0; i < prefixes.length; i++) {
-            if (uri.equals(getURI(prefixes[i]))) {
-                return prefixes[i];
+     * Returns the builtin namespace prefix that is mapped to the given
+     * builtin namespace URI as defined by the JSR 170 specification.
+     * Subclasses should override this method to support the actual
+     * registered namespaces.
+     *
+     * @param uri namespace URI
+     * @return namespace prefix
+     * @throws NamespaceException if the namespace URI was not found
+     * @see NamespaceRegistry#getPrefix(String)
+     */
+    public String getPrefix(String uri) throws RepositoryException {
+        for (int i = 0; i < NAMESPACE_URIS.length; i++) {
+            if (NAMESPACE_URIS[i].equals(uri)) {
+                return NAMESPACE_PREFIXES[i];
             }
         }
-        throw new NamespaceException("Namespace URI not registered: " + uri);
+        throw new NamespaceException("URI " + uri + " not found");
     }
 
-}
+ }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseNode.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseNode.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseNode.java Wed Oct 26 23:39:12 2005
@@ -18,6 +18,8 @@
 
 import java.io.InputStream;
 import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.InvalidItemStateException;
@@ -25,6 +27,7 @@
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.ItemVisitor;
+import javax.jcr.NamespaceException;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
@@ -33,6 +36,7 @@
 import javax.jcr.PropertyIterator;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
@@ -43,21 +47,24 @@
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
 
+import org.apache.jackrabbit.iterator.ArrayNodeIterator;
+import org.apache.jackrabbit.iterator.ArrayPropertyIterator;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.SessionNamespaceResolver;
 
 /**
  * Node base class.
  */
 public class BaseNode extends BaseItem implements Node {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BaseNode() {
-    }
-
     /**
      * Implemented by calling <code>super.getPath()</code>
      * (see {@link BaseItem#getPath() BaseItem.getPath()} and appending
@@ -88,9 +95,7 @@
     }
 
     /** Not implemented. {@inheritDoc} */
-    public Node addNode(String relPath) throws ItemExistsException,
-            PathNotFoundException, VersionException,
-            ConstraintViolationException, LockException, RepositoryException {
+    public Node addNode(String relPath) throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
@@ -102,21 +107,22 @@
      * {@inheritDoc}
      */
     public Node addNode(String relPath, String primaryNodeTypeName)
-            throws ItemExistsException, PathNotFoundException,
-            NoSuchNodeTypeException, LockException, VersionException,
-            ConstraintViolationException, RepositoryException {
+            throws RepositoryException {
         Node node = addNode(relPath);
-        String prefix =
-            getSession().getNamespacePrefix("http://www.jcp.org/jcr/1.0");
-        node.setProperty(prefix + ":primaryType", primaryNodeTypeName);
+        String primaryType;
+        String prefix = getSession().getNamespacePrefix(QName.NS_JCR_URI);
+        if (prefix.length() > 0) {
+            primaryType = prefix + ":primaryType";
+        } else {
+            primaryType = "primaryType";
+        }
+        node.setProperty(primaryType, primaryNodeTypeName);
         return node;
     }
 
     /** Not implemented. {@inheritDoc} */
     public void orderBefore(String srcChildRelPath, String destChildRelPath)
-            throws UnsupportedRepositoryOperationException, VersionException,
-            ConstraintViolationException, ItemNotFoundException, LockException,
-            RepositoryException {
+            throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
@@ -127,8 +133,7 @@
      * {@inheritDoc}
      */
     public Property setProperty(String name, Value value)
-            throws ValueFormatException, VersionException, LockException,
-            RepositoryException {
+            throws RepositoryException {
         try {
             Property property = getProperty(name);
             property.setValue(value);
@@ -376,7 +381,7 @@
 
     /** Not implemented. {@inheritDoc} */
     public NodeIterator getNodes() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return new ArrayNodeIterator(new Node[0]);
     }
 
     /** Not implemented. {@inheritDoc} */
@@ -406,7 +411,7 @@
 
     /** Not implemented. {@inheritDoc} */
     public PropertyIterator getProperties() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return new ArrayPropertyIterator(new Property[0]);
     }
 
     /** Not implemented. {@inheritDoc} */
@@ -485,12 +490,37 @@
 
     /** Not implemented. {@inheritDoc} */
     public NodeType getPrimaryNodeType() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        try {
+            Session session = getSession();
+            NamespaceResolver resolver = new SessionNamespaceResolver(session);
+            Property property = getProperty(QName.JCR_PRIMARYTYPE.toJCRName(resolver));
+            NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+            return manager.getNodeType(property.getString());
+        } catch (NoPrefixDeclaredException e) {
+            throw new NamespaceException("jcr:primaryType", e);
+        }
     }
 
     /** Not implemented. {@inheritDoc} */
     public NodeType[] getMixinNodeTypes() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        List types = new LinkedList();
+
+        Session session = getSession();
+        NamespaceResolver resolver = new SessionNamespaceResolver(session);
+        try {
+            Property property = getProperty(QName.JCR_MIXINTYPES.toJCRName(resolver));
+            Value[] values = property.getValues();
+            NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+          for (int i = 0; i < values.length; i++) {
+                types.add(manager.getNodeType(values[i].getString()));
+            }
+        } catch (NoPrefixDeclaredException e) {
+            throw new NamespaceException("jcr:mixinTypes", e);
+        } catch (PathNotFoundException e) {
+            // jcr:mixinTypes not found, fall through with no mixin types
+        }
+
+        return (NodeType[]) types.toArray(new NodeType[types.size()]);
     }
 
     /**
@@ -660,12 +690,12 @@
 
     /** Not implemented. {@inheritDoc} */
     public boolean holdsLock() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return false;
     }
 
     /** Not implemented. {@inheritDoc} */
     public boolean isLocked() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return false;
     }
 
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseRepository.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseRepository.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseRepository.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseRepository.java Wed Oct 26 23:39:12 2005
@@ -18,68 +18,97 @@
 
 import javax.jcr.Credentials;
 import javax.jcr.LoginException;
-import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.UnsupportedRepositoryOperationException;
 
 /**
- * Repository base class.
+ * Repository base class. The dummy repository implemented by this class
+ * contains no descriptors and forwards all login requests to the
+ * canonical {@link #login(Credentials, String)} method.
  */
 public class BaseRepository implements Repository {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BaseRepository() {
-    }
-
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Returns an empty to indicate that no descriptor keys are available.
+     * Subclasses should override this method to return the available
+     * descriptor keys.
+     *
+     * @return empty array
+     * @see Repository#getDescriptorKeys()
+     */
     public String[] getDescriptorKeys() {
-        throw new UnsupportedOperationException();
+        return new String[0];
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Returns <code>null</code> to indicate that the requested descriptor
+     * does not exist. Subclasses should override this method to return the
+     * actual repository descriptor values.
+     *
+     * @param key descriptor key
+     * @return always <code>null</code>
+     * @see Repository#getDescriptor(String)
+     */
     public String getDescriptor(String key) {
-        throw new UnsupportedOperationException();
+        return null;
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Throws a {@link LoginException} to indicate that logins are
+     * not available. Subclasses should override this method to allow
+     * repository logins. Note that by default the other login methods
+     * invoke this method, so all the login methods can be made to work
+     * by overriding just this method. 
+     *
+     * @param credentials login credentials
+     * @param workspaceName workspace name
+     * @return nothing (throws a LoginException)
+     * @see Repository#login(Credentials, String)
+     */
     public Session login(Credentials credentials, String workspaceName)
-            throws LoginException, NoSuchWorkspaceException,
-            RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+            throws RepositoryException {
+        throw new LoginException();
     }
 
     /**
-     * Implemented by calling
-     * <code>login(credentials, null)</code>
-     * as suggested by the JCR specification.
-     * {@inheritDoc}
+     * Implemented by calling {@link #login(Credentials, String)} with a
+     * <code>null</code> workspace name. This default implementation
+     * follows the JCR specification, so there should be little
+     * reason for subclasses to override this method.
+     *
+     * @param credentials login credentials
+     * @return repository session
+     * @see Repository#login(Credentials)
      */
-    public Session login(Credentials credentials) throws LoginException,
-            NoSuchWorkspaceException, RepositoryException {
+    public Session login(Credentials credentials) throws RepositoryException {
         return login(credentials, null);
     }
 
     /**
-     * Implemented by calling
-     * <code>login(null, workspaceName)</code>
-     * as suggested by the JCR specification.
-     * {@inheritDoc}
+     * Implemented by calling {@link #login(Credentials, String)} with
+     * <code>null</code> credentials. This default implementation
+     * follows the JCR specification, so there should be little
+     * reason for subclasses to override this method.
+     *
+     * @param workspaceName workspace name
+     * @return repository session
+     * @see Repository#login(String)
      */
-    public Session login(String workspaceName) throws LoginException,
-            NoSuchWorkspaceException, RepositoryException {
+    public Session login(String workspaceName) throws RepositoryException {
         return login(null, workspaceName);
     }
 
     /**
-     * Implemented by calling
-     * <code>login(null, null)</code>
-     * as suggested by the JCR specification.
-     * {@inheritDoc}
+     * Implemented by calling {@link #login(Credentials, String)} with a
+     * <code>null</code> workspace name and <code>null</code> credentials.
+     * This default implementation follows the JCR specification, so there
+     * should be little reason for subclasses to override this method.
+     *
+     * @return repository session
+     * @see Repository#login()
      */
-    public Session login() throws LoginException, NoSuchWorkspaceException,
-            RepositoryException {
+    public Session login() throws RepositoryException {
         return login(null, null);
     }
 

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseSession.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseSession.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseSession.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseSession.java Wed Oct 26 23:39:12 2005
@@ -20,17 +20,15 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.security.AccessControlException;
+import java.util.regex.Pattern;
 
-import javax.jcr.AccessDeniedException;
 import javax.jcr.Credentials;
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.InvalidSerializedDataException;
 import javax.jcr.Item;
-import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
-import javax.jcr.LoginException;
+import javax.jcr.ItemVisitor;
 import javax.jcr.NamespaceException;
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
@@ -38,98 +36,216 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.ValueFactory;
 import javax.jcr.Workspace;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.VersionException;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.XMLSerializer;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.xml.DocumentViewExportVisitor;
+import org.apache.jackrabbit.xml.SystemViewExportVisitor;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
 /**
- * Session base class.
+ * Session base class. The dummy session implemented by this class
+ * attempts to act like a read-only anonymous session. Subclasses must
+ * override at least the {@link #getRepository() getRepository()},
+ * {@link #getWorkspace() getWorkspace()},
+ * {@link #getRootNode() getRootNode()}, and
+ * {@link #getValueFactory() getValueFactory()} methods to make this class
+ * somewhat useful. See the method javadocs for full details of which
+ * methods to override for each required feature.
  */
 public class BaseSession implements Session {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BaseSession() {
-    }
+    /** The pattern used to match UUID strings. */
+    private static final Pattern UUID_PATTERN = Pattern.compile(
+            "[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}");
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Unsupported operation. Subclasses should override this method to
+     * return the repository to which this session is attached.
+     * Overiding this method is required for the default implementation of the
+     * {@link #impersonate(Credentials) impersonate(Credentials)} method.
+     *
+     * @return nothing, throws a {@link UnsupportedOperationException}
+     * @see Session#getRepository()
+     */
     public Repository getRepository() {
         throw new UnsupportedOperationException();
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Returns <code>null</code> to indicate that this session is associated
+     * with the "anonymous" user. Subclasses should override this method to
+     * return the actual user identity associated with the session.
+     *
+     * @return always <code>null</code>
+     * @see Session#getUserID()
+     */
     public String getUserID() {
-        throw new UnsupportedOperationException();
+        return null;
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Returns <code>null</code> to indicate that the named attribute does
+     * not exist. Subclasses should override this method to return the
+     * available attribute values.
+     *
+     * @param name attribute name
+     * @return always <code>null</code>
+     * @see Session#getAttribute(String)
+     */
     public Object getAttribute(String name) {
-        throw new UnsupportedOperationException();
+        return null;
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Returns an empty string array to indicate that no attributes are
+     * available. Subclasses should override this method to return the
+     * available attribute names.
+     *
+     * @return empty array
+     * @see Session#getAttributeNames()
+     */
     public String[] getAttributeNames() {
-        throw new UnsupportedOperationException();
+        return new String[0];
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Unsupported operation. Subclasses should override this method to
+     * return the workspace attached to this session. Overiding this method
+     * is required for the default implementations of the
+     * {@link #impersonate(Credentials) impersonate(Credentials)} and
+     * {@link #getNodeByUUID(String) getNodeByUUID(String)} methods.
+     *
+     * @return nothing, throws a {@link UnsupportedOperationException}
+     * @see Session#getWorkspace()
+     */
     public Workspace getWorkspace() {
         throw new UnsupportedOperationException();
     }
 
     /**
-     * Implemented by calling
-     * <code>getRepository().login(credentials, getWorkspace().getName())</code>.
-     * {@inheritDoc}
+     * Implemented by calling the
+     * {@link Repository#login(Credentials, String) login(Credentials, String)}
+     * method of the {@link Repository} instance returned by the
+     * {@link #getRepository() getRepository()} method. The method is invoked
+     * with the given login credentials and the workspace name returned by
+     * the {@link Workspace#getName() getName()} method of the
+     * {@link Workspace} instance returned by the
+     * {@link #getWorkspace() getWorkspace()} method.
+     * <p>
+     * There should normally be little need for subclasses to override this
+     * method unless the underlying repository implementation suggests a
+     * more straightforward implementation.
+     *
+     * @param credentials login credentials
+     * @return impersonated session
+     * @see Session#impersonate(Credentials)
      */
-    public Session impersonate(Credentials credentials) throws LoginException,
-            RepositoryException {
+    public Session impersonate(Credentials credentials)
+            throws RepositoryException {
         return getRepository().login(credentials, getWorkspace().getName());
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Unsupported operation. Subclasses should override this method to
+     * return the root node in the workspace attached to this session.
+     * Overriding this method is required for the default implementation of
+     * the {@link #getItem(String) getItem(String)} method.
+     *
+     * @return nothing, throws a {@link UnsupportedRepositoryOperationException}
+     * @see Session#getRootNode()
+     */
     public Node getRootNode() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Not implemented. {@inheritDoc} */
-    public Node getNodeByUUID(String uuid) throws ItemNotFoundException,
-            RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+    /**
+     * Implemented by making the XPath query <code>//*[@jcr:uuid='...']</code>
+     * and returning the node that matches the query. Subclasses may want to
+     * override this method if an UUID index or another more efficient
+     * lookup mechanism can be used directly.
+     *
+     * @return the identified node
+     * @throws ItemNotFoundException if the identified node does not exist
+     * @see Session#getNodeByUUID(String)
+     */
+    public Node getNodeByUUID(String uuid) throws RepositoryException {
+        if (UUID_PATTERN.matcher(uuid).matches()) {
+            String xpath;
+            String jcr = getNamespacePrefix(QName.NS_JCR_URI);
+            if (jcr.length() > 0) {
+                xpath = "//*[@" + jcr + ":uuid='" + uuid + "']";
+            } else {
+                xpath = "//*[@uuid='" + uuid + "']";
+            }
+            Query query =
+                getWorkspace().getQueryManager().createQuery(Query.XPATH, xpath);
+            QueryResult result = query.execute();
+            NodeIterator nodes = result.getNodes();
+            if (nodes.hasNext()) {
+                return nodes.nextNode();
+            }
+        }
+        throw new ItemNotFoundException(uuid);
     }
 
     /**
-     * Implemented by calling <code>getRootNode()</code> or
-     * <code>getRootNode().getNode(absPath.substring(1))</code> depending
-     * on the given absolute path.
-     * {@inheritDoc}
+     * Implemented by invoking the {@link Node#getNode(String) getNode(String)}
+     * (or {@link Node#getProperty(String) getProperty(String)} if getNode
+     * fails) method on the root node returned by the
+     * {@link #getRootNode() getRootNode()} method. The path given to the
+     * getNode or getProperty method is the given path without the leading "/".
+     * If the given path is "/" then the root node is returned directly.
+     * <p>
+     * Subclasses should not normally need to override this method as long as
+     * the referenced methods have been implemented. For performance reasons
+     * it might make sense to override this method because this implementation
+     * can cause the item path to be traversed twice.
+     *
+     * @param absPath absolute item path
+     * @return identified item
+     * @see Session#getItem(String)
      */
     public Item getItem(String absPath) throws PathNotFoundException,
             RepositoryException {
         if (absPath == null || !absPath.startsWith("/")) {
-            throw new IllegalArgumentException("Invalid path: " + absPath);
-        } else if (absPath.equals("/")) {
-            return getRootNode();
+            throw new PathNotFoundException("Invalid item path: " + absPath);
+        }
+
+        Node node = getRootNode();
+        if (absPath.equals("/")) {
+            return node;
         } else {
-            return getRootNode().getNode(absPath.substring(1));
+            String relPath = absPath.substring(1);
+            try {
+                return node.getNode(relPath);
+            } catch (PathNotFoundException e) {
+                return node.getProperty(relPath);
+            }
         }
     }
 
     /**
-     * Implemented by calling <code>getItem(absPath)</code> and returning
-     * <code>true</code> unless a
-     * {@link PathNotFoundException PathNotFoundException} is thrown.
-     * {@inheritDoc}
+     * Implemented by trying to retrieve the identified item using the
+     * {@link #getItem(String) getItem(String)} method. Subclasses may
+     * want to override this method for performance as there is no real
+     * need for instantiating the identified item.
+     *
+     * @param absPath absolute item path
+     * @return <code>true</code> if the identified item exists,
+     *         <code>false</code> otherwise
+     * @see Session#itemExists(String)
      */
     public boolean itemExists(String absPath) throws RepositoryException {
         try {
@@ -140,60 +256,106 @@
         }
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Unsupported operation. Subclasses should override this method to
+     * make it possible to move and rename items.
+     *
+     * @param srcAbsPath source item path
+     * @param destAbsPath destination item path 
+     * @see Session#move(String, String)
+     */
     public void move(String srcAbsPath, String destAbsPath)
-            throws ItemExistsException, PathNotFoundException,
-            VersionException, RepositoryException {
+            throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Not implemented. {@inheritDoc} */
-    public void save() throws AccessDeniedException,
-            ConstraintViolationException, InvalidItemStateException,
-            VersionException, LockException, RepositoryException {
+    /**
+     * Unsupported operation. Subclasses should override this method to
+     * allow modifications to the content repository.
+     *
+     * @see Session#save()
+     */
+    public void save() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Does nothing. Subclasses should override this method to correctly
+     * manage the transient state and underlying repository changes. 
+     *
+     * @param keepChanges whether to keep transient changes (ignored)
+     * @see Session#refresh(boolean)
+     */
     public void refresh(boolean keepChanges) throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Returns <code>false</code> to indicate that there are no pending
+     * changes. Subclasses should override this method to correctly manage
+     * the transient state.
+     *
+     * @return always <code>false</code>
+     * @see Session#hasPendingChanges()
+     */
     public boolean hasPendingChanges() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return false;
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Throws an {@link AccessControlException} for anything else than
+     * <code>read</code> actions to indicate that only read access is
+     * permitted. Subclasses should override this method to correctly
+     * report access controls settings.
+     *
+     * @param absPath item path
+     * @param actions action strings
+     * @throws AccessControlException if other than <code>read</code> actions
+     *                                are requested
+     * @see Session#checkPermission(String, String)
+     */
     public void checkPermission(String absPath, String actions)
             throws AccessControlException {
-        throw new UnsupportedOperationException();
+        String[] parts = actions.split(",");
+        for (int i = 0; i < parts.length; i++) {
+            if (!"read".equals(parts[i])) {
+                throw new AccessControlException(
+                        "No " + actions + " permission for " + absPath);
+            }
+        }
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Unsupported operation. Subclasses should override this method to
+     * support XML imports. Overriding this method is required for the
+     * default implementation of the
+     * {@link #importXML(String, InputStream, int) importXML(String, InputStream, int)}
+     * method.
+     *
+     * @param parentAbsPath path of the parent node
+     * @param uuidBehaviour UUID behaviour flag
+     * @return nothing, throws an {@link UnsupportedRepositoryOperationException}
+     * @see Session#getImportContentHandler(String, int)
+     */
     public ContentHandler getImportContentHandler(
             String parentAbsPath, int uuidBehaviour)
-            throws PathNotFoundException, ConstraintViolationException,
-            VersionException, LockException, RepositoryException {
+            throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
     /**
-     * Implemented by calling
-     * <code>transformer.transform(new StreamSource(in), new SAXResult(handler))</code>
-     * with an identity {@link Transformer Transformer} and a
-     * {@link ContentHandler ContentHandler} instance created by calling
-     * <code>getImportContentHandler(parentAbsPath)</code>. Possible
-     * {@see TransformerException TransformerExceptions} and
-     * {@see TransformerConfigurationException TransformerConfigurationExceptions}
-     * are converted to {@link IOException IOExceptions}.
-     * {@inheritDoc}
+     * Parses the XML input stream and feeds the SAX events to the content
+     * handler returned by the
+     * {@link #getImportContentHandler(String, int) getImportContentHandler(String, int)}
+     * method.
+     *
+     * @param parentAbsPath path of the parent node
+     * @param in XML input stream
+     * @param uuidBehaviour UUID behaviour flag
+     * @see Session#importXML(String, InputStream, int)
      */
     public void importXML(
             String parentAbsPath, InputStream in, int uuidBehaviour)
-            throws IOException, PathNotFoundException, ItemExistsException,
-            ConstraintViolationException, VersionException,
-            InvalidSerializedDataException, LockException, RepositoryException {
+            throws IOException, RepositoryException {
         try {
             ContentHandler handler =
                 getImportContentHandler(parentAbsPath, uuidBehaviour);
@@ -210,137 +372,241 @@
         }
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Creates a {@link SystemViewExportVisitor} instance and passes it
+     * to the node identified by the given path. The export visitor traverses
+     * the entire content tree and generates the system view SAX events for
+     * the given content handler. Subclasses may override this method for
+     * better performance or custom processing, but the default implementation
+     * should be good enough for general use.
+     * 
+     * @param absPath node path
+     * @param contentHandler SAX content handler
+     * @param skipBinary binary property skip flag
+     * @param noRecurse subtree recursion flag
+     * @see Session#exportSystemView(String, ContentHandler, boolean, boolean)
+     */
     public void exportSystemView(
             String absPath, ContentHandler contentHandler,
             boolean skipBinary, boolean noRecurse)
-            throws PathNotFoundException, SAXException, RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+            throws SAXException, RepositoryException {
+        Item item = getItem(absPath);
+        if (item.isNode()) {
+            ItemVisitor visitor = new SystemViewExportVisitor(
+                    contentHandler, skipBinary, noRecurse); 
+            item.accept(visitor);
+        } else {
+            throw new PathNotFoundException("Invalid node path: " + absPath);
+        }
     }
 
     /**
-     * Implemented by calling
-     * <code>exportSysView(absPath, handler, binaryAsLink, noRecurse)</code>
-     * with a content handler instance <code>handler</code> created on
-     * top fo the given output stream using the Xerces
-     * {@link XMLSerializer XMLSerializer} class. Possible
-     * {@link SAXException SAXExceptions} are converted to
-     * {@link IOException IOExceptions}.
-     * {@inheritDoc}
-     */
-    public void exportSystemView(String absPath, OutputStream out,
-            boolean skipBinary, boolean noRecurse) throws IOException,
-            PathNotFoundException, RepositoryException {
+     * Creates a SAX serializer for the given output stream and passes it to the
+     * {@link #exportSystemView(String, ContentHandler, boolean, boolean) exportSystemView(String, ContentHandler, boolean, boolean)}
+     * method along with the other parameters.
+     *
+     * @param absPath node path
+     * @param out XML output stream
+     * @param skipBinary binary property skip flag
+     * @param noRecurse subtree recursion flag
+     * @see Session#exportSystemView(String, OutputStream, boolean, boolean)
+     */
+    public void exportSystemView(
+            String absPath, OutputStream out,
+            boolean skipBinary, boolean noRecurse)
+            throws IOException, RepositoryException {
         try {
-            XMLSerializer serializer =
-                new XMLSerializer(out, new OutputFormat());
-            exportSystemView(
-                    absPath, serializer.asContentHandler(),
-                    skipBinary, noRecurse);
+            SAXTransformerFactory factory = (SAXTransformerFactory)
+                SAXTransformerFactory.newInstance();
+            TransformerHandler handler = factory.newTransformerHandler();
+            handler.setResult(new StreamResult(out));
+            exportSystemView(absPath, handler, skipBinary, noRecurse);
+        } catch (TransformerConfigurationException e) {
+            throw new IOException(
+                    "Unable to configure a SAX transformer: " + e.getMessage());
         } catch (SAXException e) {
             throw new IOException(
                     "Unable to serialize a SAX stream: " + e.getMessage());
         }
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Creates a {@link DocumentViewExportVisitor} instance and passes it
+     * to the node identified by the given path. The export visitor traverses
+     * the entire content tree and generates the document view SAX events for
+     * the given content handler. Subclasses may override this method for
+     * better performance or custom processing, but the default implementation
+     * should be good enough for general use.
+     * 
+     * @param absPath node path
+     * @param contentHandler SAX content handler
+     * @param skipBinary binary property skip flag
+     * @param noRecurse subtree recursion flag
+     * @see Session#exportDocumentView(String, ContentHandler, boolean, boolean)
+     */
     public void exportDocumentView(
             String absPath, ContentHandler contentHandler,
             boolean skipBinary, boolean noRecurse)
-            throws InvalidSerializedDataException, PathNotFoundException,
-            SAXException, RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+            throws SAXException, RepositoryException {
+        Item item = getItem(absPath);
+        if (item.isNode()) {
+            ItemVisitor visitor = new DocumentViewExportVisitor(
+                    contentHandler, skipBinary, noRecurse); 
+            item.accept(visitor);
+        } else {
+            throw new PathNotFoundException("Invalid node path: " + absPath);
+        }
     }
 
     /**
-     * Implemented by calling
-     * <code>exportDocView(absPath, handler, binaryAsLink, noRecurse)</code>
-     * with a content handler instance <code>handler</code> created on
-     * top fo the given output stream using the Xerces
-     * {@link XMLSerializer XMLSerializer} class. Possible
-     * {@link SAXException SAXExceptions} are converted to
-     * {@link IOException IOExceptions}.
-     * {@inheritDoc}
+     * Creates a SAX serializer for the given output stream and passes it to the
+     * {@link #exportDocumentView(String, ContentHandler, boolean, boolean) exportDocumentView(String, ContentHandler, boolean, boolean)}
+     * method along with the other parameters.
+     *
+     * @param absPath node path
+     * @param out XML output stream
+     * @param skipBinary binary property skip flag
+     * @param noRecurse subtree recursion flag
+     * @see Session#exportDocumentView(String, OutputStream, boolean, boolean)
      */
     public void exportDocumentView(
             String absPath, OutputStream out,
             boolean skipBinary, boolean noRecurse)
-            throws InvalidSerializedDataException, IOException,
-            PathNotFoundException, RepositoryException {
+            throws IOException, RepositoryException {
         try {
-            XMLSerializer serializer =
-                new XMLSerializer(out, new OutputFormat("xml", "UTF-8", true));
-            exportDocumentView(
-                    absPath, serializer.asContentHandler(),
-                    skipBinary, noRecurse);
+            SAXTransformerFactory factory = (SAXTransformerFactory)
+                SAXTransformerFactory.newInstance();
+            TransformerHandler handler = factory.newTransformerHandler();
+            handler.setResult(new StreamResult(out));
+            exportDocumentView(absPath, handler, skipBinary, noRecurse);
+        } catch (TransformerConfigurationException e) {
+            throw new IOException(
+                    "Unable to configure a SAX transformer: " + e.getMessage());
         } catch (SAXException e) {
             throw new IOException(
                     "Unable to serialize a SAX stream: " + e.getMessage());
         }
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Unsupported operation. Subclasses should override this method to
+     * support namespace remapping.
+     *
+     * @param prefix namespace prefix
+     * @param uri namespace uri
+     * @see Session#setNamespacePrefix(String, String)
+     */
     public void setNamespacePrefix(String prefix, String uri)
             throws NamespaceException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Returns the namespace prefixes registered in the
+     * {@link javax.jcr.NamespaceRegistry} associated with the workspace of
+     * this session. Subclasses should override this method to support
+     * namespace remapping.
+     *
+     * @return namespace prefixes
+     * @see Session#getNamespacePrefixes()
+     */
     public String[] getNamespacePrefixes() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return getWorkspace().getNamespaceRegistry().getPrefixes();
     }
 
-    /** Not implemented. {@inheritDoc} */
-    public String getNamespaceURI(String prefix) throws NamespaceException,
-            RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+    /**
+     * Returns the namespace URI registered for the given prefix in the
+     * {@link javax.jcr.NamespaceRegistry} associated with the workspace of
+     * this session. Subclasses should override this method to support
+     * namespace remapping.
+     *
+     * @param prefix namespace prefix
+     * @return namespace URI
+     * @see Session#getNamespaceURI(String)
+     */
+    public String getNamespaceURI(String prefix) throws RepositoryException {
+        return getWorkspace().getNamespaceRegistry().getURI(prefix);
     }
 
     /**
-     * Implemented by iterating over the prefix array returned by
-     * <code>getNamespacePrefixes()</code> and calling
-     * <code>getNamespaceURI(prefix)</code> repeatedly until a match
-     * is found for the given namespace URI.
-     * {@inheritDoc}
+     * Returns the namespace prefix registered for the given URI in the
+     * {@link javax.jcr.NamespaceRegistry} associated with the workspace of
+     * this session. Subclasses should override this method to support
+     * namespace remapping.
+     *
+     * @param uri namespace URI
+     * @return namespace prefix
+     * @see Session#getNamespacePrefix(String)
      */
-    public String getNamespacePrefix(String uri) throws NamespaceException,
-            RepositoryException {
-        String[] prefixes = getNamespacePrefixes();
-        for (int i = 0; i < prefixes.length; i++) {
-            if (uri.equals(getNamespaceURI(prefixes[i]))) {
-                return prefixes[i];
-            }
-        }
-        throw new NamespaceException("Unknown namespace URI " + uri);
+    public String getNamespacePrefix(String uri) throws RepositoryException {
+        return getWorkspace().getNamespaceRegistry().getPrefix(uri);
     }
 
-    /** Does nothing. {@inheritDoc} */
+    /**
+     * Does nothing. Subclasses should override this method to actually
+     * close this session.
+     *
+     * @see Session#logout()
+     */
     public void logout() {
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Unsupported operation. Subclasses should override this method to support
+     * lock token management.
+     *
+     * @param lock token
+     * @see Session#addLockToken(String)
+     */
     public void addLockToken(String lt) {
         throw new UnsupportedOperationException();
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Returns an empty string array to indicate that no lock tokens are held
+     * by this session. Subclasses should override this method to return the
+     * actual lock tokens held by this session.
+     *
+     * @return empty array
+     * @see Session#getLockTokens()
+     */
     public String[] getLockTokens() {
-        throw new UnsupportedOperationException();
+        return new String[0];
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Unsupported operation. Subclasses should override this method to support
+     * lock token management.
+     *
+     * @param lock token
+     * @see Session#removeLockToken(String)
+     */
     public void removeLockToken(String lt) {
         throw new UnsupportedOperationException();
     }
 
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Unsupported operation. Subclasses should override this method to
+     * allow the creation of new {@link javax.jcr.Value Value} instances.
+     *
+     * @param lock token
+     * @see Session#removeLockToken(String)
+     */
     public ValueFactory getValueFactory()
             throws UnsupportedRepositoryOperationException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Always returns <code>true</code>. {@inheritDoc} */
+    /**
+     * Returns <code>true</code> to indicate that the session has not been
+     * closed. Subclasses should override this method to correctly report
+     * the state of the session.
+     *
+     * @return always <code>true</code>
+     * @see Session#isLive()
+     */
     public boolean isLive() {
         return true;
     }
+
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseWorkspace.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseWorkspace.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseWorkspace.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseWorkspace.java Wed Oct 26 23:39:12 2005
@@ -51,9 +51,8 @@
  */
 public class BaseWorkspace implements Workspace {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BaseWorkspace() {
-    }
+    private static final NamespaceRegistry NAMESPACE_REGISTRY =
+        new BaseNamespaceRegistry();
 
     /** Not implemented. {@inheritDoc} */
     public Session getSession() {
@@ -116,7 +115,7 @@
 
     /** Not implemented. {@inheritDoc} */
     public NamespaceRegistry getNamespaceRegistry() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return NAMESPACE_REGISTRY;
     }
 
     /** Not implemented. {@inheritDoc} */
@@ -132,7 +131,7 @@
 
     /** Not implemented. {@inheritDoc} */
     public String[] getAccessibleWorkspaceNames() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return new String[] { getName() };
     }
 
     /** Not implemented. {@inheritDoc} */

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseItemDefinition.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseItemDefinition.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseItemDefinition.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseItemDefinition.java Wed Oct 26 23:39:12 2005
@@ -25,10 +25,6 @@
  */
 public class BaseItemDefinition implements ItemDefinition {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BaseItemDefinition() {
-    }
-
     /** Not implemented. {@inheritDoc} */
     public NodeType getDeclaringNodeType() {
         throw new UnsupportedOperationException();

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeDefinition.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeDefinition.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeDefinition.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeDefinition.java Wed Oct 26 23:39:12 2005
@@ -24,10 +24,6 @@
  */
 public class BaseNodeDefinition extends BaseItemDefinition implements NodeDefinition {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BaseNodeDefinition() {
-    }
-
     /** Always returns an empty node type array. {@inheritDoc} */
     public NodeType[] getRequiredPrimaryTypes() {
         return new NodeType[0];

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeType.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeType.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeType.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeType.java Wed Oct 26 23:39:12 2005
@@ -31,10 +31,6 @@
  */
 public class BaseNodeType implements NodeType {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BaseNodeType() {
-    }
-
     /** Not implemented. {@inheritDoc} */
     public String getName() {
         throw new UnsupportedOperationException();

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeTypeManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeTypeManager.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeTypeManager.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BaseNodeTypeManager.java Wed Oct 26 23:39:12 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.base.nodetype;
 
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Vector;
 
 import javax.jcr.RepositoryException;
@@ -32,22 +34,29 @@
  */
 public class BaseNodeTypeManager implements NodeTypeManager {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BaseNodeTypeManager() {
-    }
-
-    /** Not implemented. {@inheritDoc} */
+    /**
+     * Returns an empty node type iterator. Subclasses should override this
+     * method to return the available node types.
+     *
+     * @return empty node type iterator
+     * @see NodeTypeManager#getAllNodeTypes()
+     */
     public NodeTypeIterator getAllNodeTypes() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return new ArrayNodeTypeIterator(new NodeType[0]);
     }
 
     /**
-     * Implemented by calling <code>getAllNodeTypes()</code> and iterating
-     * through the returned node types to find the named node type.
-     * {@inheritDoc}
+     * Iterates through the node types returned by the
+     * {@link #getAllNodeTypes() getAllNodeTypes()} method and returns the
+     * node type with the given name. If a matching node type is not found,
+     * then a {@link NoSuchNodeTypeException} is thrown. Subclasses may
+     * want to override this method for better performance.
+     *
+     * @param node type name
+     * @return named node type
+     * @see NodeTypeManager#getNodeType(String)
      */
-    public NodeType getNodeType(String nodeTypeName)
-            throws NoSuchNodeTypeException, RepositoryException {
+    public NodeType getNodeType(String nodeTypeName) throws RepositoryException {
         NodeTypeIterator types = getAllNodeTypes();
         while (types.hasNext()) {
             NodeType type = types.nextNodeType();
@@ -59,12 +68,16 @@
     }
 
     /**
-     * Implemented by calling <code>getAllNodeTypes()</code> and iterating
-     * through the returned node types to select all primary node types.
-     * {@inheritDoc}
+     * Iterates through the node types returned by the
+     * {@link #getAllNodeTypes() getAllNodeTypes()} method and returns an
+     * {@link ArrayNodeTypeIterator} containing all the primary node types.
+     * Subclasses may want to override this method for better performance.
+     *
+     * @return primary node types
+     * @see NodeTypeManager#getPrimaryNodeTypes()
      */
     public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException {
-        Vector primaryTypes = new Vector();
+        List primaryTypes = new LinkedList();
 
         NodeTypeIterator types = getAllNodeTypes();
         while (types.hasNext()) {
@@ -78,17 +91,21 @@
     }
 
     /**
-     * Implemented by calling <code>getAllNodeTypes()</code> and iterating
-     * through the returned node types to select all mixin node types.
-     * {@inheritDoc}
+     * Iterates through the node types returned by the
+     * {@link #getAllNodeTypes() getAllNodeTypes()} method and returns an
+     * {@link ArrayNodeTypeIterator} containing all the mixin node types.
+     * Subclasses may want to override this method for better performance.
+     *
+     * @return mixin node types
+     * @see NodeTypeManager#getMixinNodeTypes()
      */
     public NodeTypeIterator getMixinNodeTypes() throws RepositoryException {
-        Vector mixinTypes = new Vector();
+        List mixinTypes = new LinkedList();
 
         NodeTypeIterator types = getAllNodeTypes();
         while (types.hasNext()) {
             NodeType type = types.nextNodeType();
-            if (!type.isMixin()) {
+            if (type.isMixin()) {
                 mixinTypes.add(type);
             }
         }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BasePropertyDefinition.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BasePropertyDefinition.java?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BasePropertyDefinition.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/nodetype/BasePropertyDefinition.java Wed Oct 26 23:39:12 2005
@@ -26,10 +26,6 @@
 public class BasePropertyDefinition extends BaseItemDefinition
         implements PropertyDefinition {
 
-    /** Protected constructor. This class is only useful when extended. */
-    protected BasePropertyDefinition() {
-    }
-
     /** Always returns <code>PropertyType.UNDEFINED</code>. {@inheritDoc} */
     public int getRequiredType() {
         return PropertyType.UNDEFINED;

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/package.html?rev=328807&r1=328806&r2=328807&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/package.html (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/package.html Wed Oct 26 23:39:12 2005
@@ -4,7 +4,7 @@
 This package contains simple base class implementations of the JCR API
 interfaces. These classes implement the API methods either by throwing
 Unsupported(Repository)OperationExceptions or by calling other API methods.
-For example the Property.getString() method is implemented as
+For example the BaseProperty.getString() method is implemented as
 Property.getValue().getString(). See the javadoc comments of each method
 for implementation details.
 </p>
@@ -22,21 +22,18 @@
 </p>
 <ul>
   <li>
-    No member variables. To avoid introducing any extra memory overhead
-    or complex state and object equality issues, none of these base classes
-    have any member variables, private or otherwise.
+    <strong>No member variables.</strong> To avoid introducing any extra
+    memory overhead or complex state and object equality issues, none of
+    these base classes have <em>any</em> member variables, private or
+    otherwise. However the implemented methods are free to use as many
+    local variables as they like.
   </li>
   <li>
-    Protected default constructors. Each base class contains only an empty
-    protected default constructor. This guarantees that these classes can not
-    be instantiated unless subclassed.
-  </li>
-  <li>
-    No extra methods. The only non-private methods defined in these base
-    classes are the empty protected default constructor and the public
-    methods declared in the JCR interfaces. Private utility methods are
-    allowed to avoid duplicating code, but no protected or public methods
-    other than those declared by the JCR API are allowed.
+    <strong>No extra methods.</strong> The only non-private methods defined
+    in these base classes are the public methods declared in the JCR
+    interfaces. Private utility methods are allowed to avoid duplicating code,
+    but <em>no</em> protected or public methods other than those declared by
+    the JCR API are allowed.
   </li>
 </ul>
 </body>



Mime
View raw message