jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r552861 - in /jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr: IdFactoryImpl.java ItemInfoImpl.java NodeInfoImpl.java PropertyInfoImpl.java
Date Tue, 03 Jul 2007 14:52:21 GMT
Author: angela
Date: Tue Jul  3 07:52:20 2007
New Revision: 552861

URL: http://svn.apache.org/viewvc?view=rev&rev=552861
Log:
minor improvements:
- make usage of commons IdFactory
- make ItemInfoImpl abstract
- get rid of Item field with ItemInfo

Modified:
    jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java
    jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/ItemInfoImpl.java
    jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/NodeInfoImpl.java
    jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/PropertyInfoImpl.java

Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java?view=diff&rev=552861&r1=552860&r2=552861
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/IdFactoryImpl.java
Tue Jul  3 07:52:20 2007
@@ -18,7 +18,6 @@
 
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.spi.IdFactory;
-import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.name.QName;
@@ -26,6 +25,7 @@
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.name.NameException;
+import org.apache.jackrabbit.identifier.AbstractIdFactory;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -34,52 +34,15 @@
 
 /**
  * <code>IdFactoryImpl</code>...
- * TODO: copied from spi2dav, move common part to spi-commons.
  */
-class IdFactoryImpl implements IdFactory {
+class IdFactoryImpl extends AbstractIdFactory {
 
-    private static final IdFactory idFactory = new IdFactoryImpl();
+    private static final IdFactory INSTANCE = new IdFactoryImpl();
 
-    private IdFactoryImpl() {};
+    private IdFactoryImpl() {}
 
     public static IdFactory getInstance() {
-        return idFactory;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public PropertyId createPropertyId(NodeId parentId, QName propertyName) {
-        try {
-            return new PropertyIdImpl(parentId, propertyName);
-        } catch (MalformedPathException e) {
-            throw new IllegalArgumentException(e.getMessage());
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public NodeId createNodeId(NodeId parentId, Path path) {
-        try {
-            return new NodeIdImpl(parentId, path);
-        } catch (MalformedPathException e) {
-            throw new IllegalArgumentException(e.getMessage());
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public NodeId createNodeId(String uniqueID, Path path) {
-        return new NodeIdImpl(uniqueID, path);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public NodeId createNodeId(String uniqueID) {
-        return new NodeIdImpl(uniqueID);
+        return INSTANCE;
     }
 
     /**
@@ -125,12 +88,12 @@
         }
         if (pathElements > 0) {
             try {
-                return new NodeIdImpl(uniqueId, builder.getPath());
+                return createNodeId(uniqueId, builder.getPath());
             } catch (MalformedPathException e) {
                 throw new RepositoryException(e.getMessage(), e);
             }
         } else {
-            return new NodeIdImpl(uniqueId);
+            return createNodeId(uniqueId);
         }
     }
 
@@ -156,159 +119,5 @@
             throw new RepositoryException(e.getMessage(), e);
         }
         return createPropertyId(nodeId, name);
-    }
-
-    //------------------------------------------------------< Inner classes >---
-    private static abstract class ItemIdImpl implements ItemId {
-
-        private final String uniqueID;
-        private final Path path;
-
-        private int hashCode = 0;
-
-        private ItemIdImpl(String uniqueID, Path path) {
-            if (uniqueID == null && path == null) {
-                throw new IllegalArgumentException("Only uniqueID or relative path might
be null.");
-            }
-            this.uniqueID = uniqueID;
-            this.path = path;
-        }
-
-        private ItemIdImpl(NodeId parentId, QName name) throws MalformedPathException {
-            if (parentId == null || name == null) {
-                throw new IllegalArgumentException("Invalid ItemIdImpl: parentId and name
must not be null.");
-            }
-            this.uniqueID = parentId.getUniqueID();
-            Path parentPath = parentId.getPath();
-            if (parentPath != null) {
-                this.path = Path.create(parentPath, name, true);
-            } else {
-                this.path = Path.create(name, Path.INDEX_UNDEFINED);
-            }
-        }
-
-        public abstract boolean denotesNode();
-
-        public String getUniqueID() {
-            return uniqueID;
-        }
-
-        public Path getPath() {
-            return path;
-        }
-
-        /**
-         * ItemIdImpl objects are equal if the have the same uuid and relative path.
-         *
-         * @param obj
-         * @return
-         */
-        public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
-            }
-            if (obj instanceof ItemId) {
-                ItemId other = (ItemId) obj;
-                return equals(other);
-            }
-            return false;
-        }
-
-        boolean equals(ItemId other) {
-            return (uniqueID == null ? other.getUniqueID() == null : uniqueID.equals(other.getUniqueID()))
-                && (path == null ? other.getPath() == null : path.equals(other.getPath()));
-        }
-
-        /**
-         * Returns the hash code of the uuid and the path. The computed hash code
-         * is memorized for better performance.
-         *
-         * @return hash code
-         * @see Object#hashCode()
-         */
-        public int hashCode() {
-            // since the ItemIdImpl is immutable, store the computed hash code value
-            if (hashCode == 0) {
-                hashCode = toString().hashCode();
-            }
-            return hashCode;
-        }
-
-        /**
-         * Combination of uuid and relative path
-         *
-         * @return
-         */
-        public String toString() {
-            StringBuffer b = new StringBuffer();
-            if (uniqueID != null) {
-                b.append(uniqueID);
-            }
-            if (path != null) {
-                b.append(path.toString());
-            }
-            return b.toString();
-        }
-    }
-
-    private static class NodeIdImpl extends ItemIdImpl implements NodeId {
-
-        public NodeIdImpl(String uniqueID) {
-            super(uniqueID, null);
-        }
-
-        public NodeIdImpl(String uniqueID, Path path) {
-            super(uniqueID, path);
-        }
-
-        public NodeIdImpl(NodeId parentId, Path path) throws MalformedPathException {
-            super(parentId.getUniqueID(), (parentId.getPath() != null) ? Path.create(parentId.getPath(),
path, true) : path);
-        }
-
-        public boolean denotesNode() {
-            return true;
-        }
-
-        public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
-            }
-            if (obj instanceof NodeId) {
-                return super.equals((NodeId)obj);
-            }
-            return false;
-        }
-    }
-
-    private static class PropertyIdImpl extends ItemIdImpl implements PropertyId {
-
-        private final NodeId parentId;
-
-        private PropertyIdImpl(NodeId parentId, QName name) throws MalformedPathException
{
-            super(parentId, name);
-            this.parentId = parentId;
-        }
-
-        public boolean denotesNode() {
-            return false;
-        }
-
-        public NodeId getParentId() {
-            return parentId;
-        }
-
-        public QName getQName() {
-            return getPath().getNameElement().getName();
-        }
-
-        public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
-            }
-            if (obj instanceof PropertyId) {
-                return super.equals((PropertyId)obj);
-            }
-            return false;
-        }
     }
 }

Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/ItemInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/ItemInfoImpl.java?view=diff&rev=552861&r1=552860&r2=552861
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/ItemInfoImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/ItemInfoImpl.java
Tue Jul  3 07:52:20 2007
@@ -35,12 +35,7 @@
  * <code>ItemInfoImpl</code> is a base class for <code>ItemInfo</code>
  * implementations.
  */
