dims 2003/07/03 09:48:27
Modified: java/src/org/apache/axis/wsdl/fromJava Namespaces.java
Types.java
java/test/encoding TestAutoTypes.java
java/src/org/apache/axis/encoding TypeMappingImpl.java
Log:
Additional fix and test case for Bug 18084 (for auto-typed arrays)
from [EMAIL PROTECTED] (Dan Diephouse)
Revision Changes Path
1.9 +3 -0 xml-axis/java/src/org/apache/axis/wsdl/fromJava/Namespaces.java
Index: Namespaces.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Namespaces.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Namespaces.java 22 Apr 2003 19:36:11 -0000 1.8
+++ Namespaces.java 3 Jul 2003 16:48:22 -0000 1.9
@@ -190,6 +190,9 @@
* @return namespace namespace String
*/
public static String makeNamespace (String clsName, String protocol) {
+ if ( clsName.startsWith("[L") )
+ clsName = clsName.substring( 2, clsName.length() - 1 );
+
if (clsName.lastIndexOf('.') == -1)
return protocol + "://" + "DefaultNamespace";
String packageName = clsName.substring(0, clsName.lastIndexOf('.'));
1.77 +9 -2 xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java
Index: Types.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- Types.java 27 Jun 2003 17:46:31 -0000 1.76
+++ Types.java 3 Jul 2003 16:48:23 -0000 1.77
@@ -647,10 +647,17 @@
* @return package name
*/
public static String getLocalNameFromFullName(String full) {
+ String end = "";
+ if ( full.startsWith("[L") )
+ {
+ end = "[]";
+ full = full.substring( 3, full.length() - 1 );
+ }
+
if (full.lastIndexOf('.') < 0)
- return full;
+ return full + end;
else
- return full.substring(full.lastIndexOf('.')+1);
+ return full.substring(full.lastIndexOf('.')+1) + end;
}
/**
1.2 +18 -9 xml-axis/java/test/encoding/TestAutoTypes.java
Index: TestAutoTypes.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/encoding/TestAutoTypes.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestAutoTypes.java 2 Jul 2003 19:35:57 -0000 1.1
+++ TestAutoTypes.java 3 Jul 2003 16:48:23 -0000 1.2
@@ -1,18 +1,14 @@
package test.encoding;
+import javax.xml.namespace.QName;
+
import junit.framework.TestCase;
-import org.apache.axis.Constants;
-import org.apache.axis.Message;
-import org.apache.axis.MessageContext;
-import org.apache.axis.encoding.TypeMapping;
+
import org.apache.axis.encoding.TypeMappingImpl;
import org.apache.axis.encoding.TypeMappingRegistry;
-import org.apache.axis.message.RPCElement;
-import org.apache.axis.message.RPCParam;
-import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.server.AxisServer;
-
-import javax.xml.namespace.QName;
+import org.apache.axis.wsdl.fromJava.Namespaces;
+import org.apache.axis.wsdl.fromJava.Types;
/**
* Test auto-typing.
@@ -38,5 +34,18 @@
assertTrue( tm.getDeserializer(qname) != null );
assertTrue( tm.getSerializer(AttributeBean.class) != null );
+
+ assertEquals(
+ "http://encoding.test",
+ Namespaces.makeNamespace(AttributeBean[].class.getName()));
+ assertEquals(
+ "AttributeBean[]",
+ Types.getLocalNameFromFullName(AttributeBean[].class.getName()));
+
+ qname = tm.getTypeQName( AttributeBean[].class );
+ assertEquals( "http://encoding.test",
+ qname.getNamespaceURI() );
+ assertEquals( "AttributeBean[]", qname.getLocalPart() );
+
}
}
1.43 +31 -31 xml-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java
Index: TypeMappingImpl.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- TypeMappingImpl.java 2 Jul 2003 16:47:32 -0000 1.42
+++ TypeMappingImpl.java 3 Jul 2003 16:48:24 -0000 1.43
@@ -534,7 +534,7 @@
//log.debug("getTypeQName javaType =" + javaType);
if (javaType == null)
return null;
-
+
QName xmlType = null;
Pair pair = (Pair) class2Pair.get(javaType);
if (pair == null && delegate != null) {
@@ -543,41 +543,41 @@
xmlType = pair.xmlType;
}
+ /* If auto-typing is on and the array has the default SOAP_ARRAY QName,
+ * then generate a namespace for this array intelligently. Also
+ * register it's javaType and xmlType. List classes and derivitives
+ * can't be used because they should be serialized as an anyType array.
+ */
+ if ( doAutoTypes &&
+ javaType != List.class &&
+ !List.class.isAssignableFrom(javaType) &&
+ xmlType != null &&
+ xmlType.equals(Constants.SOAP_ARRAY) )
+ {
+ xmlType = new QName(
+ Namespaces.makeNamespace( javaType.getName() ),
+ Types.getLocalNameFromFullName( javaType.getName() ) );
+
+ register( javaType,
+ xmlType,
+ new ArraySerializerFactory(),
+ new ArrayDeserializerFactory() );
+ }
+
// Can only detect arrays via code
if (xmlType == null && (javaType.isArray() ||
javaType == List.class ||
List.class.isAssignableFrom(javaType))) {
- /* If auto-typing is on, generate a namespace for this array
- * intelligently, then register it's javaType and xmlType. Also
- * make sure the class isn't derived from List, because they
- * should be serialized as an anyType array.
- */
- if ( doAutoTypes &&
- javaType != List.class &&
- !List.class.isAssignableFrom(javaType) )
- {
- xmlType = new QName(
- Namespaces.makeNamespace( javaType.getName() ),
- Types.getLocalNameFromFullName( javaType.getName() ) );
-
- register( javaType,
- xmlType,
- new ArraySerializerFactory(),
- new ArrayDeserializerFactory() );
- }
- else
- {
- // get the registered array if any
- pair = (Pair) class2Pair.get(Object[].class);
- // TODO: it always returns the last registered one,
- // so that's why the soap 1.2 typemappings have to
- // move to an other registry to differentiate them
- if (pair != null) {
- xmlType = pair.xmlType;
- } else {
- xmlType = Constants.SOAP_ARRAY;
- }
+ // get the registered array if any
+ pair = (Pair) class2Pair.get(Object[].class);
+ // TODO: it always returns the last registered one,
+ // so that's why the soap 1.2 typemappings have to
+ // move to an other registry to differentiate them
+ if (pair != null) {
+ xmlType = pair.xmlType;
+ } else {
+ xmlType = Constants.SOAP_ARRAY;
}
}