From c1061930d07751d489c86812b4f11bfbe789ed96 Mon Sep 17 00:00:00 2001 From: scottkurz Date: Wed, 27 Jul 2011 21:20:22 +0000 Subject: TUSCANY-3894. Refactor local sca binding so that the exact details of the data copy can be plugged in via the BindingProviderFactory extension point, while keeping a core, base portion of the binding to do things like calculate whether to do the pass-by-reference optimization and establish other aspects of the invoker/interceptor chain. The data handling is factored into a BindingSCATransformer class. The default impl will continue to use MediatorImpl.copyXXX methods, and will use Java-serialization first then XML/JAXB-serialization. The second impl included uses XML serialization and calculates a WSDL interfaceContract. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1151632 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultLocalSCAReferenceBindingProvider.java | 204 +++++++++++++++++++++ .../sca/binding/local/LocalSCABindingInvoker.java | 92 +++++----- .../local/LocalSCABindingProviderFactory.java | 2 +- .../local/LocalSCAReferenceBindingProvider.java | 146 --------------- .../local/XMLWFLocalSCABindingProviderFactory.java | 56 ++++++ .../XMLWFLocalSCAReferenceBindingProvider.java | 43 +++++ .../DelegatingSCAReferenceBindingProvider.java | 6 +- .../sca/transform/BindingSCATransformer.java | 26 +++ .../transform/DefaultBindingSCATransformer.java | 54 ++++++ .../sca/transform/XMLWFBindingSCATransformer.java | 74 ++++++++ 10 files changed, 507 insertions(+), 196 deletions(-) create mode 100644 sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/DefaultLocalSCAReferenceBindingProvider.java delete mode 100644 sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/LocalSCAReferenceBindingProvider.java create mode 100644 sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/XMLWFLocalSCABindingProviderFactory.java create mode 100644 sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/XMLWFLocalSCAReferenceBindingProvider.java create mode 100644 sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/BindingSCATransformer.java create mode 100644 sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/DefaultBindingSCATransformer.java create mode 100644 sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/XMLWFBindingSCATransformer.java (limited to 'sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org') diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/DefaultLocalSCAReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/DefaultLocalSCAReferenceBindingProvider.java new file mode 100644 index 0000000000..209ebedd8c --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/DefaultLocalSCAReferenceBindingProvider.java @@ -0,0 +1,204 @@ +/* + * 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.binding.local; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.binding.local.LocalSCABindingInvoker; +import org.apache.tuscany.sca.binding.sca.transform.BindingSCATransformer; +import org.apache.tuscany.sca.binding.sca.transform.DefaultBindingSCATransformer; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.interfacedef.Compatibility; +import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.EndpointReferenceAsyncProvider; +import org.apache.tuscany.sca.provider.SCABindingMapper; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.oasisopen.sca.ServiceRuntimeException; +import org.oasisopen.sca.ServiceUnavailableException; + +public class DefaultLocalSCAReferenceBindingProvider implements EndpointReferenceAsyncProvider { + private RuntimeEndpointReference endpointReference; + + protected InterfaceContractMapper interfaceContractMapper; + protected ExtensionPointRegistry extensionPoints; + protected Mediator mediator; + protected InterfaceContract wsdlBindingInterfaceContract; + + public DefaultLocalSCAReferenceBindingProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpointReference endpointReference, SCABindingMapper mapper) { + this.extensionPoints = extensionPoints; + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); + this.mediator = utilities.getUtility(Mediator.class); + + this.endpointReference = endpointReference; + } + + protected String getDataBinding() { + return DOMDataBinding.NAME; + } + + private InterfaceContract getWSDLInterfaceContract(InterfaceContract interfaceContract) { + InterfaceContract wsdlInterfaceContract = (WSDLInterfaceContract)endpointReference.getGeneratedWSDLContract(interfaceContract); + + // Validation may be unnecessary. This check may already be guaranteed at this point, not sure. + Endpoint target = endpointReference.getTargetEndpoint(); + InterfaceContract targetInterfaceContract = target.getComponentServiceInterfaceContract(); + try { + interfaceContractMapper.checkCompatibility(wsdlInterfaceContract, targetInterfaceContract, + Compatibility.SUBSET, true, false); + } catch (IncompatibleInterfaceContractException exc) { + throw new ServiceRuntimeException(exc); + } + + String dataBinding = getDataBinding(); + + // Clone + try { + wsdlInterfaceContract = (WSDLInterfaceContract)wsdlInterfaceContract.clone(); + } catch (CloneNotSupportedException exc) { + throw new ServiceRuntimeException(exc); + } + + if (wsdlInterfaceContract.getInterface() != null) { + wsdlInterfaceContract.getInterface().resetDataBinding(dataBinding); + } + if (wsdlInterfaceContract.getCallbackInterface() != null) { + wsdlInterfaceContract.getCallbackInterface().resetDataBinding(dataBinding); + } + return wsdlInterfaceContract; + + } + + @Override + public InterfaceContract getBindingInterfaceContract() { + InterfaceContract componentTypeRefIC = endpointReference.getComponentTypeReferenceInterfaceContract(); + if (componentTypeRefIC.getInterface().isRemotable()) { + this.wsdlBindingInterfaceContract = getWSDLInterfaceContract(componentTypeRefIC); + } + + // Since we want to disable DataTransformationInterceptor and handle copy in the binding + return componentTypeRefIC; + } + + + + @Override + public Invoker createInvoker(Operation operation) { + Invoker result = null; + BindingSCATransformer bindingTransformer = null; + + Endpoint target = endpointReference.getTargetEndpoint(); + if (target != null) { + RuntimeComponentService service = (RuntimeComponentService) target.getService(); + if (service != null) { // not a callback wire + + InvocationChain chain = ((RuntimeEndpoint) target).getInvocationChain(operation); + + boolean passByValue = false; + Operation targetOp = chain.getTargetOperation(); + if (!operation.getInterface().isRemotable()) { + if (interfaceContractMapper.isCompatibleByReference(operation, targetOp, Compatibility.SUBSET)) { + passByValue = false; + } + } else { + Reference ref = endpointReference.getReference().getReference(); + // The spec says both ref and service needs to + // allowsPassByReference + boolean allowsPBR = (endpointReference.getReference().isAllowsPassByReference() || (ref != null && ref.isAllowsPassByReference())) && chain.allowsPassByReference(); + + if (allowsPBR && interfaceContractMapper.isCompatibleByReference(operation, targetOp, Compatibility.SUBSET)) { + passByValue = false; + } else if (interfaceContractMapper.isCompatibleWithoutUnwrapByValue(operation, targetOp, Compatibility.SUBSET)) { + passByValue = true; + } else { + throw new IllegalStateException(); + } + bindingTransformer = getBindingTransformer(operation, chain); + } + + // it turns out that the chain source and target operations are + // the same, and are the operation + // from the target, not sure if thats by design or a bug. The + // SCA binding invoker needs to know + // the source and target class loaders so pass in the real + // source operation in the constructor + result = chain == null ? null : new LocalSCABindingInvoker(chain, operation, passByValue, endpointReference, extensionPoints, bindingTransformer); + } + } + + if (result == null) { + throw new ServiceUnavailableException("Unable to create SCA binding invoker for local target " + endpointReference.getComponent().getName() + " reference " + + endpointReference.getReference().getName() + " (bindingURI=" + endpointReference.getBinding().getURI() + " operation=" + operation.getName() + ")"); + } + + return result; + } + + protected BindingSCATransformer getBindingTransformer(Operation operation, InvocationChain chain) { + return new DefaultBindingSCATransformer(mediator, operation, chain); + } + + @Override + public boolean supportsOneWayInvocation() { + // Default for Local invocation + return false; + } + + @Override + public boolean supportsNativeAsync() { + return true; + } + + @Override + public void configure() { + // Nothing required for Local invocation + } + + @Override + public void start() { + // Nothing required for Local invocation + } + + @Override + public void stop() { + // Nothing required for Local invocation + } + + /** + * Allows us to replace the delegate EPR with the real EPR so that the local binding + * optimization operates against the correct invocation chains. + */ + public void setEndpointReference(RuntimeEndpointReference endpointReference){ + this.endpointReference = endpointReference; + } + + +} diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/LocalSCABindingInvoker.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/LocalSCABindingInvoker.java index a2eb53d5bb..5fca1ea593 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/LocalSCABindingInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/LocalSCABindingInvoker.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.binding.local; +import org.apache.tuscany.sca.binding.sca.transform.BindingSCATransformer; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.invocation.AsyncResponseInvoker; @@ -41,28 +42,26 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; */ public class LocalSCABindingInvoker extends InterceptorAsyncImpl { private InvocationChain chain; - private Mediator mediator; - private Operation sourceOperation; - private Operation targetOperation; private boolean passByValue; private RuntimeEndpointReference epr; private RuntimeEndpoint ep; private ExtensionPointRegistry registry; + private BindingSCATransformer bindingSCATransformer; /** * Construct a SCABindingInvoker that delegates to the service invocation chain */ - public LocalSCABindingInvoker(InvocationChain chain, Operation sourceOperation, Mediator mediator, - boolean passByValue, RuntimeEndpointReference epr, ExtensionPointRegistry registry) { + public LocalSCABindingInvoker(InvocationChain chain, Operation sourceOperation, + boolean passByValue, RuntimeEndpointReference epr, ExtensionPointRegistry registry, + BindingSCATransformer bindingSCATransformer) { super(); this.chain = chain; - this.mediator = mediator; - this.sourceOperation = sourceOperation; - this.targetOperation = chain.getTargetOperation(); + this.passByValue = passByValue; this.epr = epr; this.ep = (RuntimeEndpoint)epr.getTargetEndpoint(); this.registry = registry; + this.bindingSCATransformer = bindingSCATransformer; } /** @@ -78,35 +77,36 @@ public class LocalSCABindingInvoker extends InterceptorAsyncImpl { public void setNext(Invoker next) { // NOOP } - + public Message processRequest(Message msg){ if (passByValue) { - msg.setBody(mediator.copyInput(msg.getBody(), sourceOperation, targetOperation)); + Object transformedBody = bindingSCATransformer.transformInput(msg.getBody()); + msg.setBody(transformedBody); } // end if - + ep.getInvocationChains(); if ( !ep.getCallbackEndpointReferences().isEmpty() ) { RuntimeEndpointReference asyncEPR = (RuntimeEndpointReference) ep.getCallbackEndpointReferences().get(0); // Place a link to the callback EPR into the message headers... msg.getHeaders().put("ASYNC_CALLBACK", asyncEPR ); } // end if - + if( ep.isAsyncInvocation() ) { // Get the message ID String msgID = (String)msg.getHeaders().get("MESSAGE_ID"); - + String operationName = msg.getOperation().getName(); - + // Create a response invoker and add it to the message headers AsyncResponseInvoker respInvoker = - new AsyncResponseInvoker(ep, null, epr, msgID, operationName, getMessageFactory()); + new AsyncResponseInvoker(ep, null, epr, msgID, operationName, getMessageFactory()); respInvoker.setBindingType("SCA_LOCAL"); msg.getHeaders().put("ASYNC_RESPONSE_INVOKER", respInvoker); } // end if - + return msg; } // end method processRequest - + /** * Regular (sync) processing of response message */ @@ -114,54 +114,54 @@ public class LocalSCABindingInvoker extends InterceptorAsyncImpl { if (passByValue) { // Note source and target operation swapped so result is in source class loader if (msg.isFault()) { - msg.setFaultBody(mediator.copyFault(msg.getBody(), sourceOperation, targetOperation)); + Object transformedFault = bindingSCATransformer.transformFault(msg.getBody()); + msg.setFaultBody(transformedFault); } else { - if (sourceOperation.getOutputType() != null) { - msg.setBody(mediator.copyOutput(msg.getBody(), sourceOperation, targetOperation)); - } // end if + Object transformedOutput = bindingSCATransformer.transformOutput(msg.getBody()); + msg.setBody(transformedOutput); } // end if } // end if - + return msg; } // end method processResponse - + public void invokeAsyncRequest(Message msg) throws Throwable { - try{ - msg = processRequest(msg); - InvokerAsyncRequest theNext = (InvokerAsyncRequest)getNext(); - if( theNext != null ) theNext.invokeAsyncRequest(msg); - postProcessRequest(msg); - } catch (Throwable e) { - postProcessRequest(msg, e); - } // end try + try{ + msg = processRequest(msg); + InvokerAsyncRequest theNext = (InvokerAsyncRequest)getNext(); + if( theNext != null ) theNext.invokeAsyncRequest(msg); + postProcessRequest(msg); + } catch (Throwable e) { + postProcessRequest(msg, e); + } // end try } // end method invokeAsyncRequest - + public void invokeAsyncResponse(Message msg) { msg = processResponse(msg); - + // Handle async response Relates_To message ID value @SuppressWarnings("unchecked") - AsyncResponseInvoker respInvoker = - (AsyncResponseInvoker)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER"); + AsyncResponseInvoker respInvoker = + (AsyncResponseInvoker)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER"); // TODO - this deals with the Local case only - not distributed if( respInvoker != null && "SCA_LOCAL".equals(respInvoker.getBindingType()) ) { - RuntimeEndpointReference responseEPR = respInvoker.getResponseTargetAddress(); - msg.setFrom(responseEPR); - String msgID = respInvoker.getRelatesToMsgID(); - msg.getHeaders().put("RELATES_TO", msgID); + RuntimeEndpointReference responseEPR = respInvoker.getResponseTargetAddress(); + msg.setFrom(responseEPR); + String msgID = respInvoker.getRelatesToMsgID(); + msg.getHeaders().put("RELATES_TO", msgID); } // end if - + InvokerAsyncResponse thePrevious = (InvokerAsyncResponse)getPrevious(); if (thePrevious != null ) thePrevious.invokeAsyncResponse(msg); } // end method invokeAsyncResponse - + public boolean isLocalSCABIndingInvoker() { return true; } - - private MessageFactory getMessageFactory() { - FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); - return modelFactories.getFactory(MessageFactory.class); - } // end method getMessageFactory + + private MessageFactory getMessageFactory() { + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + return modelFactories.getFactory(MessageFactory.class); + } // end method getMessageFactory } diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/LocalSCABindingProviderFactory.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/LocalSCABindingProviderFactory.java index 4ba66fb47a..0d61d9e407 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/LocalSCABindingProviderFactory.java +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/LocalSCABindingProviderFactory.java @@ -40,7 +40,7 @@ public class LocalSCABindingProviderFactory implements BindingProviderFactory { + private ExtensionPointRegistry extensionPoints; + private SCABindingMapper scaBindingMapper; + + public XMLWFLocalSCABindingProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + this.scaBindingMapper = utilities.getUtility(SCABindingMapper.class); + } + + @Override + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpointReference) { + return new XMLWFLocalSCAReferenceBindingProvider(extensionPoints, endpointReference, scaBindingMapper); + } + + @Override + public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) { + return new LocalSCAServiceBindingProvider(endpoint, scaBindingMapper); + } + + @Override + public Class getModelType() { + return LocalSCABinding.class; + } + +} diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/XMLWFLocalSCAReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/XMLWFLocalSCAReferenceBindingProvider.java new file mode 100644 index 0000000000..2c5b4f73e1 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/local/XMLWFLocalSCAReferenceBindingProvider.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 org.apache.tuscany.sca.binding.local; + +import org.apache.tuscany.sca.binding.sca.transform.BindingSCATransformer; +import org.apache.tuscany.sca.binding.sca.transform.DefaultBindingSCATransformer; +import org.apache.tuscany.sca.binding.sca.transform.XMLWFBindingSCATransformer; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.provider.SCABindingMapper; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +public class XMLWFLocalSCAReferenceBindingProvider extends DefaultLocalSCAReferenceBindingProvider { + + public XMLWFLocalSCAReferenceBindingProvider(ExtensionPointRegistry extensionPoints, + RuntimeEndpointReference endpointReference, + SCABindingMapper mapper) { + super(extensionPoints, endpointReference, mapper); + } + + protected BindingSCATransformer getBindingTransformer(Operation operation, InvocationChain chain) { + Operation wsdlBindingOperation = interfaceContractMapper.map(wsdlBindingInterfaceContract.getInterface(), operation); + return new XMLWFBindingSCATransformer(mediator, operation, wsdlBindingOperation, chain); + } +} diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/DelegatingSCAReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/DelegatingSCAReferenceBindingProvider.java index 2cc71f1744..5b47443df8 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/DelegatingSCAReferenceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/DelegatingSCAReferenceBindingProvider.java @@ -20,7 +20,7 @@ package org.apache.tuscany.sca.binding.sca.provider; import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.binding.local.LocalSCAReferenceBindingProvider; +import org.apache.tuscany.sca.binding.local.DefaultLocalSCAReferenceBindingProvider; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Invoker; @@ -47,8 +47,8 @@ public class DelegatingSCAReferenceBindingProvider implements EndpointReferenceA // reset the EPR to binding.sca EPR because the local optimization assumes // this to be the case. - if (provider instanceof LocalSCAReferenceBindingProvider){ - ((LocalSCAReferenceBindingProvider)provider).setEndpointReference(endpointReference); + if (provider instanceof DefaultLocalSCAReferenceBindingProvider){ + ((DefaultLocalSCAReferenceBindingProvider)provider).setEndpointReference(endpointReference); } } } diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/BindingSCATransformer.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/BindingSCATransformer.java new file mode 100644 index 0000000000..e84668fb1d --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/BindingSCATransformer.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 org.apache.tuscany.sca.binding.sca.transform; + +public interface BindingSCATransformer { + Object transformInput(Object body); + Object transformOutput(Object body); + Object transformFault(Object body); +} diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/DefaultBindingSCATransformer.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/DefaultBindingSCATransformer.java new file mode 100644 index 0000000000..77e93f8672 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/DefaultBindingSCATransformer.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 org.apache.tuscany.sca.binding.sca.transform; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; + +public class DefaultBindingSCATransformer implements BindingSCATransformer { + + private Mediator mediator; + private Operation sourceOperation; + private Operation targetOperation; + + public DefaultBindingSCATransformer(Mediator mediator, Operation sourceOperation, InvocationChain chain) { + this.mediator = mediator; + this.sourceOperation = sourceOperation; + this.targetOperation = chain.getTargetOperation(); + } + + @Override + public Object transformInput(Object body) { + return mediator.copyInput(body, sourceOperation, targetOperation); + } + + @Override + public Object transformOutput(Object body) { + return mediator.copyOutput(body, sourceOperation, targetOperation); + } + + @Override + public Object transformFault(Object body) { + return mediator.copyFault(body, sourceOperation, targetOperation); + } + +} + diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/XMLWFBindingSCATransformer.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/XMLWFBindingSCATransformer.java new file mode 100644 index 0000000000..cc366c1f7a --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/transform/XMLWFBindingSCATransformer.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 org.apache.tuscany.sca.binding.sca.transform; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; + +public class XMLWFBindingSCATransformer implements BindingSCATransformer { + + private Mediator mediator; + private Operation sourceOperation; + private Operation wsdlBindingOperation; + private Operation targetOperation; + + public XMLWFBindingSCATransformer(Mediator mediator, Operation sourceOperation, Operation wsdlBindingOperation, InvocationChain chain) { + this.mediator = mediator; + this.sourceOperation = sourceOperation; + this.wsdlBindingOperation = wsdlBindingOperation; + this.targetOperation = chain.getTargetOperation(); + } + + @Override + public Object transformInput(Object body) { + Map map1 = new HashMap(); + Object intermediate = mediator.mediateInput(body, sourceOperation, wsdlBindingOperation, map1); + Map map2 = new HashMap(); + Object result = mediator.mediateInput(intermediate, wsdlBindingOperation, targetOperation, map2); + return result; + } + + @Override + public Object transformOutput(Object body) { + Map map1 = new HashMap(); + Object intermediate = mediator.mediateOutput(body, wsdlBindingOperation, targetOperation, map1); + Map map2 = new HashMap(); + Object result = mediator.mediateOutput(intermediate, sourceOperation, wsdlBindingOperation, map2); + + return result; + + } + + @Override + public Object transformFault(Object body) { + Map map1 = new HashMap(); + Object intermediate = mediator.mediateFault(body, wsdlBindingOperation, targetOperation, map1); + Map map2 = new HashMap(); + Object result = mediator.mediateFault(intermediate, sourceOperation, wsdlBindingOperation, map2); + return result; + + } + +} + -- cgit v1.2.3