scheu 2002/06/18 14:26:38
Modified: java/src/org/apache/axis/utils axisNLS.properties
java/src/org/apache/axis/wsdl/fromJava Types.java
Log:
If a java type cannot be converted to wsdl, a message is logged and the
java type is mapped as an xsd:anyType.
This fix was necessary to prevent wsdl from being generated that cannot
subsequently run through WSDL2Java.
Revision Changes Path
1.9 +3 -0 xml-axis/java/src/org/apache/axis/utils/axisNLS.properties
Index: axisNLS.properties
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/axisNLS.properties,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- axisNLS.properties 11 Jun 2002 13:26:16 -0000 1.8
+++ axisNLS.properties 18 Jun 2002 21:26:38 -0000 1.9
@@ -864,3 +864,6 @@
badEnum02=Unrecognized {0}: ''{1}''
badEnum03=Unrecognized {0}: ''{1}'', defaulting to ''{2}''
+beanCompatType00=The class {0} is not a bean class and cannot be converted into an
xml schema type. An xml schema anyType will be used to define this class in the wsdl
file.
+beanCompatPkg00=The class {0} is defined in a java or javax package and cannot be
converted into an xml schema type. An xml schema anyType will be used to define this
class in the wsdl file.
+beanCompatConstructor00=The class {0} does not contain a default constructor, which
is a requirement for a bean class. The class cannot be converted into an xml schema
type. An xml schema anyType will be used to define this class in the wsdl file.
1.35 +81 -4 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.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- Types.java 18 Jun 2002 15:33:21 -0000 1.34
+++ Types.java 18 Jun 2002 21:26:38 -0000 1.35
@@ -105,6 +105,7 @@
HashMap schemaElementNames = null;
HashMap schemaUniqueElementNames = null;
List stopClasses = null;
+ List beanCompatErrs = new ArrayList();
/**
* This class serailizes a <code>Class</code> to XML Schema. The constructor
@@ -378,12 +379,18 @@
} else {
factory = (SerializerFactory)defaultTM.getSerializer(type);
}
+
+ // If no factory is found, use the BeanSerializerFactory
+ // if applicable, otherwise issue errors and return anyType
if (factory == null) {
- // If no factory is found, try the BeanSerializerFactory if
- // the type is not Throwable. (There is no mapping for
- // java types that extend Throwable.)
- factory = new BeanSerializerFactory(type, getTypeQName(type));
+ if (isBeanCompatible(type, true)) {
+ factory = new BeanSerializerFactory(type, getTypeQName(type));
+ } else {
+ return Constants.NS_PREFIX_SCHEMA_XSD + ":" +
+ Constants.XSD_ANYTYPE.getLocalPart();
+ }
}
+
if (factory != null) {
ser = (Serializer)factory.getSerializerAs(Constants.AXIS_SAX);
}
@@ -836,4 +843,74 @@
{
return docHolder.createElement(elementName);
}
+
+ /**
+ * isBeanCompatible
+ * @param type Class
+ * @param boolean issueMessages if not compatible
+ * Returns true if it appears that this class is a bean and
+ * can be mapped to a complexType
+ */
+ protected boolean isBeanCompatible(Class javaType,
+ boolean issueErrors) {
+
+ // Must be a non-primitive and non array
+ if (javaType.isArray() ||
+ javaType.isPrimitive()) {
+ if (issueErrors &&
+ !beanCompatErrs.contains(javaType)) {
+ log.error(JavaUtils.getMessage("beanCompatType00",
+ javaType.getName()));
+ beanCompatErrs.add(javaType);
+ }
+ return false;
+ }
+
+ // Anything in the java or javax package that
+ // does not have a defined mapping is excluded.
+ if (javaType.getName().startsWith("java.") ||
+ javaType.getName().startsWith("javax.")) {
+ if (issueErrors &&
+ !beanCompatErrs.contains(javaType)) {
+ log.error(JavaUtils.getMessage("beanCompatPkg00",
+ javaType.getName()));
+ beanCompatErrs.add(javaType);
+ }
+ return false;
+ }
+
+ // Return true if appears to be an enum class
+ if (JavaUtils.isEnumClass(javaType)) {
+ return true;
+ }
+
+ // Must have a default public constructor if not
+ // Throwable
+ if (!java.lang.Throwable.class.isAssignableFrom(javaType)) {
+ try {
+ javaType.getConstructor(new Class[] {});
+ } catch (java.lang.NoSuchMethodException e) {
+ if (issueErrors &&
+ !beanCompatErrs.contains(javaType)) {
+ log.error(JavaUtils.getMessage("beanCompatConstructor00",
+ javaType.getName()));
+ beanCompatErrs.add(javaType);
+ }
+ return false;
+ }
+ }
+
+ // Make sure superclass is compatible
+ Class superClass = javaType.getSuperclass();
+ if (superClass != null &&
+ superClass != java.lang.Object.class &&
+ superClass != java.lang.Exception.class &&
+ superClass != org.apache.axis.AxisFault.class &&
+ (stopClasses == null ||
+ !(stopClasses.contains(superClass.getName()))) ) {
+ return isBeanCompatible(superClass, issueErrors);
+ }
+ return true;
+ }
+
}