You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ow...@apache.org on 2002/08/01 15:08:34 UTC
cvs commit: xml-axis-wsif/java/src/org/apache/wsif/compiler/schema/tools Schema2Java.java
owenb 2002/08/01 06:08:34
Modified: java/src/org/apache/wsif/base WSIFServiceImpl.java
java/src/org/apache/wsif/providers WSIFDynamicTypeMap.java
java/src/org/apache/wsif/compiler/schema/tools
Schema2Java.java
Log:
- Added support for creating mappings for simpleTypes when using service stubs
- Changed automatically generated mappings created when using stubs so that
they don't override any user defined mappings
Revision Changes Path
1.20 +23 -12 xml-axis-wsif/java/src/org/apache/wsif/base/WSIFServiceImpl.java
Index: WSIFServiceImpl.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/base/WSIFServiceImpl.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- WSIFServiceImpl.java 30 Jul 2002 14:15:42 -0000 1.19
+++ WSIFServiceImpl.java 1 Aug 2002 13:08:33 -0000 1.20
@@ -130,7 +130,7 @@
private WSIFDynamicTypeMap typeMap = new WSIFDynamicTypeMap();
private boolean typeMapInitialised = false;
private String preferredPort = null;
-
+ private Map typeReg = null;
private Port chosenPort = null;
/**
@@ -453,6 +453,20 @@
}
/**
+ * Add an association between XML and Java type.
+ * @param xmlType The qualified xml name
+ * @param javaType The Java class
+ * @param force flag to indicate if mapping should override an existing one
+ * for the same xmlType
+ */
+ private void mapType(QName xmlType, Class javaType, boolean force)
+ throws WSIFException {
+ Trc.entry(this, xmlType, javaType, new Boolean(force));
+ typeMap.mapType(xmlType, javaType, force);
+ Trc.exit();
+ }
+
+ /**
* Add an association between a namespace URI and and a Java package.
* @param namespace The namespace URI
* @param packageName The full package name
@@ -781,7 +795,10 @@
* in the wsdl
*/
private Iterator getDefaultTypeMappings() {
- HashMap typeReg = new HashMap();
+ if (typeReg != null) {
+ return typeReg.values().iterator();
+ }
+ typeReg = new HashMap();
List typesElList = Utils.getAllTypesElements(def);
if (typesElList.size() > 0) {
String schemaURI1999 = WSIFConstants.NS_URI_1999_SCHEMA_XSD;
@@ -848,17 +865,11 @@
clazz =
Class.forName(className, true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
- throw new WSIFException(
- "WSIFService could not map QName "
- + tm.elementType
- + " to class "
- + className
- + " (JavaType "
- + tm.javaType
- + ")",
- e);
+ // Ignore error - mapping will not be added
+ Trc.exception(e);
}
- mapType(tm.elementType, clazz);
+ // Create a new mapping but don't override one that already exists for this element type
+ mapType(tm.elementType, clazz, false);
}
}
} // end while
1.5 +24 -2 xml-axis-wsif/java/src/org/apache/wsif/providers/WSIFDynamicTypeMap.java
Index: WSIFDynamicTypeMap.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/WSIFDynamicTypeMap.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WSIFDynamicTypeMap.java 19 Jul 2002 15:46:30 -0000 1.4
+++ WSIFDynamicTypeMap.java 1 Aug 2002 13:08:33 -0000 1.5
@@ -75,6 +75,8 @@
*/
public class WSIFDynamicTypeMap implements Serializable {
protected Vector typeMapList = new Vector();
+ // Create a Vector of xmlTypes (QNames) for faster lookup of existing mappings
+ protected Vector xmlTypes = new Vector();
protected ArrayList allTypes;
/**
@@ -97,13 +99,32 @@
}
/**
- * Add new mapping between XML and Java type.
+ * Add new mapping between XML and Java type. This method is equivalent to
+ * calling mapType(xmlType, javaType, true)
* @param xmlType The qualified xml name
- * @param javaType The Java class
+ * @param javaType The Java class
+ * @see #mapType(QName, Class, boolean)
*/
public void mapType(QName xmlType, Class javaType) {
Trc.entry(this, xmlType, javaType);
typeMapList.add(new WSIFDynamicTypeMapping(xmlType, javaType));
+ xmlTypes.add(xmlType);
+ Trc.exit();
+ }
+
+ /**
+ * Add new mapping between XML and Java type.
+ * @param xmlType The qualified xml name
+ * @param javaType The Java class
+ * @param force flag to indicate if mapping should override an existing one
+ * for the same xmlType
+ */
+ public void mapType(QName xmlType, Class javaType, boolean force) {
+ Trc.entry(this, xmlType, javaType);
+ if (force || !xmlTypes.contains(xmlType)) {
+ typeMapList.add(new WSIFDynamicTypeMapping(xmlType, javaType));
+ xmlTypes.add(xmlType);
+ }
Trc.exit();
}
@@ -137,6 +158,7 @@
mapType(qn, cl);
}
} catch (Exception e) {
+ Trc.exception(e);
//ignore
}
Trc.exit();
1.8 +18 -5 xml-axis-wsif/java/src/org/apache/wsif/compiler/schema/tools/Schema2Java.java
Index: Schema2Java.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/compiler/schema/tools/Schema2Java.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Schema2Java.java 16 Jul 2002 09:57:21 -0000 1.7
+++ Schema2Java.java 1 Aug 2002 13:08:33 -0000 1.8
@@ -77,6 +77,7 @@
import org.apache.wsif.compiler.schema.SchemaException;
import org.apache.wsif.compiler.util.StreamFactory;
import org.apache.wsif.compiler.util.TypeMapping;
+import org.apache.wsif.logging.Trc;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -555,11 +556,10 @@
undefinedRegistry.put(qName, javaName);
- System.err.println(
- "Schema name "
+ Trc.event(this, "Schema name "
+ qName
+ " is undefined, "
- + "and generic Java name "
+ + "and so generic Java name "
+ javaName
+ " is used instead.");
@@ -932,6 +932,15 @@
isFinal,
children,
targetURI));
+ } else if (elementType.equals("simpleType")) {
+ QName base = null;
+ boolean isList = false;
+ elements.addElement(
+ new SchemaSimpleType(
+ name,
+ base,
+ isList,
+ targetURI));
} else if (elementType.equals("element")) {
QName ref = null;
elements.addElement(
@@ -1227,8 +1236,12 @@
registry.put(qName, javaType);
changed = true;
simpleTypeTable.remove(qName);
- } else
- throw new SchemaException("'simpleType' must have 'base' attribute.");
+ } else {
+ String javaType = getGenericJavaName(qName, "simpleType");
+ registry.put(qName, javaType);
+ // ignore it
+ //throw new SchemaException("'simpleType' must have 'base' attribute.");
+ }
}
}