/*
 * Cr�� le 27 juin 07
 *
 * Pour changer le mod�le de ce fichier g�n�r�, allez � :
 * Fen�tre&gt;Pr�f�rences&gt;Java&gt;G�n�ration de code&gt;Code et commentaires
 */

package fr.gouv.finances.cp.xemelios.export;

import java.util.Vector;

import org.xml.sax.SAXException;

import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;

public class ExportModel implements XmlMarshallable {
	
	public static String TAG = "export";
	
	private Vector<ExportElementModel> enfants;
	private String id, libelle, code;
	
	public ExportModel (String tagName) {
		id = libelle = code = "";
		enfants = new Vector<ExportElementModel>();
	}

	public void addCharacterData(String cData) throws SAXException {}

	public void addChild(XmlMarshallable child, String tagName) throws SAXException {
		enfants.add((ExportElementModel)child);
	}

	public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
		id = attributes.getValue("id");
		libelle = attributes.getValue("libelle");
		code = attributes.getValue("code");
		return this;
	}

	public void marshall(XmlOutputter output) {
		output.startTag("export");
		output.addAttribute("id", id);
		output.addAttribute("libelle", libelle);
		output.addAttribute("code", code);
		for (ExportElementModel em:enfants) { em.marshall(output); }
		output.endTag("export");
	}
	
	public ExportModel clone () {
		ExportModel em = new ExportModel(TAG);
		em.setId(id);
		em.setLibelle(libelle);
		em.setCode(code);
		for (ExportElementModel e:enfants) {
			try { em.addChild(e, ""); } catch (Exception ex) {}
		}
		return em;
	}

	public void validate() throws InvalidXmlDefinition {}

	public Vector<ExportElementModel> getEnfants() {
		return enfants;
	}

	public void setEnfants(Vector<ExportElementModel> enfants) {
		this.enfants = enfants;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getLibelle() {
		return libelle;
	}

	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public void addEnfant (ExportElementModel enf) {
		if (this.enfants==null) this.enfants = new Vector<ExportElementModel>();
		this.enfants.add(enf);
	}
}
