I've got a class that has constructor:
public ContEmpirical(double xs[], double fs[]) {
Check.check(xs.length == fs.length + 1 && fs.length > 0,
"Empirical distribution array mismatch");
this.xs = new double[xs.length];
this.xs = xs;
this.cs = new double[xs.length];
double fTotal = 0.0;
for (int i = 0; i < fs.length; i++)
fTotal += fs[i];
cs[0] = 0;
for (int i = 0; i &l开发者_运维问答t; fs.length; i++)
cs[i + 1] = cs[i] + fs[i] / fTotal;
}
Attributes:
private double xs[], cs[];
private double fs[]; // this attribute i added to make castors life easier since it always wants to map constructor arg to class attribute.
The mapping File i have is:
<class name="tools.ContEmpirical">
<description xmlns="">
Mapping for class tools.ContEmpirical
</description>
<map-to xml="ContEmpirical"/>
<field name="xs" type="double" collection="array" set-method="%1" get-method="getXs" required="true">
<bind-xml node="attribute"/>
</field>
<field name="fs" type="double" collection="array" set-method="%2" get-method="getFs" required="true">
<bind-xml node="attribute"/>
</field></class>
Yet when i try to marshall an instance of ContEmpirical I get this XML:
<ContEmpirical xs="0.2 0.3 0.4 0.8"/>
When really I should be getting something like this:
<ContEmpirical xs="0.2 0.3 0.4 0.8" fs="0.2 0.3 0.4 0.8"/>
Is there something I'm missing from the mapping?
Can you post the ContEmpirical class? Are you initialising the fs array to something in the field level?
UPDATE: I must be missing something. You said you "expect" fs in the output xml. But does the class have an attribute named fs? From the constructor code you have posted, fs is never assigned internally (there is a parameter called fs though which is used for computing cs).
So really, your object has only a xs and cs variable and in your xml if you declare mapping for cs you should get cs.
精彩评论