cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r897327 - in /cxf/branches/2.2.x-fixes: ./ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/ systests/databinding/src/test/java/org/apache/cxf/systest/ae...
Date Fri, 08 Jan 2010 21:33:14 GMT
Author: dkulp
Date: Fri Jan  8 21:33:13 2010
New Revision: 897327

URL: http://svn.apache.org/viewvc?rev=897327&view=rev
Log:
Merged revisions 897324 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r897324 | dkulp | 2010-01-08 16:28:22 -0500 (Fri, 08 Jan 2010) | 2 lines
  
  [CXF-2598] Add support for the minOccurs and nillable annotations on the
  method return/params
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java
    cxf/branches/2.2.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/AegisJaxWs.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java?rev=897327&r1=897326&r2=897327&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
Fri Jan  8 21:33:13 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.aegis.databinding;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.HashMap;
@@ -40,6 +41,7 @@
 import org.apache.cxf.aegis.type.TypeCreationOptions;
 import org.apache.cxf.aegis.type.TypeCreator;
 import org.apache.cxf.aegis.type.TypeMapping;
+import org.apache.cxf.aegis.type.java5.AnnotationReader;
 import org.apache.cxf.aegis.type.mtom.AbstractXOPType;
 import org.apache.cxf.common.WSDLConstants;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
@@ -350,16 +352,34 @@
                 }
             }
             
-            // The concept of type.isNillable is questionable: how are types nillable? 
+            Annotation[] anns = part.getProperty("parameter.annotations", Annotation[].class);
+
+            long miValue = -1;
+            if (type.hasMinOccurs()) {
+                miValue = type.getMinOccurs();
+            }
+            Integer i = AnnotationReader.getMinOccurs(anns);
+            if (i != null) {
+                miValue = i;
+            }
+            if (miValue > 0) {
+                part.setProperty("minOccurs", Long.toString(miValue));
+            }
+
+            
+            // The concept of type.isNillable is questionable: how are types nillable?
             // However, this if at least allow .aegis.xml files to get control.
             if (part.getProperty("nillable") == null) {
-                part.setProperty("nillable", Boolean.valueOf(type.isNillable()));
-            }
-            if (type.hasMinOccurs()) {
-                long miValue = type.getMinOccurs();
-                if (miValue != 0) {
-                    part.setProperty("minOccurs", Long.toString(miValue));
+                boolean isNil = type.isNillable();
+                Boolean b = AnnotationReader.isNillable(anns);
+                if (b != null || (miValue != 0 && isNil)) {
+                    part.setProperty("nillable", b == null ? isNil : b);
                 }
+                /*
+                if (miValue == -1 && (b == null ? isNil : b)) {
+                    part.setProperty("minOccurs", "1");
+                }
+                */
             }
             if (type.hasMaxOccurs()) {
                 String moValue;
@@ -369,6 +389,7 @@
                     part.setProperty("maxOccurs", moValue);
                 }
             }
+            
 
             part2Type.put(part, type);
 

Modified: cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java?rev=897327&r1=897326&r2=897327&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
Fri Jan  8 21:33:13 2010
@@ -78,7 +78,7 @@
 
     // PMD incorrectly identifies this as a string comparison
     @SuppressWarnings("unchecked")
-    public boolean isNillable(AnnotatedElement element) {
+    public Boolean isNillable(AnnotatedElement element) {
         return Boolean.TRUE.equals(getAnnotationValue("nillable", // NOPMD
                 element,
                 Boolean.FALSE,
@@ -86,6 +86,17 @@
                 XFIRE_XML_ELEMENT,
                 XML_ELEMENT));
     }
+    @SuppressWarnings("unchecked")
+    public static Boolean isNillable(Annotation[] anns) {
+        if (anns == null) {
+            return null;
+        }
+        return (Boolean)getAnnotationValue("nillable", // NOPMD
+                anns,
+                XmlElement.class,
+                XFIRE_XML_ELEMENT,
+                XML_ELEMENT);
+    }
 
     @SuppressWarnings("unchecked")
     public Class getType(AnnotatedElement element) {
@@ -252,7 +263,26 @@
 
         return 0;
     }
+    @SuppressWarnings("unchecked")
+    public static Integer getMinOccurs(Annotation[] anns) {
+        if (anns == null) {
+            return null;
+        }
+        String minOccurs = (String) getAnnotationValue("minOccurs",
+                anns,
+                XmlElement.class,
+                XFIRE_XML_ELEMENT);
+        if (minOccurs != null) {
+            return Integer.valueOf(minOccurs);
+        }
 
+        // check jaxb annotation
+        Boolean required = (Boolean) getAnnotationValue("required", anns, XML_ELEMENT);
+        if (Boolean.TRUE.equals(required)) {
+            return 1;
+        }
+        return null;
+    }
     @SuppressWarnings("unchecked")
     public boolean isExtensibleElements(AnnotatedElement element, boolean defaultValue) {
         Boolean extensibleElements = (Boolean) getAnnotationValue("extensibleElements",
@@ -316,8 +346,27 @@
         }
         return null;
     }
+    static Object getAnnotationValue(String name,
+                                     Annotation[] anns,
+                                     Class<? extends Annotation>... annotations) {
+        for (Class<?> annotation : annotations) {
+            if (annotation != null) {
+                try {
+                    for (Annotation ann : anns) {
+                        if (annotation.isInstance(ann)) {
+                            Method method = ann.getClass().getMethod(name);
+                            return method.invoke(ann);
+                        }
+                    }
+                } catch (Exception ignored) {
+                    // annotation did not have value
+                }
+            }
+        }
+        return null;
+    }
 
-    Object getAnnotationValue(String name,
+    static Object getAnnotationValue(String name,
             Method method,
             int index,
             Object ignoredValue,

Modified: cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java?rev=897327&r1=897326&r2=897327&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/XmlElement.java
Fri Jan  8 21:33:13 2010
@@ -26,7 +26,7 @@
 import org.apache.cxf.aegis.type.Type;
 
 @Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
+@Target({ ElementType.METHOD, ElementType.PARAMETER })
 public @interface XmlElement {
     Class type() default Type.class;
 

Modified: cxf/branches/2.2.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/AegisJaxWs.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/AegisJaxWs.java?rev=897327&r1=897326&r2=897327&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/AegisJaxWs.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/AegisJaxWs.java
Fri Jan  8 21:33:13 2010
@@ -43,6 +43,7 @@
     Map<Integer, Item> getItemsMapSpecified();
 
     @WebMethod
+    @org.apache.cxf.aegis.type.java5.XmlElement(nillable = false, minOccurs = "1")
     Item getItemByKey(@WebParam(name = "key1")
                       String key1, @WebParam(name = "key2")
                       String key2);



Mime
View raw message