view gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java @ 57:f01592cd6419

Funktionalität Feed initial bereitgestellt. gnv-artifacts/trunk@39 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 08 Sep 2009 12:22:00 +0000
parents 737d8bf63701
children f31343d80d53
line wrap: on
line source
/**
 *
 */
package de.intevation.gnv.transition;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import de.intevation.artifactdatabase.Config;
import de.intevation.gnv.artifacts.GNVArtifactBase;
import de.intevation.gnv.transition.exception.TransitionException;

/**
 * @author Tim Englich <tim.englich@intevation.de>
 *
 */
public abstract class TransitionBase implements Transition {
    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = Logger.getLogger(GNVArtifactBase.class);
    
    private String id = null;
    
    private String description = null;
    


    protected String queryID = null;
    
    private Collection<String> reachableTransitions = null;
    
    private Collection<String> inputValueNames = null;
    
    private Map<String,InputValue> inputValues = null;
    
    private Transition parent = null;
    
    private Collection<InputData> inputData = null;
    /**
     * Constructor
     */
    public TransitionBase() {
        super();
    }

    /**
     * @see de.intevation.gnv.transition.Transition#getID()
     */
    public String getID() {
        return this.id;
    }
    
    /**
     * @see de.intevation.gnv.transition.Transition#getDescription()
     */
    public String getDescription() {
        return this.description;
    }
    
    /**
     * @see de.intevation.gnv.transition.Transition#reachableTransitions()
     */
    public Collection<String> reachableTransitions() {
        return this.reachableTransitions;
    }

    /**
     * @see de.intevation.gnv.transition.Transition#getRequiredInputValues()
     */
    public Collection<InputValue> getRequiredInputValues() {
        return this.inputValues.values();
    }

    /**
     * @see de.intevation.gnv.transition.Transition#setup(org.w3c.dom.Node)
     */
    public void setup(Node configuration) {
        
        this.id = Config.getStringXPath(configuration,"@id");
        this.description = Config.getStringXPath(configuration,"@description");
        
        log.info("Transition-ID = "+ this.id);
        NodeList nodes = Config.getNodeSetXPath(configuration,"reachableTransitions/transition");
        this.reachableTransitions = new ArrayList<String>(nodes.getLength());
        for (int i = 0 ; i < nodes.getLength(); i++){
            String reachableTransition = nodes.item(i).getTextContent();
            log.info("ReachableTransition ==> "+ reachableTransition);
            this.reachableTransitions.add(reachableTransition);
            
        }
        
        NodeList inputValuesNodes = Config.getNodeSetXPath(configuration,"inputvalues/inputvalue");
        this.inputValues = new HashMap<String,InputValue>(inputValuesNodes.getLength());
        this.inputValueNames = new ArrayList<String>(inputValuesNodes.getLength());
        for (int i = 0 ; i < inputValuesNodes.getLength(); i++){
            Node inputValueNode = inputValuesNodes.item(i);
            InputValue inputValue = new DefaultInputValue(Config.getStringXPath(inputValueNode,"@name"), Config.getStringXPath(inputValueNode,"@type"));
            log.debug(inputValue.toString());
            this.inputValues.put(inputValue.getName(),inputValue);
            this.inputValueNames.add(inputValue.getName());
        }
        
        this.queryID = Config.getStringXPath(configuration,"queryID");
        log.info("QueryID ==> "+ this.queryID);
        
    }

    /**
     * @see de.intevation.gnv.transition.Transition#getParent()
     */
    public Transition getParent() {
        return this.parent;
    }

    /**
     * @see de.intevation.gnv.transition.Transition#setParent(de.intevation.gnv.transition.Transition)
     */
    public void setParent(Transition transition) {
        this.parent = transition;
    }

    /**
     * @see de.intevation.gnv.transition.Transition#putInputData(java.util.Collection)
     */
    public void putInputData(Collection<InputData> inputData) throws TransitionException {
        log.debug("TransitionBase.putInputData");
        if (inputData != null){
            Iterator<InputData> it = inputData.iterator();
            while(it.hasNext()){
                InputData tmpItem = it.next();
                InputValue inputValue = this.inputValues.get(tmpItem.getName());
                if (inputValue != null){
                    if (this.inputData == null){
                        this.inputData = new ArrayList<InputData>(inputData.size());
                        // TODO validate Value;
                        this.inputData.add(tmpItem);
                    }
                    
                }else{
                    String errMsg = "No Inputvalue given for Inputdata "+ tmpItem.getName();
                    log.warn(errMsg+ "Value will be ignored");
                    throw new TransitionException(errMsg);
                    
                }
            }
        }else{
            log.warn("No Inputdata given");
        }
    
    }
    
}

http://dive4elements.wald.intevation.org