KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > util > ejb > local > LocalEJBFunctionProvider


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.util.ejb.local;
6
7 import com.opensymphony.module.propertyset.PropertySet;
8
9 import com.opensymphony.workflow.*;
10
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13
14 import java.lang.reflect.Method JavaDoc;
15
16 import java.util.Map JavaDoc;
17
18 import javax.ejb.EJBHome JavaDoc;
19
20 import javax.naming.InitialContext JavaDoc;
21
22 import javax.rmi.PortableRemoteObject JavaDoc;
23
24
25 /**
26  *
27  *
28  * @author $Author: hani $
29  * @version $Revision: 1.2 $
30  */

31 public class LocalEJBFunctionProvider implements FunctionProvider {
32     //~ Static fields/initializers /////////////////////////////////////////////
33

34     private static final Log log = LogFactory.getLog(LocalEJBFunctionProvider.class);
35
36     //~ Methods ////////////////////////////////////////////////////////////////
37

38     public void execute(Map JavaDoc transientVars, Map JavaDoc args, PropertySet ps) throws WorkflowException {
39         FunctionProvider sessionBean = null;
40         String JavaDoc ejbLocation = (String JavaDoc) args.get(AbstractWorkflow.EJB_LOCATION);
41
42         try {
43             EJBHome JavaDoc home = (EJBHome JavaDoc) PortableRemoteObject.narrow(new InitialContext JavaDoc().lookup(ejbLocation), EJBHome JavaDoc.class);
44             Method JavaDoc create = home.getClass().getMethod("create", new Class JavaDoc[0]);
45             sessionBean = (FunctionProvider) create.invoke(home, new Object JavaDoc[0]);
46         } catch (Exception JavaDoc e) {
47             String JavaDoc message = "Could not get handle to local EJB at: " + ejbLocation;
48             log.error(message, e);
49             throw new WorkflowException(message, e);
50         }
51
52         sessionBean.execute(transientVars, args, ps);
53     }
54 }
55
Popular Tags