-class ItemInfoImpl implements ItemInfo {
-
-    /**
-     * The underlying JCR item.
-     */
-    private final Item item;
+abstract class ItemInfoImpl implements ItemInfo {
 
     /**
      * The parent node id of this item or <code>null</code> if this item
@@ -71,7 +66,6 @@
                         IdFactoryImpl idFactory,
                         NamespaceResolver nsResolver)
             throws RepositoryException {
-        this.item = item;
         try {
             if (item.getName().equals("")) {
                 this.name = QName.ROOT;
@@ -117,13 +111,6 @@
      */
     public QName getQName() {
         return name;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean denotesNode() {
-        return item.isNode();
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/NodeInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/NodeInfoImpl.java?view=diff&rev=552861&r1=552860&r2=552861
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/NodeInfoImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/NodeInfoImpl.java
Tue Jul  3 07:52:20 2007
@@ -149,4 +149,11 @@
     public IdIterator getPropertyIds() {
         return new IteratorHelper(propertyIds);
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean denotesNode() {
+        return true;
+    }
 }

Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/PropertyInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/PropertyInfoImpl.java?view=diff&rev=552861&r1=552860&r2=552861
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/PropertyInfoImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/PropertyInfoImpl.java
Tue Jul  3 07:52:20 2007
@@ -69,6 +69,7 @@
                             QValueFactory qValueFactory) throws RepositoryException {
         super(property, idFactory, nsResolver);
         this.propertyId = idFactory.createPropertyId(property, nsResolver);
+        // TODO: build QValues upon (first) usage only.
         this.type = property.getType();
         this.isMultiValued = property.getDefinition().isMultiple();
         if (isMultiValued) {
@@ -109,8 +110,13 @@
      * {@inheritDoc}
      */
     public QValue[] getValues() {
-        QValue[] vals = new QValue[values.length];
-        System.arraycopy(values, 0, vals, 0, values.length);
-        return vals;
+        return values;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean denotesNode() {
+        return false;
     }
 }



Mime
View raw message