axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r357625 - in /webservices/axis/trunk/java/src/org/apache/axis: encoding/ser/BeanDeserializer.java utils/StringUtils.java
Date Mon, 19 Dec 2005 04:10:16 GMT
Author: dims
Date: Sun Dec 18 20:10:11 2005
New Revision: 357625

URL: http://svn.apache.org/viewcvs?rev=357625&view=rev
Log:
Fix for http://issues.apache.org/jira/browse/AXIS-2346 (Issue with the way the localNames
are created in WSDL2Java)


Modified:
    webservices/axis/trunk/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java
    webservices/axis/trunk/java/src/org/apache/axis/utils/StringUtils.java

Modified: webservices/axis/trunk/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java?rev=357625&r1=357624&r2=357625&view=diff
==============================================================================
--- webservices/axis/trunk/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java (original)
+++ webservices/axis/trunk/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java Sun
Dec 18 20:10:11 2005
@@ -32,6 +32,7 @@
 import org.apache.axis.soap.SOAPConstants;
 import org.apache.axis.utils.BeanPropertyDescriptor;
 import org.apache.axis.utils.Messages;
+import org.apache.axis.utils.StringUtils;
 import org.apache.commons.logging.Log;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
@@ -209,6 +210,12 @@
         if (propDesc == null) {
             // look for a field by this name.
             propDesc = (BeanPropertyDescriptor) propertyMap.get(localName);
+            if (propDesc == null) {
+                String malformedLocalName = StringUtils.makeQNameToMatchLocalName(localName);
+                if (malformedLocalName != null) {
+                    propDesc = (BeanPropertyDescriptor) propertyMap.get(malformedLocalName);
+                }
+            }
         }
 
         // try and see if this is an xsd:any namespace="##any" element before

Modified: webservices/axis/trunk/java/src/org/apache/axis/utils/StringUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/src/org/apache/axis/utils/StringUtils.java?rev=357625&r1=357624&r2=357625&view=diff
==============================================================================
--- webservices/axis/trunk/java/src/org/apache/axis/utils/StringUtils.java (original)
+++ webservices/axis/trunk/java/src/org/apache/axis/utils/StringUtils.java Sun Dec 18 20:10:11
2005
@@ -357,6 +357,222 @@
         }
     }
 
