Author: rhauch
Date: 2008-05-24 13:08:43 -0400 (Sat, 24 May 2008)
New Revision: 198
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Changed from Externalizable to Serializable so that the graph objects can be truly
immutable. This will eliminate concurrency issues and safety issues.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java 2008-05-24
16:54:26 UTC (rev 197)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -21,8 +21,8 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Externalizable;
import java.io.InputStream;
+import java.io.Serializable;
import net.jcip.annotations.ThreadSafe;
/**
@@ -30,7 +30,7 @@
* @author Randall Hauch
*/
@ThreadSafe
-public interface Binary extends Comparable<Binary>, Externalizable {
+public interface Binary extends Comparable<Binary>, Serializable {
/**
* Get the length of this binary data.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-24
16:54:26 UTC (rev 197)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Externalizable;
+import java.io.Serializable;
import java.util.Locale;
/**
@@ -32,7 +32,7 @@
* classes.
* @author Randall Hauch
*/
-public interface DateTime extends Comparable<DateTime>, Externalizable {
+public interface DateTime extends Comparable<DateTime>, Serializable {
/**
* Get the ISO-8601 representation of this instance in time.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java 2008-05-24
16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Externalizable;
+import java.io.Serializable;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
@@ -30,7 +30,7 @@
* @author Randall Hauch
*/
@Immutable
-public interface Name extends Comparable<Name>, Externalizable {
+public interface Name extends Comparable<Name>, Serializable {
/**
* Get the local name part of this qualified name.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-24
16:54:26 UTC (rev 197)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Externalizable;
+import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import net.jcip.annotations.Immutable;
@@ -67,7 +67,7 @@
* @author Randall Hauch
*/
@Immutable
-public interface Path extends Comparable<Path>, Iterable<Path.Segment>,
Externalizable {
+public interface Path extends Comparable<Path>, Iterable<Path.Segment>,
Serializable {
/**
* The text encoder that does nothing.
@@ -121,7 +121,7 @@
* @author Randall Hauch
*/
@Immutable
- public static interface Segment extends Cloneable, Comparable<Segment>,
Externalizable {
+ public static interface Segment extends Cloneable, Comparable<Segment>,
Serializable {
/**
* Get the name component of this segment.
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java 2008-05-24
16:54:26 UTC (rev 197)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -21,13 +21,13 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Externalizable;
+import java.io.Serializable;
import org.jboss.dna.common.text.TextEncoder;
/**
* @author Randall Hauch
*/
-public interface Reference extends Comparable<Reference>, Externalizable {
+public interface Reference extends Comparable<Reference>, Serializable {
/**
* Get the string form of the Reference. The {@link Path#DEFAULT_ENCODER default
encoder} is used to encode characters in the
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-24
16:54:26 UTC (rev 197)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -21,9 +21,6 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
@@ -39,14 +36,10 @@
@Immutable
public class BasicName implements Name {
- private String namespaceUri;
- private String localName;
- private transient int hc;
+ private final String namespaceUri;
+ private final String localName;
+ private final int hc;
- public BasicName() {
- this("", "");
- }
-
public BasicName( String namespaceUri, String localName ) {
this.namespaceUri = namespaceUri != null ? namespaceUri.trim() : "";
this.localName = localName != null ? localName.trim() : "";
@@ -151,21 +144,4 @@
return "{" + this.namespaceUri + "}" + this.localName;
}
- /**
- * {@inheritDoc}
- */
- public synchronized void readExternal( ObjectInput in ) throws IOException {
- this.namespaceUri = in.readUTF();
- this.localName = in.readUTF();
- this.hc = HashCode.compute(this.namespaceUri, this.localName);
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- out.writeUTF(this.namespaceUri);
- out.writeUTF(this.localName);
- }
-
}
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-24
16:54:26 UTC (rev 197)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -21,9 +21,6 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -53,9 +50,9 @@
protected static final Path SELF_PATH = new
BasicPath(Collections.singletonList(BasicPathSegment.SELF_SEGMENT), false);
- private List<Segment> segments;
- private boolean absolute;
- private transient boolean normalized;
+ private final List<Segment> segments;
+ private final boolean absolute;
+ private final boolean normalized;
private transient String path;
/**
@@ -497,31 +494,4 @@
return getString(Path.URL_ENCODER);
}
- /**
- * {@inheritDoc}
- */
- public synchronized void readExternal( ObjectInput in ) throws IOException,
ClassNotFoundException {
- int numSegments = in.readInt();
- this.segments = new ArrayList<Segment>(numSegments);
- for (int i = 0; i != numSegments; ++i) {
- BasicPathSegment segment = new BasicPathSegment();
- segment.readExternal(in);
- this.segments.add(segment);
- }
- this.absolute = in.readBoolean();
- this.normalized = isNormalized(this.segments);
- this.path = null;
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- out.writeInt(this.segments.size());
- for (Segment segment : this.segments) {
- segment.writeExternal(out);
- }
- out.writeBoolean(this.absolute);
- }
-
}
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-24
16:54:26 UTC (rev 197)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -21,9 +21,6 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
@@ -42,13 +39,8 @@
public static final Path.Segment PARENT_SEGMENT = new BasicPathSegment(new
BasicName("", Path.PARENT));
private final Name name;
- private int index;
+ private final int index;
- public BasicPathSegment() {
- this.name = new BasicName();
- this.index = Path.NO_INDEX;
- }
-
/**
* @param name the segment name
* @throws IllegalArgumentException if the name is null or if the index is invalid
@@ -186,20 +178,4 @@
return encodedName;
}
- /**
- * {@inheritDoc}
- */
- public synchronized void readExternal( ObjectInput in ) throws IOException,
ClassNotFoundException {
- this.name.readExternal(in);
- this.index = in.readInt();
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- this.name.writeExternal(out);
- out.writeInt(this.index);
- }
-
}
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24
16:54:26 UTC (rev 197)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -22,10 +22,7 @@
package org.jboss.dna.spi.graph.impl;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Binary;
@@ -40,12 +37,8 @@
protected static final byte[] EMPTY_CONTENT = new byte[0];
- private byte[] bytes;
+ private final byte[] bytes;
- public InMemoryBinary() {
- this.bytes = EMPTY_CONTENT;
- }
-
public InMemoryBinary( byte[] bytes ) {
ArgCheck.isNotNull(bytes, "bytes");
this.bytes = bytes;
@@ -110,23 +103,6 @@
/**
* {@inheritDoc}
*/
- public synchronized void readExternal( ObjectInput in ) throws IOException {
- int length = in.readInt();
- this.bytes = new byte[length];
- in.read(this.bytes);
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- out.writeInt(this.bytes.length);
- out.write(this.bytes);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
public String toString() {
StringBuilder sb = new StringBuilder(super.toString());
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24
16:54:26 UTC (rev 197)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -21,9 +21,6 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -40,7 +37,7 @@
@Immutable
public class JodaDateTime implements org.jboss.dna.spi.graph.DateTime {
- private DateTime instance;
+ private final DateTime instance;
private transient String formattedString;
public JodaDateTime( String iso8601 ) {
@@ -282,18 +279,4 @@
return getString();
}
- /**
- * {@inheritDoc}
- */
- public synchronized void readExternal( ObjectInput in ) throws IOException {
- this.instance = new DateTime(in.readUTF());
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- out.writeUTF(this.getString());
- }
-
}
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-05-24
16:54:26 UTC (rev 197)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -21,9 +21,6 @@
*/
package org.jboss.dna.spi.graph.impl;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
@@ -98,21 +95,4 @@
return this.uuid.toString();
}
- /**
- * {@inheritDoc}
- */
- public synchronized void readExternal( ObjectInput in ) throws IOException {
- long lsb = in.readLong();
- long msb = in.readLong();
- this.uuid = new UUID(msb, lsb);
- }
-
- /**
- * {@inheritDoc}
- */
- public void writeExternal( ObjectOutput out ) throws IOException {
- out.writeLong(this.uuid.getLeastSignificantBits());
- out.writeLong(this.uuid.getMostSignificantBits());
- }
-
}
Modified:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java
===================================================================
---
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java 2008-05-24
16:54:26 UTC (rev 197)
+++
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java 2008-05-24
17:08:43 UTC (rev 198)
@@ -25,12 +25,8 @@
import static org.jboss.dna.spi.graph.impl.BinaryContains.hasContent;
import static org.jboss.dna.spi.graph.impl.BinaryContains.hasNoContent;
import static org.junit.Assert.assertThat;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import org.jboss.dna.common.util.IoUtil;
import org.jboss.dna.spi.graph.Binary;
import org.junit.Before;
@@ -113,22 +109,4 @@
assertThat(another, hasContent(shorterContent));
}
- @Test
- public void shouldBeRecoverableFromExternalizedForm() throws Exception {
- ByteArrayOutputStream contentStream = new ByteArrayOutputStream();
- ObjectOutputStream output = new ObjectOutputStream(contentStream);
- // Write the binary object ...
- binary.writeExternal(output);
- output.close();
- // Now read the object back in ...
- ByteArrayInputStream contentInputStream = new
ByteArrayInputStream(contentStream.toByteArray());
- ObjectInputStream input = new ObjectInputStream(contentInputStream);
- InMemoryBinary recovered = new InMemoryBinary();
- recovered.readExternal(input);
- input.close();
- // Compare ...
- assertThat(recovered, is(binary));
- assertThat(recovered, hasContent(binary));
- }
-
}