[482] | 1 | /** |
---|
| 2 | * Created on 17 Jan. 2007 |
---|
| 3 | * * @author |
---|
| 4 | */ |
---|
| 5 | package integration.lecture_ecriture; |
---|
| 6 | |
---|
[484] | 7 | import com.medias.EcritureLog; |
---|
[482] | 8 | import integration.exceptions.*; |
---|
| 9 | import integration.utils.Constantes; |
---|
| 10 | import integration.vues.ParametreModele; |
---|
| 11 | import java.io.File; |
---|
| 12 | import java.util.*; |
---|
| 13 | import org.jdom.Element; |
---|
| 14 | /** |
---|
| 15 | * Lecture et déchiffrrage d'un modéle XML décrivant la structure d'un fichier |
---|
| 16 | * de données correspondant é un jeu donné. |
---|
| 17 | */ |
---|
| 18 | public class LectureModeleXML { |
---|
| 19 | |
---|
| 20 | private Element root; |
---|
| 21 | |
---|
| 22 | private String categorie; |
---|
| 23 | |
---|
| 24 | private String jeu; |
---|
| 25 | |
---|
| 26 | public LectureModeleXML(String categorie, String jeu) { |
---|
| 27 | this.categorie = categorie; |
---|
| 28 | this.jeu = jeu; |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | public void lireModele() { |
---|
| 32 | // Chemin du modéle xml é manipuler |
---|
| 33 | String modele = Constantes.cheminModeles + "/" + categorie + "/" + jeu + "_modele.xml"; |
---|
| 34 | // Etape de Construction du "parser XML" |
---|
| 35 | XMLParser builder = new XMLParser(); |
---|
| 36 | File f = new File(modele); |
---|
| 37 | if (f.exists()) { |
---|
| 38 | try { |
---|
| 39 | builder.readXml(modele); |
---|
| 40 | // EcritureLog.ecrire("******* Modéle du jeu de données : "+ f.getName() + " *******", "out"); |
---|
| 41 | } catch (XMLException e) { |
---|
| 42 | e.printStackTrace(); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | } else { |
---|
[484] | 46 | EcritureLog.ecrire( "Fichier " + f.getName() + " non trouvé !", "err" ); |
---|
[482] | 47 | } |
---|
| 48 | root = builder.getRoot(); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | // Partie faisant référence é l'entéte |
---|
| 52 | public String getNomCategorie() { |
---|
| 53 | return root.getChild("entete").getAttributeValue("categorie"); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | // Références relatives au jeu |
---|
| 57 | public String getNomJeu() { |
---|
| 58 | return root.getChild("entete").getAttributeValue("jeu"); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | // Description du jeu en question |
---|
| 62 | public String getDescriptionJeu() { |
---|
| 63 | return root.getChild("entete").getAttributeValue("description"); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | // Valeur absente |
---|
| 67 | public String getValeurAbsente() { |
---|
| 68 | return root.getChild("entete").getAttributeValue("valeur_absente"); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | // Noms relatifs aux organismes |
---|
| 72 | public String getNumOrganismeJeu() { |
---|
| 73 | return root.getChild("entete").getAttributeValue("organisme"); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // Delimiteur du modéle |
---|
| 77 | public String getDelimiteur() { |
---|
| 78 | return root.getChild("entete").getAttributeValue("delimiteur"); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | // Subdivision ou non |
---|
| 82 | public String getSubdiviser() { |
---|
| 83 | return root.getChild("entete").getAttributeValue("subdiviser"); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | // Coordonnées de la personne "pi" |
---|
| 87 | public String getNumeroPi() { |
---|
| 88 | return root.getChild("entete").getChild("pi").getAttributeValue( |
---|
| 89 | "numero"); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | // Coordonnées de la personne "contact" |
---|
| 93 | public String getNumeroContact() { |
---|
| 94 | return root.getChild("entete").getChild("contact").getAttributeValue("numero"); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | // Coordonnées de la personne "integrateur" |
---|
| 98 | public String getNumeroIntegrateur() { |
---|
| 99 | return root.getChild("entete").getChild("integrateur").getAttributeValue("numero"); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | // Partie des données é manimpuler |
---|
| 103 | /** |
---|
| 104 | * Renvoie les paramétres avec leurs caractéristiques dans une liste. |
---|
| 105 | * |
---|
| 106 | * @return La liste de tous les paramétres et leurs caractéristiques. |
---|
| 107 | */ |
---|
| 108 | public ArrayList<ParametreModele> getParametres() { |
---|
| 109 | ArrayList<ParametreModele> infosParam = new ArrayList<ParametreModele>(); |
---|
| 110 | Iterator<?> it = root.getChild("donnees").getChildren("parametre").iterator(); |
---|
| 111 | while (it.hasNext()) { |
---|
| 112 | Element child = (Element) it.next(); |
---|
| 113 | infosParam.add(new ParametreModele(child.getAttributeValue("nom"), |
---|
| 114 | child.getAttributeValue("type"), child.getAttributeValue("fonction"), |
---|
| 115 | child.getAttributeValue("unite"), child.getAttributeValue("delta"), |
---|
| 116 | child.getAttributeValue("numero"),child.getAttributeValue("format"),child.getAttributeValue("lod"))); |
---|
| 117 | } |
---|
| 118 | return infosParam; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * Renvoie les paramétres associés é une valeur avec leurs caractéristiques dans une liste. |
---|
| 123 | * |
---|
| 124 | * @return La liste de tous les paramétres associés et leurs caractéristiques. |
---|
| 125 | */ |
---|
| 126 | public ArrayList<ParametreModele> getParametresValeur() { |
---|
| 127 | ArrayList<ParametreModele> infosParam = new ArrayList<ParametreModele>(); |
---|
| 128 | Iterator<?> it = root.getChild("donnees").getChildren("parametre").iterator(); |
---|
| 129 | String fonction; |
---|
| 130 | while (it.hasNext()) { |
---|
| 131 | Element child = (Element) it.next(); |
---|
| 132 | fonction = child.getAttributeValue("fonction"); |
---|
| 133 | if (fonction.equals(Constantes.nomFonctionInsererVal)) { |
---|
| 134 | infosParam.add(new ParametreModele(child.getAttributeValue("nom"), |
---|
| 135 | child.getAttributeValue("type"), fonction, |
---|
| 136 | child.getAttributeValue("unite"), child.getAttributeValue("delta"), |
---|
| 137 | child.getAttributeValue("numero"), child.getAttributeValue("format"),child.getAttributeValue("lod"))); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | return infosParam; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | /** |
---|
| 144 | * Renvoie des numéros correspondant aux plateformes et leur références. |
---|
| 145 | */ |
---|
| 146 | // Liste des plateformes é manipuler |
---|
| 147 | public ArrayList<String> getNumsPlateforme() { |
---|
| 148 | ArrayList<String> numPlats = new ArrayList<String>(); |
---|
| 149 | Iterator<?> it = root.getChild("donnees").getChildren("plateforme").iterator(); |
---|
| 150 | Element child; |
---|
| 151 | while (it.hasNext()) { |
---|
| 152 | child = (Element) it.next(); |
---|
| 153 | numPlats.add(child.getAttributeValue("numero")); |
---|
| 154 | } |
---|
| 155 | return numPlats; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | /** |
---|
| 159 | * Renvoie des numéros correspondant aux capteurs et leur références. |
---|
| 160 | */ |
---|
| 161 | // Liste des capteurs é manipuler |
---|
| 162 | public ArrayList<String> getNumsCapteur() { |
---|
| 163 | ArrayList<String> numCapts = new ArrayList<String>(); |
---|
| 164 | Iterator<?> it = root.getChild("donnees").getChildren("capteur").iterator(); |
---|
| 165 | Element child; |
---|
| 166 | while (it.hasNext()) { |
---|
| 167 | child = (Element) it.next(); |
---|
| 168 | numCapts.add(child.getAttributeValue("numero")); |
---|
| 169 | } |
---|
| 170 | return numCapts; |
---|
| 171 | } |
---|
| 172 | } |
---|