Robert,
I'm unclear on how to map bean complex attributes. There is an example on
the betwixt guide
(http://jakarta.apache.org/commons/betwixt/guide/reading.html) under the
topic "Specifying An Implementation Class In The Betwixt File" which is
essentially what I need (a Bean containing a List of Beans),
however it doesn't address how to specify the custom mapping of the nested
bean -- ExampleImpl in this case. I'm assuming that a multi-mapping would be
the way to do
this?
The primary piece that is not clear to me is, at the point that the
Digester gets to the first element that should be a member of the list,
what is the path-mapping to the root element for the corresponding class
-- does this need to be specified somewhere?
I've read your post referring to betwixt multi-mappings, but it's not
clear a) if this has been implemented in the 0.6.1-dev.jar that I'm using,
and b) exactly what needs to be done to make this work.
I noticed that on the BeanReader's XMLIntrospector property, there is a
multimappingdigester property. Does this need to be explicitly set
somehow?
Here is a code snippet of what I'm implementing. When I run the code
below, I'm getting NullPointerException at beanReader.registerMultiMapping().
Please let me know if I'm on the right track here or not. Thanks in
advance.
Don
Example XML:
<Envelope>
<Body>
<Response>
<Contract pk="500-0847281-000">
<ContCustomerCreditAcct>33230373</ContCustomerCreditAcct>
<Asset pk="153384">
<AsEquipDesc>COPIER</AsEquipDesc>
</Asset>
<Asset pk="153385">
<AsEquipDesc>COPIER</AsEquipDesc>
</Asset>
</Contract>
</Response>
</Body>
</Envelope>
.betwixt file:
<?xml version="1.0" encoding="UTF-8"?>
<betwixt-config>
<!--name of the class to map -->
<class name="com.usbank.cw.leasing.valueobjects.buyout.AgmtDetailVO">
<element name='Contract' >
<attribute name='pk'
property='agmtNum'/>
<element name='ContCustomerName'
property='custName'/>
<element name='ContNumPymtsMade'
property='pymtsMade'/>
<element
name='ContCalcPymtSchedule' property='pymtFreq'/>
<element name='ContOriginalTerm'
property='contractTerm'/>
<element name='Asset'
property='assets'
class='com.usbank.cw.leasing.valueobjects.buyout.AssetVO'/>
<addDefaults/>
</element>
</class>
<class name="com.usbank.cw.leasing.valueobjects.buyout.AssetVO">
<element name='Asset' >
<attribute name='pk'
property='assetNumber'/>
<element name='AsEquipDesc'
property='equipDesc'/>
<element name='AsModel'
property='modelNum'/>
<element name='AsSerialNumber'
property='serialNum'/>
<element name='LocEquipZip'
property='equipZip'/>
<addDefaults/>
</element>
</class>
</betwixt-config>
// AgmtDetailVO bean (at element Contract) contains a list of AssetVO beans (at
element
Asset).
java.io.File file = new File("test_contract.xml");
java.io.FileReader filereader = new
java.io.FileReader(file);
java.io.FileInputStream fis = new
java.io.FileInputStream(file);
// Now convert this to a bean using betwixt
// Create BeanReader
BeanReader beanReader = new BeanReader();
// Configure the reader
// If you're round-tripping, make sure that the
configurations are
compatible!
beanReader.getXMLIntrospector().setAttributesForPrimitives(true);
beanReader.setMatchIDs(false);
//beanReader.getXMLIntrospector();
beanReader.addObjectCreate("Envelope/Body/Response/Contract",
AgmtDetailVO.class);
beanReader.addObjectCreate("Envelope/Body/Response/Contract/Asset",
AssetVO.class);
// Register beans so that betwixt knows what the xml is
to be converted to
// Since the element mapped to a PersonBean isn't
called the same,
// need to register the path as well
beanReader.registerMultiMapping(new InputSource(fis));
// Now we parse the xml
AgmtDetailVO agmt = (AgmtDetailVO)
beanReader.parse(filereader);
// send bean to system out
System.out.println(agmt);
------------------------------------------------------------------------------
Electronic Privacy Notice. This e-mail, and any attachments, contains
information that is, or may be, covered by electronic communications privacy
laws, and is also confidential and proprietary in nature. If you are not the
intended recipient, please be advised that you are legally prohibited from
retaining, using, copying, distributing, or otherwise disclosing this
information in any manner. Instead, please reply to the sender that you have
received this communication in error, and then immediately delete it. Thank you
in advance for your cooperation.
==============================================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]