cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r592656 - in /incubator/cxf/trunk/tools: common/src/main/java/org/apache/cxf/tools/common/model/ common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/ javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/ java...
Date Wed, 07 Nov 2007 08:53:06 GMT
Author: ema
Date: Wed Nov  7 00:53:04 2007
New Revision: 592656

URL: http://svn.apache.org/viewvc?rev=592656&view=rev
Log:
[CXF-1179]Annotate wrapperbean with JAXB annotation when SEI contains these annotations

Modified:
    incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaField.java
    incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/annotator/WrapperBeanFieldAnnotator.java
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapper.java
    incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/WrapperUtil.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGeneratorTest.java
    incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/annotator/WrapperBeanFieldAnnotatorTest.java

Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaField.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaField.java?rev=592656&r1=592655&r2=592656&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaField.java
(original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/model/JavaField.java
Wed Nov  7 00:53:04 2007
@@ -19,11 +19,16 @@
 
 package org.apache.cxf.tools.common.model;
 
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.cxf.tools.util.URIParserUtil;
 
 public class JavaField extends JavaType implements JavaAnnotatable {
     private String modifier;
-    private JAnnotation annotation;
+    private List<JAnnotation> annotations = new ArrayList<JAnnotation>();
+    private Annotation[] jaxbAnnotations;
 
     public JavaField() {
     }
@@ -41,15 +46,15 @@
         this.modifier = modi;
     }
 
-    public void setAnnotation(JAnnotation anno) {
-        this.annotation = anno;
-        for (String importClz : annotation.getImports()) {
+    public void addAnnotation(JAnnotation anno) {
+        annotations.add(anno);
+        for (String importClz : anno.getImports()) {
             getOwner().addImport(importClz);
         }        
     }
 
-    public JAnnotation getAnnotation() {
-        return this.annotation;
+    public List<JAnnotation> getAnnotations() {
+        return this.annotations;
     }
 
     public void annotate(Annotator annotator) {
@@ -61,6 +66,17 @@
             return "_" + this.name;
         }
         return this.name;
+    }
+    
+    public void setJaxbAnnotations(Annotation[] anns) {
+        jaxbAnnotations = anns;
+    }
+    
+    public Annotation[] getJaxbAnnotaions() {
+        if (jaxbAnnotations == null) {
+            return new Annotation[]{};
+        } 
+        return jaxbAnnotations;
     }
     
 }

Modified: incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java?rev=592656&r1=592655&r2=592656&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
(original)
+++ incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
Wed Nov  7 00:53:04 2007
@@ -239,12 +239,7 @@
                     strbuffer.append(lineSeparator);
                     originalStrs[j + 1] = "";
                 }
-                
-                // strbuffer.append(orginalStrs[j + 1]);
-                // strbuffer.append(lineSeparator);
-                // strbuffer.append(lineSeparator);
             } else {
-                // addWhiteNamespace(strbuffer, beforeOptSpan);
                 strbuffer.append(originalStrs[j]);
                 strbuffer.append(lineSeparator);
             }

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/annotator/WrapperBeanFieldAnnotator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/annotator/WrapperBeanFieldAnnotator.java?rev=592656&r1=592655&r2=592656&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/annotator/WrapperBeanFieldAnnotator.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/annotator/WrapperBeanFieldAnnotator.java
Wed Nov  7 00:53:04 2007
@@ -19,7 +19,13 @@
 
 package org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator;
 
+import java.lang.annotation.Annotation;
+
+import javax.xml.bind.annotation.XmlAttachmentRef;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlList;
+import javax.xml.bind.annotation.XmlMimeType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.tools.common.model.Annotator;
@@ -45,6 +51,25 @@
                                                                           jField.getTargetNamespace()));
         }
 
