jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r674024 - in /jackrabbit/trunk/jackrabbit-spi-commons/src: main/java/org/apache/jackrabbit/spi/commons/identifier/ test/java/org/apache/jackrabbit/spi/commons/identifier/
Date Fri, 04 Jul 2008 12:09:02 GMT
Author: mreutegg
Date: Fri Jul  4 05:09:02 2008
New Revision: 674024

URL: http://svn.apache.org/viewvc?rev=674024&view=rev
Log:
JCR-1653: NodeIdImpl is not really serializable

Added:
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/SerializationTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/TestAll.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java?rev=674024&r1=674023&r2=674024&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/identifier/AbstractIdFactory.java
Fri Jul  4 05:09:02 2008
@@ -45,7 +45,7 @@
      */
     public NodeId createNodeId(NodeId parentId, Path path) {
         try {
-            return new NodeIdImpl(parentId, path);
+            return new NodeIdImpl(parentId, path, getPathFactory());
         } catch (RepositoryException e) {
             throw new IllegalArgumentException(e.getMessage());
         }
@@ -73,14 +73,15 @@
      */
     public PropertyId createPropertyId(NodeId parentId, Name propertyName) {
         try {
-            return new PropertyIdImpl(parentId, propertyName);
+            return new PropertyIdImpl(parentId, propertyName, getPathFactory());
         } catch (RepositoryException e) {
             throw new IllegalArgumentException(e.getMessage());
         }
     }
 
     //------------------------------------------------------< Inner classes >---
-    private abstract class ItemIdImpl implements ItemId, Serializable {
+
+    private static abstract class ItemIdImpl implements ItemId, Serializable {
 
         private final String uniqueID;
         private final Path path;
@@ -95,16 +96,17 @@
             this.path = path;
         }
 
-        private ItemIdImpl(NodeId parentId, Name name) throws RepositoryException {
+        private ItemIdImpl(NodeId parentId, Name name, PathFactory factory)
+                throws RepositoryException {
             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 = getPathFactory().create(parentPath, name, true);
+                this.path = factory.create(parentPath, name, true);
             } else {
-                this.path = getPathFactory().create(name);
+                this.path = factory.create(name);
             }
         }
 
@@ -150,7 +152,10 @@
         public int hashCode() {
             // since the ItemIdImpl is immutable, store the computed hash code value
             if (hashCode == 0) {
-                hashCode = toString().hashCode();
+                int result = 17;
+                result = 37 * result + (uniqueID != null ? uniqueID.hashCode() : 0);
+                result = 37 * result + (path != null ? path.hashCode() : 0);
+                hashCode = result;
             }
             return hashCode;
         }
@@ -172,7 +177,9 @@
         }
     }
 
-    private class NodeIdImpl extends ItemIdImpl implements NodeId {
+    private static class NodeIdImpl extends ItemIdImpl implements NodeId {
+
+        private static final long serialVersionUID = -360276648861146631L;
 
         public NodeIdImpl(String uniqueID) {
             super(uniqueID, null);
@@ -182,8 +189,9 @@
             super(uniqueID, path);
         }
 
-        public NodeIdImpl(NodeId parentId, Path path) throws RepositoryException {
-            super(parentId.getUniqueID(), (parentId.getPath() != null) ? getPathFactory().create(parentId.getPath(),
path, true) : path);
+        public NodeIdImpl(NodeId parentId, Path path, PathFactory factory)
+                throws RepositoryException {
+            super(parentId.getUniqueID(), (parentId.getPath() != null) ? factory.create(parentId.getPath(),
path, true) : path);
         }
 
         public boolean denotesNode() {
@@ -201,12 +209,15 @@
         }
     }
 
-    private class PropertyIdImpl extends ItemIdImpl implements PropertyId {
+    private static class PropertyIdImpl extends ItemIdImpl implements PropertyId, Serializable
{
+
+        private static final long serialVersionUID = -1953124047770776444L;
 
         private final NodeId parentId;
 
-        private PropertyIdImpl(NodeId parentId, Name name) throws RepositoryException {
-            super(parentId, name);
+        private PropertyIdImpl(NodeId parentId, Name name, PathFactory factory)
+                throws RepositoryException {
+            super(parentId, name, factory);
             this.parentId = parentId;
         }
 

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/SerializationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/SerializationTest.java?rev=674024&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/SerializationTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/SerializationTest.java
Fri Jul  4 05:09:02 2008
@@ -0,0 +1,70 @@
+/*
+ * 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.spi.commons.identifier;
+
+import junit.framework.TestCase;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+
+/**
+ * <code>SerializationTest</code> checks that PropertyIds and NodeIds are
+ * serializable.
+ */
+public class SerializationTest extends TestCase {
+
+    private static final IdFactory ID_FACTORY = IdFactoryImpl.getInstance();
+
+    private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
+
+    private static final Path REL_PATH = PATH_FACTORY.create(NameConstants.JCR_CONTENT);
+
+    private static final NodeId PARENT_ID = ID_FACTORY.createNodeId("unique-id", REL_PATH);
+
+    public void testPropertyId() throws Exception {
+        checkSerializable(ID_FACTORY.createPropertyId(
+                PARENT_ID, NameConstants.JCR_PRIMARYTYPE));
+    }
+
+    public void testNodeId() throws Exception {
+        checkSerializable(ID_FACTORY.createNodeId(PARENT_ID, REL_PATH));
+
+        checkSerializable(ID_FACTORY.createNodeId(PARENT_ID.getUniqueID(), REL_PATH));
+
+        checkSerializable(ID_FACTORY.createNodeId(PARENT_ID.getUniqueID()));
+    }
+
+    private void checkSerializable(ItemId id) throws Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(out);
+        oos.writeObject(id);
+        oos.close();
+        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+        ObjectInputStream ois = new ObjectInputStream(in);
+        ItemId clone = (ItemId) ois.readObject();
+        assertEquals("Deserialized ItemId not equal to original", id, clone);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/SerializationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/TestAll.java?rev=674024&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/TestAll.java
(added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/TestAll.java
Fri Jul  4 05:09:02 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.spi.commons.identifier;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.framework.TestCase;
+
+/**
+ * <code>TestAll</code> contains all identifier related test cases.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     *
+     * @return a <code>Test</code> suite that executes all tests inside this
+     *         package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("identifier tests");
+
+        suite.addTestSuite(SerializationTest.class);
+
+        return suite;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/identifier/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message