You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/08/28 20:23:54 UTC

svn commit: r437771 - in /incubator/tuscany/java: samples/sca/helloworldwsclient/ sca/bindings/binding.celtix/ sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/ sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/bin...

Author: jmarino
Date: Mon Aug 28 11:23:53 2006
New Revision: 437771

URL: http://svn.apache.org/viewvc?rev=437771&view=rev
Log:
patch from Jervis for TUSCANY-669

Modified:
    incubator/tuscany/java/samples/sca/helloworldwsclient/run_celtix.bat
    incubator/tuscany/java/sca/bindings/binding.celtix/pom.xml
    incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java
    incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java
    incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixReference.java
    incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixService.java
    incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java
    incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java
    incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java
    incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java
    incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java
    incubator/tuscany/java/sca/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java
    incubator/tuscany/java/sca/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java

Modified: incubator/tuscany/java/samples/sca/helloworldwsclient/run_celtix.bat
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sca/helloworldwsclient/run_celtix.bat?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/samples/sca/helloworldwsclient/run_celtix.bat (original)
+++ incubator/tuscany/java/samples/sca/helloworldwsclient/run_celtix.bat Mon Aug 28 11:23:53 2006
@@ -4,10 +4,13 @@
 pushd target\standalone
 jar -xf "%USERPROFILE%\.m2\repository\org\apache\tuscany\standalone\1.0-SNAPSHOT\standalone-1.0-SNAPSHOT-bin.zip" 
 jar -xf "%USERPROFILE%\.m2\repository\org\apache\tuscany\bindings\celtix\1.0-SNAPSHOT\celtix-1.0-SNAPSHOT-bin.zip" 
+rem jar -xf "%USERPROFILE%\.m2\repository\org\apache\tuscany\bindings\axis2\1.0-SNAPSHOT\axis2-1.0-SNAPSHOT-bin.zip" 
 
 popd
 move target\standalone\extension\*.jar target\standalone\boot
 copy "%USERPROFILE%\.m2\repository\org\apache\tuscany\bindings\celtix\1.0-SNAPSHOT\celtix-1.0-SNAPSHOT.jar" target\standalone\extension
+copy "%USERPROFILE%\.m2\repository\org\apache\tuscany\databinding\databinding-sdo\1.0-SNAPSHOT\databinding-sdo-1.0-SNAPSHOT.jar" target\standalone\extension
+rem copy "%USERPROFILE%\.m2\repository\org\apache\tuscany\bindings\axis2\1.0-SNAPSHOT\axis2-1.0-SNAPSHOT.jar" target\standalone\extension
 
 
 java %java_debug_set% -jar target\standalone\bin\launcher.jar  --classpath "%USERPROFILE%\.m2\repository\org\apache\tuscany\samples\sca\sample-helloworldwsclient\1.0-SNAPSHOT\sample-helloworldwsclient-1.0-SNAPSHOT.jar" %*

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/pom.xml?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/pom.xml (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/pom.xml Mon Aug 28 11:23:53 2006
@@ -58,9 +58,24 @@
             <version>${sca.version}</version>
             <scope>compile</scope>
         </dependency>
+        
         <dependency>
             <groupId>org.apache.tuscany.idl</groupId>
             <artifactId>wsdl</artifactId>
+            <version>${sca.version}</version>
+            <scope>compile</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.databinding</groupId>
+            <artifactId>databinding-sdo</artifactId>
+            <version>${sca.version}</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany</groupId>
+            <artifactId>tuscany-sdo-impl</artifactId>
             <version>${sca.version}</version>
             <scope>compile</scope>
         </dependency>

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixBindingBuilder.java Mon Aug 28 11:23:53 2006
@@ -21,7 +21,6 @@
 import java.util.Map;
 import java.util.WeakHashMap;
 
-import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry;
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.component.SCAObject;
 import org.apache.tuscany.spi.deployer.DeploymentContext;
@@ -29,11 +28,13 @@
 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 Service} or {@link org.apache.tuscany.spi.component.Reference} configured
- * with the Celtix binding
+ * Builds a {@link org.apache.tuscany.spi.component.Service} or {@link org.apache.tuscany.spi.component.Reference}
+ * configured with the Celtix binding
  *
  * @version $Rev$ $Date$
  */
