Author: dsosnoski
Date: Sat Mar 24 03:05:44 2007
New Revision: 522001
URL: http://svn.apache.org/viewvc?view=rev&rev=522001
Log:
1. Fix for null local name on QName
2. Handle create-type for objects with no default constructor
3. Handle optional elements (minOccurs='0', not just nillable='true')
4. Get binding factory from binding name and package where possible, rather
than always from class
Modified:
webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl
Modified:
webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
URL:
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java?view=diff&rev=522001&r1=522000&r2=522001
==============================================================================
---
webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
(original)
+++
webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
Sat Mar 24 03:05:44 2007
@@ -60,6 +60,7 @@
import org.jibx.binding.model.ModelVisitor;
import org.jibx.binding.model.NamespaceElement;
import org.jibx.binding.model.ValidationContext;
+import org.jibx.binding.model.ValidationProblem;
import org.jibx.runtime.JiBXException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -243,6 +244,14 @@
IncludePrevalidationVisitor ipv = new
IncludePrevalidationVisitor(vctx);
vctx.tourTree(binding, ipv);
if (vctx.getErrorCount() != 0 || vctx.getFatalCount() != 0) {
+ ArrayList probs = vctx.getProblems();
+ System.err.println("Errors in generated binding:");
+ for (int j = 0; j < probs.size(); j++) {
+ ValidationProblem prob =
(ValidationProblem)probs.get(j);
+ System.err.print(prob.getSeverity() >=
+ ValidationProblem.ERROR_LEVEL ? "Error: " :
"Warning: ");
+ System.err.println(prob.getDescription());
+ }
throw new RuntimeException("invalid jibx binding
definition file " + path);
}
}
@@ -298,7 +307,7 @@
Map complexTypeMap = new HashMap();
Map bindingMap = new HashMap();
if (binding != null) {
- collectTopLevelComponents(binding, null, elementMap,
+ collectTopLevelComponents(binding, "", elementMap,
complexTypeMap, simpleTypeMap, bindingMap);
}
@@ -337,8 +346,11 @@
ArrayList headers = inmsg.getSoapHeaders();
for (int i = 0; i < headers.size(); i++) {
SOAPHeaderMessage header =
(SOAPHeaderMessage)headers.get(i);
- mappedclass = mapMessage(header, elementMap);
- objins.add(mappedclass);
+ String cname = mapMessage(header, elementMap);
+ objins.add(cname);
+ if (mappedclass == null && isLookupClass(cname)) {
+ mappedclass = cname;
+ }
}
}
if (WSDLUtil.isOutputPresentForMEP(mep)) {
@@ -349,8 +361,11 @@
ArrayList headers = outmsg.getSoapHeaders();
for (int i = 0; i < headers.size(); i++) {
SOAPHeaderMessage header =
(SOAPHeaderMessage)headers.get(i);
- mappedclass = mapMessage(header, elementMap);
- objouts.add(mappedclass);
+ String cname = mapMessage(header, elementMap);
+ objouts.add(cname);
+ if (mappedclass == null && isLookupClass(cname)) {
+ mappedclass = cname;
+ }
}
}
if (unwrap) {
@@ -381,20 +396,29 @@
// concrete mappings, just save the mapped class name(s)
if (inmsg != null) {
- mappedclass = mapMessage(inmsg, elementMap);
- objins.add(mappedclass);
+ String cname = mapMessage(inmsg, elementMap);
+ objins.add(cname);
+ if (mappedclass == null && isLookupClass(cname)) {
+ mappedclass = cname;
+ }
}
if (outmsg != null) {
- mappedclass = mapMessage(outmsg, elementMap);
- objouts.add(mappedclass);
+ String cname = mapMessage(outmsg, elementMap);
+ objouts.add(cname);
+ if (mappedclass == null && isLookupClass(cname)) {
+ mappedclass = cname;
+ }
}
}
// always handle faults as wrapped
for (Iterator iter = op.getFaultMessages().iterator();
iter.hasNext();) {
- mappedclass = mapMessage((AxisMessage)iter.next(),
elementMap);
- objfaults.add(mappedclass);
+ String cname = mapMessage((AxisMessage)iter.next(),
elementMap);
+ objfaults.add(cname);
+ if (mappedclass == null && isLookupClass(cname)) {
+ mappedclass = cname;
+ }
}
}
@@ -540,10 +564,17 @@
}
}
}
- if (mappedclass == null) {
- mappedclass = "";
+
+ // set binding lookup parameters
+ if (binding.getName() != null && binding.getTargetPackage() !=
null) {
+ bindinit.setAttribute("binding-name", binding.getName());
+ bindinit.setAttribute("binding-package",
binding.getTargetPackage());
+ } else {
+ if (mappedclass == null) {
+ mappedclass = "";
+ }
+ bindinit.setAttribute("bound-class", mappedclass);
}
- bindinit.setAttribute("bound-class", mappedclass);
// include binding namespaces in initialization data
for (Iterator iter = nsMap.keySet().iterator(); iter.hasNext();) {
@@ -591,6 +622,19 @@
}
/**
+ * Check if a class is potentially usable for looking up binding
+ * information.
+ *
+ * @param type fully-qualified type name
+ * @return <code>true</code> if potentially usable, <code>false</code> if
+ * not
+ */
+ private static boolean isLookupClass(String type) {
+ return !type.startsWith("java.") && !type.startsWith("javax.") &&
+ !type.startsWith("org.w3c.");
+ }
+
+ /**
* Add format definition for type with built-in JiBX handling to map.
*
* @param stype schema type name
@@ -708,10 +752,12 @@
param.setAttribute("name", itemname.getLocalPart());
param.setAttribute("java-name",
toJavaName(itemname.getLocalPart(), nameset));
param.setAttribute("nillable",
Boolean.toString(element.isNillable()));
- param.setAttribute("optional",
Boolean.toString(element.getMinOccurs() == 0));
+ boolean optional = element.getMinOccurs() == 0;
+ param.setAttribute("optional", Boolean.toString(optional));
boolean isarray = element.getMaxOccurs() > 1;
param.setAttribute("array", Boolean.toString(isarray));
String javatype;
+ String createtype;
if (element.getSchemaType() instanceof
XmlSchemaSimpleType) {
// simple type translates to format element in binding
@@ -721,13 +767,13 @@
qname + ": no format definition found for type
" +
typename + " (used by element " + itemname +
')');
}
- javatype = format.getTypeName();
+ javatype = createtype = format.getTypeName();
param.setAttribute("form", "simple");
param.setAttribute("serializer",
format.getSerializerName());
param.setAttribute("deserializer",
format.getDeserializerName());
// convert primitive types to wrapper types for
nillable
- if (element.isNillable() &&
s_wrapperMap.containsKey(javatype)) {
+ if ((optional || element.isNillable()) &&
s_wrapperMap.containsKey(javatype)) {
param.setAttribute("wrapped-primitive", "true");
param.setAttribute("value-method", javatype +
"Value");
javatype = (String)s_wrapperMap.get(javatype);
@@ -761,6 +807,10 @@
typeMappedClassMap.put(typename, tindex);
}
javatype = mapping.getClassName();
+ createtype = mapping.getCreateType();
+ if (createtype == null) {
+ createtype = javatype;
+ }
param.setAttribute("form", "complex");
param.setAttribute("type-index", tindex.toString());
@@ -788,6 +838,8 @@
}
}
param.setAttribute("java-type", javatype);
+ param.setAttribute("create-type", createtype);
+
boolean isobj = !s_primitiveSet.contains(javatype);
String fulltype = javatype;
if (isarray) {
@@ -942,7 +994,7 @@
*
* @param binding
* @param dns default namespace to be used unless overridden
- * (<code>null</code> if none)
+ * (empty string if none)
* @param elementMap map from element names to concrete mapping components
* of binding
* @param complexTypeMap map from type names to abstract mapping
Modified:
webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl
URL:
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl?view=diff&rev=522001&r1=522000&r2=522001
==============================================================================
---
webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl
(original)
+++
webservices/axis2/trunk/java/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl
Sat Mar 24 03:05:44 2007
@@ -165,6 +165,9 @@
<xsl:value-of
select="out-wrapper/return-element/@java-type"/> result = results[i];
if (result == null) {
<xsl:choose>
+ <xsl:when test="out-wrapper/return-element/@optional='true'">
+ // just skip optional element
+ </xsl:when>
<xsl:when test="out-wrapper/return-element/@nillable='true'">
org.apache.axiom.om.OMElement child =
factory.createOMElement("<xsl:value-of
select='out-wrapper/return-element/@name'/>", "<xsl:value-of
select='out-wrapper/return-element/@ns'/>", "<xsl:value-of
select='out-wrapper/return-element/@prefix'/>");
org.apache.axiom.om.OMNamespace xsins =
factory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
@@ -227,7 +230,9 @@
<xsl:when test="out-wrapper/return-element/@form='complex'">
if (result == null) {
<xsl:choose>
- <xsl:when test="out-wrapper/return-element/@optional='true'"/>
+ <xsl:when test="out-wrapper/return-element/@optional='true'">
+ // just skip optional element
+ </xsl:when>
<xsl:when test="out-wrapper/return-element/@nillable='true'">
org.apache.axiom.om.OMElement child =
factory.createOMElement("<xsl:value-of
select='out-wrapper/return-element/@name'/>", "<xsl:value-of
select='out-wrapper/return-element/@ns'/>", "<xsl:value-of
select='out-wrapper/return-element/@prefix'/>");
org.apache.axiom.om.OMNamespace xsins =
factory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
@@ -503,7 +508,9 @@
<xsl:template name="marshal-array">
if (<xsl:value-of select="@java-name"/> == null || <xsl:value-of
select="@java-name"/>.length == 0) {
<xsl:choose>
- <xsl:when test="@optional='true'"></xsl:when>
+ <xsl:when test="@optional='true'">
+ // just skip optional element
+ </xsl:when>
<xsl:when test="@nillable='true'">
child = factory.createOMElement("<xsl:value-of select='@name'/>",
"<xsl:value-of select='@ns'/>", "<xsl:value-of select='@prefix'/>");
org.apache.axiom.om.OMNamespace xsins =
factory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
@@ -548,20 +555,23 @@
<!-- Marshal a simple value to a non-repeated element -->
<xsl:template name="marshal-value">
<xsl:choose>
- <xsl:when test="@object='true' and @nillable='true'">
+ <xsl:when test="@object='true'">
if (<xsl:value-of select="@java-name"/> == null) {
+ <xsl:choose>
+ <xsl:when test="@optional='true'">
+ // just skip optional element
+ </xsl:when>
+ <xsl:when test="@nillable='true'">
child = factory.createOMElement("<xsl:value-of select='@name'/>",
"<xsl:value-of select='@ns'/>", "<xsl:value-of select='@prefix'/>");
org.apache.axiom.om.OMNamespace xsins =
factory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
child.declareNamespace(xsins);
child.addAttribute("nil", "true", xsins);
wrapper.addChild(child);
- } else {
- <xsl:call-template name="serialize-value-to-child"/>
- }
- </xsl:when>
- <xsl:when test="@object='true'">
- if (<xsl:value-of select="@java-name"/> == null) {
+ </xsl:when>
+ <xsl:otherwise>
throw new org.apache.axis2.AxisFault("Null value for <xsl:value-of
select='@java-name'/>");
+ </xsl:otherwise>
+ </xsl:choose>
} else {
<xsl:call-template name="serialize-value-to-child"/>
}
@@ -704,11 +714,14 @@
String message = null;
try {
<xsl:choose>
- <xsl:when test="@bound-class=''">
- factory = new org.apache.axis2.jibx.NullBindingFactory();
+ <xsl:when test="string-length(normalize-space(@binding-name)) > 0">
+ factory =
org.jibx.runtime.BindingDirectory.getFactory("<xsl:value-of
select="@binding-name"/>", "<xsl:value-of select="@binding-package"/>",
<xsl:choose><xsl:when
test="string-length(normalize-space(/class/@name))>0"><xsl:value-of
select="/class/@name"/></xsl:when><xsl:otherwise><xsl:value-of
select="/interface/@name"/></xsl:otherwise></xsl:choose>.class.getClassLoader());
</xsl:when>
- <xsl:otherwise>
+ <xsl:when test="string-length(normalize-space(@bound-class)) > 0">
factory =
org.jibx.runtime.BindingDirectory.getFactory(<xsl:value-of
select="@bound-class"/>.class);
+ </xsl:when>
+ <xsl:otherwise>
+ factory = new org.apache.axis2.jibx.NullBindingFactory();
</xsl:otherwise>
</xsl:choose>
message = null;
@@ -886,7 +899,7 @@
<xsl:value-of
select="@deserializer"/>(uctx.parseElementText("<xsl:value-of select="@ns"/>",
"<xsl:value-of select="@name"/>"))
</xsl:when>
<xsl:when test="@form='complex'">
- uctx.getUnmarshaller(_type_index<xsl:value-of
select="@type-index"/>).unmarshal(new <xsl:value-of select="@java-type"/>(),
uctx)
+ uctx.getUnmarshaller(_type_index<xsl:value-of
select="@type-index"/>).unmarshal(new <xsl:value-of select="@create-type"/>(),
uctx)
</xsl:when>
</xsl:choose>
</xsl:template>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]