001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: TestEJB.java,v 1.4 2007/03/22 13:37:12 schnelle Exp $
021: *
022: * $Log: TestEJB.java,v $
023: * Revision 1.4 2007/03/22 13:37:12 schnelle
024: * Added test methods for EJBInvoker.
025: *
026: * Revision 1.3 2007/02/17 21:23:28 mlipp
027: * Proper cleanup.
028: *
029: * Revision 1.2 2007/02/16 20:58:37 mlipp
030: * Extended test case.
031: *
032: * Revision 1.1 2006/11/03 22:07:33 mlipp
033: * New EJB (component) for testing.
034: *
035: */
036: package de.danet.an.wfdemo.testejb;
037:
038: import java.rmi.RemoteException;
039: import java.util.Map;
040:
041: import javax.ejb.CreateException;
042: import javax.ejb.EJBException;
043: import javax.ejb.SessionBean;
044: import javax.ejb.SessionContext;
045:
046: import de.danet.an.workflow.api.CannotRemoveException;
047: import de.danet.an.workflow.api.Channel;
048: import de.danet.an.workflow.api.DefaultRequester;
049: import de.danet.an.workflow.api.InvalidKeyException;
050: import de.danet.an.workflow.api.ProcessDefinitionDirectory;
051: import de.danet.an.workflow.api.ProcessDirectory;
052: import de.danet.an.workflow.api.ProcessMgr;
053: import de.danet.an.workflow.api.SAXEventBuffer;
054: import de.danet.an.workflow.api.WorkflowService;
055: import de.danet.an.workflow.api.WorkflowServiceFactory;
056: import de.danet.an.workflow.omgcore.AlreadyRunningException;
057: import de.danet.an.workflow.omgcore.CannotStartException;
058: import de.danet.an.workflow.omgcore.InvalidRequesterException;
059: import de.danet.an.workflow.omgcore.NotEnabledException;
060: import de.danet.an.workflow.omgcore.RequesterRequiredException;
061: import de.danet.an.workflow.omgcore.WfProcess;
062: import de.danet.an.workflow.util.SAXEventBufferImpl;
063:
064: /**
065: * This class provides an EJB for tests.
066: *
067: * @author Michael Lipp
068: * @author Dirk Schnelle
069: * @ejb.bean name="TestEJB" display-name="Test EJB"
070: * jndi-name="ejb/WfMOpenTestEJB"
071: * type="Stateless" transaction-type="Container" view-type="remote"
072: * @ejb.home remote-class="de.danet.an.wfdemo.testejb.TestHome"
073: * generate="remote"
074: * @ejb.interface remote-class="de.danet.an.wfdemo.testejb.Test"
075: * generate="remote"
076: * @ejb.transaction type="Required"
077: * @ejb.permission role-name="WfMOpenAdmin"
078: */
079: public class TestEJB implements SessionBean {
080:
081: private SessionContext ctx = null;
082:
083: /**
084: * Create a new instance.
085: * @throws CreateException Throws if the EJB cannot be created.
086: * @ejb.create-method view-type="remote"
087: */
088: public void ejbCreate() throws CreateException {
089: }
090:
091: /* (non-Javadoc)
092: * @see javax.ejb.SessionBean#ejbActivate()
093: */
094: public void ejbActivate() throws EJBException, RemoteException {
095: }
096:
097: /* (non-Javadoc)
098: * @see javax.ejb.SessionBean#ejbPassivate()
099: */
100: public void ejbPassivate() throws EJBException, RemoteException {
101: }
102:
103: /* (non-Javadoc)
104: * @see javax.ejb.SessionBean#ejbRemove()
105: */
106: public void ejbRemove() throws EJBException, RemoteException {
107: }
108:
109: /* (non-Javadoc)
110: * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
111: */
112: public void setSessionContext(SessionContext ctx)
113: throws EJBException, RemoteException {
114: this .ctx = ctx;
115: }
116:
117: /**
118: * Start a process a wait for a message from the channel.
119: * @throws InvalidKeyException
120: * @throws RequesterRequiredException
121: * @throws InvalidRequesterException
122: * @throws NotEnabledException
123: * @throws AlreadyRunningException
124: * @throws CannotStartException
125: * @throws CannotRemoveException
126: *
127: * @ejb.interface-method view-type="remote"
128: * @ejb.transaction type="NotSupported"
129: */
130: public Map startAndWait() throws InvalidKeyException,
131: NotEnabledException, InvalidRequesterException,
132: RequesterRequiredException, CannotStartException,
133: AlreadyRunningException, CannotRemoveException {
134: WorkflowService workflowService = null;
135: Channel chan = null;
136: try {
137: WorkflowServiceFactory wsf = WorkflowServiceFactory
138: .newInstance();
139: workflowService = wsf.newWorkflowService();
140:
141: ProcessDefinitionDirectory procDefDir = workflowService
142: .processDefinitionDirectory();
143: ProcessDirectory procDir = workflowService
144: .processDirectory();
145: ProcessMgr pmgr = procDefDir.processMgr("chabacc",
146: "chabacc_test_sender");
147: WfProcess process = pmgr
148: .createProcess(new DefaultRequester(workflowService));
149: chan = workflowService.getChannel(process, "test_channel");
150: process.start();
151: Map pd = chan.receiveMessage();
152: return pd;
153: } catch (RemoteException e) {
154: throw new EJBException(e);
155: } finally {
156: workflowService.release(chan);
157: workflowService.release(workflowService);
158: }
159: }
160:
161: /**
162: * Start a process a wait for a message from the channel.
163: * @throws InvalidKeyException
164: * @throws RequesterRequiredException
165: * @throws InvalidRequesterException
166: * @throws NotEnabledException
167: * @throws AlreadyRunningException
168: * @throws CannotStartException
169: * @throws CannotRemoveException
170: *
171: * @ejb.interface-method view-type="remote"
172: * @ejb.transaction type="NotSupported"
173: */
174: public Map startAndWait(long timeout) throws InvalidKeyException,
175: NotEnabledException, InvalidRequesterException,
176: RequesterRequiredException, CannotStartException,
177: AlreadyRunningException, CannotRemoveException {
178: WorkflowService workflowService = null;
179: Channel chan = null;
180: try {
181: WorkflowServiceFactory wsf = WorkflowServiceFactory
182: .newInstance();
183: workflowService = wsf.newWorkflowService();
184:
185: ProcessDefinitionDirectory procDefDir = workflowService
186: .processDefinitionDirectory();
187: ProcessDirectory procDir = workflowService
188: .processDirectory();
189: ProcessMgr pmgr = procDefDir.processMgr("chabacc",
190: "chabacc_test_sender");
191: WfProcess process = pmgr
192: .createProcess(new DefaultRequester(workflowService));
193: chan = workflowService.getChannel(process, "test_channel");
194: process.start();
195: Map pd = chan.receiveMessage(timeout);
196: return pd;
197: } catch (RemoteException e) {
198: throw new EJBException(e);
199: } finally {
200: workflowService.release(chan);
201: workflowService.release(workflowService);
202: }
203: }
204:
205: /**
206: * Simple test method to say hello to the given name.
207: * @ejb.interface-method view-type="remote"
208: * @ejb.transaction type="NotSupported"
209: */
210: public String sayHello(String name) {
211: return "Hello " + name;
212: }
213:
214: /**
215: * Simple test method to add two numbers.
216: * @ejb.interface-method view-type="remote"
217: * @ejb.transaction type="NotSupported"
218: */
219: public long add(long num1, long num2) {
220: return num1 + num2;
221: }
222:
223: /**
224: * Simple test method to convert a boolean int a string
225: * @ejb.interface-method view-type="remote"
226: * @ejb.transaction type="NotSupported"
227: */
228: public String toString(boolean value) {
229: return Boolean.toString(value);
230: }
231:
232: /**
233: * Simple test method to calculate the square root of a number.
234: * @ejb.interface-method view-type="remote"
235: * @ejb.transaction type="NotSupported"
236: */
237: public double sqrt(double value) {
238: return Math.sqrt(value);
239: }
240:
241: /**
242: * Simple test method to return a string representation of the given XML.
243: * @ejb.interface-method view-type="remote"
244: * @ejb.transaction type="NotSupported"
245: */
246: public String toString(SAXEventBuffer sax) {
247: SAXEventBufferImpl impl = (SAXEventBufferImpl) sax;
248:
249: return impl.toString(false);
250: }
251:
252: }
|