Java Castor:为具有抽象属性的类创建映射文件
我有这门课:Java Castor:为具有抽象属性的类创建映射文件,java,spring,castor,Java,Spring,Castor,我有这门课: public class Source extends Node { protected DistributionSampler delay ; protected DistributionSampler batchsize ; /** * @param name The name of the source node * @param d The {@link DistributionSampler} used to generate the *
public class Source extends Node {
protected DistributionSampler delay ;
protected DistributionSampler batchsize ;
/**
* @param name The name of the source node
* @param d The {@link DistributionSampler} used to generate the
* inter-arrival times
*/
public Source( String name, DistributionSampler d ) {
super( name ) ;
delay = d ;
batchsize = new Deterministic( 1 ) ;
Sim.schedule( new Arrival( Sim.now() + delay.next() ) ) ;
}
/**
* @param name The name of the source node
* @param d The {@link DistributionSampler} used to generate the
* inter-arrival times
* @param b The {@link DistributionSampler} used to generate the
batch sizes
*/
public Source( String name, DistributionSampler d, DistributionSampler b ) {
super( name ) ;
delay = d ;
batchsize = b ;
Sim.schedule( new Arrival( Sim.now() + delay.next() ) ) ;
}
....
}
DistributionSampler是一个抽象类
在将XML转换为Java对象时,我将知道要使用抽象类的哪个具体实现(通过bean名称)
但是,我不完全确定如何编写映射文件来告诉castor如何进行转换
任何帮助都将不胜感激
<class name="network.Source">
<description xmlns="">
Default mapping for class network.Source
</description>
<map-to xml="Source"/>
<field name="name" type="java.lang.String" required="true">
<bind-xml node="element" />
</field>
<field name="delay" type="tools.DistributionSampler" required="true" set-method="initialiseDelay" get-method="getDelay">
<bind-xml auto-naming="deriveByClass" node="element" location="delay"/>
</field>
<field name="batchSize" type="tools.DistributionSampler">
<bind-xml auto-naming="deriveByClass" node="element" location="batchSize"/>
</field>
</class>
类网络的默认映射。源
auto naming=“deriveByClass”部分意味着,如果我们发送它,它将把delay中嵌入的元素的节点名绑定到一个它希望扩展distributionSampler的等效类
因此,我们很高兴处理以下xml:
<Source name="asd">
<delay>
<Deterministic time="234" />
</delay>
<batchSize>
<Erlang K="234" Theta="234" />
</batchSize>
</Source>
将使用Deterministic和Erlang的映射文件将其映射到扩展DistributionSampler的类实例。
类网络的默认映射。源
auto naming=“deriveByClass”部分意味着,如果我们发送它,它将把delay中嵌入的元素的节点名绑定到一个它希望扩展distributionSampler的等效类
因此,我们很高兴处理以下xml:
<Source name="asd">
<delay>
<Deterministic time="234" />
</delay>
<batchSize>
<Erlang K="234" Theta="234" />
</batchSize>
</Source>
将使用Deterministic和Erlang的映射文件将其映射到扩展DistributionSampler的类实例