cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject svn commit: r441062 - in /incubator/cxf/trunk: rt/core/src/main/java/org/apache/cxf/service/factory/ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/main/java/org/apache...
Date Thu, 07 Sep 2006 12:17:20 GMT
Author: tli
Date: Thu Sep  7 05:17:19 2006
New Revision: 441062

URL: http://svn.apache.org/viewvc?view=rev&rev=441062
Log:
add a map in JAXBDataBinding to hold the QName and Jaxb Java Type mapping when created to
support rpc/bare JAXB unmarshall with QName and class, when MessagePart refer to type not
element in wsdl definition

Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBeanTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/GreeterTest.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?view=diff&rev=441062&r1=441061&r2=441062
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
Thu Sep  7 05:17:19 2006
@@ -46,11 +46,13 @@
 import org.apache.cxf.wsdl11.WSDLServiceFactory;
 
 public class ReflectionServiceFactoryBean extends AbstractServiceFactoryBean {
+
     private static final Logger LOG = Logger.getLogger(ReflectionServiceFactoryBean.class.getName());
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ReflectionServiceFactoryBean.class);
 
+    protected URL wsdlURL;
+
     private Class<?> serviceClass;
-    private URL wsdlURL;
     private List<AbstractServiceConfiguration> serviceConfigurations = 
         new ArrayList<AbstractServiceConfiguration>();
     private QName serviceName;
