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

import org.enhydra.shark.api.client.wfbase.BaseException;
import org.enhydra.shark.api.client.wfservice.ConnectFailed;
import org.enhydra.shark.api.client.wfservice.NotConnected;
import org.enhydra.shark.api.client.wfservice.SharkConnection;

/**
 * This class is used as a wrapper for
 * the corresponding shark connection of the
 * POJO and CORBA version.
 * 
 * @author Andreas Koop
 */
public class WfMConnection {

    private String username;
    private String password;
    private String engine;
    private SharkConnection sharkLIBConnection = null;
    private WorkflowService.SharkConnection sharkCORBAConnection = null;
    
    public WfMConnection( String user, String pwd){
        this.username = user;
        this.password = pwd;
    }
    public WfMConnection( SharkConnection sLIBConn ){
        this.sharkLIBConnection = sLIBConn;
    }
    
    public WfMConnection( WorkflowService.SharkConnection sCORBAConn ){
        this.sharkCORBAConnection = sCORBAConn;
    }
    
    /**
     * @return Returns the sharkCORBAConnection.
     */
    public WorkflowService.SharkConnection getSharkCORBAConnection() {
        return sharkCORBAConnection;
    }

    /**
     * @return Returns the sharkLIBConnection.
     */
    public SharkConnection getSharkLIBConnection() {
        return sharkLIBConnection;
    }
    
    
    /**
     * Connects to Shark
     * @param userName
     * @param pwd
     * @param engine
     * @param scope
     * @throws BaseException
     * @throws ConnectFailed
     */
    public void connect( String userName, String pwd, String engine, String scope ) 
    	throws BaseException, ConnectFailed{
        
        this.username = userName;
        this.password = pwd;
        this.engine = engine;
        
        if(sharkLIBConnection!=null)
            sharkLIBConnection.connect(userName, pwd, engine, scope );
        
        try {
            if(sharkCORBAConnection!=null)
                sharkCORBAConnection.connect(userName, pwd, engine, scope );
        } catch (WfBase.BaseException e) {
            throw new BaseException(e);
        } catch (WorkflowService.ConnectFailed e) {
            throw new ConnectFailed(e);
        }
    }

    
    /**
     * Disconnect
     * @throws BaseException
     * @throws NotConnected
     */
    public void disconnect() throws BaseException, NotConnected{
        if(sharkLIBConnection != null)
            sharkLIBConnection.disconnect();
        
        try {
            if(sharkCORBAConnection != null)
                sharkCORBAConnection.disconnect();
        } catch (WfBase.BaseException e) {
            throw new BaseException(e);
        } catch (WorkflowService.NotConnected e) {
            throw new NotConnected(e);
        }
    }
    
    /**
     * Returns the password
     * @return the password
     */
    public String getPassword() {
        return password;
    }
    
    /**
     * Sets the password
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }
    
    /**
     * Returns the username
     * @return the username
     */
    public String getUsername() {
        return username;
    }
    
    /**
     * Sets the username
     * @param username
     */
    public void setUsername(String username) {
        this.username = username;
    }
    
    /**
     * Returns the engine name
     * @return the name of the workflow engine
     */
    public String getEngine() {
        return engine;
    }
    
    /**
     * Set the engine name
     * @param engine
     */
    public void setEngine(String engine) {
        this.engine = engine;
    }
 }