@@ -45,6 +46,10 @@
                            BoundServiceDefinition<WebServiceBinding> boundServiceDefinition,
                            DeploymentContext deploymentContext) {
         WebServiceBinding wsBinding = boundServiceDefinition.getBinding();
+        TypeHelper typeHelper = (TypeHelper) deploymentContext.getExtension(TypeHelper.class.getName());
+        if (typeHelper == null) {
+            typeHelper = TypeHelper.INSTANCE;
+        }
         if (bus == null) {
             bus = getBus(wsBinding.getWSDLDefinitionRegistry());
         }
@@ -54,13 +59,18 @@
             parent,
             wireService,
             wsBinding,
-            bus);
+            bus,
+            typeHelper);
     }
 
     public SCAObject build(CompositeComponent parent,
                            BoundReferenceDefinition<WebServiceBinding> boundReferenceDefinition,
                            DeploymentContext deploymentContext) {
         WebServiceBinding wsBinding = boundReferenceDefinition.getBinding();
+        TypeHelper typeHelper = (TypeHelper) deploymentContext.getExtension(TypeHelper.class.getName());
+        if (typeHelper == null) {
+            typeHelper = TypeHelper.INSTANCE;
+        }
         if (bus == null) {
             bus = getBus(wsBinding.getWSDLDefinitionRegistry());
         }
@@ -70,7 +80,8 @@
             parent,
             wireService,
             wsBinding,
-            bus);
+            bus,
+            typeHelper);
     }
 
     protected Class<WebServiceBinding> getBindingType() {

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixInvoker.java Mon Aug 28 11:23:53 2006
@@ -6,20 +6,21 @@
  * 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.    
+ * 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;
@@ -31,15 +32,16 @@
 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 javax.xml.ws.ProtocolException;
 
-import org.apache.tuscany.binding.celtix.io.SCADataBindingCallback;
 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;
@@ -51,9 +53,9 @@
 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>
+ * Responsible for dispatching a service operation invocation on a reference to the active Celtix <code>Bus</code>
  *
  * @version $Rev$ $Date$
  */
@@ -65,13 +67,17 @@
 
     private String operationName;
 
+    private TypeHelper typeHelper;
+
     public CeltixInvoker(String operationName,
                          Bus bus,
                          Port port,
                          Service wsdlService,
-                         Definition wsdlDef) throws BuilderException {
+                         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());
 
@@ -79,9 +85,8 @@
             String key = wsdlDef.getDocumentBaseURI();
             URL url = new URL(key);
 
-            EndpointReferenceType reference = EndpointReferenceUtils.getEndpointReference(url,
-                wsdlService.getQName(),
-                port.getName());
+            QName qName = wsdlService.getQName();
+            EndpointReferenceType reference = EndpointReferenceUtils.getEndpointReference(url, qName, port.getName());
 
             String bindingId = null;
             Binding binding = port.getBinding();
@@ -104,8 +109,7 @@
                 }
 
             }
