/*
 * $Id: ProcessInstanceInfo.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 08.07.2004
 *
 * $Log: ProcessInstanceInfo.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.Date;

import org.enhydra.shark.api.client.wfbase.BaseException;
import org.enhydra.shark.api.client.wfmodel.WfProcess;

import WorkflowModel.WfActivityHelper;
import WorkflowModel.WfRequester;


/**
 * This class represents a java bean
 * to encapsulate infos about process instances.
 * It is primary used in the presentation layer.
 * 
 * @author Andreas Koop
 */
public class ProcessInstanceInfo  extends InstanceInfo{
    
    private String processors = "---";
    
    /**
     * Empty constructor
     */
    public ProcessInstanceInfo(){}
    
    /**
     * Constructs a process instance info
     * from the given process (POJO version).
     * 
     * @param process
     * @throws BaseException
     */
    public ProcessInstanceInfo( WfProcess process ) throws BaseException{
        this.setId( process.key() );
        org.enhydra.shark.api.client.wfmodel.WfRequester requester = process.requester();
        // Falls die Processinstanz als Subflow-Aktivität fungiert
        // wird der Name der Aktivität angezeigt!
        if( requester instanceof org.enhydra.shark.api.client.wfmodel.WfActivity )
            this.setName( ((org.enhydra.shark.api.client.wfmodel.WfActivity)requester).name() );
        else
            this.setName( process.name() );
        this.setName( process.name() );
        this.setDescription( process.description() );
        this.setPriority( process.priority() );
        this.setState( process.state() );
    }

    /**
     * Constructs a process instance info
     * from the given process (CORBA version).
     * 
     * @param process
     * @throws BaseException
     */
    public ProcessInstanceInfo( WorkflowModel.WfProcess process ) throws WfBase.BaseException{
        this.setId( process.key() );
        
        WfRequester requester = process.requester();
        
        // Falls die Processinstanz als Subflow-Aktivität fungiert
        // wird der Name der Aktivität angezeigt!
        if( requester._is_a( WfActivityHelper.id() ) ){
            this.setName( WfActivityHelper.narrow(requester).name() );   
        }else
            this.setName( process.name() );
        this.setDescription( process.description() );
        this.setPriority( process.priority() );
        this.setState( process.state() );
        
        if( this.getState().startsWith( "open" ))
            this.setStartTime( new Date( process.last_state_time().time) );
        else if( this.getState().startsWith( "closed" ))
            this.setEndTime( new Date( process.last_state_time().time) );
    }
    
    
    /**
     * Return a list of current processors of this process instance
     * @return a list of current processors of this process instance
     */
    public String getProcessors() {
        return processors;
    }
    
    /**
     * Set the processors of this process instance
     * @param processor
     */
    public void setProcessors(String processor) {
        this.processors = processor;
    }
    
    /** 
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    public String toString() {
        
        return super.toString()
        	+ "\nbearbeiter  " + this.processors;
    }
}
