cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r546036 - in /incubator/cxf/trunk/rt: databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ databinding/jaxb/src/test/java/org/apache/cxf/jaxb/ frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ frontend/jaxws/src/test/java/org/apache/cxf/jax...
Date Mon, 11 Jun 2007 07:46:35 GMT
Author: ffang
Date: Mon Jun 11 00:46:34 2007
New Revision: 546036

URL: http://svn.apache.org/viewvc?view=rev&rev=546036
Log:
[CXF-340] Support adding extra classes to JAXB context

Modified:
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientFactoryBean.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsServerFactoryBeanTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBeanTest.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientFactoryBean.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
    incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ClientFactoryBeanTest.java
    incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ServerFactoryTest.java

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=546036&r1=546035&r2=546036
==============================================================================
--- 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
Mon Jun 11 00:46:34 2007
@@ -95,10 +95,11 @@
                                                                                XMLEventWriter.class,
                                                                                XMLStreamWriter.class};
 
-    
+    Class[] extraClass;
     JAXBContext context;
 
     Class cls;
+    
 
     public JAXBDataBinding() {
     }
@@ -327,6 +328,14 @@
             schemaInit.walk();
         }
     }
+    
+    public void setExtraClass(Class[] userExtraClass) {
+        extraClass = userExtraClass;
+    }
+    
+    public Class[] getExtraClass() {
+        return extraClass;
+    }
 
     private List<DOMResult> generateJaxbSchemas() throws IOException {
         final List<DOMResult> results = new ArrayList<DOMResult>();
@@ -349,11 +358,11 @@
     }
     
 
-    public static JAXBContext createJAXBContext(Set<Class<?>> classes) throws
JAXBException {
+    public JAXBContext createJAXBContext(Set<Class<?>> classes) throws JAXBException
{
         return createJAXBContext(classes, null);
     }
     
-    public static JAXBContext createJAXBContext(Set<Class<?>> classes,
+    public JAXBContext createJAXBContext(Set<Class<?>> classes,
                                                    String defaultNs) throws JAXBException
{
         Iterator it = classes.iterator();
         String className = "";
@@ -366,8 +375,8 @@
             }
         }
 
-        for (Class<?> cls : classes) {
-            if (cls.getName().endsWith("ObjectFactory")) {
+        for (Class<?> clz : classes) {
+            if (clz.getName().endsWith("ObjectFactory")) {
                 //kind of a hack, but ObjectFactories may be created with empty namespaces
                 defaultNs = null;
             }
@@ -382,7 +391,17 @@
             // maybe add a way to allow interceptors to add stuff to the
             // context?
         }
-       
+        try {
+            // add user extra class into jaxb context
+            if (extraClass != null && extraClass.length > 0) {
+                for (Class clz : extraClass) {
+                    classes.add(clz);
+                }
+            }
+        } catch (Exception e) {
+           //
+        }
+        
         Map<String, Object> map = new HashMap<String, Object>();
         if (defaultNs != null) {
             map.put("com.sun.xml.bind.defaultNamespaceRemap", defaultNs);

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java?view=diff&rev=546036&r1=546035&r2=546036
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
Mon Jun 11 00:46:34 2007
@@ -136,7 +136,7 @@
         try {
             Set<Class<?>> classes = new HashSet<Class<?>>();
             classes.add(Class.forName("java.rmi.RemoteException"));
-            assertNotNull(JAXBDataBinding.createJAXBContext(classes));
+            assertNotNull(new JAXBDataBinding().createJAXBContext(classes));
         } catch (Exception e) {
             assertFalse(true);
         }
@@ -184,6 +184,14 @@
         
         writer = jaxbDataBinding.createWriter(null);
         assertNull(writer);
+    }
+    
+    public void testExtraClass() {
+        Class[] extraClass = new Class[] {java.rmi.Remote.class, java.rmi.RemoteException.class};
+        jaxbDataBinding.setExtraClass(extraClass);
+        assertEquals(jaxbDataBinding.getExtraClass().length, 2);
+        assertEquals(jaxbDataBinding.getExtraClass()[0], java.rmi.Remote.class);
+        assertEquals(jaxbDataBinding.getExtraClass()[1], java.rmi.RemoteException.class);
     }
     
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientFactoryBean.java?view=diff&rev=546036&r1=546035&r2=546036
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientFactoryBean.java
Mon Jun 11 00:46:34 2007
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.jaxws;
 
+
+
 import org.apache.cxf.frontend.ClientFactoryBean;
 import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
 

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java?view=diff&rev=546036&r1=546035&r2=546036
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
Mon Jun 11 00:46:34 2007
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxws;
 
+
 import javax.xml.soap.SOAPMessage;
 import javax.xml.ws.soap.SOAPBinding;
 
@@ -48,8 +49,10 @@
     }
     public JaxWsServerFactoryBean(JaxWsServiceFactoryBean serviceFactory) {
         setServiceFactory(serviceFactory);
+        
         JaxWsSoapBindingConfiguration defConfig 
             = new JaxWsSoapBindingConfiguration(serviceFactory);
+        
         setBindingConfig(defConfig);
     }
 

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsServerFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsServerFactoryBeanTest.java?view=diff&rev=546036&r1=546035&r2=546036
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsServerFactoryBeanTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JaxWsServerFactoryBeanTest.java
Mon Jun 11 00:46:34 2007
@@ -32,6 +32,7 @@
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.frontend.ServerFactoryBean;
 import org.apache.cxf.helpers.XPathUtils;
+import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.jaxws.service.Hello;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.wsdl.WSDLManager;
@@ -51,6 +52,29 @@
         
         Server server = sf.create();
         assertNotNull(server);
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testJaxbExtraClass() {
+        JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
+        sf.setBus(getBus());
+        sf.setAddress("http://localhost:9000/test");
+        sf.setServiceClass(Hello.class);
+        sf.setStart(false);
+        Map props = sf.getProperties();
+        if (props == null) {
+            props = new HashMap<String, Object>();
+        }
+        props.put("jaxb.additionalContextClasses", 
+                  new Class[] {java.rmi.Remote.class, java.rmi.RemoteException.class});
+        sf.setProperties(props);
+        Server server = sf.create();
+        assertNotNull(server);
+        Class[] extraClass = ((JAXBDataBinding)sf.getServiceFactory().getDataBinding()).getExtraClass();
+        assertEquals(extraClass.length, 2);
+        assertEquals(extraClass[0], java.rmi.Remote.class);
+        assertEquals(extraClass[1], java.rmi.RemoteException.class);
     }
     
     @Test

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=546036&r1=546035&r2=546036
==============================================================================
--- 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
Mon Jun 11 00:46:34 2007
@@ -237,5 +237,7 @@
     }
     
     
+    
+    
 
 }

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientFactoryBean.java?view=diff&rev=546036&r1=546035&r2=546036
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientFactoryBean.java
Mon Jun 11 00:46:34 2007
@@ -18,12 +18,16 @@
  */
 package org.apache.cxf.frontend;
 