@@ -93,7 +95,9 @@
 
     protected void initializeServiceModel() {
         URL url = getWsdlURL();
-
+        if (getService() != null) {
+            return;
+        }
         if (url != null) {
             LOG.info("Creating Service " + getServiceQName() + " from WSDL.");
             WSDLServiceFactory factory = new WSDLServiceFactory(getBus(), url, getServiceQName());

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?view=diff&rev=441062&r1=441061&r2=441062
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
Thu Sep  7 05:17:19 2006
@@ -20,6 +20,8 @@
 package org.apache.cxf.jaxb;
 
 import java.io.IOException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -30,10 +32,10 @@
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.w3c.dom.Document;
-
 import org.xml.sax.SAXException;
 
 import org.apache.cxf.common.i18n.BundleUtils;
@@ -45,9 +47,13 @@
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.resource.URIResolver;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.MessageInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
-
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 
@@ -60,16 +66,24 @@
     JAXBDataReaderFactory reader;
     JAXBDataWriterFactory writer;
     JAXBContext context;
+    Service service;
+    Class clazz;
+    // this will be used to call unmarshall to provide the QName and Class
+    Map<BindingInfo, Map<BindingOperationInfo, Map<QName, Class>>> typeClassMap;
     
     public JAXBDataBinding() throws JAXBException {
         reader = new JAXBDataReaderFactory();
         writer = new JAXBDataWriterFactory();
     }
-    public JAXBDataBinding(Class<?> cls) throws JAXBException {
+    public JAXBDataBinding(Class<?> cls, Service pService) throws JAXBException {
         this();
+        clazz = cls;
+        service = pService;
+        typeClassMap = new HashMap<BindingInfo, Map<BindingOperationInfo, Map<QName,
Class>>>();
         context = JAXBEncoderDecoder.createJAXBContextForClass(cls);
         reader.setJAXBContext(context);
         writer.setJAXBContext(context);
+        buildTypeClassMapping();
     }
     
     public void setContext(JAXBContext ctx) {
@@ -144,6 +158,50 @@
             LOG.log(Level.SEVERE, e.getMessage());
             throw new UncheckedException(e);
         }
+    }
+
+    private void buildTypeClassMapping() {
+        for (BindingInfo bi : service.getServiceInfo().getBindings()) {
+            Map<BindingOperationInfo, Map<QName, Class>> biMap = 
+                new HashMap<BindingOperationInfo, Map<QName, Class>>();
+            typeClassMap.put(bi, biMap);
+            for (BindingOperationInfo boi : bi.getOperations()) {
+                Map<QName, Class> boiMap = new HashMap<QName, Class>();
+                biMap.put(boi, boiMap);
+                addTypeClassMapping(clazz, boiMap, boi.getOperationInfo().getInput());
+                addTypeClassMapping(clazz, boiMap, boi.getOperationInfo().getOutput());
+            }
+        }
+    }
+
+    private static void addTypeClassMapping(Class cls, Map<QName, Class> boiMap, MessageInfo
msg) {
+        if (msg == null) {
+            return;
+        }
+        for (MessagePartInfo mpi : msg.getMessageParts()) {
+            if (!mpi.isElement()) {
+                String methodName = msg.getOperation().getName().getLocalPart();
+                String paramName = mpi.getTypeQName().getLocalPart();
+                Class paramCls = getParamClass(cls, methodName, paramName);
+                if (paramCls != null) {
+                    boiMap.put(mpi.getTypeQName(), paramCls);
+                }
+            }
+        }
+    }
+    
+    private static Class getParamClass(Class cls, String methodName, String paramName) {
+        Method methods[] = cls.getMethods();
+        for (Method meth : methods) {
+            if (meth.getName().equals(methodName)) {
+                for (Type t : meth.getGenericParameterTypes()) {
+                    if (t.getClass().getSimpleName().equals(paramName)) {
+                        return t.getClass();
+                    }
+                }
+            }
+        }
+        return null;
     }
 
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?view=diff&rev=441062&r1=441061&r2=441062
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
Thu Sep  7 05:17:19 2006
@@ -67,8 +67,8 @@
         implInfo = new JaxwsImplementorInfo(implementor.getClass());
         // build up the Service model
         JaxWsServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean(implInfo);
-        serviceFactory.setServiceClass(implementor.getClass());
         serviceFactory.setBus(bus);
+        serviceFactory.setServiceClass(implementor.getClass());
         service = serviceFactory.create();
 
         // create the endpoint        

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java?view=diff&rev=441062&r1=441061&r2=441062
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
Thu Sep  7 05:17:19 2006
@@ -81,7 +81,7 @@
         handlerResolver = new HandlerResolverImpl(bus, name);
 
         try {
-            JAXBDataBinding dataBinding = new JAXBDataBinding(cls);
+            JAXBDataBinding dataBinding = new JAXBDataBinding(cls, service);
             service.setDataReaderFactory(dataBinding.getDataReaderFactory());
             service.setDataWriterFactory(dataBinding.getDataWriterFactory());
         } catch (JAXBException e) {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java?view=diff&rev=441062&r1=441061&r2=441062
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
Thu Sep  7 05:17:19 2006
@@ -104,17 +104,6 @@
 
     @Override
     public void setServiceClass(Class<?> serviceClass) {
-        super.setServiceClass(serviceClass);
-
-        try {
-            dataBinding = new JAXBDataBinding(serviceClass);
-        } catch (JAXBException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        setDataReaderFactory(dataBinding.getDataReaderFactory());
-        setDataWriterFactory(dataBinding.getDataWriterFactory());
-
         // update wsdl location
         // TODO: replace version in EndpointreferenceUtils?
         String wsdlLocation = null;
@@ -156,6 +145,21 @@
             }
             setWsdlURL(url);
         }
+
+        super.setServiceClass(serviceClass);
+
+        initializeServiceConfigurations();
+        
+        initializeServiceModel();
+        
+        try {
+            dataBinding = new JAXBDataBinding(serviceClass, getService());
+        } catch (JAXBException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        setDataReaderFactory(dataBinding.getDataReaderFactory());
+        setDataWriterFactory(dataBinding.getDataWriterFactory());
     }
 
     protected QName getServiceQName() {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java?view=diff&rev=441062&r1=441061&r2=441062
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsClientTest.java
Thu Sep  7 05:17:19 2006
@@ -102,14 +102,11 @@
 
     public void testEndpoint() throws Exception {
         JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
-        bean.setServiceClass(GreeterImpl.class);
-
         URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
         assertNotNull(resource);
         bean.setWsdlURL(resource);
-
-        bean.setBus(bus);
-        
+        bean.setBus(bus);        
+        bean.setServiceClass(GreeterImpl.class);        
         GreeterImpl greeter = new GreeterImpl();
         SimpleMethodInvoker invoker = new SimpleMethodInvoker(greeter);
         bean.setInvoker(invoker);

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBeanTest.java?view=diff&rev=441062&r1=441061&r2=441062
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBeanTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBeanTest.java
Thu Sep  7 05:17:19 2006
@@ -45,14 +45,13 @@
 public class JaxWsServiceFactoryBeanTest extends TestCase {
     public void testEndpoint() throws Exception {
         JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
-        bean.setServiceClass(GreeterImpl.class);
 
         URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
         assertNotNull(resource);
         bean.setWsdlURL(resource);
-
         Bus bus = createBus();
         bean.setBus(bus);
+        bean.setServiceClass(GreeterImpl.class);
 
         SimpleMethodInvoker invoker = new SimpleMethodInvoker(new GreeterImpl());
         bean.setInvoker(invoker);
@@ -72,6 +71,7 @@
         assertEquals("sayHi", m.getName());
         
         assertEquals(invoker, service.getInvoker());
+        
     }
 
     Bus createBus() throws Exception {

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/GreeterTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/GreeterTest.java?view=diff&rev=441062&r1=441061&r2=441062
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/GreeterTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/GreeterTest.java Thu Sep
 7 05:17:19 2006
@@ -64,14 +64,11 @@
 
     public void testEndpoint() throws Exception {
         JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
-        bean.setServiceClass(GreeterImpl.class);
-
         URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
-        assertNotNull(resource);
+        assertNotNull(resource);        
         bean.setWsdlURL(resource);
-
         bean.setBus(bus);
-        
+        bean.setServiceClass(GreeterImpl.class);
         GreeterImpl greeter = new GreeterImpl();
         SimpleMethodInvoker invoker = new SimpleMethodInvoker(greeter);
         bean.setInvoker(invoker);



Mime
View raw message