Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 67880 invoked from network); 3 Jul 2007 14:54:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jul 2007 14:54:50 -0000 Received: (qmail 98069 invoked by uid 500); 3 Jul 2007 14:54:50 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 98016 invoked by uid 500); 3 Jul 2007 14:54:50 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 97985 invoked by uid 99); 3 Jul 2007 14:54:49 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jul 2007 07:54:49 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jul 2007 07:54:41 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 2AE751A981A; Tue, 3 Jul 2007 07:54:21 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r552863 - in /jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common: NodeInfoImpl.java PropertyInfoImpl.java SerializableIdFactory.java Date: Tue, 03 Jul 2007 14:54:20 -0000 To: commits@jackrabbit.apache.org From: angela@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070703145421.2AE751A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: angela Date: Tue Jul 3 07:54:19 2007 New Revision: 552863 URL: http://svn.apache.org/viewvc?view=rev&rev=552863 Log: minor improvements: - make usage of commons IdFactory - add static create methods Modified: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/NodeInfoImpl.java jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/PropertyInfoImpl.java jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/SerializableIdFactory.java Modified: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/NodeInfoImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/NodeInfoImpl.java?view=diff&rev=552863&r1=552862&r2=552863 ============================================================================== --- jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/NodeInfoImpl.java (original) +++ jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/NodeInfoImpl.java Tue Jul 3 07:54:19 2007 @@ -20,12 +20,14 @@ import org.apache.jackrabbit.spi.NodeId; import org.apache.jackrabbit.spi.PropertyId; import org.apache.jackrabbit.spi.IdIterator; +import org.apache.jackrabbit.spi.ItemId; import org.apache.jackrabbit.name.QName; import org.apache.jackrabbit.name.Path; import java.util.List; import java.util.ArrayList; import java.util.Arrays; +import java.io.Serializable; /** * NodeInfoImpl implements a serializable NodeInfo @@ -64,6 +66,39 @@ private final List propertyIds; /** + * Creates a new serializable NodeInfo for the given + * NodeInfo. + * + * @param nodeInfo + */ + public static NodeInfo createSerializableNodeInfo(NodeInfo nodeInfo, final SerializableIdFactory idFactory) { + if (nodeInfo instanceof Serializable) { + return nodeInfo; + } else { + PropertyId[] refs = nodeInfo.getReferences(); + PropertyId[] serRefs = new PropertyId[refs.length]; + for (int i = 0; i < serRefs.length; i++) { + serRefs[i] = idFactory.createSerializablePropertyId(refs[i]); + } + NodeId parentId = null; + if (nodeInfo.getParentId() != null) { + parentId = idFactory.createSerializableNodeId(nodeInfo.getParentId()); + } + return new NodeInfoImpl(parentId, nodeInfo.getQName(), + nodeInfo.getPath(), + idFactory.createSerializableNodeId(nodeInfo.getId()), + nodeInfo.getIndex(), nodeInfo.getNodetype(), + nodeInfo.getMixins(), serRefs, + new IteratorHelper(nodeInfo.getPropertyIds()) { + public ItemId nextId() { + return idFactory.createSerializablePropertyId( + (PropertyId) super.nextId()); + } + }); + } + } + + /** * Creates a new serializable node info for the given node * info. * @@ -77,9 +112,9 @@ * @param references the references to this node. * @param propertyIds the properties of this node. */ - public NodeInfoImpl(NodeId parentId, QName name, Path path, NodeId id, - int index, QName primaryTypeName, QName[] mixinNames, - PropertyId[] references, IdIterator propertyIds) { + private NodeInfoImpl(NodeId parentId, QName name, Path path, NodeId id, + int index, QName primaryTypeName, QName[] mixinNames, + PropertyId[] references, IdIterator propertyIds) { super(parentId, name, path, true); this.id = id; this.index = index; Modified: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/PropertyInfoImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/PropertyInfoImpl.java?view=diff&rev=552863&r1=552862&r2=552863 ============================================================================== --- jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/PropertyInfoImpl.java (original) +++ jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/PropertyInfoImpl.java Tue Jul 3 07:54:19 2007 @@ -23,6 +23,8 @@ import org.apache.jackrabbit.name.QName; import org.apache.jackrabbit.name.Path; +import java.io.Serializable; + /** * PropertyInfoImpl implements a serializable * PropertyInfo based on another property info. @@ -51,7 +53,24 @@ /** * Creates a new serializable property info for the given - * property. + * PropertyInfo. + * + * @param propertyInfo + */ + public static PropertyInfo createSerializablePropertyInfo(PropertyInfo propertyInfo, SerializableIdFactory idFactory) { + if (propertyInfo instanceof Serializable) { + return propertyInfo; + } else { + return new PropertyInfoImpl(idFactory.createSerializableNodeId(propertyInfo.getParentId()), + propertyInfo.getQName(), propertyInfo.getPath(), + idFactory.createSerializablePropertyId(propertyInfo.getId()), + propertyInfo.getType(), propertyInfo.isMultiValued(), + propertyInfo.getValues()); + } + } + + /** + * Creates a new serializable property info for the given parameters. * * @param parentId the parent id. * @param name the name of this property. @@ -61,7 +80,7 @@ * @param isMultiValued whether this property is multi-valued. * @param values the values. */ - public PropertyInfoImpl(NodeId parentId, QName name, Path path, + private PropertyInfoImpl(NodeId parentId, QName name, Path path, PropertyId id, int type, boolean isMultiValued, QValue[] values) { super(parentId, name, path, false); Modified: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/SerializableIdFactory.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/SerializableIdFactory.java?view=diff&rev=552863&r1=552862&r2=552863 ============================================================================== --- jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/SerializableIdFactory.java (original) +++ jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/SerializableIdFactory.java Tue Jul 3 07:54:19 2007 @@ -16,218 +16,57 @@ */ package org.apache.jackrabbit.spi.rmi.common; -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; -import org.apache.jackrabbit.name.MalformedPathException; +import org.apache.jackrabbit.identifier.AbstractIdFactory; import java.io.Serializable; /** * SerializableIdFactory implements an id factory with serializable * item ids. - * TODO: copied from spi2dav, move common part to spi-commons. */ -public class SerializableIdFactory implements IdFactory { +public class SerializableIdFactory extends AbstractIdFactory { private static final SerializableIdFactory INSTANCE = new SerializableIdFactory(); - private SerializableIdFactory() {}; + private SerializableIdFactory() {} public static SerializableIdFactory getInstance() { return INSTANCE; } /** - * {@inheritDoc} + * Checks if the passed nodeId is serializable and if it is not + * creates a serializable version for the given nodeId. + * + * @param nodeId the node id to check. + * @return a serializable version of nodeId or the passed + * nodeId itself it is already serializable. */ - public PropertyId createPropertyId(NodeId parentId, QName propertyName) { - try { - return new PropertyIdImpl(parentId, propertyName); - } catch (MalformedPathException e) { - throw new IllegalArgumentException(e.getMessage()); + public NodeId createSerializableNodeId(NodeId nodeId) { + if (nodeId instanceof Serializable) { + return nodeId; + } else { + return INSTANCE.createNodeId(nodeId.getUniqueID(), nodeId.getPath()); } } /** - * {@inheritDoc} + * Checks if the passed propId is serializable and if it is not + * creates a serializable version for the given propId. + * + * @param propId the property id to check. + * @return a serializable version of propId or the passed + * propId itself it is already serializable. */ - 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); - } - - //------------------------------------------------------< Inner classes >--- - private static abstract class ItemIdImpl implements ItemId, Serializable { - - private final String uniqueID; - private final Path path; - - private transient 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; + public PropertyId createSerializablePropertyId(PropertyId propertyId) { + if (propertyId instanceof Serializable) { + return propertyId; + } else { + return INSTANCE.createPropertyId( + createSerializableNodeId(propertyId.getParentId()), + propertyId.getQName()); } } }