[Castor] problème de hiérarchisation de données
Bonjour,
Je débute dans l'utilisation de Castor, et je rencontre un petit soucis dans la hiérarchisation de mes données...
Voici mes classes Java :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| package fr.test.castor.ObjetXML;
import java.util.ArrayList;
public class StructurePERSONNE {
private String nom;
private String prenom;
private ArrayList<StructureADRESSE> adresse;
// constructors
/**
* constructeur de la classe
* @param nom
* @param prenom
* @param adresse
*/
public StructurePERSONNE(String nom, String prenom, ArrayList<StructureADRESSE> adresse) {
this.nom = nom;
this.prenom = prenom;
this.adresse = adresse;
}
/**
* constructeur de la classe
*/
public StructurePERSONNE() {
}
// getters and setters
/**
* @return the nom
*/
public String getNom() {
return nom;
}
/**
* @param nom the nom to set
*/
public void setNom(String nom) {
this.nom = nom;
}
/**
* @return the prenom
*/
public String getPrenom() {
return prenom;
}
/**
* @param prenom the prenom to set
*/
public void setPrenom(String prenom) {
this.prenom = prenom;
}
/**
* @return the adresse
*/
public ArrayList<StructureADRESSE> getAdresse() {
return adresse;
}
/**
* @param adresse the adresse to set
*/
public void setAdresse(ArrayList<StructureADRESSE> adresse) {
this.adresse = adresse;
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| package fr.test.castor.ObjetXML;
public class StructureADRESSE {
private String rue;
private String codePostal;
private String ville;
// constructors
/**
* constructeur de la classe
* @param rue
* @param codePostal
* @param ville
*/
public StructureADRESSE(String rue, String codePostal, String ville) {
this.rue = rue;
this.codePostal = codePostal;
this.ville = ville;
}
/**
* constructeur de la classe
*/
public StructureADRESSE() {
}
// getters and setters
/**
* @return the rue
*/
public String getRue() {
return rue;
}
/**
* @param rue the rue to set
*/
public void setRue(String rue) {
this.rue = rue;
}
/**
* @return the codePostal
*/
public String getCodePostal() {
return codePostal;
}
/**
* @param codePostal the codePostal to set
*/
public void setCodePostal(String codePostal) {
this.codePostal = codePostal;
}
/**
* @return the ville
*/
public String getVille() {
return ville;
}
/**
* @param ville the ville to set
*/
public void setVille(String ville) {
this.ville = ville;
}
} |
J'ai donc une classe StructurePERSONNE qui contient un élément adresse étant lui même une ArrayList d'éléments de type StructureADRESSE.
Il me faut obtenir en sortie un XML qui ressemble à :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <PERSONNE>
<NOM>LeHaricot</NOM>
<PRENOM>Toto</PRENOM>
<ADRESSE>
<ITEM>
<RUE>rue du Havre</RUE>
<CODE_POSTAL>92100</CODE_POSTAL>
<VILLE>Boulogne Billancourt</VILLE>
</ITEM>
<ITEM>
<RUE>rue des Couches Tards</RUE>
<CODE_POSTAL>75001</CODE_POSTAL>
<VILLE>Paris</VILLE>
</ITEM>
</ADRESSE>
</PERSONNE> |
or avec mon fichier de mapping :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN" "http://castor.org/mapping.dtd">
<mapping>
<description>Mapping de StructurePERSONNE</description>
<class name="fr.test.castor.ObjetXML.StructurePERSONNE">
<map-to xml="PERSONNE" />
<field name="nom">
<bind-xml name="NOM" />
</field>
<field name="prenom">
<bind-xml name="PRENOM" />
</field>
<field name="adresse" collection="arraylist" type="fr.ugap.sapconnexion.castor.ObjetXML.StructureADRESSE" >
<bind-xml name="ADRESSE" />
</field>
</class>
<class name="fr.test.castor.ObjetXML.StructureADRESSE">
<field name="rue">
<bind-xml name="RUE"/>
</field>
<field name="codePostal">
<bind-xml name="CODE_POSTAL"/>
</field>
<field name="ville">
<bind-xml name="VILLE"/>
</field>
</class>
</mapping> |
je n'obtient que :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <PERSONNE>
<NOM>LeHaricot</NOM>
<PRENOM>Toto</PRENOM>
<ADRESSE>
<RUE>rue du Havre</RUE>
<CODE_POSTAL>92100</CODE_POSTAL>
<VILLE>Boulogne Billancourt</VILLE>
</ADRESSE>
<ADRESSE>
<RUE>rue des Couches Tards</RUE>
<CODE_POSTAL>75001</CODE_POSTAL>
<VILLE>Paris</VILLE>
</ADRESSE>
</PERSONNE> |
c'est où que j'ai tout faux ???