-            clientBinding = bus.getBindingManager().getBindingFactory(bindingId).createClientBinding(
-                reference);
+            clientBinding = bus.getBindingManager().getBindingFactory(bindingId).createClientBinding(reference);
         } catch (MalformedURLException e) {
             throw new InvokerCreationException(e);
         } catch (BusException e) {
@@ -123,7 +127,7 @@
      * @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) {
+    public Object invokeTarget(final Object args) throws InvocationTargetException {
         WSDLOperationInfo opInfo = wsdlCache.getOperationInfo(operationName);
         if (opInfo == null) {
             // REVISIT - really map the operation name to a WSDL operation
@@ -150,8 +154,7 @@
         }
 
         if (opInfo.getParamsLength() == 0) {
-            // REVISIT - opInfo doesn't return the needed info for the wrapped
-            // doc/lit case.
+            // REVISIT - opInfo doesn't return the needed info for the wrapped doc/lit case.
             // Bug in Celtix
             realArgs = argsArray;
         } else {
@@ -167,18 +170,15 @@
         }
         objMsgContext.setMessageObjects(realArgs);
         boolean isOneway = opInfo.isOneWay();
-        DataBindingCallback callback = new SCADataBindingCallback(opInfo, hasInOut);
+        DataBindingCallback callback = new SCADataBindingCallback(opInfo, hasInOut, typeHelper);
         try {
             if (isOneway) {
-                clientBinding.invokeOneWay(objMsgContext,
-                    callback);
+                clientBinding.invokeOneWay(objMsgContext, callback);
             } else {
-                objMsgContext = clientBinding.invoke(objMsgContext,
-                    callback);
+                objMsgContext = clientBinding.invoke(objMsgContext, callback);
             }
         } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            throw new InvocationTargetException(e);
         }
 
         if (objMsgContext.getException() != null) {
@@ -188,7 +188,7 @@
              * (Exception)objMsgContext.getException(); } else { throw new
              * ProtocolException(objMsgContext.getException()); }
              */
-            throw new ProtocolException(objMsgContext.getException());
+            throw new InvocationTargetException(objMsgContext.getException());
         }
 
         if (hasInOut) {

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixReference.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixReference.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixReference.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixReference.java Mon Aug 28 11:23:53 2006
@@ -6,15 +6,15 @@
  * 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.    
+ * under the License.
  */
 package org.apache.tuscany.binding.celtix;
 
@@ -23,10 +23,13 @@
 import javax.wsdl.Port;
 import javax.wsdl.Service;
 
+import commonj.sdo.helper.TypeHelper;
+
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.extension.ReferenceExtension;
 import org.apache.tuscany.spi.wire.TargetInvoker;
 import org.apache.tuscany.spi.wire.WireService;
+
 import org.objectweb.celtix.Bus;
 
 /**
@@ -41,22 +44,24 @@
     private Port port;
     private Definition wsdlDef;
     private Service wsdlService;
+    private TypeHelper typeHelper;
 
     public CeltixReference(String name,
                            Class<T> interfaze,
                            CompositeComponent<?> parent,
                            WireService wireService,
                            WebServiceBinding binding,
-                           Bus bus) {
+                           Bus theBus,
+                           TypeHelper theTypeHelper) {
         super(name, interfaze, parent, wireService);
         this.wsdlDef = binding.getWSDLDefinition();
         this.port = binding.getWSDLPort();
         this.wsdlService = binding.getWSDLService();
-        this.bus = bus;
+        this.bus = theBus;
+        this.typeHelper = theTypeHelper;
     }
 
     public TargetInvoker createTargetInvoker(Method operation) {
-        //FIXME - can we pass in the method name as the operation name?
-        return new CeltixInvoker(operation.getName(), bus, port, wsdlService, wsdlDef);
+        return new CeltixInvoker(operation.getName(), bus, port, wsdlService, wsdlDef, typeHelper);
     }
 }

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixService.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixService.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/CeltixService.java Mon Aug 28 11:23:53 2006
@@ -38,13 +38,18 @@
 import javax.xml.namespace.QName;
 import javax.xml.ws.WebServiceProvider;
 
-import org.apache.tuscany.binding.celtix.io.SCAServerDataBindingCallback;
+import org.osoa.sca.annotations.Destroy;
+
 import org.apache.tuscany.spi.CoreRuntimeException;
 import org.apache.tuscany.spi.builder.BuilderConfigException;
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.extension.ServiceExtension;
 import org.apache.tuscany.spi.wire.WireService;
+
+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;
@@ -55,9 +60,9 @@
 import org.objectweb.celtix.ws.addressing.AttributedURIType;
 import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
 import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
-import org.osoa.sca.annotations.Destroy;
 import org.xmlsoap.schemas.wsdl.http.AddressType;
 
+
 /**
  * An implementation of a {@link Service} configured with the Celtix binding
  *
@@ -70,6 +75,7 @@
     private Definition wsdlDef;
     private Service wsdlService;
     private WSDLMetaDataCache wsdlCache;
+    private TypeHelper typeHelper;
 
     private Map<QName, ServerDataBindingCallback> opMap =
         new ConcurrentHashMap<QName, ServerDataBindingCallback>();
@@ -80,13 +86,15 @@
                          CompositeComponent parent,
                          WireService wireService,
                          WebServiceBinding binding,
-                         Bus bus) {
+                         Bus bus,
+                         TypeHelper theTypeHelper) {
         super(theName, interfaze, parent, wireService);
         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() {
@@ -104,9 +112,9 @@
             throw new CeltixServiceInitException(e);
         }
 
-        EndpointReferenceType reference = EndpointReferenceUtils.getEndpointReference(url,
-                                                                                      wsdlService.getQName(),
-                                                                                      port.getName());
+        QName qName = wsdlService.getQName();
+        String portName = port.getName();
+        EndpointReferenceType reference = EndpointReferenceUtils.getEndpointReference(url,qName,portName);
 
         AttributedURIType address = new AttributedURIType();
 
@@ -138,20 +146,21 @@
             //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.
-            ClassLoader previousLoader = Thread.currentThread().getContextClassLoader();
+            previousLoader = Thread.currentThread().getContextClassLoader();
             Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
-
-            ServerBinding serverBinding = bus.getBindingManager()
-                .getBindingFactory(bindingId).createServerBinding(reference, this);
+            BindingFactory bindingFactory = bus.getBindingManager().getBindingFactory(bindingId);
+            ServerBinding serverBinding = bindingFactory.createServerBinding(reference, this);
             serverBinding.activate();
-
-            Thread.currentThread().setContextClassLoader(previousLoader);
         } catch (Exception e) {
             throw new CeltixServiceInitException(e);
+        } finally {
+            if (previousLoader != null) {
+                Thread.currentThread().setContextClassLoader(previousLoader);
+            }
         }
     }
 
@@ -173,8 +182,7 @@
                 }
             }
 
-            ServerDataBindingCallback cb = getDataBindingCallback(qn, null,
-                                                                  DataBindingCallback.Mode.PARTS);
+            ServerDataBindingCallback cb = getDataBindingCallback(qn, null, DataBindingCallback.Mode.PARTS);
             opMap.put(qn, cb);
             if (!"".equals(cb.getRequestWrapperQName().getLocalPart())) {
                 opMap.put(cb.getRequestWrapperQName(), cb);
@@ -210,7 +218,7 @@
 
         Object proxy = this.getServiceInstance();
 
-        return new SCAServerDataBindingCallback(opInfo, inout, meth, proxy);
+        return new SCAServerDataBindingCallback(opInfo, inout, meth, proxy, typeHelper);
     }
 
     protected Method getMethod(Class<?> serviceInterface, String operationName) {
@@ -228,7 +236,7 @@
             }
         }
         throw new BuilderConfigException("no operation named " + operationName
-                                         + " found on service interface: " + serviceInterface.getName());
+            + " found on service interface: " + serviceInterface.getName());
     }
 
     public DataBindingCallback getFaultDataBindingCallback(ObjectMessageContext objContext) {

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/WebServiceBindingLoader.java Mon Aug 28 11:23:53 2006
@@ -34,9 +34,11 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
-import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry;
-import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl;
-import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl.Monitor;
+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;
@@ -44,10 +46,9 @@
 import org.apache.tuscany.spi.loader.LoaderException;
 import org.apache.tuscany.spi.loader.LoaderRegistry;
 
-import org.osoa.sca.annotations.Constructor;
-import org.osoa.sca.annotations.Scope;
-import org.xml.sax.InputSource;
-import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+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>WebServiceBinding</code> entry in an assembly XML file
@@ -60,7 +61,7 @@
 
     protected WSDLDefinitionRegistry wsdlRegistry;
 
-    @Constructor({"registry", "wsdlregistry" })
+    @Constructor({"registry", "wsdlregistry"})
     public WebServiceBindingLoader(@Autowire LoaderRegistry registry,
                                    @Autowire WSDLDefinitionRegistry theWsdlRegistry) {
         super(registry);
@@ -73,11 +74,12 @@
                 Monitor monitor = new Monitor() {
                     public void readingWSDL(String namespace, URL location) {
                     }
+
                     public void cachingDefinition(String namespace, URL location) {
                     }
                 };
 
-                ((WSDLDefinitionRegistryImpl)wsdlRegistry).setMonitor(monitor);
+                ((WSDLDefinitionRegistryImpl) wsdlRegistry).setMonitor(monitor);
             } catch (javax.wsdl.WSDLException e) {
                 //do nothing
             }

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataReader.java Mon Aug 28 11:23:53 2006
@@ -6,40 +6,49 @@
  * 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.    
+ * 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 commonj.sdo.DataObject;
-//import commonj.sdo.Property;
-//import commonj.sdo.helper.XMLDocument;
 
-//import org.apache.tuscany.databinding.sdo.SDOXMLHelper;
-//import org.apache.tuscany.sdo.helper.XMLHelperImpl;
+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.databinding.TransformationContext;
+import org.apache.tuscany.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> {
 
-    SCADataBindingCallback callback;
+    private SCADataBindingCallback callback;
 
     public NodeDataReader(SCADataBindingCallback cb) {
         callback = cb;
@@ -50,24 +59,27 @@
     }
 
     public Object read(QName name, int idx, Node input) {
-//FIXME: This part of code should not depend on SDO direclty. Use a data mediation system service?
-/*
         try {
-            byte bytes[] = getNodeBytes(input);
-            //FIXME: get TypeHelper
-            //            Object os[] = SDOXMLHelper.toObjects(callback.getTypeHelper(), bytes, false);
-            return os[0];
-        } catch (RuntimeException e) {
-            throw e;
+            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) {
-            throw new WebServiceException(e);
+            //REVISIT: better handling of exceptions
         }
-*/
         return null;
     }
 
     public void readWrapper(ObjectMessageContext objCtx, boolean isOutBound, Node input) {
-/*
         try {
             QName wrapperName;
             if (isOutBound) {
@@ -78,63 +90,82 @@
 
             Node nd = input.getFirstChild();
             while (nd != null
-                   && !wrapperName.getNamespaceURI().equals(nd.getNamespaceURI())
-                   && !wrapperName.getLocalPart().equals(nd.getLocalName())) {
+                && !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);
-            //            XMLDocument document = new XMLHelperImpl(new commonj.sdo.helper.TypeHelper()).load(in);
-            //            XMLDocument document = new XMLHelperImpl(callback.getTypeHelper()).load(in);
-            DataObject object = null;
-
-            List ips = object.getInstanceProperties();
-            Object[] os = new Object[object.getInstanceProperties().size()];
-            for (int i = 0; i < os.length; i++) {
-                os[i] = object.get((Property)ips.get(i));
-            }
+            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(os[0]);
+                    objCtx.setReturn(objects[0]);
                 } else {
-                    objCtx.setMessageObjects(os);
+                    objCtx.setMessageObjects(objects);
                 }
             }
-            //        } catch (IOException e) {
-            //            throw new WebServiceException(e);
-        } catch (ClassCastException e) {
-            throw new WebServiceException(e);
-        } catch (ClassNotFoundException e) {
-            throw new WebServiceException(e);
-        } catch (InstantiationException e) {
-            throw new WebServiceException(e);
-        } catch (IllegalAccessException e) {
-            throw new WebServiceException(e);
+        } 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 {
+        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(DOMImplementationRegistry.PROPERTY,
-                               "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
+            System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
             registry = DOMImplementationRegistry.newInstance();
         }
-        DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
+        DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
         if (impl == null) {
-            System.setProperty(DOMImplementationRegistry.PROPERTY,
-                               "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
+            System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
             registry = DOMImplementationRegistry.newInstance();
-            impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
+            impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
         }
         LSOutput output = impl.createLSOutput();
         ByteArrayOutputStream bout = new ByteArrayOutputStream();
@@ -152,16 +183,14 @@
         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(DOMImplementationRegistry.PROPERTY,
-                               "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
+            System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
             registry = DOMImplementationRegistry.newInstance();
         }
-        DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
+        DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
         if (impl == null) {
-            System.setProperty(DOMImplementationRegistry.PROPERTY,
-                               "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
+            System.setProperty(PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
             registry = DOMImplementationRegistry.newInstance();
-            impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
+            impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
         }
         LSOutput output = impl.createLSOutput();
         RawByteArrayOutputStream bout = new RawByteArrayOutputStream();

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/NodeDataWriter.java Mon Aug 28 11:23:53 2006
@@ -18,28 +18,35 @@
  */
 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.xml.sax.Attributes;
-import org.xml.sax.helpers.DefaultHandler;
-//import commonj.sdo.DataObject;
-//import commonj.sdo.Property;
-//import commonj.sdo.helper.TypeHelper;
-//import commonj.sdo.helper.XSDHelper;
-
-//import org.apache.tuscany.databinding.sdo.SDOXMLHelper;
-//import org.apache.tuscany.sdo.helper.DataFactoryImpl;
-//import org.apache.tuscany.sdo.helper.XMLHelperImpl;
-//import org.apache.tuscany.sdo.helper.XSDHelperImpl;
+
+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> {
-    SCADataBindingCallback callback;
+    private static final String XML_NS = "http://www.w3.org/2000/xmlns/";
+    private SCADataBindingCallback callback;
 
     public NodeDataWriter(SCADataBindingCallback cb) {
         callback = cb;
@@ -50,37 +57,23 @@
     }
 
     public void write(Object obj, QName elName, Node output) {
-        Document doc = output.getOwnerDocument();
-        if (doc == null && output instanceof Document) {
-            doc = (Document)output;
-        }
-
-        Element newEl = doc.createElementNS("anyuri", elName.getLocalPart());
-        output.appendChild(newEl);
-
-        /*
-        byte bytes[] = SDOXMLHelper.toXMLBytes(
-            callback.getTypeHelper(),
-            new Object[] {obj},
-            elName,
-            false);
-        ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
-        SAXParserFactory factory = SAXParserFactory.newInstance();
-        factory.setNamespaceAware(true);
+        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 {
-            SAXParser parser = factory.newSAXParser();
-            parser.parse(bin, new NodeContentHandler(output));
-        } catch (RuntimeException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new WebServiceException(e);
+            //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 nd) {
-/*
+    public void writeWrapper(ObjectMessageContext objCtx, boolean isOutbound, Node output) {
+        boolean isWrapped = true;
         QName wrapperName;
         if (isOutbound) {
             wrapperName = callback.getOperationInfo().getResponseWrapperQName();
@@ -88,39 +81,21 @@
             wrapperName = callback.getOperationInfo().getRequestWrapperQName();
         }
 
-        DataObject obj = toWrappedDataObject(callback.getTypeHelper(),
-            isOutbound ? objCtx.getReturn() : null,
-            objCtx.getMessageObjects(),
-            wrapperName);
+        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 {
-            //REVISIT - this is SUCH a hack.   SDO needs to be able to
-            //go directly to some formats other than streams.  They are working
-            //on stax, but not there yet.
-            RawByteArrayOutputStream bout = new RawByteArrayOutputStream();
-            new XMLHelperImpl(callback.getTypeHelper()).save(obj,
-                wrapperName.getNamespaceURI(),
-                wrapperName.getLocalPart(),
-                bout);
-            ByteArrayInputStream bin = new ByteArrayInputStream(bout.getBytes(),
-                                                                0,
-                                                                bout.size());
-            SAXParserFactory factory = SAXParserFactory.newInstance();
-            factory.setNamespaceAware(true);
-            SAXParser parser = factory.newSAXParser();
-            parser.parse(bin, new NodeContentHandler(nd));
-        } catch (IOException e) {
-            throw new WebServiceException(e);
-        } catch (ParserConfigurationException e) {
-            throw new WebServiceException(e);
-        } catch (SAXException e) {
-            throw new WebServiceException(e);
+            readDocElements(output, reader, true, null);
+        } catch (XMLStreamException e) {
+            e.printStackTrace();
+            throw new InvocationRuntimeException(e.getMessage());
         }
-*/
     }
-
 /*
-    public static DataObject toWrappedDataObject(TypeHelper typeHelper,
+    private DataObject toWrappedDataObject(TypeHelper typeHelper,
                                                  Object ret,
                                                  Object[] os,
                                                  QName typeQN) {
@@ -145,38 +120,203 @@
         return dataObject;
     }
 */
-    class NodeContentHandler extends DefaultHandler {
-        Node current;
-        Document doc;
 
-        public NodeContentHandler(Node nd) {
-            doc = nd.getOwnerDocument();
-            if (doc == null && nd instanceof Document) {
-                doc = (Document)nd;
+    /**
+     * 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();
             }
-            current = nd;
+        }
+    }
+
+    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());
         }
 
-        public void characters(char[] ch, int start, int length) {
-            current.appendChild(doc.createTextNode(new String(ch, start, length)));
+        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);
         }
 
-        public void startElement(String uri, String localName,
-                                 String qName, Attributes attributes) {
-            Element newEl = doc.createElementNS(uri, qName);
-            current.appendChild(newEl);
-            current = newEl;
-            for (int x = 0; x < attributes.getLength(); x++) {
-                newEl.setAttributeNS(attributes.getURI(x),
-                                     attributes.getQName(x),
-                                     attributes.getValue(x));
+        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());
         }
 
-        public void endElement(String uri, String localName, String qName) {
-            current = current.getParentNode();
+        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;
+    }
 }

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCADataBindingCallback.java Mon Aug 28 11:23:53 2006
@@ -20,24 +20,26 @@
 
 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) {
+    public SCADataBindingCallback(WSDLOperationInfo op, boolean inout, TypeHelper theTypeHelper) {
         super(op);
-        hasInOut = inout;
+        this.hasInOut = inout;
+        this.typeHelper = theTypeHelper;
     }
 
     public boolean hasInOut() {
@@ -52,10 +54,14 @@
         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 (DataWriter<T>) new NodeDataWriter(this);
         }
         return null;
     }
@@ -63,7 +69,7 @@
     @SuppressWarnings("unchecked")
     public <T> DataReader<T> createReader(Class<T> cls) {
         if (cls == Node.class) {
-            return (DataReader<T>)new NodeDataReader(this);
+            return (DataReader<T>) new NodeDataReader(this);
         }
         //REVISIT - need to figure out what to do with Faults
         return null;

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/main/java/org/apache/tuscany/binding/celtix/io/SCAServerDataBindingCallback.java Mon Aug 28 11:23:53 2006
@@ -6,25 +6,28 @@
  * 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.    
+ * under the License.
  */
 package org.apache.tuscany.binding.celtix.io;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
+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$
@@ -37,8 +40,9 @@
     public SCAServerDataBindingCallback(WSDLOperationInfo op,
                                         boolean inout,
                                         Method meth,
-                                        Object target) {
-        super(op, inout);
+                                        Object target,
+                                        TypeHelper theTypeHelper) {
+        super(op, inout, theTypeHelper);
         method = meth;
         targetObject = target;
     }

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixInvokerTestCase.java Mon Aug 28 11:23:53 2006
@@ -6,21 +6,19 @@
  * 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.    
+ * under the License.
  */
 package org.apache.tuscany.binding.celtix;
 
 import java.net.URL;
-
-
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
 import javax.wsdl.Service;
@@ -31,11 +29,8 @@
 import org.xml.sax.InputSource;
 
 import junit.framework.TestCase;
-
 import org.apache.tuscany.binding.celtix.io.SCADataBindingCallback;
-
 import org.easymock.classextension.EasyMock;
-
 import org.objectweb.celtix.Bus;
 import org.objectweb.celtix.bindings.BindingManager;
 import org.objectweb.celtix.bus.bindings.soap.SOAPBindingFactory;
@@ -53,12 +48,11 @@
         String operationName = "greetMe";
         ObjectMessageContextImpl inputCtx = new ObjectMessageContextImpl();
         CeltixInvoker invoker = createCeltixInvoker(wsdlLocation,
-                operationName, inputCtx);
+            operationName, inputCtx);
 
         Object[] args = new Object[1];
-        String inputvalue = new String("hello");
-        args[0] = inputvalue;
-        Object result = invoker.invokeTarget(args);
+        args[0] = new String("hello");
+        invoker.invokeTarget(args);
 
         // Check the input object after processing is correct
         // Should be no change for input if only IN parameters involved
@@ -72,7 +66,7 @@
         String operationName = "greetMe";
         ObjectMessageContextImpl inputCtx = new ObjectMessageContextImpl();
         CeltixInvoker invoker = createCeltixInvoker(wsdlLocation,
-                operationName, inputCtx);
+            operationName, inputCtx);
 
         Object[] args = new Object[1];
         String inputvalue = new String("hello");
@@ -90,29 +84,27 @@
     // NOTE: For convenience this method presumes the soap service name is
     // SOAPService and port name is SoapPort
     private CeltixInvoker createCeltixInvoker(String wsdlLocation,
-            String operationName, ObjectMessageContextImpl inputCtx)
+                                              String operationName,
+                                              ObjectMessageContextImpl inputCtx)
         throws Exception {
-        
+
         // Make following call to return a mocked SOAPClientBinding:
         // bus.getBindingManager().getBindingFactory(bindingId).createClientBinding(reference)
         SOAPClientBinding clientBinding = EasyMock
-                .createMock(SOAPClientBinding.class);
+            .createMock(SOAPClientBinding.class);
         clientBinding.createObjectContext();
         EasyMock.expectLastCall().andReturn(inputCtx);
         clientBinding.invoke(EasyMock.isA(ObjectMessageContextImpl.class),
-                EasyMock.isA(SCADataBindingCallback.class));
+            EasyMock.isA(SCADataBindingCallback.class));
         EasyMock.expectLastCall().andReturn(new ObjectMessageContextImpl());
         EasyMock.replay(clientBinding);
 
-        SOAPBindingFactory bindingFactory = EasyMock
-                .createNiceMock(SOAPBindingFactory.class);
-        bindingFactory.createClientBinding(EasyMock
-                .isA(EndpointReferenceType.class));
+        SOAPBindingFactory bindingFactory = EasyMock.createNiceMock(SOAPBindingFactory.class);
+        bindingFactory.createClientBinding(EasyMock.isA(EndpointReferenceType.class));
         EasyMock.expectLastCall().andReturn(clientBinding);
         EasyMock.replay(bindingFactory);
 
-        BindingManager bindingManager = EasyMock
-                .createNiceMock(BindingManager.class);
+        BindingManager bindingManager = EasyMock.createNiceMock(BindingManager.class);
         String bindingId = "http://schemas.xmlsoap.org/wsdl/soap/";
         bindingManager.getBindingFactory(bindingId);
         EasyMock.expectLastCall().andReturn(bindingFactory);
@@ -132,13 +124,11 @@
         reader.setFeature("javax.wsdl.verbose", false);
         InputSource input = new InputSource(url.openStream());
         Definition wsdlDef = reader.readWSDL(url.toString(), input);
-        Service wsdlService = wsdlDef.getService(new QName(
-                "http://objectweb.org/hello_world_soap_http", "SOAPService"));
+        QName qName = new QName("http://objectweb.org/hello_world_soap_http", "SOAPService");
+        Service wsdlService = wsdlDef.getService(qName);
         Port port = wsdlService.getPort("SoapPort");
 
-        CeltixInvoker invoker = new CeltixInvoker(operationName, bus, port,
-                wsdlService, wsdlDef);
-        return invoker;
+        return new CeltixInvoker(operationName, bus, port, wsdlService, wsdlDef, null);
     }
 
 }

