Hi All:
I am new to Castor and I am using it in one of my projects. I am stuck with
a problem of using a non default constructor for a field specified as
interface (see below). I know we can use xsi:type in the xml to specify the
concrete implementation of the interface. But I have not been able to
specify the value to intialize the concrete instance ? If I use the value
in the element text (as shown below) - I get an exception:
org.xml.sax.SAXException: Illegal Text data found as child of processor
The text indicated in the exception is actually the value with which I'd
like to initialize the object ?
Here is a sample scenario from Castor's documentation:
Java class:
public interface IProcessor
{
public void process();
}
..
public class Engine
{
private IProcessor processor;
public IProcessor getProcessor()
{
return processor;
}
public void setProcessor(IProcessor processor)
{
this.processor = processor;
}
}
A typical mapping file for such a design may be:
<mapping>
<class name="Engine">
<map-to xml="engine" />
<field name="processor" type="IProcessor" required="true">
<bind-xml name="processor" node="element" />
</field>
</class>
</mapping>
XML file:
...
<engine>
<processor xsi:type="java:com.abc.MyProcessor" />
</engine>
...
In my case com.abc.MyProcessor has no default constructors. I tried:
<engine>
<processor xsi:type="java:com.abc.MyProcessor">abc</processor>
</engine>
to initialize MyProcessor with the data "abc"
But this results in the above mentioned exception.
Any suggestions would be greatly appreciated.
Thanks.
I am new to Castor and I am using it in one of my projects. I am stuck with
a problem of using a non default constructor for a field specified as
interface (see below). I know we can use xsi:type in the xml to specify the
concrete implementation of the interface. But I have not been able to
specify the value to intialize the concrete instance ? If I use the value
in the element text (as shown below) - I get an exception:
org.xml.sax.SAXException: Illegal Text data found as child of processor
The text indicated in the exception is actually the value with which I'd
like to initialize the object ?
Here is a sample scenario from Castor's documentation:
Java class:
public interface IProcessor
{
public void process();
}
..
public class Engine
{
private IProcessor processor;
public IProcessor getProcessor()
{
return processor;
}
public void setProcessor(IProcessor processor)
{
this.processor = processor;
}
}
A typical mapping file for such a design may be:
<mapping>
<class name="Engine">
<map-to xml="engine" />
<field name="processor" type="IProcessor" required="true">
<bind-xml name="processor" node="element" />
</field>
</class>
</mapping>
XML file:
...
<engine>
<processor xsi:type="java:com.abc.MyProcessor" />
</engine>
...
In my case com.abc.MyProcessor has no default constructors. I tried:
<engine>
<processor xsi:type="java:com.abc.MyProcessor">abc</processor>
</engine>
to initialize MyProcessor with the data "abc"
But this results in the above mentioned exception.
Any suggestions would be greatly appreciated.
Thanks.
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
