summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:26:33 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:26:33 +0000
commita40e527938d76ba71f211da7e327adb50384ba69 (patch)
treecb8f99f1727122b040a3f0fbb6649292b6a74302 /sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider
parent968721109881107520d7aefa91d7fcc0519d7739 (diff)
Moving 1.x tags
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835157 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider')
-rw-r--r--sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.java48
-rw-r--r--sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.java55
-rw-r--r--sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java62
-rw-r--r--sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java74
4 files changed, 239 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.java
new file mode 100644
index 0000000000..e3d52fa703
--- /dev/null
+++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.java
@@ -0,0 +1,48 @@
+/*
+ * 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.provider;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+/**
+ * Interceptor for the sample echo binding.
+ */
+public class EchoBindingInvoker implements Invoker {
+
+ private Object echo(Object[] args) throws InvocationTargetException {
+ // echo back the result, a real binding would invoke some API for flowing the request
+ return args[0];
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ Object resp = echo((Object[])msg.getBody());
+ msg.setBody(resp);
+ } catch (InvocationTargetException e) {
+ msg.setFaultBody(e.getCause());
+ } catch (Throwable e) {
+ msg.setFaultBody(e);
+ }
+ return msg;
+ }
+
+}
diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.java
new file mode 100644
index 0000000000..623cb0e16e
--- /dev/null
+++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.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.provider;
+
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+import echo.EchoBinding;
+
+
+/**
+ * Implementation of the Echo binding model.
+ */
+public class EchoBindingProviderFactory implements BindingProviderFactory<EchoBinding> {
+
+ private MessageFactory messageFactory;
+
+ public EchoBindingProviderFactory(MessageFactory messageFactory) {
+ this.messageFactory = messageFactory;
+ }
+
+ public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, EchoBinding binding) {
+ return new EchoReferenceBindingProvider(component, reference, binding);
+ }
+
+ public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, EchoBinding binding) {
+ return new EchoServiceBindingProvider(component, service, binding, messageFactory);
+ }
+
+ public Class<EchoBinding> getModelType() {
+ return EchoBinding.class;
+ }
+}
diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java
new file mode 100644
index 0000000000..dd1a8f42f8
--- /dev/null
+++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java
@@ -0,0 +1,62 @@
+/*
+ * 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.provider;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+
+import echo.EchoBinding;
+
+/**
+ * Implementation of the Echo binding provider.
+ */
+public class EchoReferenceBindingProvider implements ReferenceBindingProvider {
+
+ private RuntimeComponentReference reference;
+
+ public EchoReferenceBindingProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ EchoBinding binding) {
+ this.reference = reference;
+ }
+
+ public Invoker createInvoker(Operation operation, boolean isCallback) {
+ if (isCallback) {
+ throw new UnsupportedOperationException();
+ } else {
+ return new EchoBindingInvoker();
+ }
+ }
+
+ public InterfaceContract getBindingInterfaceContract() {
+ return reference.getInterfaceContract();
+ }
+
+ public void start() {
+ }
+
+ public void stop() {
+ }
+
+}
diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java
new file mode 100644
index 0000000000..896e40df8d
--- /dev/null
+++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java
@@ -0,0 +1,74 @@
+/*
+ * 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.provider;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+
+import echo.EchoBinding;
+import echo.server.EchoServer;
+import echo.server.EchoService;
+
+/**
+ * Implementation of the Echo binding provider.
+ */
+public class EchoServiceBindingProvider implements ServiceBindingProvider {
+
+ private RuntimeComponent component;
+ private RuntimeComponentService service;
+ private EchoBinding binding;
+ private MessageFactory messageFactory;
+
+ public EchoServiceBindingProvider(RuntimeComponent component,
+ RuntimeComponentService service, EchoBinding binding, MessageFactory messageFactory) {
+ this.component = component;
+ this.service = service;
+ this.binding = binding;
+ this.messageFactory = messageFactory;
+ }
+
+ public InterfaceContract getBindingInterfaceContract() {
+ return service.getInterfaceContract();
+ }
+
+ public void start() {
+
+ RuntimeComponentService componentService = (RuntimeComponentService) service;
+ RuntimeWire wire = componentService.getRuntimeWire(binding);
+ InvocationChain chain = wire.getInvocationChains().get(0);
+
+ // Register with the hosting server
+ String uri = component.getURI() + "/" + binding.getName();
+ EchoServer.getServer().register(uri, new EchoService(chain.getHeadInvoker(), messageFactory));
+ }
+
+ public void stop() {
+
+ // Unregister from the hosting server
+ String uri = component.getURI() + "/" + binding.getName();
+ EchoServer.getServer().unregister(uri);
+ }
+
+}