Modified: incubator/tuscany/java/sca/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java?rev=437771&r1=437770&r2=437771&view=diff
==============================================================================
--- incubator/tuscany/java/sca/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java (original)
+++ incubator/tuscany/java/sca/bindings/binding.celtix/src/test/java/org/apache/tuscany/binding/celtix/CeltixServiceTestCase.java Mon Aug 28 11:23:53 2006
@@ -6,15 +6,15 @@
  * 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.    
+ * under the License.
  */
 package org.apache.tuscany.binding.celtix;
 
@@ -28,15 +28,14 @@
 
 import org.xml.sax.InputSource;
 
-import junit.framework.TestCase;
-
 import org.apache.tuscany.spi.wire.InboundWire;
 import org.apache.tuscany.spi.wire.WireService;
 
+import junit.framework.TestCase;
 import org.easymock.classextension.EasyMock;
 import org.objectweb.celtix.Bus;
 import org.objectweb.celtix.bindings.BindingManager;
-import org.objectweb.celtix.bindings.DataBindingCallback;
+import static org.objectweb.celtix.bindings.DataBindingCallback.Mode.PARTS;
 import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
 import org.objectweb.celtix.bindings.ServerDataBindingCallback;
 import org.objectweb.celtix.bus.bindings.soap.SOAPBindingFactory;
