You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2007/06/29 14:24:44 UTC
svn commit: r551869 - in
/jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit:
identifier/ identifier/AbstractIdFactory.java identifier/IdFactoryImpl.java
value/ValueFactoryImplEx.java
Author: angela
Date: Fri Jun 29 05:24:43 2007
New Revision: 551869
URL: http://svn.apache.org/viewvc?view=rev&rev=551869
Log:
Resolve TODO in spi2jcr, spi-rmi and spi2dav and move common parts
of IdFactory and extended ValueFactory to spi-commons
Added:
jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/
jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/AbstractIdFactory.java (with props)
jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/IdFactoryImpl.java (with props)
jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImplEx.java (with props)
Added: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/AbstractIdFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/AbstractIdFactory.java?view=auto&rev=551869
==============================================================================
--- jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/AbstractIdFactory.java (added)
+++ jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/AbstractIdFactory.java Fri Jun 29 05:24:43 2007
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.identifier;
+
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.MalformedPathException;
+import org.apache.jackrabbit.name.QName;
+
+import java.io.Serializable;
+
+/**
+ * <code>AbstractIdFactory</code>...
+ */
+public abstract class AbstractIdFactory implements IdFactory {
+
+ /**
+ * {@inheritDoc}
+ * @see IdFactory#createNodeId(NodeId, Path)
+ */
+ public NodeId createNodeId(NodeId parentId, Path path) {
+ try {
+ return new NodeIdImpl(parentId, path);
+ } catch (MalformedPathException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see IdFactory#createNodeId(String, Path)
+ */
+ public NodeId createNodeId(String uniqueID, Path path) {
+ return new NodeIdImpl(uniqueID, path);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see IdFactory#createNodeId(String)
+ */
+ public NodeId createNodeId(String uniqueID) {
+ return new NodeIdImpl(uniqueID);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see IdFactory#createPropertyId(NodeId, QName)
+ */
+ public PropertyId createPropertyId(NodeId parentId, QName propertyName) {
+ try {
+ return new PropertyIdImpl(parentId, propertyName);
+ } catch (MalformedPathException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
+
+ //------------------------------------------------------< 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;
+ }
+ }
+}
\ No newline at end of file
Propchange: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/AbstractIdFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/AbstractIdFactory.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url
Added: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/IdFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/IdFactoryImpl.java?view=auto&rev=551869
==============================================================================
--- jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/IdFactoryImpl.java (added)
+++ jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/IdFactoryImpl.java Fri Jun 29 05:24:43 2007
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.identifier;
+
+import org.apache.jackrabbit.spi.IdFactory;
+
+/**
+ * <code>IdFactoryImpl</code>...
+ */
+public final class IdFactoryImpl extends AbstractIdFactory {
+
+ private static final IdFactory INSTANCE = new IdFactoryImpl();
+
+ private IdFactoryImpl() {}
+
+ public static IdFactory getInstance() {
+ return IdFactoryImpl.INSTANCE;
+ }
+}
Propchange: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/IdFactoryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/identifier/IdFactoryImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url
Added: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImplEx.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImplEx.java?view=auto&rev=551869
==============================================================================
--- jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImplEx.java (added)
+++ jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImplEx.java Fri Jun 29 05:24:43 2007
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.value;
+
+import javax.jcr.ValueFactory;
+import javax.jcr.Value;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFormatException;
+import javax.jcr.PropertyType;
+import java.util.Calendar;
+import java.io.InputStream;
+
+/**
+ * <code>ValueFactoryImplEx</code>...
+ */
+public class ValueFactoryImplEx implements ValueFactory {
+
+ private static final ValueFactory INSTANCE = new ValueFactoryImplEx();
+
+ /**
+ * Delegatee for all calls except for REFERENCE values.
+ */
+ private final ValueFactory commonsFactory = ValueFactoryImpl.getInstance();
+
+ /**
+ * Constructs a <code>ValueFactory</code> object.
+ */
+ private ValueFactoryImplEx() {
+ }
+
+ public static ValueFactory getInstance() {
+ return INSTANCE;
+ }
+
+ public Value createValue(Node value) throws RepositoryException {
+ return new ReferenceValue(value);
+ }
+
+ public Value createValue(String string) {
+ return commonsFactory.createValue(string);
+ }
+
+ public Value createValue(String value, int type) throws ValueFormatException {
+ Value val;
+ switch (type) {
+ case PropertyType.REFERENCE:
+ val = ReferenceValue.valueOf(value);
+ break;
+ default:
+ val = commonsFactory.createValue(value, type);
+ }
+ return val;
+ }
+
+ public Value createValue(long l) {
+ return commonsFactory.createValue(l);
+ }
+
+ public Value createValue(double v) {
+ return commonsFactory.createValue(v);
+ }
+
+ public Value createValue(boolean b) {
+ return commonsFactory.createValue(b);
+ }
+
+ public Value createValue(Calendar calendar) {
+ return commonsFactory.createValue(calendar);
+ }
+
+ public Value createValue(InputStream inputStream) {
+ return commonsFactory.createValue(inputStream);
+ }
+
+ /**
+ * A <code>ReferenceValue</code> provides an implementation
+ * of the <code>Value</code> interface representing a <code>REFERENCE</code> value
+ * (a jcr:uuid property of an existing, referenceable node).
+ */
+ private static class ReferenceValue extends org.apache.jackrabbit.value.ReferenceValue {
+
+ private ReferenceValue(String uuid) {
+ super(uuid);
+ }
+
+ /**
+ * Constructs a <code>ReferenceValue</code> object representing the UUID of
+ * an existing node.
+ *
+ * @param target the node to be referenced
+ * @throws IllegalArgumentException If <code>target</code> is nonreferenceable.
+ * @throws RepositoryException If another error occurs.
+ */
+ private ReferenceValue(Node target) throws RepositoryException {
+ super(target);
+ }
+
+ /**
+ * Returns a new <code>ReferenceValue</code> initialized to the value
+ * represented by the specified <code>String</code>.
+ * <p/>
+ * The specified <code>String</code> must denote the jcr:uuid property
+ * of an existing node.
+ *
+ * @param s the string to be parsed.
+ * @return a newly constructed <code>ReferenceValue</code> representing
+ * the specified value.
+ * @throws ValueFormatException If the <code>String</code> is
+ * null or empty String.
+ */
+ public static org.apache.jackrabbit.value.ReferenceValue valueOf(String s) throws ValueFormatException {
+ if (s != null && !"".equals(s)) {
+ return new ReferenceValue(s);
+ } else {
+ throw new ValueFormatException("Invalid format for jcr:uuid");
+ }
+ }
+ }
+}
Propchange: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImplEx.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImplEx.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url