cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject [1/3] git commit: [CXF-5596]:Schema element generated from exception class doesn't honor @XmlElement annotation
Date Thu, 06 Mar 2014 13:49:06 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.6.x-fixes 1adf37424 -> d611bcfca


[CXF-5596]:Schema element generated from exception class doesn't honor @XmlElement annotation


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/95f6611b
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/95f6611b
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/95f6611b

Branch: refs/heads/2.6.x-fixes
Commit: 95f6611bb036871c68ad4029f0383a9b80ac3397
Parents: 7d946b3
Author: jimma <ema@redhat.com>
Authored: Thu Mar 6 17:55:52 2014 +0800
Committer: Jim Ma <ema@apache.org>
Committed: Thu Mar 6 21:48:37 2014 +0800

----------------------------------------------------------------------
 .../apache/cxf/jaxb/JAXBSchemaInitializer.java  | 27 ++++++++++++++------
 .../org/apache/cxf/frontend/WSDLGetUtils.java   |  3 ++-
 .../processor/JavaToProcessorTest.java          | 17 ++++++------
 3 files changed, 29 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/95f6611b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
index 881807d..f9bbc44 100644
--- a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
@@ -40,6 +40,7 @@ import javax.xml.bind.JAXBContext;
 import javax.xml.bind.annotation.XmlAccessOrder;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorOrder;
+import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlList;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
@@ -552,7 +553,8 @@ class JAXBSchemaInitializer extends ServiceModelVisitor {
             } else {
                 JAXBBeanInfo beanInfo = getBeanInfo(type);
                 if (beanInfo != null) {
-                    addElement(schema, seq, beanInfo, new QName(namespace, f.getName()),
isArray(type));
+                    XmlElement xmlElementAnno = f.getAnnotation(XmlElement.class);
+                    addElement(schema, seq, beanInfo, new QName(namespace, f.getName()),
isArray(type), xmlElementAnno);
                 }
             }
         }
@@ -574,7 +576,8 @@ class JAXBSchemaInitializer extends ServiceModelVisitor {
                     int idx = m.getName().startsWith("get") ? 3 : 2;
                     String name = m.getName().substring(idx);
                     name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
-                    addElement(schema, seq, beanInfo, new QName(namespace, name), isArray(type));
+                    XmlElement  xmlElementAnno =  m.getAnnotation(XmlElement.class);
+                    addElement(schema, seq, beanInfo, new QName(namespace, name), isArray(type),
xmlElementAnno);
                 }
             }
         }