-        jField.setAnnotation(xmlElementAnnotation);
+        jField.addAnnotation(xmlElementAnnotation);
+        
+        for (Annotation ann : jField.getJaxbAnnotaions()) {
+            if (ann instanceof XmlMimeType) {
+                JAnnotation mimeAnno = new JAnnotation(XmlMimeType.class);
+                mimeAnno.addElement(new JAnnotationElement("value", ((XmlMimeType)ann).value()));
+                jField.addAnnotation(mimeAnno);
+            } else if (ann instanceof XmlJavaTypeAdapter) {           
+                JAnnotation jaxbAnn = new JAnnotation(XmlJavaTypeAdapter.class);
+                jaxbAnn.addElement(new JAnnotationElement("value", ((XmlJavaTypeAdapter)ann).value()));
+                jaxbAnn.addElement(new JAnnotationElement("type", ((XmlJavaTypeAdapter)ann).type()));
+                jField.addAnnotation(jaxbAnn);
+            } else if (ann instanceof XmlAttachmentRef) {
+                JAnnotation jaxbAnn = new JAnnotation(XmlJavaTypeAdapter.class);
+                jField.addAnnotation(jaxbAnn);
+            } else if (ann instanceof XmlList) {
+                JAnnotation jaxbAnn = new JAnnotation(XmlList.class);
+                jField.addAnnotation(jaxbAnn);
+            }
+        }
     }
 }

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm?rev=592656&r1=592655&r2=592656&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/wrapperbean.vm
Wed Nov  7 00:53:04 2007
@@ -35,8 +35,8 @@
 public class $bean.Name {
 
 #foreach ($field in $bean.Fields)
-#if($field.Annotation)
-$field.Annotation
+#foreach($anno in $field.Annotations)
+$anno
 #end
     private $field.Type $field.Name;
 #end

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java?rev=592656&r1=592655&r2=592656&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/RequestWrapper.java
Wed Nov  7 00:53:04 2007
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.tools.java2wsdl.processor.internal.jaxws;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
@@ -43,7 +44,7 @@
         javax.xml.ws.RequestWrapper reqWrapper = method.getAnnotation(javax.xml.ws.RequestWrapper.class);
         return getClassName() == null && (reqWrapper == null || StringUtils.isEmpty(reqWrapper.className()));
     }
-    
+
     public String getWrapperTns(Method method) {
         javax.xml.ws.RequestWrapper reqWrapper = method.getAnnotation(javax.xml.ws.RequestWrapper.class);
         if (reqWrapper != null) {
@@ -56,7 +57,7 @@
     protected List<JavaField> buildFields() {
         return buildFields(getMethod(), getOperationInfo().getUnwrappedOperation().getInput());
     }
-    
+
     protected List<JavaField> buildFields(final Method method, final MessageInfo message)
{
         List<JavaField> fields = new ArrayList<JavaField>();
         String name;
@@ -77,9 +78,10 @@
                 type = clz.getName();
             }
             JavaField field = new JavaField(name, type, "");
-            field.setTargetNamespace("");
+            field.setTargetNamespace("");           
+            List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method, idx);
+            field.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
             fields.add(field);
-            
         }
 
         return fields;
@@ -90,11 +92,11 @@
         javax.xml.ws.RequestWrapper reqWrapper = method.getAnnotation(javax.xml.ws.RequestWrapper.class);
         String reqClassName = getClassName();
         String reqNs = null;
-        
+
         if (reqWrapper != null) {
             reqClassName = reqWrapper.className().length() > 0 ? reqWrapper.className()
: reqClassName;
             reqNs = reqWrapper.targetNamespace().length() > 0 ? reqWrapper.targetNamespace()
: null;
-        } 
+        }
         if (reqClassName == null) {
             reqClassName = getPackageName(method) + ".jaxws." + StringUtils.capitalize(method.getName());
         }
@@ -104,4 +106,5 @@
         jClass.setNamespace(reqNs);
         return jClass;
     }
