2010-03-03 55 views
1

我有这个类:蓖麻:创建映射文件有抽象类属性

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 Object的转换时,我会知道要使用哪个抽象类的具体实现(通过bean名称)。

但是,我并不完全知道如何编写映射文件来告诉脚轮如何进行翻译。

任何帮助将不胜感激。

回答

1
<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> 

自动命名=“deriveByClass”部分是指,如果我们把它用于将内嵌延迟它希望扩展distributionSampler等价类中的元素绑定节点名称。

所以通过其乐意处理以下XML:

<Source name="asd"> 
    <delay> 
     <Deterministic time="234" /> 
    </delay> 

    <batchSize> 
     <Erlang K="234" Theta="234" /> 
    </batchSize> 
</Source> 

将用于确定性和Erlang的文件映射到其对应的类实例whihc延伸DistributionSampler。