Fellow XMLBeans
users,
I have an xmlbean
and some code that uses the xmlbean. The code works as
expected when launched from the java command-line
or launched via
Ant's 'java' task. I wrote a simple Ant custom task to run the code. When the
custom task is executed an ArrayStoreException is thrown in the bean's
get*Array() method. I'm
using XMLBeans 2.1.0 and Ant 1.6.4. Below is a snippet from the
stacktrace:
java.lang.ArrayStoreException
at
com.commerce360.internal.cm.starteam.query.xml.impl.QueryDefinitionSetXmlBeanImpl.getQueryArray(QueryDefinitionSetXmlBeanImpl.java:59)
The XSD fragment for
the bean looks like this:
<xs:complexType name="queryDefinitionSet">
<xs:sequence>
<xs:element ref="query" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType><xs:complexType name="queryDefinition" abstract="true">
<xs:sequence>
<xs:element name="id" type="xs:ID" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="itemQueryDefinition" abstract="true">
<xs:complexContent>
<xs:extension base="queryDefinition">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="changeRequestQueryDefinition">
<xs:complexContent>
<xs:extension base="itemQueryDefinition">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="fileQueryDefinition">
<xs:complexContent>
<xs:extension base="itemQueryDefinition">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="query" type="queryDefinition"/>
The code
generated for the xmlbean's getQueryArray() method looks like
this:
public class
QueryDefinitionSetXmlBeanImpl extends
org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionSetXmlBean
{
public QueryDefinitionSetXmlBeanImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType);
}
private static final javax.xml.namespace.QName QUERY$0 =
new javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/query/xml", "query");
private static final org.apache.xmlbeans.QNameSet QUERY$1 = org.apache.xmlbeans.QNameSet.forArray(
{
public QueryDefinitionSetXmlBeanImpl(org.apache.xmlbeans.SchemaType sType)
{
super(sType);
}
private static final javax.xml.namespace.QName QUERY$0 =
new javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/query/xml", "query");
private static final org.apache.xmlbeans.QNameSet QUERY$1 = org.apache.xmlbeans.QNameSet.forArray(
new javax.xml.namespace.QName[] {
new javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/query/xml", "item-query"),
new javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/query/xml", "file-query"),
new javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/query/xml", "change-request-query"),
new javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/query/xml", "query"),
});
/**
* Gets array of all "query" elements
*/
public com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[] getQueryArray()
{
synchronized (monitor())
{
check_orphaned();
java.util.List targetList = new java.util.ArrayList();
get_store().find_all_element_users(QUERY$1, targetList);
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[] result = new
new javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/query/xml", "item-query"),
new javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/query/xml", "file-query"),
new javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/query/xml", "change-request-query"),
new javax.xml.namespace.QName("http://www.360commerce.com/internal/starteam/query/xml", "query"),
});
/**
* Gets array of all "query" elements
*/
public com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[] getQueryArray()
{
synchronized (monitor())
{
check_orphaned();
java.util.List targetList = new java.util.ArrayList();
get_store().find_all_element_users(QUERY$1, targetList);
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[] result = new
com.commerce360.internal.cm.starteam.query.xml.QueryDefinitionXmlBean[targetList.size()];
targetList.toArray(result);
return result;
}
}
targetList.toArray(result);
return result;
}
}
.....
.....
......
}
The exception occurs
at the 'targetList.toArray(result)' line. What's happening is that when the code
is run as a custom ant task,
the class of the
elements in the 'targetList' ArrayList is
'org.apache.xmlbeans.impl.values.XmlAnyTypeImpl' whereas when the same
code
is successfully run
as a command-line java app, the class is
'com.commerce360.internal.cm.starteam.query.xml.impl.ChangeRequestQueryDefinitionXmlBeanImpl'.
I am using the same classpath
and input XML in
both cases.
I did some googling
and found another person who experienced the same exception but over
RMI:
Does anyone have
insight as to why the XMLBeans unmarshalling code would type my objects as
XmlAnyTypeImpl when
run as a custom Ant
task? This
smells like one of those esoteric classloader issues and I suspect it
requires a deeper knowlegde of XMLBeans
internals than I
currently have to debug it.
Any help or insights
would be appreciated.
Thanks,
--
Tellis

