summaryrefslogtreecommitdiffstats
path: root/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix')
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/BusService.java35
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/BusServiceImpl.java65
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java100
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java245
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixReferenceBinding.java77
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceBinding.java281
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceInitException.java43
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/InvokerCreationException.java43
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/TuscanyWSDLManager.java89
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingDefinition.java90
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java197
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java205
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java322
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/RawByteArrayOutputStream.java30
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java83
-rw-r--r--sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java81
16 files changed, 1986 insertions, 0 deletions
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/BusService.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/BusService.java
new file mode 100644
index 0000000000..238fbe97b0
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/BusService.java
@@ -0,0 +1,35 @@
+/*
+ * 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.binding.celtix;
+
+import org.objectweb.celtix.Bus;
+
+/**
+ * A system service that returns the active Celtix <code>Bus</code> for the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public interface BusService {
+
+ /**
+ * Returns the active bus
+ */
+ Bus getBus();
+
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/BusServiceImpl.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/BusServiceImpl.java
new file mode 100644
index 0000000000..6b02dd0b15
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/BusServiceImpl.java
@@ -0,0 +1,65 @@
+/*
+ * 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.binding.celtix;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Scope;
+
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry;
+import org.objectweb.celtix.Bus;
+import org.objectweb.celtix.BusException;
+
+/**
+ * The default implementation of the Celtix Bus system service
+ *
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+@EagerInit
+public class BusServiceImpl implements BusService {
+ protected WSDLDefinitionRegistry wsdlRegistry;
+ private Bus bus;
+
+ public BusServiceImpl(@Property(override = "may")WSDLDefinitionRegistry wsdlRegistry) throws BusException {
+ this.wsdlRegistry = wsdlRegistry;
+ Map<String, Object> properties = new WeakHashMap<String, Object>();
+ properties.put("celtix.WSDLManager", new TuscanyWSDLManager(wsdlRegistry));
+ bus = Bus.init(new String[0], properties);
+ }
+
+ public Bus getBus() {
+ return bus;
+ }
+
+ /**
+ * Shuts down the bus, called when the runtime stops the Celtix system composite
+ *
+ * @throws BusException
+ */
+ @Destroy
+ public void stop() throws BusException {
+ bus.shutdown(true);
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java
new file mode 100644
index 0000000000..7eec916261
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java
@@ -0,0 +1,100 @@
+/*
+ * 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.binding.celtix;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+
+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.BoundReferenceDefinition;
+import org.apache.tuscany.spi.model.BoundServiceDefinition;
+
+import commonj.sdo.helper.TypeHelper;
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry;
+import org.objectweb.celtix.Bus;
+
+/**
+ * Builds a {@link org.apache.tuscany.spi.component.ServiceBinding} or {@link org.apache.tuscany.spi.component.ReferenceBinding}
+ * configured with the Celtix binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class CeltixBindingBuilder extends BindingBuilderExtension<WebServiceBindingDefinition> {
+
+ private Bus bus;
+
+ public ServiceBinding build(CompositeComponent parent,
+ BoundServiceDefinition boundServiceDefinition,
+ WebServiceBindingDefinition bindingDefinition,
+ DeploymentContext deploymentContext) {
+ TypeHelper typeHelper = (TypeHelper) deploymentContext.getExtension(TypeHelper.class.getName());
+ if (typeHelper == null) {
+ typeHelper = TypeHelper.INSTANCE;
+ }
+ if (bus == null) {
+ bus = getBus(bindingDefinition.getWSDLDefinitionRegistry());
+ }
+ return new CeltixServiceBinding(
+ boundServiceDefinition.getName(),
+ parent,
+ bindingDefinition,
+ bus,
+ typeHelper);
+ }
+
+ public ReferenceBinding build(CompositeComponent parent,
+ BoundReferenceDefinition boundReferenceDefinition,
+ WebServiceBindingDefinition wsBinding,
+ DeploymentContext deploymentContext) {
+ TypeHelper typeHelper = (TypeHelper) deploymentContext.getExtension(TypeHelper.class.getName());
+ if (typeHelper == null) {
+ typeHelper = TypeHelper.INSTANCE;
+ }
+ if (bus == null) {
+ bus = getBus(wsBinding.getWSDLDefinitionRegistry());
+ }
+ return new CeltixReferenceBinding(
+ boundReferenceDefinition.getName(),
+ parent,
+ wsBinding,
+ bus,
+ typeHelper);
+ }
+
+ protected Class<WebServiceBindingDefinition> getBindingType() {
+ return WebServiceBindingDefinition.class;
+ }
+
+ private Bus getBus(WSDLDefinitionRegistry wsdlDefinitionRegistry) {
+ Bus celtixBus = null;
+ try {
+ Map<String, Object> properties = new WeakHashMap<String, Object>();
+ properties.put("celtix.WSDLManager", new TuscanyWSDLManager(wsdlDefinitionRegistry));
+ celtixBus = Bus.init(new String[0], properties);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return celtixBus;
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java
new file mode 100644
index 0000000000..3982d9c879
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java
@@ -0,0 +1,245 @@
+/*
+ * 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.binding.celtix;
+
+import java.io.IOException;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import javax.jws.WebParam;
+import javax.wsdl.Binding;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Holder;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import commonj.sdo.helper.TypeHelper;
+import org.apache.tuscany.binding.celtix.io.SCADataBindingCallback;
+import org.objectweb.celtix.Bus;
+import org.objectweb.celtix.BusException;
+import org.objectweb.celtix.bindings.ClientBinding;
+import org.objectweb.celtix.bindings.DataBindingCallback;
+import org.objectweb.celtix.bus.bindings.WSDLMetaDataCache;
+import org.objectweb.celtix.bus.bindings.WSDLOperationInfo;
+import org.objectweb.celtix.context.ObjectMessageContext;
+import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
+import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
+import org.xmlsoap.schemas.wsdl.http.AddressType;
+
+
+/**
+ * Responsible for dispatching a service operation invocation on a reference to the active Celtix <code>Bus</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class CeltixInvoker implements TargetInvoker {
+
+ private WSDLMetaDataCache wsdlCache;
+
+ private ClientBinding clientBinding;
+
+ private String operationName;
+
+ private TypeHelper typeHelper;
+
+ public CeltixInvoker(String operationName,
+ Bus bus,
+ Port port,
+ Service wsdlService,
+ Definition wsdlDef,
+ TypeHelper theTypeHelper) throws BuilderException {
+ this.wsdlCache = new WSDLMetaDataCache(wsdlDef, port);
+ this.operationName = operationName;
+ this.typeHelper = theTypeHelper;
+ // Definition wsdlDef = wsBinding.getWSDLDefinition();
+ // wsdlCache = new WSDLMetaDataCache(wsdlDef, wsBinding.getWSDLPort());
+
+ try {
+ String key = wsdlDef.getDocumentBaseURI();
+ URL url = new URL(key);
+
+ QName qName = wsdlService.getQName();
+ EndpointReferenceType reference = EndpointReferenceUtils.getEndpointReference(url, qName, port.getName());
+
+ String bindingId = null;
+ Binding binding = port.getBinding();
+ if (null != binding) {
+ List list = binding.getExtensibilityElements();
+ if (!list.isEmpty()) {
+ bindingId = ((ExtensibilityElement) list.get(0)).getElementType().getNamespaceURI();
+ }
+ }
+ if (bindingId == null) {
+ List<?> list = port.getExtensibilityElements();
+ for (Object ep : list) {
+ ExtensibilityElement ext = (ExtensibilityElement) ep;
+ if (ext instanceof SOAPAddress) {
+ bindingId = ((SOAPAddress) ext).getLocationURI();
+ }
+ if (ext instanceof AddressType) {
+ bindingId = ((AddressType) ext).getLocation();
+ }
+ }
+
+ }
+ clientBinding = bus.getBindingManager().getBindingFactory(bindingId).createClientBinding(reference);
+ } catch (MalformedURLException e) {
+ throw new InvokerCreationException(e);
+ } catch (BusException e) {
+ throw new InvokerCreationException(e);
+ } catch (WSDLException e) {
+ throw new InvokerCreationException(e);
+ } catch (IOException e) {
+ throw new InvokerCreationException(e);
+ }
+ }
+
+ /**
+ * Invoke an operation on the external Web service.
+ *
+ * @param args the Java object arguments to the WS operation
+ * @return the response from the WS as a Java object
+ */
+ public Object invokeTarget(final Object args, final short sequence) throws InvocationTargetException {
+ WSDLOperationInfo opInfo = wsdlCache.getOperationInfo(operationName);
+ if (opInfo == null) {
+ // REVISIT - really map the operation name to a WSDL operation
+ for (String opName : wsdlCache.getAllOperationInfo().keySet()) {
+ if (operationName.equalsIgnoreCase(opName)) {
+ opInfo = wsdlCache.getOperationInfo(opName);
+ break;
+ }
+ }
+ }
+
+ ObjectMessageContext objMsgContext = clientBinding.createObjectContext();
+
+ boolean hasInOut = false;
+ int inOutCount = 0;
+ Object realArgs[];
+ Object argsArray[];
+ if (args.getClass().isArray()) {
+ argsArray = (Object[]) args;
+ realArgs = new Object[Array.getLength(args)];
+ } else {
+ argsArray = new Object[0];
+ realArgs = new Object[0];
+ }
+
+ if (opInfo.getParamsLength() == 0) {
+ // REVISIT - opInfo doesn't return the needed info for the wrapped doc/lit case.
+ // Bug in Celtix
+ realArgs = argsArray;
+ } else {
+ for (int x = 0; x < argsArray.length; x++) {
+ if (opInfo.getWebParam(x).mode() == WebParam.Mode.IN) {
+ realArgs[x] = argsArray[x];
+ } else {
+ realArgs[x] = new Holder<Object>(argsArray[x]);
+ inOutCount++;
+ hasInOut = true;
+ }
+ }
+ }
+ objMsgContext.setMessageObjects(realArgs);
+ boolean isOneway = opInfo.isOneWay();
+ DataBindingCallback callback = new SCADataBindingCallback(opInfo, hasInOut, typeHelper);
+ try {
+ if (isOneway) {
+ clientBinding.invokeOneWay(objMsgContext, callback);
+ } else {
+ objMsgContext = clientBinding.invoke(objMsgContext, callback);
+ }
+ } catch (IOException e) {
+ throw new InvocationTargetException(e);
+ }
+
+ if (objMsgContext.getException() != null) {
+ // REVISIT - Exceptions
+ /*
+ * if (isValidException(objMsgContext)) { throw
+ * (Exception)objMsgContext.getException(); } else { throw new
+ * ProtocolException(objMsgContext.getException()); }
+ */
+ throw new InvocationTargetException(objMsgContext.getException());
+ }
+
+ if (hasInOut) {
+ Object ret[] = new Object[inOutCount + 1];
+ ret[0] = objMsgContext.getReturn();
+ inOutCount = 1;
+ for (int x = 0; x < argsArray.length; x++) {
+ if (opInfo.getWebParam(x).mode() != WebParam.Mode.IN) {
+ Holder<?> holder = (Holder<?>) realArgs[x];
+ ret[inOutCount] = holder.value;
+ inOutCount++;
+ }
+ }
+ return ret;
+ }
+ return objMsgContext.getReturn();
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ Object resp = invokeTarget(msg.getBody(), TargetInvoker.NONE);
+ msg.setBody(resp);
+ } catch (Throwable e) {
+ msg.setBodyWithFault(e);
+ }
+ return msg;
+ }
+
+ public void setNext(Interceptor next) {
+ throw new UnsupportedOperationException();
+ }
+
+ public CeltixInvoker clone() throws CloneNotSupportedException {
+ try {
+ return (CeltixInvoker) super.clone();
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ return null;
+ }
+ }
+
+ public boolean isCacheable() {
+ return true;
+ }
+
+ public void setCacheable(boolean cacheable) {
+
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixReferenceBinding.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixReferenceBinding.java
new file mode 100644
index 0000000000..c596701880
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixReferenceBinding.java
@@ -0,0 +1,77 @@
+/*
+ * 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.binding.celtix;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.xml.namespace.QName;
+
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+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;
+
+import commonj.sdo.helper.TypeHelper;
+import org.objectweb.celtix.Bus;
+
+/**
+ * The implementation of a {@link org.apache.tuscany.spi.component.ReferenceBinding} configured with the Celtix binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class CeltixReferenceBinding<T> extends ReferenceBindingExtension {
+ private static final QName BINDING_WS = new QName(XML_NAMESPACE_1_0, "binding.ws");
+
+ private Bus bus;
+ private Port port;
+ private Definition wsdlDef;
+ private Service wsdlService;
+ private TypeHelper typeHelper;
+
+ public CeltixReferenceBinding(String name,
+ CompositeComponent parent,
+ WebServiceBindingDefinition binding,
+ Bus theBus,
+ TypeHelper theTypeHelper) {
+ super(name, parent);
+ this.wsdlDef = binding.getWSDLDefinition();
+ this.port = binding.getWSDLPort();
+ this.wsdlService = binding.getWSDLService();
+ this.bus = theBus;
+ this.typeHelper = theTypeHelper;
+ }
+
+ public QName getBindingType() {
+ return BINDING_WS;
+ }
+
+ public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) {
+ try {
+ return new CeltixInvoker(operation.getName(), bus, port, wsdlService, wsdlDef, typeHelper);
+ } catch (BuilderException e) {
+ // fixme
+ throw new CeltixServiceInitException(e);
+ }
+ }
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceBinding.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceBinding.java
new file mode 100644
index 0000000000..96996e73c1
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceBinding.java
@@ -0,0 +1,281 @@
+/*
+ * 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.binding.celtix;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executor;
+import javax.jws.soap.SOAPBinding;
+import javax.wsdl.Binding;
+import javax.wsdl.BindingInput;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap.SOAPBody;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceProvider;
+
+import org.osoa.sca.annotations.Destroy;
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.extension.ServiceBindingExtension;
+
+import commonj.sdo.helper.TypeHelper;
+import org.apache.tuscany.binding.celtix.io.SCAServerDataBindingCallback;
+import org.objectweb.celtix.Bus;
+import org.objectweb.celtix.bindings.BindingFactory;
+import org.objectweb.celtix.bindings.DataBindingCallback;
+import org.objectweb.celtix.bindings.ServerBinding;
+import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
+import org.objectweb.celtix.bindings.ServerDataBindingCallback;
+import org.objectweb.celtix.bus.bindings.WSDLMetaDataCache;
+import org.objectweb.celtix.bus.bindings.WSDLOperationInfo;
+import org.objectweb.celtix.context.ObjectMessageContext;
+import org.objectweb.celtix.ws.addressing.AttributedURIType;
+import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
+import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
+import org.xmlsoap.schemas.wsdl.http.AddressType;
+
+
+/**
+ * An implementation of a {@link Service} configured with the Celtix binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class CeltixServiceBinding extends ServiceBindingExtension implements ServerBindingEndpointCallback {
+ private static final QName BINDING_WS = new QName(XML_NAMESPACE_1_0, "binding.ws");
+
+ private Bus bus;
+ private Port port;
+ private Definition wsdlDef;
+ private Service wsdlService;
+ private WSDLMetaDataCache wsdlCache;
+ private TypeHelper typeHelper;
+
+ private Map<QName, ServerDataBindingCallback> opMap =
+ new ConcurrentHashMap<QName, ServerDataBindingCallback>();
+
+
+ public CeltixServiceBinding(String theName,
+ CompositeComponent parent,
+ WebServiceBindingDefinition binding,
+ Bus bus,
+ TypeHelper theTypeHelper) {
+ super(theName, parent);
+ this.wsdlDef = binding.getWSDLDefinition();
+ this.port = binding.getWSDLPort();
+ this.wsdlService = binding.getWSDLService();
+ this.bus = bus;
+ this.wsdlCache = new WSDLMetaDataCache(wsdlDef, port);
+ this.typeHelper = theTypeHelper;
+ }
+
+ public void start() {
+ super.start();
+ initOperationMap();
+ startServerBinding();
+ }
+
+ private void startServerBinding() {
+ String key = wsdlDef.getDocumentBaseURI();
+ URL url;
+ try {
+ url = new URL(key);
+ } catch (MalformedURLException e) {
+ throw new CeltixServiceInitException(e);
+ }
+
+ QName qName = wsdlService.getQName();
+ String portName = port.getName();
+ EndpointReferenceType reference = EndpointReferenceUtils.getEndpointReference(url, qName, portName);
+
+ AttributedURIType address = new AttributedURIType();
+
+ String bindingId = null;
+ Binding binding = port.getBinding();
+ if (null != binding) {
+ List list = binding.getExtensibilityElements();
+ if (!list.isEmpty()) {
+ bindingId = ((ExtensibilityElement) list.get(0)).getElementType().getNamespaceURI();
+ }
+ }
+ List<?> list = port.getExtensibilityElements();
+ for (Object ep : list) {
+ ExtensibilityElement ext = (ExtensibilityElement) ep;
+ if (ext instanceof SOAPAddress) {
+ if (bindingId == null) {
+ bindingId = ((SOAPAddress) ext).getLocationURI();
+ }
+ address.setValue(((SOAPAddress) ext).getLocationURI());
+ }
+ if (ext instanceof AddressType) {
+ if (bindingId == null) {
+ bindingId = ((AddressType) ext).getLocation();
+ }
+ address.setValue(((AddressType) ext).getLocation());
+ }
+ }
+ if (reference.getAddress() == null) {
+ //REVIST - bug in Celtix that the HTTP transport won't find the address correctly
+ reference.setAddress(address);
+ }
+ ClassLoader previousLoader = null;
+ try {
+ //FIXME: This hack is because SAAJImpl uses Thread.currentThread().getContextClassLoader(),
+ //this classloader is different from current classLoader.
+ previousLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ BindingFactory bindingFactory = bus.getBindingManager().getBindingFactory(bindingId);
+ ServerBinding serverBinding = bindingFactory.createServerBinding(reference, this);
+ serverBinding.activate();
+ } catch (Exception e) {
+ throw new CeltixServiceInitException(e);
+ } finally {
+ if (previousLoader != null) {
+ Thread.currentThread().setContextClassLoader(previousLoader);
+ }
+ }
+ }
+
+ private void initOperationMap() {
+ List ops = port.getBinding().getBindingOperations();
+ for (Object op1 : ops) {
+ BindingOperation op = (BindingOperation) op1;
+ BindingInput bindingInput = op.getBindingInput();
+ List elements = bindingInput.getExtensibilityElements();
+ QName qn = new QName(wsdlDef.getTargetNamespace(), op.getName());
+
+ //In case soap:body namespace is different from targetNamespace
+ for (Object element : elements) {
+ if (SOAPBody.class.isInstance(element)) {
+ SOAPBody body = (SOAPBody) element;
+ if (body.getNamespaceURI() != null) {
+ qn = new QName(body.getNamespaceURI(), op.getName());
+ }
+ }
+ }
+
+ ServerDataBindingCallback cb = getDataBindingCallback(qn, null, DataBindingCallback.Mode.PARTS);
+ opMap.put(qn, cb);
+ if (!"".equals(cb.getRequestWrapperQName().getLocalPart())) {
+ opMap.put(cb.getRequestWrapperQName(), cb);
+ }
+ }
+ }
+
+ @Destroy
+ public void stop() throws CoreRuntimeException {
+ super.stop();
+ }
+
+ public ServerDataBindingCallback getDataBindingCallback(QName operationName,
+ ObjectMessageContext objContext,
+ DataBindingCallback.Mode mode) {
+ if (opMap.containsKey(operationName)) {
+ return opMap.get(operationName);
+ }
+ WSDLOperationInfo opInfo = wsdlCache.getOperationInfo(operationName.getLocalPart());
+ if (opInfo == null) {
+ //REVISIT - really map the operation name to a WSDL operation
+ for (String opName : wsdlCache.getAllOperationInfo().keySet()) {
+ if (operationName.getLocalPart().equalsIgnoreCase(opName)) {
+ opInfo = wsdlCache.getOperationInfo(opName);
+ break;
+ }
+ }
+ }
+ boolean inout = false;
+
+ // Class<?> serviceInterface = this.getInterface();
+ // Method meth = getMethod(serviceInterface, operationName.getLocalPart());
+
+ // Object proxy = null;
+// try {
+// // proxy = this.getServiceInstance();
+// } catch (TargetException e) {
+// throw new CeltixServiceInitException(e);
+// }
+
+ return new SCAServerDataBindingCallback(opInfo,
+ inout,
+ operationName.getLocalPart(),
+ getInboundWire(),
+ typeHelper);
+ }
+
+// protected Method getMethod(Class<?> serviceInterface, String operationName) {
+// // Note: this doesn't support overloaded operations
+// Method[] methods = serviceInterface.getMethods();
+// for (Method m : methods) {
+// if (m.getName().equals(operationName)) {
+// return m;
+// }
+// // tolerate WSDL with capatalized operation name
+// StringBuilder sb = new StringBuilder(operationName);
+// sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
+// if (m.getName().equals(sb.toString())) {
+// return m;
+// }
+// }
+// // FIXME
+// throw new CeltixServiceInitException("no operation named " + operationName
+// + " found on service interface: " + serviceInterface.getName());
+// }
+
+ public DataBindingCallback getFaultDataBindingCallback(ObjectMessageContext objContext) {
+ // REVISIT - what to do about faults
+ return null;
+ }
+
+ public Map<QName, ? extends DataBindingCallback> getOperations() {
+ return opMap;
+ }
+
+ public SOAPBinding.Style getStyle() {
+ return wsdlCache.getStyle();
+ }
+
+ public DataBindingCallback.Mode getServiceMode() {
+ return DataBindingCallback.Mode.PARTS;
+ }
+
+ public WebServiceProvider getWebServiceProvider() {
+ //not needed I think
+ return null;
+ }
+
+ public Executor getExecutor() {
+ //Let the transport handle it (or it goes to the Bus default wq
+ //if the transport cannot handle it
+ return null;
+ }
+
+
+ public QName getBindingType() {
+ return BINDING_WS;
+ }
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceInitException.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceInitException.java
new file mode 100644
index 0000000000..28c4dfaf2a
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/CeltixServiceInitException.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.binding.celtix;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+
+/**
+ * Denotes an exception starting a {@link CeltixServiceBinding} instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class CeltixServiceInitException extends CoreRuntimeException {
+ public CeltixServiceInitException() {
+ }
+
+ public CeltixServiceInitException(String message) {
+ super(message);
+ }
+
+ public CeltixServiceInitException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public CeltixServiceInitException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/InvokerCreationException.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/InvokerCreationException.java
new file mode 100644
index 0000000000..e08a3193d8
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/InvokerCreationException.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.binding.celtix;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+
+/**
+ * Thrown when an error is encountered creating a {@link CeltixInvoker}
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvokerCreationException extends BuilderException {
+ public InvokerCreationException() {
+ }
+
+ public InvokerCreationException(String message) {
+ super(message);
+ }
+
+ public InvokerCreationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvokerCreationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/TuscanyWSDLManager.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/TuscanyWSDLManager.java
new file mode 100644
index 0000000000..18efe80da5
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/TuscanyWSDLManager.java
@@ -0,0 +1,89 @@
+/*
+ * 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.binding.celtix;
+
+import java.io.IOException;
+import java.net.URL;
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensionRegistry;
+import javax.wsdl.factory.WSDLFactory;
+
+import org.w3c.dom.Element;
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry;
+
+import org.objectweb.celtix.wsdl.WSDLManager;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyWSDLManager implements WSDLManager {
+ WSDLDefinitionRegistry wsdlDefinitionRegistry;
+
+ public TuscanyWSDLManager(WSDLDefinitionRegistry w) {
+ wsdlDefinitionRegistry = w;
+ }
+
+ public WSDLFactory getWSDLFactory() {
+ //Not supported
+ return null;
+ }
+
+ public ExtensionRegistry getExtenstionRegistry() {
+ return wsdlDefinitionRegistry.getExtensionRegistry();
+ }
+
+ public Definition getDefinition(URL url) throws WSDLException {
+ try {
+ return wsdlDefinitionRegistry.loadDefinition(null, url);
+ } catch (IOException e) {
+ //FIXME
+ throw new WSDLException("", "", e);
+ }
+ }
+
+ public Definition getDefinition(String url) throws WSDLException {
+ try {
+ //The namespace is the wsdl targetNamesapce, it is only used
+ //when the wsdl is created into cache. we are ok here to set it to null.
+ //FIXME pass the current ResourceLoader
+ return wsdlDefinitionRegistry.loadDefinition(null, new URL(url));
+ } catch (IOException e) {
+ throw new WSDLException(WSDLException.CONFIGURATION_ERROR, e.getMessage());
+ }
+ }
+
+ public Definition getDefinition(Element el) throws WSDLException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Definition getDefinition(Class<?> sei) throws WSDLException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addDefinition(Object key, Definition wsdl) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void shutdown() {
+ }
+
+
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingDefinition.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingDefinition.java
new file mode 100644
index 0000000000..4efd039c26
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingDefinition.java
@@ -0,0 +1,90 @@
+/*
+ * 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.binding.celtix;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry;
+import org.apache.tuscany.spi.model.BindingDefinition;
+
+/**
+ * Represents a Celtix binding configuration in an assembly
+ *
+ * @version $Rev$ $Date$
+ */
+public class WebServiceBindingDefinition extends BindingDefinition {
+
+ private Definition definition;
+ private Port port;
+ private Service service;
+ //private String portURI;
+ private String uri;
+ //We have to use WebServiceBindingDefinition to pass WSDLDefinitionRegistry to BindingBuilder
+ private WSDLDefinitionRegistry wsdlDefinitionRegistry;
+
+ public WebServiceBindingDefinition(Definition definition, Port port, String uri, String portURI, Service service) {
+ this.definition = definition;
+ this.port = port;
+ this.uri = uri;
+ //this.portURI = portURI;
+ this.service = service;
+ }
+
+ public Port getWSDLPort() {
+ return port;
+ }
+
+ public Service getWSDLService() {
+ return service;
+ }
+
+ public void setWSDLPort(Port value) {
+ port = value;
+ }
+
+ public Definition getWSDLDefinition() {
+ return definition;
+ }
+
+ public void setWSDLDefinition(Definition def) {
+ definition = def;
+ }
+
+ public WSDLDefinitionRegistry getWSDLDefinitionRegistry() {
+ return wsdlDefinitionRegistry;
+ }
+
+ public void setWSDLDefinitionRegistry(WSDLDefinitionRegistry theWsdlDefinitionRegistry) {
+ wsdlDefinitionRegistry = theWsdlDefinitionRegistry;
+ }
+
+// public void setPortURI(String uri) {
+// portURI = uri;
+// }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String theUri) {
+ this.uri = theUri;
+ }
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java
new file mode 100644
index 0000000000..804cdc09fd
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java
@@ -0,0 +1,197 @@
+/*
+ * 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.binding.celtix;
+
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.xml.sax.InputSource;
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Scope;
+
+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.model.ModelObject;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry;
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl;
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl.Monitor;
+
+/**
+ * Parses a <code>WebServiceBindingDefinition</code> entry in an assembly XML file
+ *
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+public class WebServiceBindingLoader extends LoaderExtension<WebServiceBindingDefinition> {
+ public static final QName BINDING_WS = new QName(XML_NAMESPACE_1_0, "binding.ws");
+
+ protected WSDLDefinitionRegistry wsdlRegistry;
+
+ @Constructor({"registry"})
+ public WebServiceBindingLoader(@Autowire LoaderRegistry registry) {
+ super(registry);
+
+ //FIXME: this is a hack, WSDLDefinitionRegistry should not be created here
+ if (wsdlRegistry == null) {
+ try {
+ wsdlRegistry = new WSDLDefinitionRegistryImpl();
+ Monitor monitor = new Monitor() {
+ public void readingWSDL(String namespace, URL location) {
+ }
+
+ public void cachingDefinition(String namespace, URL location) {
+ }
+ };
+
+ ((WSDLDefinitionRegistryImpl) wsdlRegistry).setMonitor(monitor);
+ } catch (javax.wsdl.WSDLException e) {
+ //do nothing
+ }
+ }
+ }
+
+ public QName getXMLType() {
+ return BINDING_WS;
+ }
+
+ public WebServiceBindingDefinition load(CompositeComponent parent,
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+ // not sure what uri was here ? String uri = reader.getAttributeValue(null, "uri");
+ String uri = null;
+ String endpointAttribute = reader.getAttributeValue(null, "endpoint");
+ //String portURI = reader.getAttributeValue(null, "port");
+ String wsdlLocation = reader.getAttributeValue(null, "location");
+ try {
+ return createBinding(uri, endpointAttribute, wsdlLocation, deploymentContext);
+ } catch (Exception e) {
+
+ throw new LoaderException(e);
+ }
+ }
+
+ private WebServiceBindingDefinition createBinding(String port, String portURI, String wsdlLocation,
+ DeploymentContext deploymentContext)
+ throws WSDLException, IOException {
+ List<Definition> definitions = null;
+ // FIXME wsdlRegistry.getDefinitionsForNamespace(portNamespace,
+ // resourceLoader);
+ // Get the WSDL port namespace and name
+ if (port == null && portURI != null) {
+ int h = portURI.indexOf('#');
+ String portNamespace = portURI.substring(0, h);
+ String serviceName;
+ String portName;
+
+ String fragment = portURI.substring(h + 1);
+ if (fragment.startsWith("wsdl.endpoint(") && fragment.endsWith(")")) {
+ fragment = fragment.substring(14, fragment.length() - 1);
+ int slash = fragment.indexOf('/');
+ if (slash != -1) {
+ serviceName = fragment.substring(0, slash);
+ portName = fragment.substring(slash + 1);
+ } else {
+ serviceName = null;
+ portName = fragment;
+ }
+ } else {
+ serviceName = null;
+ portName = fragment;
+ }
+
+ // FIXME need to find out how to get wsdl and what context to use --- terrible hack attack!
+ // URL wsdlurl = Thread.currentThread().getContextClassLoader().getResource(wsdlLocation);
+ if (null == wsdlLocation) {
+ throw new RuntimeException("Failed to determin wsdl location on binding. "
+ + "Try specifying 'location' attribute on binding.");
+ }
+ URL wsdlurl = deploymentContext.getClassLoader().getResource(wsdlLocation);
+ if (wsdlurl == null) {
+ throw new RuntimeException("Failed to load wsdl from '" + wsdlLocation + "'");
+ }
+
+ WSDLFactory factory = WSDLFactory.newInstance();
+ WSDLReader reader = factory.newWSDLReader();
+ reader.setFeature("javax.wsdl.verbose", false);
+ InputSource input = new InputSource(wsdlurl.openStream());
+ Definition wsdlDef = reader.readWSDL(wsdlurl.toString(), input);
+ definitions = new LinkedList<Definition>();
+ definitions.add(wsdlDef);
+ // FIXME all the above needs to better addressed.
+
+ //FIXME: if a global wsdl cached is used, we need to do a registration here
+ String namespace = wsdlDef.getTargetNamespace();
+ wsdlRegistry.loadDefinition(namespace, wsdlurl);
+
+ Definition definition = null;
+ Port thePort = null;
+ Service service = null;
+ for (Definition def : definitions) {
+
+ // Find the port with the given name
+ for (Service serv : (Collection<Service>) def.getServices().values()) {
+ QName sqn = serv.getQName();
+ if (serviceName != null
+ && !serviceName.equals(sqn.getLocalPart())) {
+ continue;
+ }
+
+ Port p = serv.getPort(portName);
+ if (p != null) {
+ service = serv;
+ definition = def;
+ thePort = p;
+ break;
+ }
+ }
+ }
+ if (thePort == null) {
+ throw new IllegalArgumentException("Cannot find WSDL port " + portURI);
+
+ }
+ WebServiceBindingDefinition wsBinding = new WebServiceBindingDefinition(definition, thePort, port, portURI, service);
+ wsBinding.setWSDLDefinitionRegistry(wsdlRegistry);
+ return wsBinding;
+ }
+ // FIXME - return a broken binding for now
+ return new WebServiceBindingDefinition(null, null, null, portURI, null);
+
+ }
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java
new file mode 100644
index 0000000000..7a14ab33fc
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java
@@ -0,0 +1,205 @@
+/*
+ * 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.binding.celtix.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.List;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import static org.w3c.dom.bootstrap.DOMImplementationRegistry.PROPERTY;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSSerializer;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.DataType;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Type;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLDocument;
+
+import org.apache.tuscany.core.databinding.impl.TransformationContextImpl;
+import org.apache.tuscany.databinding.sdo.XMLStreamReader2XMLDocument;
+import org.objectweb.celtix.bindings.DataReader;
+import org.objectweb.celtix.context.ObjectMessageContext;
+
+public class NodeDataReader implements DataReader<Node> {
+
+ private SCADataBindingCallback callback;
+
+ public NodeDataReader(SCADataBindingCallback cb) {
+ callback = cb;
+ }
+
+ public Object read(int idx, Node input) {
+ return read(null, idx, input);
+ }
+
+ public Object read(QName name, int idx, Node input) {
+ try {
+ InputStream in = getNodeStream(input);
+ XMLInputFactory staxFactory = XMLInputFactory.newInstance();
+ XMLStreamReader reader = staxFactory.createXMLStreamReader(in);
+
+ XMLStreamReader2XMLDocument transformer = new XMLStreamReader2XMLDocument();
+ TransformationContext context = new TransformationContextImpl();
+ DataType<QName> binding = new DataType<QName>(DataObject.class, null);
+ binding.setMetadata(TypeHelper.class.getName(), callback.getTypeHelper());
+ context.setTargetDataType(binding);
+ XMLDocument document = transformer.transform(reader, context);
+
+ boolean isWrapped = false;
+ return toObjects(document, isWrapped);
+ } catch (Exception e) {
+ //REVISIT: better handling of exceptions
+ }
+ return null;
+ }
+
+ public void readWrapper(ObjectMessageContext objCtx, boolean isOutBound, Node input) {
+ try {
+ QName wrapperName;
+ if (isOutBound) {
+ wrapperName = callback.getOperationInfo().getResponseWrapperQName();
+ } else {
+ wrapperName = callback.getOperationInfo().getRequestWrapperQName();
+ }
+
+ Node nd = input.getFirstChild();
+ while (nd != null
+ && !wrapperName.getNamespaceURI().equals(nd.getNamespaceURI())
+ && !wrapperName.getLocalPart().equals(nd.getLocalName())) {
+ nd = nd.getNextSibling();
+ }
+
+ //REVISIT - This is SUCH a HACK. This needs to be done with StAX or something
+ //a bit better than streaming and reparsing
+ InputStream in = getNodeStream(nd);
+ XMLInputFactory staxFactory = XMLInputFactory.newInstance(
+ "javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
+ XMLStreamReader reader = staxFactory.createXMLStreamReader(in);
+
+ XMLStreamReader2XMLDocument transformer = new XMLStreamReader2XMLDocument();
+ TransformationContext context = new TransformationContextImpl();
+ DataType<QName> binding = new DataType<QName>(DataObject.class, null);
+ binding.setMetadata(TypeHelper.class.getName(), callback.getTypeHelper());
+ context.setTargetDataType(binding);
+ XMLDocument document = transformer.transform(reader, context);
+
+ //boolean isWrapped = true;
+ Object[] objects = toObjects(document, true);
+
+ if (callback.hasInOut()) {
+ //REVISIT - inOuts
+ } else {
+ if (isOutBound) {
+ objCtx.setReturn(objects[0]);
+ } else {
+ objCtx.setMessageObjects(objects);
+ }
+ }
+ } catch (Exception e) {
+ //REVISIT: better handling of exceptions
+ }
+ }
+
+ /**
+ * Convert a typed DataObject to Java objects
+ *
+ * @param document
+ * @param isWrapped
+ * @return the array of Objects from the DataObject
+ */
+ public static Object[] toObjects(XMLDocument document, boolean isWrapped) {
+ DataObject dataObject = document.getRootObject();
+ if (isWrapped) {
+ List ips = dataObject.getInstanceProperties();
+ Object[] os = new Object[ips.size()];
+ for (int i = 0; i < ips.size(); i++) {
+ os[i] = dataObject.get((Property) ips.get(i));
+ }
+ return os;
+ } else {
+ Object object = dataObject;
+ Type type = dataObject.getType();
+ if (type.isSequenced()) {
+ object = dataObject.getSequence().getValue(0);
+ }
+ return new Object[]{object};
+ }
+ }
+
+ byte[] getNodeBytes(Node node)
+ throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+
+ //This is also a hack, the JDK should already have this set, but it doesn't
+ DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
+ if (registry == null) {
+ System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
+ registry = DOMImplementationRegistry.newInstance();
+ }
+ DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
+ if (impl == null) {
+ System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
+ registry = DOMImplementationRegistry.newInstance();
+ impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
+ }
+ LSOutput output = impl.createLSOutput();
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ output.setByteStream(bout);
+ LSSerializer writer = impl.createLSSerializer();
+ writer.write(node, output);
+
+ return bout.toByteArray();
+ }
+
+ InputStream getNodeStream(Node node)
+ throws ClassCastException, ClassNotFoundException,
+ InstantiationException, IllegalAccessException {
+
+ DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
+ if (registry == null) {
+ //This is also a hack, the JDK should already have this set, but it doesn't
+ System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
+ registry = DOMImplementationRegistry.newInstance();
+ }
+ DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
+ if (impl == null) {
+ System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
+ registry = DOMImplementationRegistry.newInstance();
+ impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
+ }
+ LSOutput output = impl.createLSOutput();
+ RawByteArrayOutputStream bout = new RawByteArrayOutputStream();
+ output.setByteStream(bout);
+ LSSerializer writer = impl.createLSSerializer();
+ writer.write(node, output);
+
+ return new ByteArrayInputStream(bout.getBytes(), 0, bout.size());
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java
new file mode 100644
index 0000000000..d870cafa87
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java
@@ -0,0 +1,322 @@
+/*
+ * 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.binding.celtix.io;
+
+import java.util.List;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+import org.apache.tuscany.databinding.sdo.XMLDocument2XMLStreamReader;
+import org.apache.tuscany.sdo.util.SDOUtil;
+import org.objectweb.celtix.bindings.DataWriter;
+import org.objectweb.celtix.context.ObjectMessageContext;
+
+public class NodeDataWriter implements DataWriter<Node> {
+ private static final String XML_NS = "http://www.w3.org/2000/xmlns/";
+ private SCADataBindingCallback callback;
+
+ public NodeDataWriter(SCADataBindingCallback cb) {
+ callback = cb;
+ }
+
+ public void write(Object obj, Node output) {
+ write(obj, null, output);
+ }
+
+ public void write(Object obj, QName elName, Node output) {
+ boolean isWrapped = false;
+
+ XMLDocument document = toXMLDocument(callback.getTypeHelper(), new Object[]{obj}, elName, isWrapped);
+ // HACK: [rfeng] We should use the transformer in an interceptor
+ XMLDocument2XMLStreamReader transformer = new XMLDocument2XMLStreamReader();
+ XMLStreamReader reader = transformer.transform(document, null);
+
+ try {
+ //CeltixFire supports Stax, we should not need to do following anymore.
+ readDocElements(output, reader, true, null);
+ } catch (XMLStreamException e) {
+ throw new InvocationRuntimeException(e.getMessage());
+ }
+ }
+
+ public void writeWrapper(ObjectMessageContext objCtx, boolean isOutbound, Node output) {
+ boolean isWrapped = true;
+ QName wrapperName;
+ if (isOutbound) {
+ wrapperName = callback.getOperationInfo().getResponseWrapperQName();
+ } else {
+ wrapperName = callback.getOperationInfo().getRequestWrapperQName();
+ }
+
+ XMLDocument document = toXMLDocument(
+ callback.getTypeHelper(), objCtx.getMessageObjects(), wrapperName, isWrapped);
+ // HACK: [rfeng] We should use the transformer in an interceptor
+ XMLDocument2XMLStreamReader transformer = new XMLDocument2XMLStreamReader();
+ XMLStreamReader reader = transformer.transform(document, null);
+
+ try {
+ readDocElements(output, reader, true, null);
+ } catch (XMLStreamException e) {
+ e.printStackTrace();
+ throw new InvocationRuntimeException(e.getMessage());
+ }
+ }
+/*
+ private DataObject toWrappedDataObject(TypeHelper typeHelper,
+ Object ret,
+ Object[] os,
+ QName typeQN) {
+ XSDHelper xsdHelper = new XSDHelperImpl(typeHelper);
+ Property property = xsdHelper.getGlobalProperty(typeQN.getNamespaceURI(),
+ typeQN.getLocalPart(), true);
+ DataObject dataObject = new DataFactoryImpl(typeHelper).create(property.getType());
+ List ips = dataObject.getInstanceProperties();
+ int offset = 0;
+ if (ret != null) {
+ dataObject.set(0, ret);
+ offset = 1;
+ }
+ for (int i = offset; i < ips.size(); i++) {
+ if (os[i - offset] instanceof Holder) {
+ Holder<?> holder = (Holder<?>)os[i - offset];
+ dataObject.set(i, holder.value);
+ } else {
+ dataObject.set(i, os[i - offset]);
+ }
+ }
+ return dataObject;
+ }
+*/
+
+ /**
+ * Convert objects to typed DataObject
+ *
+ * @param typeHelper
+ * @param os
+ * @param elementQName
+ * @param isWrapped
+ * @return the DataObject
+ */
+ private static XMLDocument toXMLDocument(TypeHelper typeHelper,
+ Object[] os,
+ QName elementQName,
+ boolean isWrapped) {
+ XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper);
+
+ Property property = xsdHelper.getGlobalProperty(
+ elementQName.getNamespaceURI(), elementQName.getLocalPart(), true);
+ if (null == property) {
+ throw new InvocationRuntimeException(
+ "Type '" + elementQName.toString() + "' not found in registered SDO types.");
+ }
+ DataObject dataObject;
+ if (isWrapped) {
+ DataFactory dataFactory = SDOUtil.createDataFactory(typeHelper);
+ dataObject = dataFactory.create(property.getType());
+ List ips = dataObject.getInstanceProperties();
+ for (int i = 0; i < ips.size(); i++) {
+ dataObject.set(i, os[i]);
+ }
+ } else {
+ Object value = os[0];
+ Type type = property.getType();
+ if (!type.isDataType()) {
+ dataObject = (DataObject) value;
+ } else {
+ dataObject = SDOUtil.createDataTypeWrapper(type, value);
+ }
+ }
+
+ XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper);
+ return xmlHelper.createDocument(dataObject, elementQName.getNamespaceURI(), elementQName.getLocalPart());
+
+ }
+
+ //REVISIT: We should not need to do following anymore with CeltixFire.
+ //As CeltixFire supports stax directly.
+
+ /**
+ * @param parent
+ * @param reader
+ * @param repairing
+ * @param stopAt: stop at the specified element
+ * @throws XMLStreamException
+ */
+ public static void readDocElements(Node parent, XMLStreamReader reader, boolean repairing, QName stopAt)
+ throws XMLStreamException {
+ Document doc = getDocument(parent);
+
+ int event = reader.getEventType();
+
+ while (reader.hasNext()) {
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ if (startElement(parent, reader, repairing, stopAt) == null) {
+ return;
+ }
+ if (parent instanceof Document && stopAt != null) {
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ return;
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ return;
+ case XMLStreamConstants.NAMESPACE:
+ break;
+ case XMLStreamConstants.ATTRIBUTE:
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ if (parent != null) {
+ parent.appendChild(doc.createTextNode(reader.getText()));
+ }
+
+ break;
+ case XMLStreamConstants.COMMENT:
+ if (parent != null) {
+ parent.appendChild(doc.createComment(reader.getText()));
+ }
+
+ break;
+ case XMLStreamConstants.CDATA:
+ parent.appendChild(doc.createCDATASection(reader.getText()));
+
+ break;
+ case XMLStreamConstants.PROCESSING_INSTRUCTION:
+ parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData()));
+
+ break;
+ case XMLStreamConstants.ENTITY_REFERENCE:
+ parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData()));
+
+ break;
+ default:
+ break;
+ }
+
+ if (reader.hasNext()) {
+ event = reader.next();
+ }
+ }
+ }
+
+ private static Document getDocument(Node parent) {
+ return (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument();
+ }
+
+ /**
+ * @param parent
+ * @param reader
+ * @return
+ * @throws XMLStreamException
+ */
+ private static Element startElement(Node parent, XMLStreamReader reader, boolean repairing, QName stopAt)
+ throws XMLStreamException {
+ Document doc = getDocument(parent);
+
+ if (stopAt != null && stopAt.getNamespaceURI().equals(reader.getNamespaceURI())
+ && stopAt.getLocalPart().equals(reader.getLocalName())) {
+ return null;
+ }
+
+ Element e = doc.createElementNS(reader.getNamespaceURI(), reader.getLocalName());
+
+ if (reader.getPrefix() != null) {
+ e.setPrefix(reader.getPrefix());
+ }
+
+ parent.appendChild(e);
+
+ for (int ns = 0; ns < reader.getNamespaceCount(); ns++) {
+ String uri = reader.getNamespaceURI(ns);
+ String prefix = reader.getNamespacePrefix(ns);
+
+ declare(e, uri, prefix);
+ }
+
+ for (int att = 0; att < reader.getAttributeCount(); att++) {
+ String name = reader.getAttributeLocalName(att);
+ String prefix = reader.getAttributePrefix(att);
+ if (prefix != null && prefix.length() > 0) {
+ name = prefix + ":" + name;
+ }
+
+ Attr attr = doc.createAttributeNS(reader.getAttributeNamespace(att), name);
+ attr.setValue(reader.getAttributeValue(att));
+ e.setAttributeNode(attr);
+ }
+
+ reader.next();
+
+ readDocElements(e, reader, repairing, stopAt);
+
+ if (repairing && !isDeclared(e, reader.getNamespaceURI(), reader.getPrefix())) {
+ declare(e, reader.getNamespaceURI(), reader.getPrefix());
+ }
+
+ return e;
+ }
+
+ private static void declare(Element node, String uri, String prefix) {
+ if (prefix != null && prefix.length() > 0) {
+ node.setAttributeNS(XML_NS, "xmlns:" + prefix, uri);
+ } else {
+ if (uri != null /* && uri.length() > 0 */) {
+ node.setAttributeNS(XML_NS, "xmlns", uri);
+ }
+ }
+ }
+
+ private static boolean isDeclared(Element e, String namespaceURI, String prefix) {
+ Attr att;
+ if (prefix != null && prefix.length() > 0) {
+ att = e.getAttributeNodeNS(XML_NS, "xmlns:" + prefix);
+ } else {
+ att = e.getAttributeNode("xmlns");
+ }
+
+ if (att != null && att.getNodeValue().equals(namespaceURI)) {
+ return true;
+ }
+
+ if (e.getParentNode() instanceof Element) {
+ return isDeclared((Element) e.getParentNode(), namespaceURI, prefix);
+ }
+
+ return false;
+ }
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/RawByteArrayOutputStream.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/RawByteArrayOutputStream.java
new file mode 100644
index 0000000000..057481041b
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/RawByteArrayOutputStream.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binding.celtix.io;
+
+import java.io.ByteArrayOutputStream;
+
+/**
+ * Just to allow raw access to the byte[] to avoid a copy
+ */
+class RawByteArrayOutputStream extends ByteArrayOutputStream {
+ public byte[] getBytes() {
+ return buf;
+ }
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java
new file mode 100644
index 0000000000..47d130383f
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java
@@ -0,0 +1,83 @@
+/*
+ * 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.binding.celtix.io;
+
+import org.w3c.dom.Node;
+
+import commonj.sdo.helper.TypeHelper;
+import org.objectweb.celtix.bindings.DataReader;
+import org.objectweb.celtix.bindings.DataWriter;
+import org.objectweb.celtix.bus.bindings.AbstractWSDLOperationDataBindingCallback;
+import org.objectweb.celtix.bus.bindings.WSDLOperationInfo;
+import org.objectweb.celtix.context.ObjectMessageContext;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCADataBindingCallback extends AbstractWSDLOperationDataBindingCallback {
+
+ protected boolean hasInOut;
+ protected TypeHelper typeHelper;
+
+ public SCADataBindingCallback(WSDLOperationInfo op, boolean inout, TypeHelper theTypeHelper) {
+ super(op);
+ this.hasInOut = inout;
+ this.typeHelper = theTypeHelper;
+ }
+
+ public boolean hasInOut() {
+ return hasInOut;
+ }
+
+ public Mode getMode() {
+ return Mode.PARTS;
+ }
+
+ public Class<?>[] getSupportedFormats() {
+ return new Class<?>[]{Node.class};
+ }
+
+ public TypeHelper getTypeHelper() {
+ return typeHelper;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> DataWriter<T> createWriter(Class<T> cls) {
+ if (cls == Node.class) {
+ return (DataWriter<T>) new NodeDataWriter(this);
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> DataReader<T> createReader(Class<T> cls) {
+ if (cls == Node.class) {
+ return (DataReader<T>) new NodeDataReader(this);
+ }
+ //REVISIT - need to figure out what to do with Faults
+ return null;
+ }
+
+ public void initObjectContext(ObjectMessageContext octx) {
+ //REVISIT - is this even used?
+ }
+
+
+}
diff --git a/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java
new file mode 100644
index 0000000000..056c571ec4
--- /dev/null
+++ b/sandbox/old/contrib/binding-celtix/binding/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java
@@ -0,0 +1,81 @@
+/*
+ * 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.binding.celtix.io;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import commonj.sdo.helper.TypeHelper;
+import org.objectweb.celtix.bindings.ServerDataBindingCallback;
+import org.objectweb.celtix.bus.bindings.WSDLOperationInfo;
+import org.objectweb.celtix.context.ObjectMessageContext;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCAServerDataBindingCallback extends SCADataBindingCallback
+ implements ServerDataBindingCallback {
+ String operationName;
+ InboundWire wire;
+
+ public SCAServerDataBindingCallback(WSDLOperationInfo op,
+ boolean inout,
+ String operationName,
+ InboundWire wire,
+ TypeHelper theTypeHelper) {
+ super(op, inout, theTypeHelper);
+ this.operationName = operationName;
+ this.wire = wire;
+ }
+
+
+ public void invoke(ObjectMessageContext octx) throws InvocationTargetException {
+ Object ret;
+ try {
+ InboundInvocationChain chain = null;
+ for (Map.Entry<Operation<?>, InboundInvocationChain> entry : wire.getInvocationChains().entrySet()) {
+ if (entry.getKey().getName().equals(operationName)) {
+ chain = entry.getValue();
+ break;
+ }
+ }
+ MessageImpl msg = new MessageImpl();
+ msg.setBody(octx.getMessageObjects());
+ ret = chain.getHeadInterceptor().invoke(msg);
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new InvocationTargetException(e);
+ }
+ octx.setReturn(ret);
+ }
+
+// public void initObjectContext(ObjectMessageContext octx) {
+// Object o[] = new Object[method.getParameterTypes().length];
+// //REVIST - holders?
+// octx.setMessageObjects(o);
+// }
+
+}