Hi Todd,

Yes, it's definitely possible to map polymorphic collections in a couple 
of different ways. But to do so, you need to make use of the class 
structure. Your binding references the (private) fields of the abstract 
base class directly from within the <mapping> of the child class, so the 
fields aren't found by the binding compiler and you get the errors.

The binding tutorial has a section discussing this: 
http://jibx.sourceforge.net/tutorial/binding-mappings.html#inherit The 
key point is that if you want to make use of an abstract <mapping> for a 
base class you use a <struct map-as="base-class-name"> to do so. I did 
try to improve this section of the tutorial somewhat in the latest 
version, so may have clarified some issues that were ambiguous in the 
1.1.3 docs. You may also want to update to the 1.1.5 release, since I 
fixed a few issues relating to polymorphism in that release.

  - Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Todd Nine wrote:
> Hello all,
>   I have several objects that subclass my base abstract object.  Is it 
> possible to map a polymorphic collection?  I'm trying to do so, but 
> the compiler (version 1.1.3) won't accept my mapping documents.  Below 
> are my classes and binding configuration.  Any help would be greatly 
> appreciated.  I'm using the maven2 jibx plugin, and have changed the 
> dependency version of jibx to 1.1.3, and re-deployed as a custom 
> modified plugin.  I receive the following error.
>
> [INFO] [jibx:bind]
> [INFO] Running JiBX binding compiler (single-module mode) on 1 binding 
> file(s)
> Running binding compiler version jibx_1_1_3
> Error: Nonstatic field suffix not found in class 
> com.purdueefcu.statements.processor.bean.Savings; on value element at 
> (line 50, col 41, in statement-binding.xml)
> Error: Nonstatic field description not found in class 
> com.purdueefcu.statements.processor.bean.Savings; on value element at 
> (line51, col 51, in statement-binding.xml)
> Error: Nonstatic field beginningBalance not found in class 
> com.purdueefcu.statements.processor.bean.Savings ; on value element at 
> (line 52, col 61, in statement-binding.xml)
> Error: Nonstatic field totalDeposits not found in class 
> com.purdueefcu.statements.processor.bean.Savings; on value element at 
> (line 53, col 55, in statement-binding.xml )
> Error: Nonstatic field totalWithdrawals not found in class 
> com.purdueefcu.statements.processor.bean.Savings; on value element at 
> (line 54, col 61, in statement-binding.xml)
> Error: Nonstatic field endingBalance not found in class 
> com.purdueefcu.statements.processor.bean.Savings; on value element at 
> (line 55, col 55, in statement-binding.xml)
>
> Thanks,
> Todd
>
> binding file
>
> <?xml version="1.0" encoding="UTF-8"?>
> <binding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>     xsi:noNamespaceSchemaLocation="binding.xsd">
>
>     <!--  statement info -->
>     <mapping class="com.purdueefcu.statements.processor.bean.Statement"
>         name="Statement">
>         <value name="startDate" field="startDate" />
>         <value name="endDate" field="endDate" />
>         <value name="accountNumber" field="accountNumber" />
>         <value name="name" field="name" />
>         <value name="jointName" field="jointName" />
>         <value name="name" field="name" />
>         <structure field="emailInfo" />
>     </mapping>
>
>     <!--  email info -->
>     <mapping class=" com.purdueefcu.statements.processor.bean.EmailInfo"
>         name="EmailInfo">
>         <value name="address" field="address" />
>         <value name="subject" field="subject" />
>         <value name="message" field="message" />
>         <value name="from" field="from" />
>     </mapping>
>
>     <!--  Transaction mapping -->
>     <mapping
>         class="com.purdueefcu.statements.processor.bean.Transaction"
>         name="Transaction">
>         <value name="description" field="description" />
>         <value name="date" field="date" />
>         <value name="balance" field="balance" />
>         <value name="amount" field="amount" />
>     </mapping>
>
>     <!--Abstract share mapping.  All child shares should extend this 
> mapping since it maps 70%+ of the attributes-->
>     <mapping class="com.purdueefcu.statements.processor.bean.Share " 
> abstract="true">
>         <value name="suffix" field="suffix" />
>         <value name="description" field="description" />
>         <value name="beginningBalance" field="beginningBalance" />
>         <value name="totalDeposits" field="totalDeposits" />
>         <value name="totalWithdrawals" field="totalWithdrawals" />
>         <value name="endingBalance" field="endingBalance" />
>         <!--TODO Once we're done with initial prototyping remove 
> flexible = true to make sure we've mapped all our sub classes-->
>         <collection field="transactions" flexible="true" 
> ordered="false"/>
>     </mapping>
>
>     <!--Savings binding, should extend Share bindings-->
>     <mapping class="com.purdueefcu.statements.processor.bean.Savings" 
> name="Savings">
>         <value name="suffix" field="suffix" />
>         <value name="description" field="description" />
>         <value name="beginningBalance" field="beginningBalance" />
>         <value name="totalDeposits" field="totalDeposits" />
>         <value name="totalWithdrawals" field="totalWithdrawals" />
>         <value name="endingBalance" field="endingBalance" />
>     </mapping>
> </binding>
>
> Objects (share and savings)
>
>
> /**
>  * The bean that represents shares
>  *
>  * @author Todd Nine
>  */
> public abstract class Share {
>
>     private String suffix;
>
>     private BigDecimal beginningBalance;
>    
>     private BigDecimal totalDeposits;
>
>     private BigDecimal totalWithdrawals;
>
>     private BigDecimal endingBalance;
>    
>     private String description;
> ..setters and getters
> }
>
> /**
>  * The bean that holds our savings information
>  *
>  * @author Todd Nine
>  */
> public class Savings extends Share {
>
>     private BigDecimal apy;
>    
>     private BigDecimal apye;
>    
>     private BigDecimal dividendsEarned;
>    
>     private BigDecimal ytdDividends;
>
> ..setters and getters..
> }
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>   

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to