Author: rhauch
Date: 2008-05-24 12:54:26 -0400 (Sat, 24 May 2008)
New Revision: 197
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/Path.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
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Correctly implemented the externalizable methods, and provided no-arg constructors. Note
that all Externalizable.readObject(...) methods are synchronized to ensure that they
properly reconstitute the object in the face of multiple concurrent calls.
Unfortunately, using Externalizable makes these classes technically not immutable, since
anybody may call "readObject" to change the instance. That may warrant changing
back to Serializable.
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:51:54 UTC (rev 196)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java 2008-05-24
16:54:26 UTC (rev 197)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Serializable;
+import java.io.Externalizable;
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>, Serializable {
+public interface Name extends Comparable<Name>, Externalizable {
/**
* 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:51:54 UTC (rev 196)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-24
16:54:26 UTC (rev 197)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import java.io.Serializable;
+import java.io.Externalizable;
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>,
Serializable {
+public interface Path extends Comparable<Path>, Iterable<Path.Segment>,
Externalizable {
/**
* The text encoder that does nothing.
@@ -121,7 +121,7 @@
* @author Randall Hauch
*/
@Immutable
- public static interface Segment extends Cloneable, Comparable<Segment>,
Serializable {
+ public static interface Segment extends Cloneable, Comparable<Segment>,
Externalizable {
/**
* Get the name component of this segment.
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:51:54 UTC (rev 196)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-24
16:54:26 UTC (rev 197)
@@ -21,6 +21,9 @@
*/
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;
@@ -36,10 +39,14 @@
@Immutable
public class BasicName implements Name {
- private final String namespaceUri;
- private final String localName;
- private final int hc;
+ private String namespaceUri;
+ private String localName;
+ private transient int hc;
+ public BasicName() {
+ this("", "");
+ }
+
public BasicName( String namespaceUri, String localName ) {
this.namespaceUri = namespaceUri != null ? namespaceUri.trim() : "";
this.localName = localName != null ? localName.trim() : "";
@@ -144,4 +151,21 @@
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:51:54 UTC (rev 196)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-24
16:54:26 UTC (rev 197)
@@ -21,6 +21,9 @@
*/
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;
@@ -50,9 +53,9 @@
protected static final Path SELF_PATH = new
BasicPath(Collections.singletonList(BasicPathSegment.SELF_SEGMENT), false);
- private final List<Segment> segments;
- private final boolean absolute;
- private final boolean normalized;
+ private List<Segment> segments;
+ private boolean absolute;
+ private transient boolean normalized;
private transient String path;
/**
@@ -494,4 +497,31 @@
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:51:54 UTC (rev 196)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-24
16:54:26 UTC (rev 197)
@@ -21,6 +21,9 @@
*/
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,8 +42,13 @@
public static final Path.Segment PARENT_SEGMENT = new BasicPathSegment(new
BasicName("", Path.PARENT));
private final Name name;
- private final int index;
+ private 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
@@ -178,4 +186,20 @@
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:51:54 UTC (rev 196)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24
16:54:26 UTC (rev 197)
@@ -110,7 +110,7 @@
/**
* {@inheritDoc}
*/
- public void readExternal( ObjectInput in ) throws IOException {
+ public synchronized void readExternal( ObjectInput in ) throws IOException {
int length = in.readInt();
this.bytes = new byte[length];
in.read(this.bytes);
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:51:54 UTC (rev 196)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24
16:54:26 UTC (rev 197)
@@ -285,7 +285,7 @@
/**
* {@inheritDoc}
*/
- public void readExternal( ObjectInput in ) throws IOException {
+ public synchronized void readExternal( ObjectInput in ) throws IOException {
this.instance = new DateTime(in.readUTF());
}
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:51:54 UTC (rev 196)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-05-24
16:54:26 UTC (rev 197)
@@ -101,7 +101,7 @@
/**
* {@inheritDoc}
*/
- public void readExternal( ObjectInput in ) throws IOException {
+ public synchronized void readExternal( ObjectInput in ) throws IOException {
long lsb = in.readLong();
long msb = in.readLong();
this.uuid = new UUID(msb, lsb);