cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r537244 - /incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java
Date Fri, 11 May 2007 17:44:07 GMT
Author: dkulp
Date: Fri May 11 10:44:06 2007
New Revision: 537244

URL: http://svn.apache.org/viewvc?view=rev&rev=537244
Log:
Minor wrapper getter optization

Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java?view=diff&rev=537244&r1=537243&r2=537244
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java
Fri May 11 10:44:06 2007
@@ -174,40 +174,55 @@
     public static Object getWrappedPart(String partName, Object wrapperType, String elementType)
         throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
 
-        String fieldName = partName;
-        if (JAXBUtils.isJavaKeyword(partName)) {
-            fieldName = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.VARIABLE);
+        String accessor = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.GETTER);
+        Method method = null;
+        NoSuchMethodException nsex = null;
+        try {
+            method = wrapperType.getClass().getMethod(accessor, new Class[0]); 
+        } catch (NoSuchMethodException ex) {
+            //ignore for now
+            nsex = (NoSuchMethodException)ex.fillInStackTrace();
         }
 
         Field elField = null;
-        for (Field field : wrapperType.getClass().getDeclaredFields()) {
-            if (field.getName().equals(fieldName)) {
-                elField = field;
-                break;
+        if (method == null
+            && elementType != null
+            && "boolean".equals(elementType.toLowerCase())) {
+            
+            elField = getElField(partName, wrapperType);
+                
+            if (!Collection.class.isAssignableFrom(elField.getType())
+                && !elField.getType().isArray()) {
+    
+                try {
+                    method = wrapperType.getClass().getMethod(accessor.replaceFirst("get",
"is"),
+                                                              new Class[0]); 
+                } catch (NoSuchMethodException ex) {
+                    //ignore for now
+                }            
             }
-        }        
-        
-        String accessor = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.GETTER);
-        String accessor2 = accessor;
-        if ("return".equals(partName)) {
-            accessor2 = "get_return";
         }
-
-        if (elementType != null 
-            && "boolean".equals(elementType.toLowerCase())
-            && !Collection.class.isAssignableFrom(elField.getType())) {
-            // JAXB Exception to get the Boolean property
-            accessor = accessor.replaceFirst("get", "is");
-            accessor2 = accessor2.replaceFirst("get", "is");
-        }
-
-        Method method = wrapperType.getClass().getMethod(accessor, new Class[0]);
-        if (method == null) {
-            method = wrapperType.getClass().getMethod(accessor2, new Class[0]);
+        if (method == null 
+            && "return".equals(partName)) {
+            //RI generated code uses this
+            try {
+                method = wrapperType.getClass().getMethod("get_return", new Class[0]);
+            } catch (NoSuchMethodException ex) {
+                try {
+                    method = wrapperType.getClass().getMethod("is_return",
+                                                              new Class[0]);
+                } catch (NoSuchMethodException ex2) {
+                    //ignore for now
+                } 
+            }                
         }
+        
         if (method != null) {
             return getValue(method, wrapperType);
         }
+        if (elField == null) {
+            elField = getElField(partName, wrapperType);
+        }
         if (elField != null) {
             // JAXB Type get XmlElement Annotation
             XmlElement el = elField.getAnnotation(XmlElement.class);
@@ -216,11 +231,28 @@
                 elField.setAccessible(true);
                 return elField.get(wrapperType);
             }
+        } else if (nsex != null) {
+            throw nsex;
         }
         
         return null;
     }
 
+    private static Field getElField(String partName, Object wrapperType) {
+        String fieldName = partName;
+        Field elField = null;
+        if (JAXBUtils.isJavaKeyword(partName)) {
+            fieldName = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.VARIABLE);
+        }
+        for (Field field : wrapperType.getClass().getDeclaredFields()) {
+            if (field.getName().equals(fieldName)) {
+                elField = field;
+                break;
+            }
+        }        
+        return elField;
+    }
+    
     public static Object getWrappedPart(String partName, Object wrapperType) throws IllegalAccessException,
         NoSuchMethodException, InvocationTargetException {
         String accessor = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.GETTER);



Mime
View raw message