+import java.util.Map;
+
 import org.apache.cxf.BusException;
+import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.ClientImpl;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
 import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
 import org.apache.cxf.service.factory.ServiceConstructionException;
 
@@ -33,6 +37,7 @@
     public ClientFactoryBean() {
         super();
         setServiceFactory(new ReflectionServiceFactoryBean());
+        
     }
 
     public Client create() {
@@ -51,7 +56,7 @@
         }
         
         applyFeatures();
-        
+        applyExtraClass();
         return client;
     }
 
@@ -63,6 +68,17 @@
         if (getFeatures() != null) {
             for (AbstractFeature feature : getFeatures()) {
                 feature.initialize(client, getBus());
+            }
+        }
+    }
+    
+    protected void applyExtraClass() {
+        DataBinding dataBinding = getServiceFactory().getDataBinding();
+        if (dataBinding instanceof JAXBDataBinding) {
+            Map props = this.getProperties();
+            if (props != null && props.get("jaxb.additionalContextClasses") != null)
{
+                Class[] extraClass = (Class[])this.getProperties().get("jaxb.additionalContextClasses");
+                ((JAXBDataBinding)dataBinding).setExtraClass(extraClass);
             }
         }
     }

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java?view=diff&rev=546036&r1=546035&r2=546036
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java
Mon Jun 11 00:46:34 2007
@@ -19,13 +19,16 @@
 package org.apache.cxf.frontend;
 
 import java.io.IOException;
+import java.util.Map;
 
 import org.apache.cxf.BusException;
+import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.endpoint.ServerImpl;
 import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
 import org.apache.cxf.service.factory.ServiceConstructionException;
 import org.apache.cxf.service.invoker.BeanInvoker;
@@ -69,6 +72,7 @@
     public ServerFactoryBean() {
         super();
         setServiceFactory(new ReflectionServiceFactoryBean());
+        
     }
     
     public String getBeanName() {
@@ -103,7 +107,7 @@
         }
         
         applyFeatures();
