/*
 * $Id: PackageInfo.java,v 1.2 2004/09/20 10:26:13 koppy Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * Created on 10.07.2004
 *
 * $Log: PackageInfo.java,v $
 * Revision 1.2  2004/09/20 10:26:13  koppy
 * +javadoc Dokumentation
 *
 * Revision 1.1  2004/08/30 14:49:55  koppy
 * Initiale Version der Workflow-Komponente
 *
 */
package vkc.workflow.model;

import java.util.Iterator;
import java.util.List;

import vkc.workflow.util.WorkflowUtils;

/**
 * This class represents a java bean
 * to encapsulate infos about a workflow package.
 * It is primary used in the presentation layer.
 * 
 * @author Andreas Koop
 */
public class PackageInfo {

    private String packageId = null;
    private String path = null;
    private boolean opened;
    private List processDefinitions = null;
    
    
    /**
     * Adds a process definition to this package.
     * @param p process definition info
     */
    public void addProcessDefinition( ProcessDefinitionInfo p ){
        processDefinitions.add(p);
    }
    
    
    /**
     * Returns the package id.
     * @return Returns the packageId.
     */
    public String getPackageId() {
        return packageId;
    }
    /**
     * Sets the package id.
     * @param packageId The packageId to set.
     */
    public void setPackageId(String packageId) {
        this.packageId = packageId;
    }
    /**
     * Returns the processDefinitions.
     * @return Returns the processDefinitions.
     */
    public List getProcessDefinitions() {
        return processDefinitions;
    }
    
    /**
     * Indicated whether this package is opened or not.
     * @return true if opened, false otherwise.
     */
    public boolean isOpened() {
        return opened;
    }
    
    /**
     * Sets whether this package is opened or not.
     * @param opened boolean flag
     */
    public void setOpened(boolean opened) {
        this.opened = opened;
    }
    
    /**
     * Returns the path of this package.
     * @return the package path
     */
    public String getPath() {
        return path;
    }
    
    /**
     * Sets the path of this package.
     * @param path the path of package
     */
    public void setPath(String path) {
        this.path = path;
    }
    
    /**
     * Sets a list of process definitions.
     * @param processDefinitions list of process definitions
     */
    public void setProcessDefinitions(List processDefinitions) {
        this.processDefinitions = processDefinitions;
    }
    
    /**
     * if there exist at least one enabled process definition
     * or the processlist is empty
     * then the surrounding package is enabled per definition!
     */
    public boolean isEnabled(){
        if( WorkflowUtils.isEmpty( this.processDefinitions ))
            return true;
        
        for (Iterator iter = processDefinitions.iterator(); iter.hasNext();) {
            ProcessDefinitionInfo d = (ProcessDefinitionInfo) iter.next();
            if(d.isEnabled())
                return true;
        }
        
        return false;
    }
}
