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

但是,我不完全确定如何编写映射文件来告诉 castor 如何进行翻译。

任何帮助将非常感激。

4

1 回答 1

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>

auto-naming="deriveByClass" 部分意味着如果我们发送它会将嵌入延迟中的元素的节点名称绑定到它希望扩展distributionSampler 的等效类。

所以通过它很高兴处理以下xml:

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

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

将使用 Deterministic 和 Erlang 的映射文件将其映射到扩展 DistributionSampler 的类实例。

于 2010-03-05T21:43:42.087 回答