+
 }

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapper.java?rev=592656&r1=592655&r2=592656&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapper.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/ResponseWrapper.java
Wed Nov  7 00:53:04 2007
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.tools.java2wsdl.processor.internal.jaxws;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
@@ -31,6 +32,7 @@
 import org.apache.cxf.tools.common.model.JavaField;
 import org.apache.cxf.tools.java2wsdl.generator.wsdl11.model.WrapperBeanClass;
 
+
 public final class ResponseWrapper extends Wrapper { 
     @Override
     public void setOperationInfo(final OperationInfo op) {
@@ -81,7 +83,9 @@
             } else {
                 type = returnType.getName();
             }
+            List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method);
             field.setType(type);
+            field.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
             field.setTargetNamespace("");
             
         }
@@ -103,6 +107,9 @@
                 } else {
                     type = clz.getName();
                 }
+                JavaField jf = new JavaField(name, type, "");
+                List<Annotation> jaxbAnns = WrapperUtil.getJaxbAnnotations(method,
idx - 1);
+                jf.setJaxbAnnotations(jaxbAnns.toArray(new Annotation[jaxbAnns.size()]));
                 fields.add(new JavaField(name, type, ""));
                
             }
@@ -132,4 +139,8 @@
         jClass.setNamespace(resNs);
         return jClass;
     }
+    
+    
+
+    
 }

Modified: incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/WrapperUtil.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/WrapperUtil.java?rev=592656&r1=592655&r2=592656&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/WrapperUtil.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/jaxws/WrapperUtil.java
Wed Nov  7 00:53:04 2007
@@ -19,12 +19,19 @@
 
 package org.apache.cxf.tools.java2wsdl.processor.internal.jaxws;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.jws.Oneway;
+import javax.xml.bind.annotation.XmlAttachmentRef;
+import javax.xml.bind.annotation.XmlList;
+import javax.xml.bind.annotation.XmlMimeType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
 public final class WrapperUtil {
-    
+
     private WrapperUtil() {
     }
 
@@ -43,5 +50,44 @@
             return false;
         }
         return true;
+    }
+
+    public static List<Annotation> getJaxbAnnotations(Method method) {
+        List<Annotation> jaxbAnnotation = new ArrayList<Annotation>();
+        Annotation ann = method.getAnnotation(XmlAttachmentRef.class);
+        if (ann != null) {
+            jaxbAnnotation.add(ann);
+        }
+        ann = method.getAnnotation(XmlMimeType.class);
+        if (ann != null) {
+            jaxbAnnotation.add(ann);
+        }
+        ann = method.getAnnotation(XmlJavaTypeAdapter.class);
+        if (ann != null) {
+            jaxbAnnotation.add(ann);
+        }
+        ann = method.getAnnotation(XmlList.class);
+        if (ann != null) {
+            jaxbAnnotation.add(ann);
+        }
+        return jaxbAnnotation;
+    }
+
+    public static List<Annotation> getJaxbAnnotations(Method method, int idx) {
+        List<Annotation> jaxbAnnotation = new ArrayList<Annotation>();
+        Annotation[][] anns = method.getParameterAnnotations();
+        for (int i = 0; i < method.getParameterTypes().length; i++) {            
+            if (i == idx) {
+                for (Annotation ann : anns[i]) {
+                    if (ann.annotationType() == XmlAttachmentRef.class
+                        || ann.annotationType() == XmlMimeType.class
+                        || ann.annotationType() == XmlJavaTypeAdapter.class
+                        || ann.annotationType() == XmlList.class) {
+                        jaxbAnnotation.add(ann);
+                    }                   
+                }
+            }
+        }
+        return jaxbAnnotation;
     }
 }

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGeneratorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGeneratorTest.java?rev=592656&r1=592655&r2=592656&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGeneratorTest.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/WrapperBeanGeneratorTest.java
Wed Nov  7 00:53:04 2007
@@ -21,12 +21,16 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.lang.reflect.Field;
+
+import javax.xml.bind.annotation.XmlList;
 
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.tools.common.ProcessorTestBase;
 import org.apache.cxf.tools.common.ToolConstants;
 import org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor;
