summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/core/src/main
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-10 05:57:51 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-10 05:57:51 +0000
commit1265ef2c9979752024588a8aacbde31fed1e6df1 (patch)
tree986ece3dd1b45fa8829d95ba1f2c835da9e7b554 /java/sca/modules/core/src/main
parent6c21cd40d156d91d02d1a2ea6c658fbfac3c0d3a (diff)
Create the runtime version of Endpoint2 for serialization
Serialize the EP using XML git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@783213 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/core/src/main')
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java40
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java15
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java109
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java61
4 files changed, 225 insertions, 0 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
new file mode 100644
index 0000000000..1cdc1c6209
--- /dev/null
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointSerializer.java
@@ -0,0 +1,40 @@
+/*
+ * 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.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;
+
+/**
+ * A utility to seralize/deserialize Endpoint/EndpointReference objects
+ */
+public interface EndpointSerializer {
+ void readExternal(Endpoint2 endpoint, ObjectInput input) throws IOException;
+
+ void writeExternal(Endpoint2 endpoint, ObjectOutput output) throws IOException;
+
+ void readExternal(EndpointReference2 endpointReference, ObjectInput input) throws IOException;
+
+ void writeExternal(EndpointReference2 endpointReference, ObjectOutput output) throws IOException;
+}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java
index 547c8f6750..27845b445c 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java
@@ -26,7 +26,10 @@ import org.apache.tuscany.sca.assembly.ComponentReference;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Contract;
import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Endpoint2;
+import org.apache.tuscany.sca.assembly.EndpointReference2;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl;
import org.apache.tuscany.sca.core.assembly.impl.EndpointReferenceImpl;
import org.apache.tuscany.sca.core.assembly.impl.ReferenceParametersImpl;
import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentImpl;
@@ -78,4 +81,16 @@ public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements As
return new ReferenceParametersImpl();
}
+ @Override
+ public Endpoint2 createEndpoint() {
+ // Create an instance of EndpointImpl that can be serialized/deserialized using the Tuscany
+ // runtime extension points and extensions
+ return new RuntimeEndpointImpl(registry);
+ }
+
+ @Override
+ public EndpointReference2 createEndpointReference() {
+ return super.createEndpointReference();
+ }
+
}
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
new file mode 100644
index 0000000000..bf3339d8ad
--- /dev/null
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java
@@ -0,0 +1,109 @@
+/*
+ * 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.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;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.Endpoint2;
+import org.apache.tuscany.sca.assembly.EndpointReference2;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.EndpointSerializer;
+
+public class EndpointSerializerImpl implements EndpointSerializer {
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+ private StAXArtifactProcessor<Endpoint2> processor;
+ private StAXArtifactProcessor<EndpointReference2> refProcessor;
+
+ public EndpointSerializerImpl(ExtensionPointRegistry registry) {
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ inputFactory = factories.getFactory(XMLInputFactory.class);
+ outputFactory = factories.getFactory(XMLOutputFactory.class);
+ StAXArtifactProcessorExtensionPoint processors =
+ registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ processor = processors.getProcessor(Endpoint2.class);
+ refProcessor = processors.getProcessor(EndpointReference2.class);
+ }
+
+ public void readExternal(Endpoint2 endpoint, ObjectInput input) 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());
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+
+ }
+
+ public void writeExternal(Endpoint2 endpoint, ObjectOutput output) throws IOException {
+ StringWriter sw = new StringWriter();
+ try {
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
+ processor.write(endpoint, writer);
+ writer.flush();
+ output.writeUTF(sw.toString());
+ writer.close();
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+
+ public void readExternal(EndpointReference2 endpointReference, ObjectInput input) 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());
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+
+ public void writeExternal(EndpointReference2 endpointReference, ObjectOutput output) throws IOException {
+ StringWriter sw = new StringWriter();
+ try {
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
+ refProcessor.write(endpointReference, writer);
+ writer.flush();
+ output.writeUTF(sw.toString());
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000000..41222a1148
--- /dev/null
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java
@@ -0,0 +1,61 @@
+/*
+ * 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.tuscany.sca.core.assembly.impl;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.apache.tuscany.sca.assembly.impl.Endpoint2Impl;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.assembly.EndpointSerializer;
+
+/**
+ * Runtime model for Endpoint that supports java serialization
+ */
+public class RuntimeEndpointImpl extends Endpoint2Impl implements Externalizable {
+ private static EndpointSerializer serializer;
+
+ /**
+ * No-arg constructor for Java serilization
+ */
+ public RuntimeEndpointImpl() {
+ super(null);
+ }
+
+ public RuntimeEndpointImpl(ExtensionPointRegistry registry) {
+ super(registry);
+ if (registry != null) {
+ serializer = new EndpointSerializerImpl(registry);
+ }
+ }
+
+ 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);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ serializer.writeExternal(this, out);
+ }
+
+}