-        
+        applyExtraClass();
         return server;
     }
 
@@ -115,6 +119,17 @@
         }
     }
 
+    protected void applyExtraClass() {
+        DataBinding dataBinding = getServiceFactory().getDataBinding();
+        if (dataBinding instanceof JAXBDataBinding) {
+            Map props = this.getProperties();
+            if (props != null && props.get("jaxb.additionalContextClasses") != null)
{
+                Class[] extraClass = (Class[])this.getProperties().get("jaxb.additionalContextClasses");
+                ((JAXBDataBinding)dataBinding).setExtraClass(extraClass);
+            }
+        }
+    }
+    
     protected Invoker createInvoker() {
         return new BeanInvoker(serviceBean);
     }

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?view=diff&rev=546036&r1=546035&r2=546036
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
Mon Jun 11 00:46:34 2007
@@ -114,9 +114,11 @@
     private Map<String, Object> properties;
     private QName endpointName;
     private boolean populateFromClass;
+    
 
     public ReflectionServiceFactoryBean() {
         getServiceConfigurations().add(0, new DefaultServiceConfiguration());
+        
         setDataBinding(new JAXBDataBinding());
 
         ignoredClasses.add("java.lang.Object");

Modified: incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ClientFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ClientFactoryBeanTest.java?view=diff&rev=546036&r1=546035&r2=546036
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ClientFactoryBeanTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ClientFactoryBeanTest.java
Mon Jun 11 00:46:34 2007
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.service.factory;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import javax.wsdl.extensions.soap.SOAPAddress;
@@ -28,6 +29,7 @@
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.frontend.ClientFactoryBean;
+import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.BindingInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
@@ -72,5 +74,28 @@
         assertNotNull(sop);
         assertEquals("", sop.getAction());
         assertEquals("document", sop.getStyle());
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testJaxbExtraClass() throws Exception {
+        
+        ClientFactoryBean cfBean = new ClientFactoryBean();
+        cfBean.setAddress("http://localhost/Hello");
+        cfBean.setBus(getBus());
+        cfBean.setServiceClass(HelloService.class);
+        Map props = cfBean.getProperties();
+        if (props == null) {
+            props = new HashMap<String, Object>();
+        }
+        props.put("jaxb.additionalContextClasses", 
+                  new Class[] {java.rmi.Remote.class, java.rmi.RemoteException.class});
+        cfBean.setProperties(props);
+        Client client = cfBean.create();
+        assertNotNull(client);
+        Class[] extraClass = ((JAXBDataBinding)cfBean.getServiceFactory().getDataBinding()).getExtraClass();
+        assertEquals(extraClass.length, 2);
+        assertEquals(extraClass[0], java.rmi.Remote.class);
+        assertEquals(extraClass[1], java.rmi.RemoteException.class);
     }
 }

Modified: incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ServerFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ServerFactoryTest.java?view=diff&rev=546036&r1=546035&r2=546036
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ServerFactoryTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ServerFactoryTest.java
Mon Jun 11 00:46:34 2007
@@ -20,10 +20,13 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.cxf.endpoint.ServerImpl;
 import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.AbstractTransportFactory;
@@ -46,6 +49,28 @@
 
         ServerImpl server = (ServerImpl)svrBean.create();
         assertTrue(server.getDestination() instanceof CustomDestination);
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testJaxbExtraClass() throws Exception {
+        ServerFactoryBean svrBean = new ServerFactoryBean();
+        svrBean.setAddress("http://localhost/Hello");
+        svrBean.setServiceClass(HelloService.class);
+        svrBean.setBus(getBus());
+
+        Map props = svrBean.getProperties();
+        if (props == null) {
+            props = new HashMap<String, Object>();
+        }
+        props.put("jaxb.additionalContextClasses", 
+                  new Class[] {java.rmi.Remote.class, java.rmi.RemoteException.class});
+        svrBean.setProperties(props);
+        svrBean.create();
+        Class[] extraClass = ((JAXBDataBinding)svrBean.getServiceFactory().getDataBinding()).getExtraClass();
+        assertEquals(extraClass.length, 2);
+        assertEquals(extraClass[0], java.rmi.Remote.class);
+        assertEquals(extraClass[1], java.rmi.RemoteException.class);
     }
 
     public class CustomDestinationFactory extends AbstractTransportFactory implements DestinationFactory
{



Mime
View raw message