@@ -55,12 +54,11 @@
         QName operationName = new QName("greetMe");
         ObjectMessageContextImpl ctx = new ObjectMessageContextImpl();
         ctx.setMessageObjects(new String[]{"Celtix"});
-        ServerDataBindingCallback callback1 = celtixService.getDataBindingCallback(operationName,
-                ctx, DataBindingCallback.Mode.PARTS);
+        ServerDataBindingCallback callback1 = celtixService.getDataBindingCallback(operationName, ctx, PARTS);
         assertNotNull(callback1);
 
         callback1.invoke(ctx);
-        Object rtn = (String)ctx.getReturn();
+        Object rtn = (String) ctx.getReturn();
         assertEquals("Hello Celtix", rtn);
 
     }
@@ -72,11 +70,11 @@
         serverBinding.activate();
         EasyMock.replay(serverBinding);
 
-        ServerBindingEndpointCallback callback = EasyMock.createNiceMock(ServerBindingEndpointCallback.class);
+        //ServerBindingEndpointCallback callback = EasyMock.createNiceMock(ServerBindingEndpointCallback.class);
 
         SOAPBindingFactory bindingFactory = EasyMock.createNiceMock(SOAPBindingFactory.class);
         bindingFactory.createServerBinding(EasyMock.isA(EndpointReferenceType.class),
-                                           EasyMock.isA(ServerBindingEndpointCallback.class));
+            EasyMock.isA(ServerBindingEndpointCallback.class));
         EasyMock.expectLastCall().andReturn(serverBinding);
         EasyMock.replay(bindingFactory);
 
@@ -102,7 +100,7 @@
         InputSource input = new InputSource(url.openStream());
         Definition wsdlDef = reader.readWSDL(url.toString(), input);
         Service wsdlService = wsdlDef.getService(new QName("http://objectweb.org/hello_world_soap_http",
-                                                           "SOAPService"));
+            "SOAPService"));
         Port port = wsdlService.getPort("SoapPort");
 
         WebServiceBinding wsBinding = new WebServiceBinding(wsdlDef, port, "uri", "portURI", wsdlService);
@@ -119,7 +117,7 @@
         EasyMock.expectLastCall().andReturn(new GreeterImpl()).anyTimes();
         EasyMock.replay(wireService);
 
-        CeltixService celtixService = new CeltixService("name", Greeter.class, null, wireService, wsBinding, bus);
+        CeltixService celtixService = new CeltixService("name", Greeter.class, null, wireService, wsBinding, bus, null);
         //Not sure how InboundWire is set to CeltixService, is the following way correct?
         celtixService.setInboundWire(inboundWire);
         celtixService.start();



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org