Polymorphism in XSD schema and JAXB classes - xsd

I have an xml like this:
<todo>
<doLaundry cost="1"/>
<washCar cost="10"/>
<tidyBedroom cost="0" experiencePoints="5000"/>
</todo>
And the XSD schema for it is:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="todo">
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="doLaundry" type="doLaundry" />
<xs:element name="washCar" type="washCar" />
<xs:element name="tidyBedroom" type="tidyBedroom" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="doLaundry">
<xs:attribute name="cost" type="xs:int" />
</xs:complexType>
<xs:complexType name="washCar">
<xs:attribute name="cost" type="xs:int" />
</xs:complexType>
<xs:complexType name="tidyBedroom">
<xs:attribute name="cost" type="xs:int" />
<xs:attribute name="experiencePoints" type="xs:int" />
</xs:complexType>
</xs:schema>
And when I process this schema through JAXB I get a class with a method like this:
public class Todo {
public List<Object> getDoLaundryOrWashCarOrTidyBedroom() {
...
}
}
Ideally, what I would like is a way to define a generic base type that all the other XSD types extend. The Jaxb classes generated from the XSD schema should have a method to return a list of generic tasks. This would make it very easy to add new tasks to the todo list:
public class Todo {
public List<Task> getTasks() {
...
}
}
public abstract class Task {
public int getCost() {
...
}
}
public class TidyBedroom extends Task {
public int getExperiencePoints() {
...
}
}
What should the XSD schema look like in order to generate the above Java classes?

I found the answer with the help of Blaise Doughan's article here: http://bdoughan.blogspot.com/2010/11/jaxb-and-inheritance-using-xsitype.html
This schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="todo">
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="doLaundry" type="doLaundry" />
<xs:element name="washCar" type="washCar" />
<xs:element name="tidyBedroom" type="tidyBedroom" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType abstract="true" name="Task">
<xs:attribute name="cost" type="xs:int" use="required" />
</xs:complexType>
<xs:complexType name="doLaundry">
<xs:complexContent>
<xs:extension base="Task">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="washCar">
<xs:complexContent>
<xs:extension base="Task">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="tidyBedroom">
<xs:complexContent>
<xs:extension base="Task">
<xs:attribute name="experiencePoints" type="xs:int" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
combined with a binding file:
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings>
<jxb:bindings schemaLocation="todo.xsd" node="/xs:schema/xs:complexType[#name='todo']/xs:sequence/xs:choice">
<jxb:property name="Tasks"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
Will give abstract and inherited classes as I described in the question. The binding file will change Jaxb's default method name from getDoLaundryOrWashCarOrTidyBedroom() to getTasks().

xsd:choice corresponds to the #XmlElements annotation. You could apply this annotation directly to your desired object model.
For more information see:
http://bdoughan.blogspot.com/2010/10/jaxb-and-xsd-choice-xmlelements.html

Use xs:extension in your schema and your JAXB classes will be inherited (extended) as you define in your schema.

Maybe I'm not 'getting' the question, but what is wrong with..
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="todo">
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="doLaundry" type="task" />
<xs:element name="washCar" type="task" />
<xs:element name="tidyBedroom" type="task" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="task">
<xs:attribute name="cost" type="xs:int" />
<xs:attribute name="experiencePoints" type="xs:int" />
</xs:complexType>
</xs:schema>

Related

jaxb2 & xjc - generate fields with inherited type