+	/**
+     * <p>This method provides a way to convert the a QName to local name. This need
+     * to be done is because Axis 1.x follow the java naming convetation for local name
+     * rather then xml naming convenation for the local name. </p>
+     *
+     * <p>A <code>null</code> input String returns <code>null</code>.</p>
+     *
+     * <pre>
+ 	 *	makeQNameToMatchLocalName("Foo.bar")  = fooBar
+	 *	makeQNameToMatchLocalName("Foo.Bar")  = fooBar
+	 *	makeQNameToMatchLocalName("FooBar")   = fooBar
+	 *	makeQNameToMatchLocalName("Foobar")   = fooBar
+	 *	makeQNameToMatchLocalName("fooBar")   = fooBar
+	 *	makeQNameToMatchLocalName("foobar")   = foobar
+	 *	makeQNameToMatchLocalName("Foo:bar")  = fooBar
+	 *	makeQNameToMatchLocalName("Foo-Bar")  = fooBar
+	 *	makeQNameToMatchLocalName("Foo-bar")  = fooBar
+	 *	makeQNameToMatchLocalName("Foo_bar")  = foo_bar
+	 *	makeQNameToMatchLocalName("Foo_Bar")  = foo_Bar
+	 * 	makeQNameToMatchLocalName("foo:bar")  = fooBar
+     * </pre>
+     *
+     * @param str  the String to parse, may be null
+     *  <code>null</code> splits on whitespace
+     * @return an array of parsed Strings, <code>null</code> if null String input
+     *
+     * <code>return null</code> if null passed. 
+     * @return String the java naming compliante name
+     */
+	public static String makeQNameToMatchLocalName(String str){
+    	
+    	if(str == null){
+    		return null;
+    	}
+    	
+    	StringBuffer sb = new StringBuffer(str);
+    	
+    	char firstChar = sb.charAt(0);
+    	
+    	if(Character.isUpperCase(firstChar)){
+    		sb.setCharAt(0,Character.toLowerCase(firstChar));    		
+    	}
+    	int iIndex = str.indexOf('.');
+    	
+    	if(iIndex == 0){
+			sb.deleteCharAt(0);
+			
+			if(sb.length() > 0){
+	    		iIndex = sb.toString().indexOf(':');
+	    		if(iIndex == 0){    			
+		    		str = makeQNameToMatchLocalName(sb.toString()); 
+		    		sb.delete(0,sb.length());
+		    		sb.append(str);    			
+	    		}    			
+	    	}
+
+			if(sb.length() > 0){
+	    		iIndex = sb.toString().indexOf('-');
+	    		if(iIndex == 0){    			
+		    		str = makeQNameToMatchLocalName(sb.toString()); 
+		    		sb.delete(0,sb.length());
+		    		sb.append(str);    			
+	    		}    			
+			}
+    	}else if(iIndex > 0){    		
+	    		str = deleteCharAndChangeNextCharToUpperCase(sb.toString(),".");
+	    		sb.delete(0,sb.length());
+	    		sb.append(str);	    		
+    	}
+    	
+    	iIndex = str.indexOf(':');
+    	if(iIndex == 0){
+			sb.deleteCharAt(0);
+    		
+			if(sb.length() > 0){
+				iIndex = sb.toString().indexOf('.');
+	    		if(iIndex == 0){    			
+		    		str = makeQNameToMatchLocalName(sb.toString());	    		
+		    		sb.delete(0,sb.length());
+		    		sb.append(str);    			
+	    		}
+			}
+    		
+			if(sb.length() > 0){
+	    		iIndex = sb.toString().indexOf('-');
+	    		if(iIndex == 0){    			
+		    		str = makeQNameToMatchLocalName(sb.toString()); 
+		    		sb.delete(0,sb.length());
+		    		sb.append(str);    				    		
+	    		}    			
+			}
+        		
+    	}else if(iIndex > 0){
+    		str = deleteCharAndChangeNextCharToUpperCase(sb.toString(),":");
+    		sb.delete(0,sb.length());
+    		sb.append(str);    		
+    	}
+    	
+    	iIndex = str.indexOf('-');
+    	if(iIndex == 0){
+			sb.deleteCharAt(0);
+
+			if(sb.length() > 0){
+				iIndex = sb.toString().indexOf('.');
+	    		if(iIndex == 0){    			
+		    		str = makeQNameToMatchLocalName(sb.toString()); 
+		    		sb.delete(0,sb.length());
+		    		sb.append(str);    			
+	    		}
+			}
+			
+			if(sb.length() > 0){
+	    		iIndex = sb.toString().indexOf(':');
+	    		if(iIndex == 0){    			
+		    		str = makeQNameToMatchLocalName(sb.toString()); 
+		    		sb.delete(0,sb.length());
+		    		sb.append(str);	    		
+	    		}    			
+			}
+    	}else if(iIndex > 0){
+    		str = deleteCharAndChangeNextCharToUpperCase(sb.toString(),"-");
+    		sb.delete(0,sb.length());
+    		sb.append(str);    		
+    	}
+    
+    	if(sb.length() > 0){
+	    	firstChar = sb.charAt(0);
+	    	
+	    	if(Character.isUpperCase(firstChar)){
+	    		sb.setCharAt(0,Character.toLowerCase(firstChar));    		
+	    	}
+    	}
+    	
+    	return StringUtils.isEmpty(sb.toString())?null:sb.toString();
+    }
+	
+     /**
+     * <p>This method provided a way to delete the given string and change the
+     * following first character to capital letter, this is provided because 
+     * Axis 1.x follow the java naming convenation rather then xml naming convention
+     * for there local name.</p>
+     *
+     *
+     * <p>A <code>null</code> input String returns <code>null</code>.</p>
+     *
+     * <pre>
+     * 	deleteCharAndChangeNextCharToUpperCase("Foo.bar") = fooBar
+     *  deleteCharAndChangeNextCharToUpperCase("Foo.Bar") = fooBar
+     *  deleteCharAndChangeNextCharToUpperCase("Foo:bar") = fooBar
+     *  deleteCharAndChangeNextCharToUpperCase("Foo-Bar") = fooBar
+     * 	deleteCharAndChangeNextCharToUpperCase("Foo-bar") = fooBar
+     * 	deleteCharAndChangeNextCharToUpperCase("Foo_bar") = foo_bar
+     * 	deleteCharAndChangeNextCharToUpperCase("Foo_Bar") = foo_Bar
+     * 	deleteCharAndChangeNextCharToUpperCase("Foo_bar") = foo_bar
+     * 	deleteCharAndChangeNextCharToUpperCase("foo:bar") = fooBar
+     * </pre>
+     *
+     * @param psWord the String to be changed
+     * <code>return null</code> if null passed. 
+     * @param psReplace the String that need to be eliminated, 
+     * <code>return null or psWord if psWord is not null</code>
+     *  if null passed.
+     * @return String the java naming compliant name
+     */
+    public static String deleteCharAndChangeNextCharToUpperCase(String psWord, String psReplace)
{
+
+    	if(psWord == null){
+    		return null;
+    	}
+    	
+    	if(psReplace == null && psWord == null){
+    		return null;
+    	}
+    	
+    	if(psReplace == null && psWord != null){
+    		return psWord;
+    	}
+    	
+    	StringBuffer lsNewStr = new StringBuffer();
+        
+        int liFound = 0;
+        int liLastPointer = 0;
+        boolean skipNextChar = false;
+
+        do {
+            liFound = psWord.indexOf(psReplace, liLastPointer);
+            if (liFound < 0){
+            	if(!skipNextChar){
+            		lsNewStr.append(psWord
+            				.substring(liLastPointer, psWord.length()));            		
+            	}else{
+            		lsNewStr.append(psWord
+            				.substring(liLastPointer + 1, psWord.length()));
+            		skipNextChar = false;
+            	}
+            }
+            else {
+            	char nextChar = 0;
+            	if((liFound + psReplace.length()) < psWord.length()){
+            		nextChar = psWord.charAt(liFound + psReplace.length());            		
+            	}
+                if (liFound > liLastPointer && nextChar > 0){
+                    lsNewStr.append(psWord.substring(liLastPointer, (liFound)));
+                    if(!Character.isUpperCase(nextChar)){
+                    	lsNewStr.append(Character.toUpperCase(nextChar));
+                    }else{
+                    	lsNewStr.append(nextChar);
+                    }
+                }                
+                liLastPointer = liFound + psReplace.length();
+                skipNextChar = true;
+            }
+        } while (liFound > -1);
+
+        return lsNewStr.toString();    
+    }  
     /**
      * <p>Unescapes numeric character referencs found in the <code>String</code>.</p>
      *



Mime
View raw message