Hello Keith,
Thanks for your inputs, I am making progress and want to improve further the
way I am mapping my objects. The classes basically I have are like this:
Public class TcmMdlListeEntites{
ArrayList _list;
ArrayList _listeComptes;
ArrayList _listePersonnes;
}
Public abstract class TcmModel{
}
Public class TcmMdlCompte extends TcmModel{
}
Public class TcmMdlPersonne extends TcmModel{
}
The application adds a TcmModel to the _list and it could either be
TcmMdlCompte or TcmMdlPersonne or any other
Derived class.
I want to get rid of these 2 list variables just to handle sub-classes. The
mapping I have currently is this:
<?xml version="1.0"?>
<mapping>
<class name="tcm.mdl.TcmMdlListeEntites" auto-complete="false">
<map-to xml="TCM"/>
<field name="_listeComptes" type="tcm.mdl.TcmMdlCompte"
collection="arraylist" get-method="getComptes" set-method="setListeComptes">
<bind-xml name="Compte" node="element"/>
</field>
<field name="_listePersonnes" type="tcm.mdl.TcmMdlPersonne"
collection="arraylist" get-method="getPersonnes" set-method="setListePersonnes">
<bind-xml name="Personne" node="element"/>
</field>
</class>
<class name="tcm.mdl.TcmMdlCompte" auto-complete="false">
<map-to xml="Compte"/>
<field name="_refPersonne" type="string" get-method="getRefPersonne"
set-method="setRefPersonne">
<bind-xml name="ReferencePersonne" node="element"/>
</field>
<field name="_typeImpot" type="string" get-method="getTypeImpot"
set-method="setTypeImpot">
<bind-xml name="TypeImpot" node="element"/>
</field>
<field name="_anneeFiscale" type="string" get-method="getAnneeFiscale"
set-method="setAnneeFiscale">
<bind-xml name="AnneeFiscale" node="element"/>
</field>
<field name="_numeroOrdre" type="string" get-method="getNumeroOrdre"
set-method="setNumeroOrdre">
<bind-xml name="NumeroOrdre" node="element"/>
</field>
</class>
<class name="tcm.mdl.TcmMdlPersonne" auto-complete="false">
<map-to xml="Personne"/>
<field name="_referencePersonne" type="string"
get-method="getReferencePersonne" set-method="setReferencePersonne">
<bind-xml name="ReferencePersonne" node="element"/>
</field>
</class>
</mapping>
Which gives me this after marshalling:
<?xml version="1.0" encoding="UTF-8"?>
<TCM>
<Compte>
<ReferencePersonne>14602769</ReferencePersonne>
<TypeImpot>90</TypeImpot>
<AnneeFiscale>2002</AnneeFiscale>
<NumeroOrdre>1</NumeroOrdre>
</Compte>
<Personne>
<ReferencePersonne>14602769</ReferencePersonne>
</Personne>
</TCM>
Is there a way that a mapping file could work with just the _list variable
without having to create 2 separate lists for sub-classes ? Is there a mapping
like this somewhere or would really appreciate if you get time to provide a
mapping that can do this...I will implement this if possible across all our
apps...
I am refactoring the application and trying to do things the best way possible.
Would appreciate your inputs.
Thanks a lot
Saurabh
-----Message d'origine-----
De : Keith Visco [mailto:[EMAIL PROTECTED]
Envoyé : mercredi, 9. novembre 2005 05:52
À : [email protected]
Objet : Re: TR: [castor-user] Problem while unmarshalling
Does your getListeComptes() method return the actual ArrayList or a copy
of it? Unfortunately, Castor will actually attempt to incrementally add
the items to the ArrayList returned from the getter. If it returns a
copy then that explains why the list is empty after unmarshalling. There
are two workarounds:
1. Return the actual list reference instead of a copy
-or-
2. Specify an add method instead of the actual list mutator, for example:
set-method="addListeCompte"
where you have a method defined as such:
public void addListeCompte(Compte compte) {
_myListCompte.add(compte);
}
HTH,
--Keith
Bhatia Saurab (CHA) wrote:
> Gentlemen,
> I also tried using the approach listed on the castor site to get my
> unmarshalling to work but to no avail yet :-(. This is the xml I am
> trying to unmarshall ...
>
> Please note that marshalling works just fine thanks to Castor...If you
> need any classes, I would be glad to post ...
>
> Thanks a lot and I am sure there is solution somewhere...maybe I should
> try another way to unmarshal. I am not using descriptors since there
> arent really any constraints to define yet....
>
> <?xml version="1.0" encoding="UTF-8"?>
> <TCM>
> <Compte>
> <ReferencePersonne>14602769</ReferencePersonne>
> <TypeImpot>90</TypeImpot>
> <AnneeFiscale>2002</AnneeFiscale>
> <NumeroOrdre>1</NumeroOrdre>
> </Compte>
> <Personne>
> <ReferencePersonne>14602769</ReferencePersonne>
> </Personne>
> </TCM>
>
> -------------------------------------------------------------------
> TcmMdlListeAExporter listeLue = null ;
> Unmarshaller unmarshaller = null;
> InputSource is = null;
> try
> {
> if (pFile.exists())
> is = new InputSource(new FileReader(pFile));
> // Create a new Unmarshaller
> unmarshaller = new Unmarshaller(TcmMdlListeAExporter.class);
> unmarshaller.setMapping(pMapping);
> // Unmarshal the person object
> listeLue = (TcmMdlListeAExporter)unmarshaller.unmarshal(is);
> } catch ....
>
>
> ------------------------------------------------------------------------
> *De :* Bhatia Saurabh (CHA) [mailto:[EMAIL PROTECTED]
> *Envoyé :* lundi, 7. novembre 2005 13:40
> *À :* [email protected]
> *Objet :* [castor-user] Problem while unmarshalling
>
> Hi,
>
> A) I am only using a mapping file for marshalling and unmarshalling
> "sans descriptors" since its supposedly quite straightforward and I dont
> have many XML schema constraints to specify in the descriptors anyway.
>
> It works all fine for marshalling but the unmarshalling doesnt work at all.
>
> unmarshaller = new Unmarshaller(pMapping);
> listeLue = (TcmMdlListeAExporter)unmarshaller.unmarshal(new
> InputSource(new FileReader(file)));
>
> My "listeLue" variable which is an ArrayList is always empty after
> execution of this statement. Maybe I should unmarshall another way...
>
> Thanks in advance
>
> <mapping>
> <class name="tcm.mdl.TcmMdlListeAExporter" auto-complete="false">
> <map-to xml="TCM"/>
> <field name="_listeComptes" type="tcm.mdl.TcmMdlCompte"
> collection="arraylist" get-method="getListeComptes"
> set-method="setListeComptes">
>
> <bind-xml name="Compte" node="element"/>
> </field>
> <field name="_listePersonnes" type="tcm.mdl.TcmMdlPersonne"
> collection="arraylist" get-method="getListePersonnes"
> set-method="setListePersonnes">
>
> <bind-xml name="Personne" node="element"/>
> </field>
> </class>
> <class name="tcm.mdl.TcmMdlCompte" auto-complete="false">
> <map-to xml="Compte"/>
> <field name="_refPersonne" type="string"
> get-method="getRefPersonne" set-method="setRefPersonne">
> <bind-xml name="ReferencePersonne" node="element"/>
> </field>
> <field name="_typeImpot" type="string" get-method="getTypeImpot"
> set-method="setTypeImpot">
> <bind-xml name="TypeImpot" node="element"/>
> </field>
> <field name="_anneeFiscale" type="string"
> get-method="getAnneeFiscale" set-method="setAnneeFiscale">
> <bind-xml name="AnneeFiscale" node="element"/>
> </field>
> <field name="_numeroOrdre" type="string"
> get-method="getNumeroOrdre" set-method="setNumeroOrdre">
> <bind-xml name="NumeroOrdre" node="element"/>
> </field>
> </class>
> <class name="tcm.mdl.TcmMdlPersonne" auto-complete="false">
> <map-to xml="Personne"/>
> <field name="_referencePersonne" type="string"
> get-method="getReferencePersonne" set-method="setReferencePersonne">
>
> <bind-xml name="ReferencePersonne" node="element"/>
> </field>
> </class>
> </mapping>
>
>
>
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------