Package de.danet.an.wfdemo.testejb

Source Code of de.danet.an.wfdemo.testejb.TestEJB

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
* All rights reserved.
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* $Id: TestEJB.java 2310 2007-03-22 13:37:12Z schnelle $
*
* $Log$
* Revision 1.3  2007/02/17 21:23:28  mlipp
* Proper cleanup.
*
* Revision 1.2  2007/02/16 20:58:37  mlipp
* Extended test case.
*
* Revision 1.1  2006/11/03 22:07:33  mlipp
* New EJB (component) for testing.
*
*/
package de.danet.an.wfdemo.testejb;

import java.rmi.RemoteException;
import java.util.Map;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

import de.danet.an.workflow.api.CannotRemoveException;
import de.danet.an.workflow.api.Channel;
import de.danet.an.workflow.api.DefaultRequester;
import de.danet.an.workflow.api.InvalidKeyException;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.ProcessDirectory;
import de.danet.an.workflow.api.ProcessMgr;
import de.danet.an.workflow.api.SAXEventBuffer;
import de.danet.an.workflow.api.WorkflowService;
import de.danet.an.workflow.api.WorkflowServiceFactory;
import de.danet.an.workflow.omgcore.AlreadyRunningException;
import de.danet.an.workflow.omgcore.CannotStartException;
import de.danet.an.workflow.omgcore.InvalidRequesterException;
import de.danet.an.workflow.omgcore.NotEnabledException;
import de.danet.an.workflow.omgcore.RequesterRequiredException;
import de.danet.an.workflow.omgcore.WfProcess;
import de.danet.an.workflow.util.SAXEventBufferImpl;

/**
* This class provides an EJB for tests.
*
* @author Michael Lipp
* @author Dirk Schnelle
* @ejb.bean name="TestEJB" display-name="Test EJB"
* jndi-name="ejb/WfMOpenTestEJB"
* type="Stateless" transaction-type="Container" view-type="remote"
* @ejb.home remote-class="de.danet.an.wfdemo.testejb.TestHome"
* generate="remote"
* @ejb.interface remote-class="de.danet.an.wfdemo.testejb.Test"
* generate="remote"
* @ejb.transaction type="Required"
* @ejb.permission role-name="WfMOpenAdmin"
*/
public class TestEJB implements SessionBean {

    private SessionContext ctx = null;
   
    /**
     * Create a new instance.
     * @throws CreateException Throws if the EJB cannot be created.
     * @ejb.create-method view-type="remote"
     */
    public void ejbCreate() throws CreateException {
    }

    /* (non-Javadoc)
     * @see javax.ejb.SessionBean#ejbActivate()
     */
    public void ejbActivate() throws EJBException, RemoteException {
    }

    /* (non-Javadoc)
     * @see javax.ejb.SessionBean#ejbPassivate()
     */
    public void ejbPassivate() throws EJBException, RemoteException {
    }

    /* (non-Javadoc)
     * @see javax.ejb.SessionBean#ejbRemove()
     */
    public void ejbRemove() throws EJBException, RemoteException {
    }

    /* (non-Javadoc)
     * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
     */
    public void setSessionContext(SessionContext ctx) throws EJBException,
            RemoteException {
        this.ctx = ctx;
    }

    /**
     * Start a process a wait for a message from the channel.
     * @throws InvalidKeyException
     * @throws RequesterRequiredException
     * @throws InvalidRequesterException
     * @throws NotEnabledException
     * @throws AlreadyRunningException
     * @throws CannotStartException
     * @throws CannotRemoveException
     *
     * @ejb.interface-method view-type="remote"
     * @ejb.transaction type="NotSupported"
     */
    public Map startAndWait ()
        throws InvalidKeyException, NotEnabledException,
            InvalidRequesterException, RequesterRequiredException,
            CannotStartException, AlreadyRunningException,
            CannotRemoveException {
        WorkflowService workflowService = null;
        Channel chan = null;
        try {
            WorkflowServiceFactory wsf = WorkflowServiceFactory.newInstance();
            workflowService = wsf.newWorkflowService();
       
            ProcessDefinitionDirectory procDefDir
                = workflowService.processDefinitionDirectory();
            ProcessDirectory procDir = workflowService.processDirectory();
            ProcessMgr pmgr = procDefDir.processMgr
                ("chabacc", "chabacc_test_sender");
            WfProcess process
                = pmgr.createProcess(new DefaultRequester (workflowService));
            chan = workflowService.getChannel(process, "test_channel");
            process.start();
            Map pd = chan.receiveMessage();
            return pd;
        } catch (RemoteException e) {
            throw new EJBException (e);
        } finally {
            workflowService.release(chan);
            workflowService.release(workflowService);
        }
    }

    /**
     * Start a process a wait for a message from the channel.
     * @throws InvalidKeyException
     * @throws RequesterRequiredException
     * @throws InvalidRequesterException
     * @throws NotEnabledException
     * @throws AlreadyRunningException
     * @throws CannotStartException
     * @throws CannotRemoveException
     *
     * @ejb.interface-method view-type="remote"
     * @ejb.transaction type="NotSupported"
     */
    public Map startAndWait (long timeout)
        throws InvalidKeyException, NotEnabledException,
            InvalidRequesterException, RequesterRequiredException,
            CannotStartException, AlreadyRunningException,
            CannotRemoveException {
        WorkflowService workflowService = null;
        Channel chan = null;
        try {
            WorkflowServiceFactory wsf = WorkflowServiceFactory.newInstance();
            workflowService = wsf.newWorkflowService();
       
            ProcessDefinitionDirectory procDefDir
                = workflowService.processDefinitionDirectory();
            ProcessDirectory procDir = workflowService.processDirectory();
            ProcessMgr pmgr = procDefDir.processMgr
                ("chabacc", "chabacc_test_sender");
            WfProcess process
                = pmgr.createProcess(new DefaultRequester (workflowService));
            chan = workflowService.getChannel(process, "test_channel");
            process.start();
            Map pd = chan.receiveMessage(timeout);
            return pd;
        } catch (RemoteException e) {
            throw new EJBException (e);
        } finally {
          workflowService.release (chan);
            workflowService.release(workflowService);
        }
    }
   
    /**
     * Simple test method to say hello to the given name.
     * @ejb.interface-method view-type="remote"
     * @ejb.transaction type="NotSupported"
     */
    public String sayHello(String name) {
        return "Hello " + name;
    }
   
    /**
     * Simple test method to add two numbers.
     * @ejb.interface-method view-type="remote"
     * @ejb.transaction type="NotSupported"
     */
    public long add(long num1, long num2) {
        return num1 + num2;
    }
   
    /**
     * Simple test method to convert a boolean int a string
     * @ejb.interface-method view-type="remote"
     * @ejb.transaction type="NotSupported"
     */
    public String toString(boolean value) {
        return Boolean.toString(value);
    }

    /**
     * Simple test method to calculate the square root of a number.
     * @ejb.interface-method view-type="remote"
     * @ejb.transaction type="NotSupported"
     */
    public double sqrt(double value) {
        return Math.sqrt(value);
    }

    /**
     * Simple test method to return a string representation of the given XML.
     * @ejb.interface-method view-type="remote"
     * @ejb.transaction type="NotSupported"
     */
    public String toString(SAXEventBuffer sax) {
        SAXEventBufferImpl impl = (SAXEventBufferImpl) sax;
       
        return impl.toString(false);
    }
   
}
TOP

Related Classes of de.danet.an.wfdemo.testejb.TestEJB

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.