summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider')
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.java52
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingPoliciedInvoker.java70
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.java61
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java69
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java80
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingEncryptionPolicy.java44
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingEncryptionPolicyProcessor.java36
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingPolicy.java43
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingPolicyProcessor.java78
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EncryptionPolicyHandler.java47
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EncryptionStrategy.java26
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/PolicyHandler.java29
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/ReverseEncryptionStrategy.java33
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/WSPolicy.java43
-rw-r--r--sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/WSPolicyProcessor.java54
15 files changed, 765 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.java
new file mode 100644
index 0000000000..1d9e28a899
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.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.provider;
+
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+import echo.server.EchoServer;
+
+/**
+ * Invoker for the sample echo binding.
+ */
+class EchoBindingInvoker implements Invoker {
+ private String uri;
+
+ EchoBindingInvoker(String uri) {
+ this.uri = uri;
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ System.out.println("Passing thro invoker...");
+ Object[] args = msg.getBody();
+
+ // echo back the first parameter, a real binding would invoke some API for flowing the request
+ Object result = EchoServer.getServer().call(uri, args);
+
+ msg.setBody(result);
+
+ } catch (Exception e) {
+ msg.setFaultBody(e);
+ }
+ return msg;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingPoliciedInvoker.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingPoliciedInvoker.java
new file mode 100644
index 0000000000..342fd6e0e7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingPoliciedInvoker.java
@@ -0,0 +1,70 @@
+/*
+ * 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.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+import echo.provider.policy.EncryptionPolicyHandler;
+import echo.provider.policy.PolicyHandler;
+
+/**
+ * Invoker that applies policies before invocation for the sample echo binding.
+ */
+public class EchoBindingPoliciedInvoker implements Invoker {
+ List<PolicySet> policies = null;
+ Map<QName, PolicyHandler> policyHandlers = new HashMap<QName, PolicyHandler>();
+
+ public EchoBindingPoliciedInvoker(List<PolicySet> policies) {
+ this.policies = policies;
+ policyHandlers.put(new QName("http://test", "EncryptionPolicy"), new EncryptionPolicyHandler());
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ Object[] args = msg.getBody();
+
+ applyPolicies(args);
+
+ // echo back the first parameter, a real binding would invoke some API for flowing the request
+ Object result = args[0];
+
+ msg.setBody(result);
+
+ } catch (Exception e) {
+ msg.setFaultBody(e);
+ }
+ return msg;
+ }
+
+ private void applyPolicies(Object[] args) throws Exception {
+ for (PolicySet policySet : policies) {
+ PolicyHandler policyHandler = policyHandlers.get(policySet.getName());
+ policyHandler.applyPolicy(args, policySet);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.java
new file mode 100644
index 0000000000..adbc436950
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.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 echo.provider;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+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(ExtensionPointRegistry extensionPoints) {
+ ModelFactoryExtensionPoint factories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ this.messageFactory = factories.getFactory(MessageFactory.class);
+ }
+
+ 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/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java
new file mode 100644
index 0000000000..3178c50a2a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java
@@ -0,0 +1,69 @@
+/*
+ * 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.policy.PolicySetAttachPoint;
+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.
+ */
+class EchoReferenceBindingProvider implements ReferenceBindingProvider {
+
+ private RuntimeComponentReference reference;
+ private EchoBinding binding;
+
+ EchoReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, EchoBinding binding) {
+ this.reference = reference;
+ this.binding = binding;
+ }
+
+ public Invoker createInvoker(Operation operation) {
+ if (binding instanceof PolicySetAttachPoint) {
+ PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)binding;
+ if (!policySetAttachPoint.getPolicySets().isEmpty()) {
+ return new EchoBindingPoliciedInvoker(policySetAttachPoint.getPolicySets());
+ }
+ }
+ return new EchoBindingInvoker(binding.getURI());
+ }
+
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+ public InterfaceContract getBindingInterfaceContract() {
+ return reference.getInterfaceContract();
+ }
+
+ public void start() {
+ }
+
+ public void stop() {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java
new file mode 100644
index 0000000000..43eb562c55
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java
@@ -0,0 +1,80 @@
+/*
+ * 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.EchoServiceListener;
+
+/**
+ * Implementation of the Echo binding provider.
+ */
+class EchoServiceBindingProvider implements ServiceBindingProvider {
+
+ private RuntimeComponent component;
+ private RuntimeComponentService service;
+ private EchoBinding binding;
+ private MessageFactory messageFactory;
+
+ 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 boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+ 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 = binding.getURI();
+ EchoServer.getServer().register(uri, new EchoServiceListener(chain.getHeadInvoker(), messageFactory));
+ }
+
+ public void stop() {
+
+ // Unregister from the hosting server
+ String uri = component.getURI() + "/" + binding.getName();
+ EchoServer.getServer().unregister(uri);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingEncryptionPolicy.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingEncryptionPolicy.java
new file mode 100644
index 0000000000..c1f1269db6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingEncryptionPolicy.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.provider.policy;
+
+/**
+ */
+public class EchoBindingEncryptionPolicy extends EchoBindingPolicy {
+
+ private String encryptionStrategyClassName;
+ private Class<? extends EncryptionStrategy> strategyClass;
+
+ public String getEncryptionStrategyClassName() {
+ return encryptionStrategyClassName;
+ }
+
+ public void setEncryptionStrategyClassName(String encryptionStrategyClassName) {
+ this.encryptionStrategyClassName = encryptionStrategyClassName;
+ }
+
+ public Class<? extends EncryptionStrategy> getStrategyClass() {
+ return strategyClass;
+ }
+
+ public void setStrategyClass(Class<? extends EncryptionStrategy> strategy) {
+ this.strategyClass = strategy;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingEncryptionPolicyProcessor.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingEncryptionPolicyProcessor.java
new file mode 100644
index 0000000000..da47bbfac3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingEncryptionPolicyProcessor.java
@@ -0,0 +1,36 @@
+/*
+ * 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.policy;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ *
+ */
+public class EchoBindingEncryptionPolicyProcessor extends EchoBindingPolicyProcessor<EchoBindingEncryptionPolicy> {
+
+ public EchoBindingEncryptionPolicyProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ }
+
+ public Class<EchoBindingEncryptionPolicy> getModelType() {
+ return EchoBindingEncryptionPolicy.class;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingPolicy.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingPolicy.java
new file mode 100644
index 0000000000..0dab68075d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingPolicy.java
@@ -0,0 +1,43 @@
+/*
+ * 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.policy;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.Policy;
+
+/**
+
+ */
+public class EchoBindingPolicy implements Policy {
+ private boolean unresolved = true;
+
+ public QName getSchemaName() {
+ return new QName("http://sample/policy", "echoBindingPolicy");
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingPolicyProcessor.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingPolicyProcessor.java
new file mode 100644
index 0000000000..72b8002238
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EchoBindingPolicyProcessor.java
@@ -0,0 +1,78 @@
+/*
+ * 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.policy;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+
+/**
+ *
+ */
+public abstract class EchoBindingPolicyProcessor<T extends EchoBindingPolicy> implements StAXArtifactProcessor<T> {
+ public static final String ENCRYPTION = "Encryption";
+
+ public QName getArtifactType() {
+ return new QName("http://sample/policy", "echoBindingPolicy");
+ }
+
+ public T read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ String name = reader.getAttributeValue(null, "name");
+ if (name != null && name.equals(ENCRYPTION)) {
+ EchoBindingEncryptionPolicy policy = new EchoBindingEncryptionPolicy();
+ policy.setEncryptionStrategyClassName(reader.getAttributeValue(null, "strategy"));
+ return (T)policy;
+ }
+ return null;
+ }
+
+ public void write(T arg0, XMLStreamWriter arg1) throws ContributionWriteException, XMLStreamException {
+ }
+
+ public void resolve(T policy, ModelResolver resolver) throws ContributionResolveException {
+ if (policy instanceof EchoBindingEncryptionPolicy) {
+ EchoBindingEncryptionPolicy ePolicy = (EchoBindingEncryptionPolicy)policy;
+
+ ClassReference classReference = new ClassReference(ePolicy.getEncryptionStrategyClassName());
+ classReference = resolver.resolveModel(ClassReference.class, classReference);
+ Class javaClass = classReference != null ? classReference.getJavaClass() : null;
+ if (javaClass == null) {
+ //throw new ContributionResolveException(new ClassNotFoundException(ePolicy.getEncryptionStrategyClass()));
+ }
+ //ePolicy.setStrategyClass(javaClass);
+ //FIXME: need to resolve this thro resolver
+ try {
+ ePolicy.setStrategyClass((Class<? extends EncryptionStrategy>)Class.forName(ePolicy
+ .getEncryptionStrategyClassName()));
+ } catch (Exception e) {
+ throw new ContributionResolveException(e);
+ }
+ ePolicy.setStrategyClass(ePolicy.getStrategyClass());
+ ePolicy.setUnresolved(false);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EncryptionPolicyHandler.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EncryptionPolicyHandler.java
new file mode 100644
index 0000000000..cf98b3830f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EncryptionPolicyHandler.java
@@ -0,0 +1,47 @@
+/*
+ * 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.policy;
+
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Sample policy handler
+ */
+public class EncryptionPolicyHandler implements PolicyHandler {
+
+ public void applyPolicy(Object msg, PolicySet policySet) throws Exception {
+ for (Object aPolicy : policySet.getPolicies()) {
+ if (aPolicy instanceof EchoBindingEncryptionPolicy) {
+ encrypt(msg, (EchoBindingEncryptionPolicy)aPolicy);
+ }
+ }
+ }
+
+ private void encrypt(Object msg, EchoBindingEncryptionPolicy policy) throws Exception {
+ if (!policy.isUnresolved() && msg instanceof Object[]) {
+ EncryptionStrategy strategy = policy.getStrategyClass().newInstance();
+ Object[] msgArgs = (Object[])msg;
+ for (int count = 0; count < msgArgs.length; ++count) {
+ msgArgs[count] = strategy.encryptMessage(msgArgs[count]);
+ }
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EncryptionStrategy.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EncryptionStrategy.java
new file mode 100644
index 0000000000..ffadfc7fff
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/EncryptionStrategy.java
@@ -0,0 +1,26 @@
+/*
+ * 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.policy;
+
+/**
+
+ */
+public interface EncryptionStrategy {
+ Object encryptMessage(Object msg);
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/PolicyHandler.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/PolicyHandler.java
new file mode 100644
index 0000000000..6fa5f26977
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/PolicyHandler.java
@@ -0,0 +1,29 @@
+/*
+ * 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.policy;
+
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Sample Policy Handler Interface
+ *
+ */
+public interface PolicyHandler {
+ void applyPolicy(Object msg, PolicySet policySet) throws Exception;
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/ReverseEncryptionStrategy.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/ReverseEncryptionStrategy.java
new file mode 100644
index 0000000000..3220102926
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/ReverseEncryptionStrategy.java
@@ -0,0 +1,33 @@
+/*
+ * 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.policy;
+
+/**
+ */
+public class ReverseEncryptionStrategy implements EncryptionStrategy {
+
+ public Object encryptMessage(Object msg) {
+ if (msg instanceof String) {
+ StringBuffer sb = new StringBuffer((String)msg);
+ msg = sb.reverse().toString();
+ }
+ return msg;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/WSPolicy.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/WSPolicy.java
new file mode 100644
index 0000000000..598683c251
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/WSPolicy.java
@@ -0,0 +1,43 @@
+/*
+ * 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.policy;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.Policy;
+
+/**
+
+ */
+public class WSPolicy implements Policy {
+ private boolean unresolved = true;
+
+ public QName getSchemaName() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/WSPolicyProcessor.java b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/WSPolicyProcessor.java
new file mode 100644
index 0000000000..fcb250b444
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.6.2/samples/binding-echo-extension/src/main/java/echo/provider/policy/WSPolicyProcessor.java
@@ -0,0 +1,54 @@
+/*
+ * 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.policy;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+
+public class WSPolicyProcessor implements StAXArtifactProcessor<WSPolicy> {
+
+ public QName getArtifactType() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public WSPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ //FIXME Implement this method
+ return new WSPolicy();
+ }
+
+ public void write(WSPolicy wsPolicy, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ //FIXME Implement this method
+ }
+
+ public Class<WSPolicy> getModelType() {
+ return WSPolicy.class;
+ }
+
+ public void resolve(WSPolicy wsPolicy, ModelResolver modelResolver) throws ContributionResolveException {
+
+ }
+}