summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java')
-rw-r--r--sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBinding.java32
-rw-r--r--sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBindingLoader.java58
-rw-r--r--sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBuilder.java52
-rw-r--r--sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoInvoker.java68
-rw-r--r--sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoReference.java55
-rw-r--r--sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoService.java44
6 files changed, 309 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBinding.java b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBinding.java
new file mode 100644
index 0000000000..da44906cf6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBinding.java
@@ -0,0 +1,32 @@
+/*
+ * 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 echo;
+
+import org.apache.tuscany.spi.model.BindingDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EchoBinding extends BindingDefinition {
+
+ public Object clone() {
+ return this;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBindingLoader.java b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBindingLoader.java
new file mode 100644
index 0000000000..b77dcca3b9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBindingLoader.java
@@ -0,0 +1,58 @@
+/*
+ * 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 echo;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EchoBindingLoader extends LoaderExtension<EchoBinding> {
+
+ public static final QName BINDING_ECHO = new QName(SCA_NS, "binding.echo");
+
+ @Constructor
+ public EchoBindingLoader(@Autowire LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return BINDING_ECHO;
+ }
+
+ public EchoBinding load(CompositeComponent parent,
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext context) throws XMLStreamException, LoaderException {
+ return new EchoBinding();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBuilder.java b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBuilder.java
new file mode 100644
index 0000000000..7cf1b35617
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoBuilder.java
@@ -0,0 +1,52 @@
+/*
+ * 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 echo;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.BindingBuilderExtension;
+import org.apache.tuscany.spi.model.AbstractReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EchoBuilder extends BindingBuilderExtension<EchoBinding> {
+
+ public ServiceBinding build(CompositeComponent parent,
+ ServiceDefinition boundServiceDefinition,
+ EchoBinding bindingDefinition,
+ DeploymentContext deploymentContext) throws BuilderException {
+ return new EchoService(boundServiceDefinition.getName(), parent);
+ }
+
+ public ReferenceBinding build(CompositeComponent parent,
+ AbstractReferenceDefinition boundReferenceDefinition,
+ EchoBinding bindingDefinition,
+ DeploymentContext deploymentContext) throws BuilderException {
+ return new EchoReference(boundReferenceDefinition.getName(), parent);
+ }
+
+ protected Class<EchoBinding> getBindingType() {
+ return EchoBinding.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoInvoker.java b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoInvoker.java
new file mode 100644
index 0000000000..972dae843f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoInvoker.java
@@ -0,0 +1,68 @@
+/*
+ * 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 echo;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EchoInvoker implements TargetInvoker {
+
+ private boolean cacheable;
+
+ public boolean isCacheable() {
+ return cacheable;
+ }
+
+ public void setCacheable(boolean cacheable) {
+ this.cacheable = cacheable;
+ }
+
+ public boolean isOptimizable() {
+ return isCacheable();
+ }
+
+ public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException {
+ // echo back the result, a real binding would invoke some API for flowing the request
+ Object result = ((Object[]) payload)[0];
+ System.out.println("Echo: " + result);
+ return result;
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ Object resp = invokeTarget(msg.getBody(), NONE);
+ msg.setBody(resp);
+ } catch (InvocationTargetException e) {
+ msg.setBodyWithFault(e.getCause());
+ } catch (Throwable e) {
+ msg.setBodyWithFault(e);
+ }
+ return msg;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoReference.java b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoReference.java
new file mode 100644
index 0000000000..9eaf0914cc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoReference.java
@@ -0,0 +1,55 @@
+/*
+ * 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 echo;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.extension.ReferenceBindingExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EchoReference extends ReferenceBindingExtension {
+
+ private static final String OM_DATA_BINDING = OMElement.class.getName();
+
+ private static final QName BINDING_ECHO = new QName(SCA_NS, "binding.echo");
+
+ public EchoReference(String name, CompositeComponent parent) {
+ super(name, parent);
+ }
+
+ public QName getBindingType() {
+ return BINDING_ECHO;
+ }
+
+ @SuppressWarnings("unchecked")
+ public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) {
+ // HACK to set the databinding
+ operation.setDataBinding(OM_DATA_BINDING);
+ return new EchoInvoker();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoService.java b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoService.java
new file mode 100644
index 0000000000..85ed497799
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-integration/samples/sca/echo-databinding/src/main/java/echo/EchoService.java
@@ -0,0 +1,44 @@
+/*
+ * 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 echo;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.extension.ServiceBindingExtension;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EchoService extends ServiceBindingExtension {
+ private static final QName BINDING_ECHO = new QName(SCA_NS, "binding.echo");
+
+ public EchoService(String name, CompositeComponent parent) throws CoreRuntimeException {
+ super(name, parent);
+ // do nothing, but this could register with the host environment
+ }
+
+
+ public QName getBindingType() {
+ return BINDING_ECHO;
+ }
+}