@@ -724,16 +727,20 @@ class JAXBSchemaInitializer extends ServiceModelVisitor {
 
     protected void addElement(XmlSchema schema,
                               XmlSchemaSequence seq, JAXBBeanInfo beanInfo,
-                              QName name, boolean isArray) {
+                              QName name, boolean isArray, XmlElement xmlElementAnno) {
         XmlSchemaElement el = new XmlSchemaElement(schema, false);
-
         if (isArray) {
             el.setMinOccurs(0);
             el.setMaxOccurs(Long.MAX_VALUE);
         } else {
-            el.setMinOccurs(1);
-            el.setMaxOccurs(1);
-            el.setNillable(true);
+            if (xmlElementAnno == null) {
+                el.setMinOccurs(0);
+                el.setNillable(false);
+            } else {
+                el.setNillable(xmlElementAnno.nillable());
+                int minOccurs = xmlElementAnno.required() ? 1 : 0;
+                el.setMinOccurs(minOccurs);
+            }
         }
 
         if (beanInfo.isElement()) {
@@ -743,7 +750,11 @@ class JAXBSchemaInitializer extends ServiceModelVisitor {
             el.setNillable(false);
             el.getRef().setTargetQName(el2.getQName());
         } else {
-            el.setName(name.getLocalPart());
+            if (xmlElementAnno != null && !StringUtils.isEmpty(xmlElementAnno.name()))
{
+                el.setName(xmlElementAnno.name());
+            } else {
+                el.setName(name.getLocalPart());
+            }
             Iterator<QName> itr = beanInfo.getTypeNames().iterator();
             if (!itr.hasNext()) {
                 return;

http://git-wip-us.apache.org/repos/asf/cxf/blob/95f6611b/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java b/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
index ef9f9f6..11fed9b 100644
--- a/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
+++ b/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
@@ -57,6 +57,7 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.catalog.OASISCatalogManager;
 import org.apache.cxf.catalog.OASISCatalogManagerHelper;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.util.UrlUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
@@ -68,7 +69,7 @@ import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.wsdl.WSDLManager;
 import org.apache.cxf.wsdl11.ResourceManagerWSDLLocator;
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
-import org.springframework.util.StringUtils;
+
 
 /**
  * 

http://git-wip-us.apache.org/repos/asf/cxf/blob/95f6611b/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
----------------------------------------------------------------------
diff --git a/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
index d85697b..1359ba7 100644
--- a/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
+++ b/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
@@ -719,9 +719,9 @@ public class JavaToProcessorTest extends ProcessorTestBase {
         File wsdlFile = new File(output, "exception_prop_order.wsdl");
         assertTrue(wsdlFile.exists());
         String wsdlContent = getStringFromFile(wsdlFile).replaceAll("  ", " ");
-        int summaryIndex = wsdlContent.indexOf("<xs:element name=\"summary\"");
-        int fromIndex = wsdlContent.indexOf("<xs:element name=\"from\"");
-        int idIndex = wsdlContent.indexOf("<xs:element name=\"id\"");
+        int summaryIndex = wsdlContent.indexOf("name=\"summary\"");
+        int fromIndex = wsdlContent.indexOf("name=\"from\"");
+        int idIndex = wsdlContent.indexOf("name=\"id\"");
         
         assertTrue(summaryIndex > -1);
         assertTrue(fromIndex > -1);
@@ -744,9 +744,9 @@ public class JavaToProcessorTest extends ProcessorTestBase {
         assertTrue(wsdlFile.exists());
         String wsdlContent = getStringFromFile(wsdlFile).replaceAll("  ", " ");
 
-        int fromIndex = wsdlContent.indexOf("<xs:element name=\"from\"");
-        int idIndex = wsdlContent.indexOf("<xs:element name=\"id\"");
-        int summaryIndex = wsdlContent.indexOf("<xs:element name=\"summary\"");
+        int fromIndex = wsdlContent.indexOf("name=\"from\"");
+        int idIndex = wsdlContent.indexOf("name=\"id\"");
+        int summaryIndex = wsdlContent.indexOf("name=\"summary\"");
         
         
         assertTrue(fromIndex > -1);
@@ -793,7 +793,7 @@ public class JavaToProcessorTest extends ProcessorTestBase {
         File wsdlFile = new File(output, "exception-ref-nillable.wsdl");
         assertTrue(wsdlFile.exists());
         String wsdlContent = getStringFromFile(wsdlFile).replaceAll("  ", " ");
-        int refElement = wsdlContent.indexOf("<xs:element ref=\"tns:item\"/>");
+        int refElement = wsdlContent.indexOf("ref=\"tns:item\"/>");
         assertTrue(refElement > -1);
 
     }
@@ -815,9 +815,8 @@ public class JavaToProcessorTest extends ProcessorTestBase {
         String wsdlContent = getStringFromFile(wsdlFile).replaceAll("  ", " ");
         int class2Element = wsdlContent.indexOf("<xs:complexType name=\"myClass2\">");
         assertTrue(class2Element > -1);
-        int refElement = wsdlContent.indexOf("<xs:element name=\"adapted\" nillable=\"true\"
type=\"tns:myClass2\"/>");
+        int refElement = wsdlContent.indexOf("<xs:element minOccurs=\"0\" name=\"adapted\"
type=\"tns:myClass2\"/>");
         assertTrue(refElement > -1);
-
     }
     
     


Mime
View raw message