开发者

Castor: Creating Mapping Files for Classes that have Abstract attributes

I have this class:

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 is an AbstractClass.

At the time of conversion from XML to Java Object, I will know which concrete implementation of my abstract class to use (via the bean name).

However, I'm not entirely sure how to write the mapping file to tell castor how to do the translation.

Any help would be much appreciated.


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

The auto-naming="deriveByClass" part means that if we send it will bind node name for the element embedded inside delay to an equivalent class which it hopes extends distributionSampler.

So passing its happy to process the following xml:

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

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

Will use the mapping files for Deterministic and Erlang to map it to the class instances whihc extend DistributionSampler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