jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r169146 - in /incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base: BaseItem.java BaseNamespaceRegistry.java BaseNode.java BaseProperty.java BaseRepository.java BaseSession.java BaseWorkspace.java package.html
Date Sun, 08 May 2005 17:47:18 GMT
Author: jukka
Date: Sun May  8 10:47:17 2005
New Revision: 169146

URL: http://svn.apache.org/viewcvs?rev=169146&view=rev
Log:
JCR-EXT: Cleaning up and upgrading to 0.16.4.1 (work in progress, does not compile!)

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/BaseProperty.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/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=169146&r1=169145&r2=169146&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 Sun May  8 10:47:17 2005
@@ -31,183 +31,130 @@
 import javax.jcr.version.VersionException;
 
 /**
- * TODO
+ * Item base class.
  */
 public class BaseItem implements Item {
-    
-    private Item item;
 
+    /** Protected constructor. This class is only useful when extended. */
     protected BaseItem() {
-        this.item = null;
     }
 
-    protected BaseItem(Item item) {
-        this.item = item;
-    }
-
-    protected void setProxyItem(Item item) {
-        this.item = item;
-    }
-
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getParent().getPath()</code> and
+     * appending <code>getName()</code> to the returned parent path.
+     * Returns the root path <code>/</code> if an
+     * {@link ItemNotFoundException ItemNotFoundException} is thrown by
+     * <code>getParent()</code> (indicating that this is the root node).
+     * {@inheritDoc}
+     */
     public String getPath() throws RepositoryException {
-        if (item != null) {
-            return item.getPath();
-        } else {
-            try {
-                Node parent = getParent();
-                String path = parent.getPath();
-                if (path.equals("/")) {
-                    return path + getName();
-                } else {
-                    return path + "/" + getName();
-                }
-            } catch (ItemNotFoundException e) {
-                return "/";
+        try {
+            String path = getParent().getPath();
+            if (path.equals("/")) {
+                return path + getName();
+            } else {
+                return path + "/" + getName();
             }
+        } catch (ItemNotFoundException e) {
+            return "/";
         }
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String getName() throws RepositoryException {
-        if (item != null) {
-            return item.getName();
-        } else {
-            throw new UnsupportedRepositoryOperationException();
-        }
+        throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getDepth()</code> and returning either
+     * this item, <code>getSession().getRootNode()</code>, or
+     * <code>getParent().getAncestor()</code>, or throwing an
+     * {@link ItemNotFoundException ItemNotFoundException} depending on the
+     * given depth.
+     * {@inheritDoc}
+     */
     public Item getAncestor(int depth) throws ItemNotFoundException,
             AccessDeniedException, RepositoryException {
-        if (item != null) {
-            return item.getAncestor(depth);
+        int thisDepth = getDepth();
+        if (thisDepth == depth) {
+            return this;
+        } else if (depth == 0) {
+            return getSession().getRootNode();
+        } else if (depth > 0 && depth < thisDepth) {
+            return getParent().getAncestor(depth);
         } else {
-            int thisDepth = getDepth();
-            if (depth >= 0 || depth < thisDepth) {
-                return getParent().getAncestor(depth);
-            } else if (thisDepth == depth) {
-                return this;
-            } else {
-                throw new ItemNotFoundException(
-                        "Invalid ancestor depth " + depth);
-            }
+            throw new ItemNotFoundException("Invalid ancestor depth " + depth);
         }
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Node getParent() throws ItemNotFoundException,
             AccessDeniedException, RepositoryException {
-        if (item != null) {
-            return item.getParent();
-        } else {
-            throw new UnsupportedRepositoryOperationException();
-        }
+        throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getParent().getDepth() + 1</code> and
+     * returning <code>0</code> if an
+     * {@link ItemNotFoundException ItemNotFoundException} is thrown by
+     * <code>getParent()</code> (indicating that this is the root node).
+     * {@inheritDoc}
+     */
     public int getDepth() throws RepositoryException {
-        if (item != null) {
-            return item.getDepth();
-        } else {
-            try {
-                return getParent().getDepth() + 1;
-            } catch (ItemNotFoundException e) {
-                return 0;
-            }
+        try {
+            return getParent().getDepth() + 1;
+        } catch (ItemNotFoundException e) {
+            return 0;
         }
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Session getSession() throws RepositoryException {
-        if (item != null) {
-            return item.getSession();
-        } else {
-            throw new UnsupportedRepositoryOperationException();
-        }
+        throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Always returns <code>false</code>. {@inheritDoc} */
     public boolean isNode() {
-        if (item != null) {
-            return item.isNode();
-        } else {
-            return this instanceof Node;
-        }
+        return false;
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public boolean isNew() {
-        if (item != null) {
-            return item.isNew();
-        } else {
-            throw new UnsupportedOperationException();
-        }
+        throw new UnsupportedOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public boolean isModified() {
-        if (item != null) {
-            return item.isModified();
-        } else {
-            throw new UnsupportedOperationException();
-        }
+        throw new UnsupportedOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public boolean isSame(Item otherItem) {
-        try {
-            if (item != null) {
-                return item.isSame(otherItem);
-            } else if (otherItem == this) {
-                return true;
-            } else {
-                return getPath().equals(otherItem.getPath());
-            }
-        } catch (RepositoryException e) {
-            throw new RuntimeException(e);
-        }
+        throw new UnsupportedOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Does nothing. {@inheritDoc} */
     public void accept(ItemVisitor visitor) throws RepositoryException {
-        if (item != null) {
-            item.accept(visitor);
-        } else {
-            throw new UnsupportedRepositoryOperationException();
-        }
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void save() throws AccessDeniedException,
             ConstraintViolationException, InvalidItemStateException,
             ReferentialIntegrityException, VersionException, LockException,
             RepositoryException {
-        if (item != null) {
-            item.save();
-        } else {
-            throw new UnsupportedRepositoryOperationException();
-        }
+        throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void refresh(boolean keepChanges) throws InvalidItemStateException,
             RepositoryException {
-        if (item != null) {
-            item.refresh(keepChanges);
-        } else {
-            throw new UnsupportedRepositoryOperationException();
-        }
+        throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void remove() throws VersionException, LockException,
             RepositoryException {
-        if (item != null) {
-            item.remove();
-        } else {
-            throw new UnsupportedRepositoryOperationException();
-        }
+        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=169146&r1=169145&r2=169146&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 Sun May  8 10:47:17 2005
@@ -22,38 +22,35 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 
 /**
- * General base class for implementing the JCR NamespaceRegistry interface.
+ * NamespaceRegistry base class.
  */
 public class BaseNamespaceRegistry implements NamespaceRegistry {
 
-    /**
-     * The default constructor is protected to signify that this
-     * class needs to be subclassed to be of any real use.
-     */
+    /** Protected constructor. This class is only useful when extended. */
     protected BaseNamespaceRegistry() {
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void registerNamespace(String prefix, String uri)
             throws NamespaceException, UnsupportedRepositoryOperationException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void unregisterNamespace(String prefix) throws NamespaceException,
             UnsupportedRepositoryOperationException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String[] getPrefixes() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
     /**
-     * Implemented by mapping all prefixes returned by
-     * <code>getPrefixes()</code> into namespace URIs using
+     * Implemented by calling <code>getPrefixes()</code> and
+     * mapping all returned prefixes into namespace URIs using
      * <code>getURI(prefix)</code>.
      * {@inheritDoc}
      */
@@ -66,15 +63,15 @@
         return uris;
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String getURI(String prefix) throws NamespaceException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
     /**
-     * Implemented by iterating over the prefixes returned by
-     * <code>getPrefixes()</code> and selecting the prefix for which
+     * 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}
      */
@@ -86,8 +83,7 @@
                 return prefixes[i];
             }
         }
-        throw new NamespaceException(
-                "Namespace URI " + uri + " is not registered.");
+        throw new NamespaceException("Namespace URI not registered: " + uri);
     }
 
 }

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=169146&r1=169145&r2=169146&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 Sun May  8 10:47:17 2005
@@ -20,82 +20,99 @@
 import java.util.Calendar;
 
 import javax.jcr.AccessDeniedException;
-import javax.jcr.BinaryValue;
-import javax.jcr.BooleanValue;
-import javax.jcr.DateValue;
-import javax.jcr.DoubleValue;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.Item;
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.ItemVisitor;
-import javax.jcr.LongValue;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
-import javax.jcr.ReferenceValue;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.StringValue;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
+import javax.jcr.ValueFactory;
 import javax.jcr.ValueFormatException;
 import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.nodetype.NodeDef;
+import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
 
+import org.apache.jackrabbit.name.Path;
+
 /**
- * TODO
+ * Node base class.
  */
 public class BaseNode extends BaseItem implements Node {
 
+    /** Protected constructor. This class is only useful when extended. */
     protected BaseNode() {
     }
 
-    protected BaseNode(Item item) {
-        super(item);
-    }
-
+    /**
+     * Implemented by calling <code>super.getPath()</code>
+     * (see {@link BaseItem#getPath() BaseItem.getPath()} and appending
+     * <code>"[" + getIndex() + "]"</code> if
+     * <code>getDefinition().allowsSameNameSiblings()</code> returns
+     * <code>true</code>.
+     * {@inheritDoc}
+     */
     public String getPath() throws RepositoryException {
-        if (getDefinition().allowSameNameSibs()) {
+        if (getDefinition().allowsSameNameSiblings()) {
             return super.getPath() + "[" + getIndex() + "]";
         } else {
             return super.getPath();
         }
     }
 
+    /**
+     * Implemented by calling <code>visitor.visit(this)</code>.
+     * {@inheritDoc}
+     */
     public void accept(ItemVisitor visitor) throws RepositoryException {
         visitor.visit(this);
     }
 
+    /** Always returns <code>true</code>. {@inheritDoc} */
     public boolean isNode() {
         return true;
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Node addNode(String relPath) throws ItemExistsException,
             PathNotFoundException, VersionException,
             ConstraintViolationException, LockException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>addNode(relPath).setProperty(prefix + ":primaryType", primaryNodeTypeName)</code>
+     * and returning the created node. The prefix is acquired by calling
+     * <code>getSession().getNamespacePrefix("http://www.jcp.org/jcr/1.0")</code>.
+     * {@inheritDoc}
+     */
     public Node addNode(String relPath, String primaryNodeTypeName)
             throws ItemExistsException, PathNotFoundException,
             NoSuchNodeTypeException, LockException, VersionException,
             ConstraintViolationException, RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        Node node = addNode(relPath);
+        String prefix =
+            getSession().getNamespacePrefix("http://www.jcp.org/jcr/1.0");
+        node.setProperty(prefix + ":primaryType", primaryNodeTypeName);
+        return node;
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void orderBefore(String srcChildRelPath, String destChildRelPath)
             throws UnsupportedRepositoryOperationException, VersionException,
             ConstraintViolationException, ItemNotFoundException, LockException,
@@ -103,146 +120,324 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getProperty(name).setValue(value)</code>
+     * and returning the retrieved property. Adding new properties is not
+     * implemented.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, Value value)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        try {
+            Property property = getProperty(name);
+            property.setValue(value);
+            return property;
+        } catch (PathNotFoundException e) {
+            throw new UnsupportedRepositoryOperationException();
+        }
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Converts a value to the given type. A new value instance is
+     * created using the current value factory
+     * (<code>getSession().getValueFactory()</code>) unless the given
+     * value already is of the given type or the given type is undefined.
+     * <p>
+     * This internal utility method is used by the property setters
+     * in this class.
+     *
+     * @param value original value
+     * @param type  value type
+     * @return converted value
+     * @throws ValueFormatException if the value can not be converted
+     * @throws RepositoryException  if another error occurs
+     */
+    private Value convert(Value value, int type)
+            throws ValueFormatException, RepositoryException {
+        if (type == PropertyType.UNDEFINED || value.getType() == type) {
+            return value;
+        } else {
+            ValueFactory factory = getSession().getValueFactory();
+            switch (type) {
+            case PropertyType.BINARY:
+                return factory.createValue(value.getStream());
+            case PropertyType.BOOLEAN:
+                return factory.createValue(value.getBoolean());
+            case PropertyType.DATE:
+                return factory.createValue(value.getDate());
+            case PropertyType.DOUBLE:
+                return factory.createValue(value.getDouble());
+            case PropertyType.LONG:
+                return factory.createValue(value.getLong());
+            case PropertyType.STRING:
+                return factory.createValue(value.getString());
+            default:
+                return factory.createValue(value.getString(), type);
+            }
+        }
+    }
+
+    /**
+     * Implemented by calling
+     * <code>setProperty(name, value)</code> after converting the given
+     * value to the given type.
+     * {@inheritDoc}
+     */
+    public Property setProperty(String name, Value value, int type)
+            throws ValueFormatException, VersionException, LockException,
+            RepositoryException {
+        return setProperty(name, convert(value, type));
+    }
+
+    /**
+     * Implemented by calling <code>getProperty(name).setValue(values)</code>
+     * and returning the retrieved property. Adding new properties is not
+     * implemented.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, Value[] values)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        try {
+            Property property = getProperty(name);
+            property.setValue(values);
+            return property;
+        } catch (PathNotFoundException e) {
+            throw new UnsupportedRepositoryOperationException();
+        }
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>setProperty(name, convertedValues)</code>
+     * with an array of values that were converted from the given values to
+     * the given type.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, Value[] values, int type)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        ValueFactory factory = getSession().getValueFactory();
+        Value[] convertedValues = new Value[values.length];
+        for (int i = 0; i < values.length; i++) {
+            convertedValues[i] = convert(values[i], type);
+        }
+        return setProperty(name, convertedValues);
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>setProperty(name, stringValues)</code>
+     * with an array of values that were created from the given strings by
+     * <code>getSession().getValueFactory().createValue(values[i]))</code>.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, String[] values)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        ValueFactory factory = getSession().getValueFactory();
+        Value[] stringValues = new Value[values.length];
+        for (int i = 0; i < values.length; i++) {
+            stringValues[i] = factory.createValue(values[i]);
+        }
+        return setProperty(name, stringValues);
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>setProperty(name, stringValues, type)</code>
+     * with an array of Values that were created from the given strings by
+     * <code>getSession().getValueFactory().createValue(values[i]))</code>.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, String[] values, int type)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        ValueFactory factory = getSession().getValueFactory();
+        Value[] stringValues = new Value[values.length];
+        for (int i = 0; i < values.length; i++) {
+            stringValues[i] = factory.createValue(values[i]);
+        }
+        return setProperty(name, stringValues, type);
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setProperty(name, getSession().getValueFactory().createValue(value)</code>.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, String value)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        return setProperty(name, new StringValue(value));
+        ValueFactory factory = getSession().getValueFactory();
+        return setProperty(name, factory.createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setProperty(name, getSession().getValueFactory().createValue(value, type)</code>.
+     * {@inheritDoc}
+     */
+    public Property setProperty(String name, String value, int type)
+            throws ValueFormatException, VersionException, LockException,
+            RepositoryException {
+        ValueFactory factory = getSession().getValueFactory();
+        return setProperty(name, factory.createValue(value, type));
+    }
+
+    /**
+     * Implemented by calling
+     * <code>setProperty(name, getSession().getValueFactory().createValue(value)</code>.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, InputStream value)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        return setProperty(name, new BinaryValue(value));
+        ValueFactory factory = getSession().getValueFactory();
+        return setProperty(name, factory.createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setProperty(name, getSession().getValueFactory().createValue(value)</code>.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, boolean value)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        return setProperty(name, new BooleanValue(value));
+        ValueFactory factory = getSession().getValueFactory();
+        return setProperty(name, factory.createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setProperty(name, getSession().getValueFactory().createValue(value)</code>.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, double value)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        return setProperty(name, new DoubleValue(value));
+        ValueFactory factory = getSession().getValueFactory();
+        return setProperty(name, factory.createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setProperty(name, getSession().getValueFactory().createValue(value)</code>.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, long value)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        return setProperty(name, new LongValue(value));
+        ValueFactory factory = getSession().getValueFactory();
+        return setProperty(name, factory.createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setProperty(name, getSession().getValueFactory().createValue(value)</code>.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, Calendar value)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        return setProperty(name, new DateValue(value));
+        ValueFactory factory = getSession().getValueFactory();
+        return setProperty(name, factory.createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setProperty(name, getSession().getValueFactory().createValue(value)</code>.
+     * {@inheritDoc}
+     */
     public Property setProperty(String name, Node value)
             throws ValueFormatException, VersionException, LockException,
             RepositoryException {
-        return setProperty(name, new ReferenceValue(value));
+        ValueFactory factory = getSession().getValueFactory();
+        return setProperty(name, factory.createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>Path.resolve(this, relPath)</code> from
+     * the {@link Path Path} utility class. If the given path resolves to
+     * a property, then a {@link PathNotFoundException PathNotFoundException}
+     * is thrown.
+     * {@inheritDoc}
+     */
     public Node getNode(String relPath) throws PathNotFoundException,
             RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        Item item = Path.resolve(this, relPath);
+        if (item.isNode()) {
+            return (Node) item;
+        } else {
+            throw new PathNotFoundException("Node not found: " + relPath);
+        }
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public NodeIterator getNodes() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public NodeIterator getNodes(String namePattern) throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>Path.resolve(this, relPath)</code> from
+     * the {@link Path Path} utility class. If the given path resolves to
+     * a node, then a {@link PathNotFoundException PathNotFoundException}
+     * is thrown.
+     * {@inheritDoc}
+     */
     public Property getProperty(String relPath) throws PathNotFoundException,
             RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        Item item = Path.resolve(this, relPath);
+        if (item.isNode()) {
+            throw new PathNotFoundException("Property not found: " + relPath);
+        } else {
+            return (Property) item;
+        }
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public PropertyIterator getProperties() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public PropertyIterator getProperties(String namePattern)
             throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Item getPrimaryItem() throws ItemNotFoundException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String getUUID() throws UnsupportedRepositoryOperationException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Always returns <code>1</code>. {@inheritDoc} */
     public int getIndex() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        return 1;
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public PropertyIterator getReferences() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getNode(relPath)</code> and returning
+     * <code>true</code> unless a
+     * {@link PathNotFoundException PathNotFoundException} is thrown.
+     * {@inheritDoc}
+     */
     public boolean hasNode(String relPath) throws RepositoryException {
         try {
             getNode(relPath);
@@ -252,7 +447,12 @@
         }
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getProperty(relPath)</code> and returning
+     * <code>true</code> unless a
+     * {@link PathNotFoundException PathNotFoundException} is thrown.
+     * {@inheritDoc}
+     */
     public boolean hasProperty(String relPath) throws RepositoryException {
         try {
             getProperty(relPath);
@@ -262,27 +462,39 @@
         }
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getNodes().hasNext()</code>.
+     * {@inheritDoc}
+     */
     public boolean hasNodes() throws RepositoryException {
-        return getNodes().getSize() > 0;
+        return getNodes().hasNext();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getProperties().hasNext()</code>.
+     * {@inheritDoc}
+     */
     public boolean hasProperties() throws RepositoryException {
-        return getProperties().getSize() > 0;
+        return getProperties().hasNext();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public NodeType getPrimaryNodeType() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public NodeType[] getMixinNodeTypes() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>type.isNodeType(nodeTypeName)</code>
+     * for the primary type and all mixin types of this node. Returns
+     * <code>true</code> if any of these calls return <code>true</code>.
+     * Returns <code>false</code> otherwise.
+     * {@inheritDoc}
+     */
     public boolean isNodeType(String nodeTypeName) throws RepositoryException {
         if (getPrimaryNodeType().isNodeType(nodeTypeName)) {
             return true;
@@ -297,85 +509,85 @@
         return false;
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void addMixin(String mixinName) throws NoSuchNodeTypeException,
             VersionException, ConstraintViolationException, LockException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void removeMixin(String mixinName) throws NoSuchNodeTypeException,
             VersionException, ConstraintViolationException, LockException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public boolean canAddMixin(String mixinName) throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
-    public NodeDef getDefinition() throws RepositoryException {
+    /** Not implemented. {@inheritDoc} */
+    public NodeDefinition getDefinition() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Version checkin() throws VersionException,
             UnsupportedRepositoryOperationException, InvalidItemStateException,
             LockException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void checkout() throws UnsupportedRepositoryOperationException,
             LockException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void doneMerge(Version version) throws VersionException,
             InvalidItemStateException, UnsupportedRepositoryOperationException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void cancelMerge(Version version) throws VersionException,
             InvalidItemStateException, UnsupportedRepositoryOperationException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void update(String srcWorkspaceName)
             throws NoSuchWorkspaceException, AccessDeniedException,
             LockException, InvalidItemStateException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
-    public void merge(String srcWorkspace, boolean bestEffort)
+    /** Not implemented. {@inheritDoc} */
+    public NodeIterator merge(String srcWorkspace, boolean bestEffort)
             throws UnsupportedRepositoryOperationException,
             NoSuchWorkspaceException, AccessDeniedException, VersionException,
             LockException, InvalidItemStateException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String getCorrespondingNodePath(String workspaceName)
             throws ItemNotFoundException, NoSuchWorkspaceException,
             AccessDeniedException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public boolean isCheckedOut() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void restore(String versionName, boolean removeExisting)
             throws VersionException, ItemExistsException,
             UnsupportedRepositoryOperationException, LockException,
@@ -383,7 +595,7 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void restore(Version version, boolean removeExisting)
             throws VersionException, ItemExistsException,
             UnsupportedRepositoryOperationException, LockException,
@@ -391,7 +603,7 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void restore(Version version, String relPath, boolean removeExisting)
             throws PathNotFoundException, ItemExistsException,
             VersionException, ConstraintViolationException,
@@ -400,7 +612,7 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void restoreByLabel(String versionLabel, boolean removeExisting)
             throws VersionException, ItemExistsException,
             UnsupportedRepositoryOperationException, LockException,
@@ -408,19 +620,19 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public VersionHistory getVersionHistory()
             throws UnsupportedRepositoryOperationException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Version getBaseVersion()
             throws UnsupportedRepositoryOperationException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Lock lock(boolean isDeep, boolean isSessionScoped)
             throws UnsupportedRepositoryOperationException, LockException,
             AccessDeniedException, InvalidItemStateException,
@@ -428,25 +640,25 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Lock getLock() throws UnsupportedRepositoryOperationException,
             LockException, AccessDeniedException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void unlock() throws UnsupportedRepositoryOperationException,
             LockException, AccessDeniedException, InvalidItemStateException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public boolean holdsLock() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public boolean isLocked() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseProperty.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseProperty.java?rev=169146&r1=169145&r2=169146&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseProperty.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/base/BaseProperty.java Sun May  8 10:47:17 2005
@@ -19,160 +19,220 @@
 import java.io.InputStream;
 import java.util.Calendar;
 
-import javax.jcr.BinaryValue;
-import javax.jcr.BooleanValue;
-import javax.jcr.DateValue;
-import javax.jcr.DoubleValue;
-import javax.jcr.Item;
 import javax.jcr.ItemVisitor;
-import javax.jcr.LongValue;
 import javax.jcr.Node;
 import javax.jcr.Property;
-import javax.jcr.ReferenceValue;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.StringValue;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
+import javax.jcr.ValueFactory;
 import javax.jcr.ValueFormatException;
 import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.PropertyDef;
+import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.version.VersionException;
 
 /**
- * TODO
+ * Property base class.
  */
 public class BaseProperty extends BaseItem implements Property {
 
-    protected BaseProperty(Item item) {
-        super(item);
+    /** Protected constructor. This class is only useful when extended. */
+    protected BaseProperty() {
     }
 
+    /**
+     * Implemented by calling <code>visitor.visit(this)</code>.
+     * {@inheritDoc}
+     */
     public void accept(ItemVisitor visitor) throws RepositoryException {
         visitor.visit(this);
     }
 
+    /** Always returns <code>false</code>. {@inheritDoc} */
     public boolean isNode() {
         return false;
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void setValue(Value value) throws ValueFormatException,
             VersionException, LockException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void setValue(Value[] values) throws ValueFormatException,
             VersionException, LockException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setValue(getSession().getValueFactory().createValue(value))</code>.
+     * {@inheritDoc}
+     */
     public void setValue(String value) throws ValueFormatException,
             VersionException, LockException, RepositoryException {
-        setValue(new StringValue(value));
+        setValue(getSession().getValueFactory().createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>setValue(stringValues)</code> with
+     * an array of Values that were created from the given strings by
+     * <code>getSession().getValueFactory().createValue(values[i]))</code>.
+     * {@inheritDoc}
+     */
     public void setValue(String[] values) throws ValueFormatException,
             VersionException, LockException, RepositoryException {
+        ValueFactory factory = getSession().getValueFactory();
         Value[] stringValues = new Value[values.length];
         for (int i = 0; i < values.length; i++) {
-            stringValues[i] = new StringValue(values[i]);
+            stringValues[i] = factory.createValue(values[i]);
         }
         setValue(stringValues);
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setValue(getSession().getValueFactory().createValue(value))</code>.
+     * {@inheritDoc}
+     */
     public void setValue(InputStream value) throws ValueFormatException,
             VersionException, LockException, RepositoryException {
-        setValue(new BinaryValue(value));
+        setValue(getSession().getValueFactory().createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setValue(getSession().getValueFactory().createValue(value))</code>.
+     * {@inheritDoc}
+     */
     public void setValue(long value) throws ValueFormatException,
             VersionException, LockException, RepositoryException {
-        setValue(new LongValue(value));
+        setValue(getSession().getValueFactory().createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setValue(getSession().getValueFactory().createValue(value))</code>.
+     * {@inheritDoc}
+     */
     public void setValue(double value) throws ValueFormatException,
             VersionException, LockException, RepositoryException {
-        setValue(new DoubleValue(value));
+        setValue(getSession().getValueFactory().createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setValue(getSession().getValueFactory().createValue(value))</code>.
+     * {@inheritDoc}
+     */
     public void setValue(Calendar value) throws ValueFormatException,
             VersionException, LockException, RepositoryException {
-        setValue(new DateValue(value));
+        setValue(getSession().getValueFactory().createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setValue(getSession().getValueFactory().createValue(value))</code>.
+     * {@inheritDoc}
+     */
     public void setValue(boolean value) throws ValueFormatException,
             VersionException, LockException, RepositoryException {
-        setValue(new BooleanValue(value));
+        setValue(getSession().getValueFactory().createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>setValue(getSession().getValueFactory().createValue(value))</code>.
+     * {@inheritDoc}
+     */
     public void setValue(Node value) throws ValueFormatException,
             VersionException, LockException, RepositoryException {
-        try {
-            setValue(new ReferenceValue(value));
-        } catch (IllegalArgumentException e) {
-            throw new ValueFormatException("Invalid reference target", e);
-        }
+        setValue(getSession().getValueFactory().createValue(value));
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Value getValue() throws ValueFormatException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Value[] getValues() throws ValueFormatException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getValue().getString()</code>.
+     * {@inheritDoc}
+     */
     public String getString() throws ValueFormatException, RepositoryException {
         return getValue().getString();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getValue().getStream()</code>.
+     * {@inheritDoc}
+     */
     public InputStream getStream() throws ValueFormatException,
             RepositoryException {
         return getValue().getStream();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getValue().getLong()</code>.
+     * {@inheritDoc}
+     */
     public long getLong() throws ValueFormatException, RepositoryException {
         return getValue().getLong();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getValue().getDouble()</code>.
+     * {@inheritDoc}
+     */
     public double getDouble() throws ValueFormatException, RepositoryException {
         return getValue().getDouble();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getValue().getDate()</code>.
+     * {@inheritDoc}
+     */
     public Calendar getDate() throws ValueFormatException, RepositoryException {
         return getValue().getDate();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getValue().getBoolean()</code>.
+     * {@inheritDoc}
+     */
     public boolean getBoolean() throws ValueFormatException,
             RepositoryException {
         return getValue().getBoolean();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>getSession().getNodeByUUID(getString())</code>.
+     * {@inheritDoc}
+     */
     public Node getNode() throws ValueFormatException, RepositoryException {
         return getSession().getNodeByUUID(getString());
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getType()</code> and returning
+     * <code>-1</code> if type is binary or <code>getString().length()</code>
+     * otherwise.
+     * {@inheritDoc}
+     */
     public long getLength() throws ValueFormatException, RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        if (getType() == PropertyType.BINARY) {
+            return -1;
+        } else {
+            return getString().length();
+        }
     }
 
     /** {@inheritDoc} */
@@ -180,12 +240,15 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
-    public PropertyDef getDefinition() throws RepositoryException {
+    /** Not implemented. {@inheritDoc} */
+    public PropertyDefinition getDefinition() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getValue().getType()</code>.
+     * {@inheritDoc}
+     */
     public int getType() throws RepositoryException {
         return getValue().getType();
     }

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=169146&r1=169145&r2=169146&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 Sun May  8 10:47:17 2005
@@ -25,47 +25,59 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 
 /**
- * General base class for implementing the JCR Repository interface.
+ * Repository base class.
  */
 public class BaseRepository implements Repository {
 
-    /**
-     * The default constructor is protected to signify that this
-     * class needs to be subclassed to be of any real use.
-     */
+    /** Protected constructor. This class is only useful when extended. */
     protected BaseRepository() {
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String[] getDescriptorKeys() {
         throw new UnsupportedOperationException();
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String getDescriptor(String key) {
         throw new UnsupportedOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Session login(Credentials credentials, String workspaceName)
             throws LoginException, NoSuchWorkspaceException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Calls <code>login(credentials, null)</code>. {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>login(credentials, null)</code>
+     * as suggested by the JCR specification.
+     * {@inheritDoc}
+     */
     public Session login(Credentials credentials) throws LoginException,
             NoSuchWorkspaceException, RepositoryException {
         return login(credentials, null);
     }
 
-    /** Calls <code>login(null, workspaceName)</code>. {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>login(null, workspaceName)</code>
+     * as suggested by the JCR specification.
+     * {@inheritDoc}
+     */
     public Session login(String workspaceName) throws LoginException,
             NoSuchWorkspaceException, RepositoryException {
         return login(null, workspaceName);
     }
 
-    /** Calls <code>login(null, null)</code>. {@inheritDoc} */
+    /**
+     * Implemented by calling
+     * <code>login(null, null)</code>
+     * as suggested by the JCR specification.
+     * {@inheritDoc}
+     */
     public Session login() throws LoginException, NoSuchWorkspaceException,
             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=169146&r1=169145&r2=169146&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 Sun May  8 10:47:17 2005
@@ -36,6 +36,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.ValueFactory;
 import javax.jcr.Workspace;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
@@ -53,44 +54,41 @@
 import org.xml.sax.SAXException;
 
 /**
- * General base class for implementing the JCR Session interface.
+ * Session base class.
  */
 public class BaseSession implements Session {
 
-    /**
-     * The default constructor is protected to signify that this
-     * class needs to be subclassed to be of any real use.
-     */
+    /** Protected constructor. This class is only useful when extended. */
     protected BaseSession() {
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Repository getRepository() {
         throw new UnsupportedOperationException();
     }
 
-    /** Unsupported operation. {@inheritDoc} */
-    public String getUserId() {
+    /** Not implemented. {@inheritDoc} */
+    public String getUserID() {
         throw new UnsupportedOperationException();
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Object getAttribute(String name) {
         throw new UnsupportedOperationException();
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String[] getAttributeNames() {
         throw new UnsupportedOperationException();
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Workspace getWorkspace() {
         throw new UnsupportedOperationException();
     }
 
     /**
-     * Calls
+     * Implemented by calling
      * <code>getRepository().login(credentials, getWorkspace().getName())</code>.
      * {@inheritDoc}
      */
@@ -99,80 +97,89 @@
         return getRepository().login(credentials, getWorkspace().getName());
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Node getRootNode() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Node getNodeByUUID(String uuid) throws ItemNotFoundException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Implemented by calling <code>getRootNode()</code> or
+     * <code>getRootNode().getNode(absPath.substring(1))</code> depending
+     * on the given absolute path.
+     * {@inheritDoc}
+     */
     public Item getItem(String absPath) throws PathNotFoundException,
             RepositoryException {
-        throw new UnsupportedRepositoryOperationException();
+        if (absPath == null || !absPath.startsWith("/")) {
+            throw new IllegalArgumentException("Invalid path: " + absPath);
+        } else if (absPath.equals("/")) {
+            return getRootNode();
+        } else {
+            return getRootNode().getNode(absPath.substring(1));
+        }
     }
 
     /**
-     * Calls <code>getItem(absPath)</code> and returns <code>true</code>
-     * if a {@link PathNotFoundException PathNotFoundException} is not thrown.
-     * Throws a {@link RuntimeException RuntimeException} if a general
-     * {@link RepositoryException RepositoryException} is thrown by getItem().
+     * Implemented by calling <code>getItem(absPath)</code> and returning
+     * <code>true</code> unless a
+     * {@link PathNotFoundException PathNotFoundException} is thrown.
      * {@inheritDoc}
      */
-    public boolean itemExists(String absPath) {
+    public boolean itemExists(String absPath) throws RepositoryException {
         try {
             getItem(absPath);
             return true;
         } catch (PathNotFoundException e) {
             return false;
-        } catch (RepositoryException e) {
-            throw new RuntimeException(e);
         }
     }
 
-    /** Unsupported repository operation.{@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void move(String srcAbsPath, String destAbsPath)
             throws ItemExistsException, PathNotFoundException,
             VersionException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void save() throws AccessDeniedException,
             ConstraintViolationException, InvalidItemStateException,
             VersionException, LockException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void refresh(boolean keepChanges) throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public boolean hasPendingChanges() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void checkPermission(String absPath, String actions)
             throws AccessControlException {
         throw new UnsupportedOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
-    public ContentHandler getImportContentHandler(String parentAbsPath)
+    /** Not implemented. {@inheritDoc} */
+    public ContentHandler getImportContentHandler(
+            String parentAbsPath, int uuidBehaviour)
             throws PathNotFoundException, ConstraintViolationException,
             VersionException, LockException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
     /**
-     * Calls
+     * 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
@@ -182,34 +189,37 @@
      * are converted to {@link IOException IOExceptions}.
      * {@inheritDoc}
      */
-    public void importXML(String parentAbsPath, InputStream in)
+    public void importXML(
+            String parentAbsPath, InputStream in, int uuidBehaviour)
             throws IOException, PathNotFoundException, ItemExistsException,
             ConstraintViolationException, VersionException,
             InvalidSerializedDataException, LockException, RepositoryException {
         try {
-            ContentHandler handler = getImportContentHandler(parentAbsPath);
+            ContentHandler handler =
+                getImportContentHandler(parentAbsPath, uuidBehaviour);
 
             TransformerFactory factory = TransformerFactory.newInstance();
             Transformer transformer = factory.newTransformer();
             transformer.transform(new StreamSource(in), new SAXResult(handler));
         } catch (TransformerConfigurationException e) {
             throw new IOException(
-                    "Unable to deserialize a SAX stream: " + e.getMessage());
+                    "Unable to configure a SAX transformer: " + e.getMessage());
         } catch (TransformerException e) {
             throw new IOException(
                     "Unable to deserialize a SAX stream: " + e.getMessage());
         }
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
-    public void exportSysView(String absPath, ContentHandler contentHandler,
+    /** Not implemented. {@inheritDoc} */
+    public void exportSystemView(
+            String absPath, ContentHandler contentHandler,
             boolean skipBinary, boolean noRecurse)
             throws PathNotFoundException, SAXException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
     /**
-     * Calls
+     * 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
@@ -218,23 +228,24 @@
      * {@link IOException IOExceptions}.
      * {@inheritDoc}
      */
-    public void exportSysView(String absPath, OutputStream out,
+    public void exportSystemView(String absPath, OutputStream out,
             boolean skipBinary, boolean noRecurse) throws IOException,
             PathNotFoundException, RepositoryException {
         try {
             XMLSerializer serializer =
                 new XMLSerializer(out, new OutputFormat());
-            exportDocView(absPath, serializer.asContentHandler(),
+            exportSystemView(
+                    absPath, serializer.asContentHandler(),
                     skipBinary, noRecurse);
         } catch (SAXException e) {
             throw new IOException(
-                    "Unable to serialize a system view SAX stream: "
-                    + e.getMessage());
+                    "Unable to serialize a SAX stream: " + e.getMessage());
         }
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
-    public void exportDocView(String absPath, ContentHandler contentHandler,
+    /** Not implemented. {@inheritDoc} */
+    public void exportDocumentView(
+            String absPath, ContentHandler contentHandler,
             boolean skipBinary, boolean noRecurse)
             throws InvalidSerializedDataException, PathNotFoundException,
             SAXException, RepositoryException {
@@ -242,7 +253,7 @@
     }
 
     /**
-     * Calls
+     * 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
@@ -251,34 +262,35 @@
      * {@link IOException IOExceptions}.
      * {@inheritDoc}
      */
-    public void exportDocView(String absPath, OutputStream out,
+    public void exportDocumentView(
+            String absPath, OutputStream out,
             boolean skipBinary, boolean noRecurse)
             throws InvalidSerializedDataException, IOException,
             PathNotFoundException, RepositoryException {
         try {
             XMLSerializer serializer =
                 new XMLSerializer(out, new OutputFormat("xml", "UTF-8", true));
-            exportDocView(absPath, serializer.asContentHandler(),
+            exportDocumentView(
+                    absPath, serializer.asContentHandler(),
                     skipBinary, noRecurse);
         } catch (SAXException e) {
             throw new IOException(
-                    "Unable to serialize a document view SAX stream: "
-                    + e.getMessage());
+                    "Unable to serialize a SAX stream: " + e.getMessage());
         }
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void setNamespacePrefix(String prefix, String uri)
             throws NamespaceException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String[] getNamespacePrefixes() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String getNamespaceURI(String prefix) throws NamespaceException,
             RepositoryException {
         throw new UnsupportedRepositoryOperationException();
@@ -306,19 +318,29 @@
     public void logout() {
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void addLockToken(String lt) {
         throw new UnsupportedOperationException();
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String[] getLockTokens() {
         throw new UnsupportedOperationException();
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void removeLockToken(String lt) {
         throw new UnsupportedOperationException();
     }
 
+    /** Not implemented. {@inheritDoc} */
+    public ValueFactory getValueFactory()
+            throws UnsupportedRepositoryOperationException, RepositoryException {
+        throw new UnsupportedRepositoryOperationException();
+    }
+
+    /** Always returns <code>true</code>. {@inheritDoc} */
+    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=169146&r1=169145&r2=169146&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 Sun May  8 10:47:17 2005
@@ -47,28 +47,28 @@
 import org.xml.sax.ContentHandler;
 
 /**
- * General base class for implementing the JCR Workspace interface.
+ * Workspace base class.
  */
 public class BaseWorkspace implements Workspace {
 
-    /**
-     * The default constructor is protected to signify that this
-     * class needs to be subclassed to be of any real use.
-     */
+    /** Protected constructor. This class is only useful when extended. */
     protected BaseWorkspace() {
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public Session getSession() {
         throw new UnsupportedOperationException();
     }
 
-    /** Unsupported operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String getName() {
         throw new UnsupportedOperationException();
     }
 
-    /** Calls <code>copy(getName(), srcAbsPath, destAbsPath). {@inheritDoc} */
+    /**
+     * Implemented by calling <code>copy(getName(), srcAbsPath, destAbsPath).
+     * {@inheritDoc}
+     */
     public void copy(String srcAbsPath, String destAbsPath)
             throws ConstraintViolationException, VersionException,
             AccessDeniedException, PathNotFoundException, ItemExistsException,
@@ -76,7 +76,7 @@
         copy(getName(), srcAbsPath, destAbsPath);
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void copy(String srcWorkspace, String srcAbsPath, String destAbsPath)
             throws NoSuchWorkspaceException, ConstraintViolationException,
             VersionException, AccessDeniedException, PathNotFoundException,
@@ -84,7 +84,7 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void clone(String srcWorkspace, String srcAbsPath,
             String destAbsPath, boolean removeExisting)
             throws NoSuchWorkspaceException, ConstraintViolationException,
@@ -93,7 +93,7 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void move(String srcAbsPath, String destAbsPath)
             throws ConstraintViolationException, VersionException,
             AccessDeniedException, PathNotFoundException, ItemExistsException,
@@ -101,7 +101,7 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public void restore(Version[] versions, boolean removeExisting)
             throws ItemExistsException,
             UnsupportedRepositoryOperationException, VersionException,
@@ -109,33 +109,33 @@
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public QueryManager getQueryManager() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public NamespaceRegistry getNamespaceRegistry() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public NodeTypeManager getNodeTypeManager() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public ObservationManager getObservationManager()
             throws UnsupportedRepositoryOperationException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public String[] getAccessibleWorkspaceNames() throws RepositoryException {
         throw new UnsupportedRepositoryOperationException();
     }
 
-    /** Unsupported repository operation. {@inheritDoc} */
+    /** Not implemented. {@inheritDoc} */
     public ContentHandler getImportContentHandler(String parentAbsPath,
             int uuidBehavior) throws PathNotFoundException,
             ConstraintViolationException, VersionException, LockException,
@@ -144,7 +144,7 @@
     }
 
     /**
-     * Calls
+     * 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
@@ -167,7 +167,7 @@
             transformer.transform(new StreamSource(in), new SAXResult(handler));
         } catch (TransformerConfigurationException e) {
             throw new IOException(
-                    "Unable to deserialize a SAX stream: " + e.getMessage());
+                    "Unable to configure a SAX transformer: " + e.getMessage());
         } catch (TransformerException e) {
             throw new IOException(
                     "Unable to deserialize a SAX stream: " + e.getMessage());

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=169146&r1=169145&r2=169146&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 Sun May  8 10:47:17 2005
@@ -1,15 +1,42 @@
 <body>
-General base classes for JCR implementations.
+General base classes for implementing the JCR interfaces.
 <p>
 This package contains simple base class implementations of the JCR API
-interfaces. The API methods are implemented either by throwing
-{@link javax.jcr.UnsupportedRepositoryOperationException UnsupportedRepositoryOperationExceptions}
-or
-{@link java.lang.UnsupportedOperationException UnsupportedOperationExceptions},
-or (if possible) by calling other API methods. The implementation mechanism
-of each method is documented using the respective Javadoc comment.
+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
+Property.getValue().getString(). See the javadoc comments of each method
+for implementation details.
+</p>
 <p>
-The purpose of this package is to make it easy for JCR implementations
-to implement the JCR API incrementally without creating a large numbers of
-stub methods.
+The purpose of this package is to make it easy to incrementally implement
+the JCR API without creating a large numbers of stub methods. A JCR
+implementation class can inherit one of these base classes and only override
+the methods it needs.
+</p>
+<h2>Desing principles</h2>
+<p>
+The base classes in this package follow the design principles listed below.
+The purpose of these design principles is to avoid introducing unnecessary
+dependencies or complexities.
+</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.
+  </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.
+  </li>
+</ul>
 </body>



Mime
View raw message