com.ail.core.factory
Class CastorXMLFactory
java.lang.Object
com.ail.core.factory.AbstractFactory
com.ail.core.factory.CastorXMLFactory
public class CastorXMLFactory
- extends AbstractFactory
Factory to create class instances from XML using the core's FromXML service.
This builder expects to find a configuration parameter called either "Script" or Url", and optionally
a parameter called "Extends".
The "Script" and "Url" parameters offer alternative ways for the factory to find the XML string defining
the type. If "Script" is used, then the value if the Script parameter is taken to be a string of XML which
can be passed directly into castor. If "Url" is used, then the factory will attempt to load content from
the URL and pass that into castor.
The "Extends" parameter tells the factory that this type is based on another, and that it should merge
the values from that type into this one before returning. See Type.mergeDonorIntoSubject(Type, Type, Core)
for a description of the rules used during merging.
For example, assume that the following two types have been defined in configuration:
<type name="BaseType" builder="CastorXMLBuilder">
<parameter name="Script"><![CDATA[
<type lock="false" serialVersion="21" xsi:type="java:com.ail.core.Version" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<author>T.S.Elliot</author>
<comment>The loganberry's are sweet</comment>
<copyright>Copyright us.</copyright>
<version>1.0</version>
<attribute id="baseattr" format="string" value="2"/>
<attribute id='one' value='valueone'/>
<attribute id='two' value='valuetwo' format='string,32'/>
</type>
]]></parameter>
</type>
<type name="ExtendingType" builder="CastorXMLBuilder">
<parameter name="Extends">BaseType</parameter>
<parameter name="Script"><![CDATA[
<type lock="true" xsi:type="java:com.ail.core.Version" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<author>H.G.Wells</author>
<source>Peach and mint</source>
<state>state</state>
<date>27/07/2006</date>
<attribute id="subattr" format="string" value="2"/>
<attribute id="one" format="string" unit="feet"/>
<attribute id="two" value="overriden-two"/>
</type>
]]></parameter>
</type>
Here we have two types: BaseType, and ExtendingType, both of which define a Version. ExtendingType
extends BaseType. Incidentally, there is no reason why BaseType shouldn't extends another type.
The result of calling core.ToXML(core.newType("ExtendingType")) would be the following String:
<type lock="true" serialVersion="21" xsi:type="java:com.ail.core.Version" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<author>H.G.Wells</author>
<comment>The loganberry's are sweet</comment>
<source>Peach and mint</source>
<copyright>Copyright us.</copyright>
<state>state</state>
<date>27/07/2006</date>
<version>1.0</version>
<attribute id="subattr" format="string" value="2"/>
<attribute id="baseattr" format="string" value="2"/>
<attribute id="one" format="string" unit="feet"/>
<attribute id="two" value="overriden-two" format='string,32'/>
</type>
As you can see, in the resulting instance the property values defined in ExtendingType have overriden those is BaseType. So,
"H.G.Wells" has replaced "T.S.Elliot". But where ExtendingType doesn't define a value ('comment' for example), BaseType's
value appears in the result. Also, notice that the merge is 'deep'; if you look at the properties on the 'id="two"' attribute
you can see that the same merging rules have been applied to them.
- Version:
- $Revision: 1.8 $
- See Also:
CastorFromXMLService
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CastorXMLFactory
public CastorXMLFactory()