/*
 * 
 * Copyright
 *  2009 axYus - www.axyus.com
 *  2009 Christophe Marchand <christophe.marchand@axyus.com>
 * 
 * This file is part of XEMELIOS.
 * 
 * XEMELIOS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * XEMELIOS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 */

package fr.gouv.finances.cp.xemelios.data.impl.mysql.serialization;

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;
import fr.gouv.finances.cp.xemelios.updater.config.TexteModel;
import fr.gouv.finances.dgfip.xemelios.auth.XemeliosUser;
import java.util.Vector;
import javax.xml.namespace.QName;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

/**
 *
 * @author Christophe Marchand <christophe.marchand@axyus.com>
 */
public class UserModel implements XmlMarshallable {
    public static final QName QN = new QName("user");
    
    private String id=null, libelle=null;
    private String collectivite = null;
    private String document=null;
    private Vector<String> roles = null;

    public UserModel(QName qn) {
        super();
        roles = new Vector<String>();
    }

    public UserModel(XemeliosUser user) {
        this(QN);
    }

    public void addCharacterData(String cData) throws SAXException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void addChild(XmlMarshallable child, QName tag) throws SAXException {
        roles.add(((TexteModel)child).getText());
    }

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

    public XmlMarshallable getChildToModify(String uri, String localName, String qName, Attributes atts) {
        return null;
    }

    public void marshall(XmlOutputter output) {
        output.startTag(QN);
        output.addAttribute("id", id);
        output.addAttribute("libelle",libelle);
        output.addAttribute("collectivite",collectivite);
        output.addAttribute("document",document);
        for(String role:roles) {
            output.startTag("role");
            output.addCharacterData(role);
            output.endTag("role");
        }
        output.endTag(QN);
    }

    public void validate() throws InvalidXmlDefinition {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public QName getQName() {
        return QN;
    }

    public UserModel clone() { return this; }

    public String getCollectivite() {
        return collectivite;
    }

    public void setCollectivite(String collectivite) {
        this.collectivite = collectivite;
    }

    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 Vector<String> getRoles() {
        return roles;
    }

    public void setRoles(Vector<String> roles) {
        this.roles = roles;
    }

    public String getDocument() {
        return document;
    }

    public void setDocument(String document) {
        this.document = document;
    }

}
