summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/core
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-11 05:29:44 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-11 05:29:44 +0000
commit846b8fa2a3853c426f98d42fc49d9bbbd1d92dee (patch)
treebfb66dd29f67a609eb4f95cf1772466991ffaae2 /java/sca/modules/core
parent6ecd6c5f7101ca2d127bbde07206f08df5f9e995 (diff)
Use uri for Endpoint/EndpointReference
Defer the deserilization of Endpoint to later point to avoid NPE git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@783634 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/core')
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java10
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java19
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java32
3 files changed, 41 insertions, 20 deletions
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java
index 1cdc1c6209..ff2c98cefb 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java
@@ -20,8 +20,6 @@
package org.apache.tuscany.sca.core.assembly;
import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import org.apache.tuscany.sca.assembly.Endpoint2;
import org.apache.tuscany.sca.assembly.EndpointReference2;
@@ -30,11 +28,11 @@ import org.apache.tuscany.sca.assembly.EndpointReference2;
* A utility to seralize/deserialize Endpoint/EndpointReference objects
*/
public interface EndpointSerializer {
- void readExternal(Endpoint2 endpoint, ObjectInput input) throws IOException;
+ void read(Endpoint2 endpoint, String xml) throws IOException;
- void writeExternal(Endpoint2 endpoint, ObjectOutput output) throws IOException;
+ String write(Endpoint2 endpoint) throws IOException;
- void readExternal(EndpointReference2 endpointReference, ObjectInput input) throws IOException;
+ void read(EndpointReference2 endpointReference, String xml) throws IOException;
- void writeExternal(EndpointReference2 endpointReference, ObjectOutput output) throws IOException;
+ String write(EndpointReference2 endpointReference) throws IOException;
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java
index bf3339d8ad..1cef109553 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java
@@ -20,8 +20,6 @@
package org.apache.tuscany.sca.core.assembly.impl;
import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.io.StringReader;
import java.io.StringWriter;
@@ -54,54 +52,55 @@ public class EndpointSerializerImpl implements EndpointSerializer {
refProcessor = processors.getProcessor(EndpointReference2.class);
}
- public void readExternal(Endpoint2 endpoint, ObjectInput input) throws IOException {
+ public void read(Endpoint2 endpoint, String xml) throws IOException {
try {
- String xml = input.readUTF();
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml));
Endpoint2 result = processor.read(reader);
endpoint.setComponent(result.getComponent());
endpoint.setService(result.getService());
endpoint.setBinding(result.getBinding());
+ endpoint.setInterfaceContract(result.getService().getInterfaceContract());
} catch (Exception e) {
throw new IOException(e);
}
}
- public void writeExternal(Endpoint2 endpoint, ObjectOutput output) throws IOException {
+ public String write(Endpoint2 endpoint) throws IOException {
StringWriter sw = new StringWriter();
try {
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
processor.write(endpoint, writer);
writer.flush();
- output.writeUTF(sw.toString());
writer.close();
+ return sw.toString();
} catch (Exception e) {
throw new IOException(e);
}
}
- public void readExternal(EndpointReference2 endpointReference, ObjectInput input) throws IOException {
+ public void read(EndpointReference2 endpointReference, String xml) throws IOException {
try {
- String xml = input.readUTF();
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml));
EndpointReference2 result = refProcessor.read(reader);
reader.close();
endpointReference.setComponent(result.getComponent());
endpointReference.setReference(result.getReference());
endpointReference.setBinding(result.getBinding());
+ endpointReference.setInterfaceContract(result.getReference().getInterfaceContract());
} catch (Exception e) {
throw new IOException(e);
}
}
- public void writeExternal(EndpointReference2 endpointReference, ObjectOutput output) throws IOException {
+ public String write(EndpointReference2 endpointReference) throws IOException {
StringWriter sw = new StringWriter();
try {
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
refProcessor.write(endpointReference, writer);
writer.flush();
- output.writeUTF(sw.toString());
+ writer.close();
+ return sw.toString();
} catch (Exception e) {
throw new IOException(e);
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java
index 41222a1148..da21e9f8ba 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java
@@ -32,7 +32,12 @@ import org.apache.tuscany.sca.core.assembly.EndpointSerializer;
* Runtime model for Endpoint that supports java serialization
*/
public class RuntimeEndpointImpl extends Endpoint2Impl implements Externalizable {
+ /**
+ * FIXME: What's the best way to get the extension point registry upon deserialization?
+ * We can expose a method to receive the extension point registry
+ */
private static EndpointSerializer serializer;
+ private String xml;
/**
* No-arg constructor for Java serilization
@@ -49,13 +54,32 @@ public class RuntimeEndpointImpl extends Endpoint2Impl implements Externalizable
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- // When this method is invoked, the instance is created using the no-arg constructor
- // We need to keep the serializer as a static
- serializer.readExternal(this, in);
+ this.uri = in.readUTF();
+ this.xml = in.readUTF();
+ // Defer the loading to resolve();
}
public void writeExternal(ObjectOutput out) throws IOException {
- serializer.writeExternal(this, out);
+ out.writeUTF(getURI());
+ out.writeUTF(serializer.write(this));
+ }
+
+ @Override
+ protected void reset() {
+ super.reset();
+ this.xml = null;
+ }
+
+ @Override
+ protected void resolve() {
+ if (component == null && xml != null) {
+ try {
+ serializer.read(this, xml);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ super.resolve();
}
}