cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject [2/2] git commit: [CXF-5596]:Schema element generated from exception class doesn't honor @XmlElement annotation
Date Thu, 06 Mar 2014 09:57:49 GMT
[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/21205201
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/21205201
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/21205201

Branch: refs/heads/master
Commit: 212052017423ccf95a0f0780b9059653ef232698
Parents: 37e455e
Author: jimma <ema@redhat.com>
Authored: Thu Mar 6 17:55:52 2014 +0800
Committer: jimma <ema@redhat.com>
Committed: Thu Mar 6 17:56:35 2014 +0800

----------------------------------------------------------------------
 .../apache/cxf/jaxb/JAXBSchemaInitializer.java  | 27 ++++++++++++++------
 .../processor/JavaToProcessorTest.java          |  3 ++-
 2 files changed, 21 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/21205201/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 d64e096..f48cc06 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);
                 }
             }
         }
@@ -723,16 +726,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()) {
@@ -742,7 +749,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/21205201/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 89a4ede..54d8997 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
@@ -35,6 +35,7 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
+
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.XPathUtils;
@@ -907,7 +908,7 @@ public class JavaToProcessorTest extends ProcessorTestBase {
         
         String at = ((Element)nd).getAttribute("type");
         assertTrue(at.contains("myClass2"));
-        assertEquals("true", ((Element)nd).getAttribute("nillable"));
+        assertEquals("0", ((Element)nd).getAttribute("minOccurs"));
     }
     
     


Mime
View raw message