Package com.fiveht.tick.api.parser

Source Code of com.fiveht.tick.api.parser.ProjectParser

/*
* Copyright (C) 2012 FiveHT Media Ltd.
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package com.fiveht.tick.api.parser;

import com.fiveht.tick.api.Project;
import com.fiveht.tick.api.Task;
import com.fiveht.tick.util.NodeListIterator;
import java.beans.PropertyVetoException;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
*
* @author Nathan Crause
*/
public class ProjectParser extends Parser<Project> {
   
    @Override
    public Project parse(Element element) {
        Project project = new Project();
       
        try {
            project.setId(getInt(element, "id"));
            project.setName(get(element, "name"));
            project.setBudget(getDecimal(element, "budget"));
            project.setClientId(getInt(element, "client_id"));
            project.setOwnerId(getInt(element, "owner_id"));
            project.setOpenedOn(getDate(element, "opened_on"));
            project.setClosedOn(getDate(element, "closed_on"));
            project.setCreatedAt(getDatetime(element, "created_at"));
            project.setUpdatedAt(getDatetime(element, "updated_at"));
            project.setClientName(get(element, "client_name"));
            project.setSumHours(getDecimal(element, "sum_hours"));
            project.setUserCount(getInt(element, "user_count"));
           
            project.addTasks(parseTasks(element));
        }
        catch (PropertyVetoException ex) {
            throw new RuntimeException(
                    "PANIC! This is a new object - there should be no vetoing",
                    ex);
        }
       
//        System.out.println(">>>>>>>" + project);
       
        return project;
    }

    private List<Task> parseTasks(Element parent) {
        NodeList list = parent.getElementsByTagName("tasks");
       
        if (list.getLength() != 1) {
            throw new RuntimeException("Unexpectedly received "
                    + list.getLength() + " tasks (expected only one)");
        }
       
        Element root = (Element) list.item(0);
        List<Task> results = new ArrayList<Task>();
        TaskParser parser = new TaskParser();
       
        for (Element e : new NodeListIterator<Element>(root.getElementsByTagName("task"))) {
            results.add(parser.parse(e));
        }
       
        return results;
    }
   
}
TOP

Related Classes of com.fiveht.tick.api.parser.ProjectParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.