+import org.apache.cxf.tools.util.AnnotationUtil;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -34,13 +38,17 @@
 public class WrapperBeanGeneratorTest extends ProcessorTestBase {
     JavaToWSDLProcessor processor = new JavaToWSDLProcessor();
     String classPath = "";
+    ClassLoader classLoader;
 
     @Before
     public void setUp() throws Exception {
-        super.setUp();
+        super.setUp();        
         classPath = System.getProperty("java.class.path");
-        System.setProperty("java.class.path", getClassPath());
+        String pathSeperoatr = System.getProperty("path.separator");
+        System.setProperty("java.class.path", getClassPath() + pathSeperoatr + output.getPath());
+        classLoader = AnnotationUtil.getClassLoader(Thread.currentThread().getContextClassLoader());
         processor.setEnvironment(env);
+        
     }
 
     @After
@@ -111,4 +119,20 @@
         contents = IOUtils.toString(new FileInputStream(requestWrapperClass));
         assertTrue(contents.indexOf("org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean[]")
!= -1);
     }
+    
+    @Test
+    public void testGenJaxbAnno() throws Exception {
+        String testingClass = "org.apache.cxf.tools.fortest.withannotation.doc.SayHiNoWrapperBean";
+        env.put(ToolConstants.CFG_CLASSNAME, testingClass);
+        
+        WrapperBeanGenerator generator = new WrapperBeanGenerator();
+        generator.setServiceModel(getServiceInfo());
+        
+        generator.generate(output);
+        Class clz = classLoader.loadClass("org.apache.cxf.SayHi");
+        assertNotNull(clz);
+        Field field = clz.getDeclaredField("arg0");
+        assertNotNull(field.getAnnotation(XmlList.class));
+    }
+    
 }

Modified: incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/annotator/WrapperBeanFieldAnnotatorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/annotator/WrapperBeanFieldAnnotatorTest.java?rev=592656&r1=592655&r2=592656&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/annotator/WrapperBeanFieldAnnotatorTest.java
(original)
+++ incubator/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/generator/wsdl11/annotator/WrapperBeanFieldAnnotatorTest.java
Wed Nov  7 00:53:04 2007
@@ -20,6 +20,8 @@
 package org.apache.cxf.tools.java2wsdl.generator.wsdl11.annotator;
 
 
+import java.util.List;
+
 import org.apache.cxf.tools.common.model.JAnnotation;
 import org.apache.cxf.tools.common.model.JavaClass;
 import org.apache.cxf.tools.common.model.JavaField;
@@ -38,15 +40,15 @@
                                            "http://doc.withannotation.fortest.tools.cxf.apache.org/");
 
         reqField.setOwner(clz);
-        JAnnotation annotation = reqField.getAnnotation();
-        assertNull(annotation);
+        List<JAnnotation> annotation = reqField.getAnnotations();
+        assertEquals(0, annotation.size());
         
         reqField.annotate(new WrapperBeanFieldAnnotator());
-        annotation = reqField.getAnnotation();
+        annotation = reqField.getAnnotations();
 
         String expectedNamespace = "http://doc.withannotation.fortest.tools.cxf.apache.org/";
         assertEquals("@XmlElement(name = \"array\", namespace = \"" + expectedNamespace +
"\")",
-                     annotation.toString());
+                     annotation.get(0).toString());
 
         clz.setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHiResponse");
         JavaField resField = new JavaField("return",
@@ -54,8 +56,8 @@
                                            "http://doc.withannotation.fortest.tools.cxf.apache.org/");
         resField.setOwner(clz);
         resField.annotate(new WrapperBeanFieldAnnotator());
-        annotation = resField.getAnnotation();
+        annotation = resField.getAnnotations();
         assertEquals("@XmlElement(name = \"return\", namespace = \"" + expectedNamespace
+ "\")",
-                     annotation.toString());
+                     annotation.get(0).toString());
     }
 }



Mime
View raw message