I'm having some trouble with an xsd that was supplied to us. I'm not really sure how to describe my issue without example so I created a test xsd that has the same issue.
Here's the xsd:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder" type="shipordertype"/> <!-- note: name is equal to name of a complex type further down -->
<xs:complexType name="shiptotype">
<xs:sequence>
<xs:element name="name" type="stringtype"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="myshiptotype">
<xs:complexContent>
<xs:restriction base="shiptotype">
<xs:sequence>
<xs:element name="name" type="stringtype">
<xs:annotation>
<xs:documentation source="Yellow Field"/>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="shiporder">
<xs:sequence>
<xs:element name="orderperson" type="stringtype"/>
<xs:element name="shipto" type="shiptotype"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="shipordertype">
<xs:complexContent>
<xs:restriction base="shiporder">
<xs:sequence>
<xs:element name="orderperson" type="stringtype"/>
<xs:element name="shipto" type="myshiptotype">
<xs:annotation>
<xs:documentation source="Yellow Field"/>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="stringtype">
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:schema>
I've got this external binding file:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<jaxb:bindings schemaLocation="test.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:complexType[#name='shiporder']">
<jaxb:class name="InnerShipOrder" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Now when I generate java classes I get the following classes:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "shipordertype")
#XmlRootElement(name = "shiporder")
public class Shiporder
extends InnerShipOrder
implements Serializable
{
private final static long serialVersionUID = -1L;
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "shiporder", propOrder = {
"orderperson",
"shipto"
})
#XmlSeeAlso({
Shiporder.class
})
public class InnerShipOrder
implements Serializable
{
private final static long serialVersionUID = -1L;
#XmlElement(required = true)
protected String orderperson;
#XmlElement(required = true)
protected Shiptotype shipto;
// some getter and setter functions
Now, in the xsd the shipordertype has a 'shipto' field of the type 'myshiptotype'. However in the generated classes, shipordertype extends shiporder which has a 'shipto' field of the type 'shiptotype'.
Is it possible to make it so that the generated ShipOrder class has a 'shipto' field of the 'myshiptotype'?

How to change XmlType of generated JAXB classes

I am using gradle to generate Java classes based on an XML Schema file. I am using 'org.glassfish.jaxb:jaxb-xjc:2.2.11' and 'org.glassfish.jaxb:jaxb-runtime:2.2.11' as dependencies so I can use the 'com.sun.tools.xjc.XJC2Task' class to generate the classes.
This is the schema file:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="test"
targetNamespace="urn:oio:records:1.0.0"
xmlns="urn:oio:records:1.0.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="records" type="recordsType"/>
<xs:element name="record" type="recordType"/>
<xs:complexType name="recordsType">
<xs:sequence>
<xs:element ref="record" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="recordType">
<xs:attribute name="key" type="xs:string"/>
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
</xs:schema>
One of the generated classes look like this:
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "recordType")
public class RecordType {
#XmlAttribute(name = "key")
protected String key;
#XmlAttribute(name = "value")
protected String value;
public String getKey() {return key;}
public void setKey(String value) {this.key = value;}
public String getValue() {return value;}
public void setValue(String value) {this.value = value;}
}
How can I change the name value in the #XmlType annotation? I would like it to be
#XmlType(name = "record")
I have tried using a bindingsfile and tried to experiment with the <javaType> tag in the bindingsfile, but without luck.
EDIT:
The reason I need to change this is that I need to split an XML file using the stax splitter from Camel (http://camel.apache.org/stax.html section called "Iterate over a collection using JAXB and StAX").
This looks at the name attribute of the #XmlType annotation to recognize the xml tag to split on in the file. The recognized tag (<record>) will then be JAXB parsed to a RecordType java class.
The name in the #XmlType annotation is the name of the complexType in your schema file. This is how the parameter 'name' is defined for this annotation.
So, if you want to change it, you have to change the name of the complexType in your schema:
<xs:complexType name="record">
<xs:attribute name="key" type="xs:string"/>
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
You can use the jaxb2-annotate-plugin to override the value of the name attribute in the generated Java class.
For your code, it would look like this:
<xs:schema id="test"
targetNamespace="urn:oio:records:1.0.0"
xmlns="urn:oio:records:1.0.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="annox"
elementFormDefault="qualified">
<xs:element name="records" type="recordsType"/>
<xs:element name="record" type="recordType"/>
<xs:complexType name="recordsType">
<xs:sequence>
<xs:element ref="record" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="recordType">
<xs:annotation>
<xs:appinfo>
<annox:annotate target="class">
#javax.xml.bind.annotation.XmlType(name = "record")
</annox:annotate>
</xs:appinfo>
</xs:annotation>
<xs:attribute name="key" type="xs:string"/>
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
</xs:schema>
I don't know if this should be considered a hack, but it does the trick. Interestingly enough, in my case even the namespace attribute of XmlType is still generated and filled with the same value as without adding that explicit annotation.

Problems creating DynamicEntities - DynamicHelper.createQuery: Dynamic type not found:

I seem to be having an issue that for the life of me I can not see why. I suspect it is a name space problem.
The following code always results in the following error: DynamicHelper.createQuery: Dynamic type not found:
I have tried numerous namespaces
"mmckenzie.stockcontrol/supplier"
"supplier"
"supplierDAO"
"mmckenzie.stockcontrol/supplierDAO"
I fully expect that this is going to be user error. Any guidence is most welcome.
JAVA CODE:
package model;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.xml.bind.JAXBException;
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class Test
{
public static void main(String[] args)
{
try {
URL schema = new URL("http://localhost:8080/stockcontrol/schema/stockcontrol.xsd");
InputStream xsd = schema.openStream();
EntityResolver er = new EntityResolver()
{
#Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
{
URL schema = new URL("http://localhost:8080/stockcontrol/schema/"+(new File(systemId)).getName());
InputStream xsd = schema.openStream();
InputSource is = new InputSource(xsd);
is.setSystemId(schema.getPath());
return is;
}
};
//create the context from the XSD
DynamicJAXBContext xmlContext = DynamicJAXBContextFactory.createContextFromXSD(xsd,er, null, null);
//create a DYNAMICEntity for the supplier object.
DynamicEntity de = xmlContext.newDynamicEntity("mmckenzie.stockcontrol/supplier");
}
catch (IOException | JAXBException e)
{
e.printStackTrace();
}
}
}
XSD
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema elementFormDefault="qualified" version="1.0" targetNamespace="mmckenzie.stockcontrol" xmlns:tns="mmckenzie.stockcontrol" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="stockcontrol2.xsd"/>
<xs:element name="batch" type="tns:batchDAO"/>
<xs:element name="batches" type="tns:batchesDAO"/>
<xs:element name="component" type="tns:componentDAO"/>
<xs:element name="components" type="tns:componentsDAO"/>
<xs:element name="prefixes" type="tns:componentPrefixesDAO"/>
<xs:element name="product" type="tns:productDAO"/>
<xs:element name="product_batches" type="tns:productBatchesDAO"/>
<xs:element name="productbatch" type="tns:productBatchDAO"/>
<xs:element name="products" type="tns:productsDAO"/>
<xs:element name="supplier" type="tns:supplierDAO"/>
<xs:element name="suppliers" type="tns:suppliersDAO"/>
<xs:complexType name="batchesDAO">
<xs:sequence>
<xs:element name="batch" type="tns:batchDAO" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="batchDAO">
<xs:sequence>
<xs:element name="idbatch" type="xs:int"/>
<xs:element name="dateReceived" type="xs:long"/>
<xs:element name="dateConsumed" type="xs:long"/>
<xs:element name="invoice" type="xs:string" minOccurs="0"/>
<xs:element name="qty" type="xs:int"/>
<xs:element name="qtyInStock" type="xs:int"/>
<xs:element name="unitCost" type="xs:decimal" minOccurs="0"/>
<xs:element name="componentId" type="xs:int"/>
<xs:element name="supplierId" type="xs:int"/>
<xs:element name="unitType" type="unitType" minOccurs="0"/>
<xs:element name="isActive" type="xs:boolean"/>
<xs:element ref="tns:products" minOccurs="0"/>
<xs:element name="batchCost" type="xs:decimal" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="productsDAO">
<xs:sequence>
<xs:element name="product" type="tns:productDAO" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="productDAO">
<xs:sequence>
<xs:element name="idProduct" type="xs:int"/>
<xs:element name="cost" type="xs:decimal" minOccurs="0"/>
<xs:element name="description" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:int"/>
<xs:element name="sellPrice" type="xs:decimal" minOccurs="0"/>
<xs:element name="productBatches" type="tns:productBatchesDAO" minOccurs="0"/>
<xs:element name="date_sold" type="timestamp" minOccurs="0"/>
<xs:element name="date_produced" type="timestamp" minOccurs="0"/>
<xs:element ref="tns:components" minOccurs="0"/>
<xs:element name="hours_worked" type="xs:double"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="productBatchesDAO">
<xs:sequence>
<xs:element name="productbatches" type="tns:productBatchDAO" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="productBatchDAO">
<xs:sequence>
<xs:element ref="tns:component" minOccurs="0"/>
<xs:element ref="tns:batch" minOccurs="0"/>
<xs:element name="quantyUsed" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="componentDAO">
<xs:sequence>
<xs:element name="idcomponent" type="xs:int"/>
<xs:element name="componentName" type="xs:string" minOccurs="0"/>
<xs:element ref="tns:batches" minOccurs="0"/>
<xs:element name="componentPrefix" type="componentPrefix" minOccurs="0"/>
<xs:element name="qtyInStock" type="xs:int"/>
<xs:element ref="tns:products" minOccurs="0"/>
<xs:element name="quantity" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="componentsDAO">
<xs:sequence>
<xs:element name="component" type="tns:componentDAO" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="suppliersDAO">
<xs:sequence>
<xs:element name="supplier" type="tns:supplierDAO" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="supplierDAO">
<xs:sequence>
<xs:element name="idsupplier" type="xs:int"/>
<xs:element name="modified" type="timestamp" minOccurs="0"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element ref="tns:batches" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="componentPrefixesDAO">
<xs:sequence>
<xs:element name="prefix" type="componentPrefix" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
All comments suggestions most welcome.
The way that it creates the namespaces is not what I was expecting. The correct answer for this example would be
DynamicEntity de = xmlContext.newDynamicEntity("stockcontrol.mmckenzie.SupplierDAO");
This article was useful in finding the resolution.
Appendix D: Binding XML Names to Java Identifiers" of the Java Architecture for XML Binding (JAXB) 2.2 Specification (http://jcp.org/en/jsr/detail?id=222)
However using the eclipse debugger I was able for find the Helper names spaces. To use this method follow these steps in eclipse (Mars in mycase).
start your app in debugger with a break point just after your DynamicJAXBContext code.
in the eclipse varibles tab, find your DynamicJAXBContext object.
(your context)->ContextState->Helpers->ElementData->(non null object)->fqClassNameToDescripters->table->(non null entry)->key
The key value will give you an idea of what namespace it is expecting.

Reusable complexType, and xml-registry, xml-element-decl usage

I've the below TimePeriodType
<xs:simpleType name="UnitOfTimePeriodType">
<xs:restriction base="xs:token">
<xs:enumeration value="Months"/>
<xs:enumeration value="Days"/>
<xs:enumeration value="Years"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="TimePeriodType">
<xs:sequence>
<xs:element name="Length" type="digit1-3"/>
</xs:sequence>
<xs:attribute name="unitOfLength" type="UnitOfTimePeriodType" use="optional" default="Months"/>
</xs:complexType>
which gets used in multiple types as shown below
<xs:complexType name="USAddressType">
<xs:complexContent>
<xs:extension base="AddressType">
<xs:sequence>
<xs:element name="LengthAtAddress" type="TimePeriodType" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="CanadaAddressType">
<xs:complexContent>
<xs:extension base="AddressType">
<xs:sequence>
<xs:element name="LengthAtAddress" type="TimePeriodType" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
So, the below instance xml
<LengthAtAddress unitOfLength="Months">
<Length>36</Length>
</LengthAtAddress>
should be mapped to the following pojo
public abstract class AbstractAddress
{
protected int lengthAtAddress;
protected UnitOfLengthType unitOfLengthAtAddress;
public int getLengthAtAddress()
{
return lengthAtAddress;
}
public UnitOfLengthType getUnitOfLengthAtAddress()
{
return unitOfLengthAtAddress;
}
//setters
}
I think I should be using a combination of xml-registry and xml-element-decl while using external mapping. Not able to figure our how. Any help is appreciated.
FIX
<xml-element java-attribute="lengthAtAddress" xml-path="LengthAtAddress/Length/text()"/>
<xml-element java-attribute="unitOfLengthAtAddress" xml-path="LengthAtAddress/#unitOfLength">
<xml-java-type-adapter value="com.equifax.ic.platform.sts.domain.transformation.response.CommonsEnumAdapter"/>
</xml-element>
You could use MOXy's #XmlPath extension or the equivalent in MOXy's external mapping document.
#XmlPath("LengthAtAddress/Length/text()")
public int getLengthAtAddress()
{
return lengthAtAddress;
}

SAXParserException while trying to read the xsd

My project has a JAXWS class where an XSD is read and finally validated in another method.
Here is the java code where they read the XSD
private static final ThreadLocal <DocumentBuilder> parser =
new ThreadLocal <DocumentBuilder> () {
#Override protected DocumentBuilder initialValue() {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// loading Schema file
//System.out.println("Hi .. am in parser");
DocumentBuilder parserBuilder = null;
if(finalXsd !=null){
logger.info("finalXsd FILE"+finalXsd);
Source schemaFile = new StreamSource(new File(finalXsd));
try{
logger.info ("place-0") ;
Schema schema = factory.newSchema(schemaFile);
logger.info ("place-1") ;
docBuilderFactory.setValidating(false); // true is used for DTD based validation, for schema validation set to false
logger.info ("place-2") ;
docBuilderFactory.setSchema(schema);
logger.info ("place-3") ;
parserBuilder = docBuilderFactory.newDocumentBuilder();
logger.info ("place-4") ;
parserBuilder.setErrorHandler( new JythonResponseErrorHandler() );
logger.info ("place-5") ;
}catch(SAXException s)
{
logger.error("SAXException in ThreadLocal.");
s.printStackTrace() ;
return null;
} catch (ParserConfigurationException e) {
e.printStackTrace();
logger.error("ParserConfigurationException in ThreadLocal.");
return null;
}
}
return parserBuilder;
}
};
XSD FILE (which the above code trying to read) :
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2010 rel. 2 (http://www.altova.com) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="TAG">
<xs:complexType>
<xs:attribute name="name" use="required" type="xs:string" />
<xs:attribute name="value" use="optional" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="STRING">
<xs:complexType>
<xs:sequence>
<xs:element ref="EN" />
<xs:element ref="ES" />
</xs:sequence>
<xs:attribute name="name" use="required" type="xs:string">
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="FRACTION">
<xs:complexType>
<xs:sequence>
<xs:element ref="N" />
<xs:element ref="D" />
</xs:sequence>
<xs:attribute name="name" use="required" >
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="RESULTLIST">
<xs:complexType>
<xs:sequence>
<xs:element ref="RESPONSE" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="RESPONSE">
<xs:complexType mixed="true" >
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PLURAL">
<xs:complexType>
<xs:sequence>
<xs:element ref="STRING" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NAME">
<xs:complexType>
<xs:sequence>
<xs:element ref="STRING" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="INTEGER">
</xs:element>
<xs:element name="ID" type="xs:int">
</xs:element>
<xs:element name="GENDER">
<xs:complexType>
<xs:sequence>
<xs:element ref="STRING" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="BOOL">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:boolean">
<xs:attribute name="name" use="required" type="xs:string">
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="FILE_ID" type="xs:int">
</xs:element>
<xs:element name="ES" type="xs:string" />
<xs:element name="EN" type="xs:string" />
<xs:element name="N" type="xs:int" />
<xs:element name="D" type="xs:int" />
<xs:element name="DICTIONARY">
<xs:complexType mixed="true">
<xs:choice>
<xs:any minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:attribute name="name" use="required" type="xs:string">
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="ASSET">
<xs:complexType>
<xs:sequence>
<xs:element ref="NAME" />
<xs:element ref="PLURAL" />
<xs:element ref="ALTTEXT" />
<xs:element ref="GENDER" />
<xs:element ref="ID" />
<xs:element ref="FILE_ID" />
<xs:element ref="DICTIONARY" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="name" use="required" >
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="ARRAY">
<xs:complexType>
<xs:choice>
<xs:element ref="ARRAY" minOccurs="0" maxOccurs="unbounded" />
<xs:element ref="STRING" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="ASSET" maxOccurs="unbounded"/>
<xs:element ref="INTEGER" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="FRACTION" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="DICTIONARY" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:attribute name="name" use="required" type="xs:string">
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="ALTTEXT">
<xs:complexType>
<xs:sequence>
<xs:element ref="STRING" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
while sending a response from SOAP-UI, the above code gets executed and throws below exception
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'file:/D:/softwares/jboss-5.1.0.GA/server/default/deploy/poctest.war/WEB-INF/classes/final.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:594)
at com.hmco.ssms.services.poc.SoarPocJaxWS$1.initialValue(SoarPocJaxWS.java:59)
at com.hmco.ssms.services.poc.SoarPocJaxWS$1.initialValue(SoarPocJaxWS.java:46)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:141)
at java.lang.ThreadLocal.get(ThreadLocal.java:131)
at com.hmco.ssms.services.poc.SoarPocJaxWS.getParametersMultiple(SoarPocJaxWS.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.wsf.container.jboss50.invocation.InvocationHandlerJSE.invoke(InvocationHandlerJSE.java:108)
at org.jboss.ws.core.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:222)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHandlerImpl.java:474)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:295)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl.java:205)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:131)
at org.jboss.wsf.common.servlet.AbstractEndpointServlet.service(AbstractEndpointServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
I even tried changing XS to XSD in the xsd file. but stil i get this exception.
Please help me on this
Thanks
Arun
Issue is fixed,
This is because, in jboss-5 the files inside the WAR file cannot be read using getResource() and hence there were no proper file-binding SchemaFactory
I changed the path of the file and now it is working cool !!

Resources