KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > util > ejb > remote > RemoteEJBFunctionProvider


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

5 package com.opensymphony.workflow.util.ejb.remote;
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.rmi.RemoteException JavaDoc;
17
18 import java.util.Map JavaDoc;
19
20 import javax.ejb.EJBHome JavaDoc;
21
22 import javax.naming.InitialContext JavaDoc;
23
24 import javax.rmi.PortableRemoteObject JavaDoc;
25
26
27 /**
28  *
29  *
30  * @author $Author: hani $
31  * @version $Revision: 1.2 $
32  */

33 public class RemoteEJBFunctionProvider implements FunctionProvider {
34     //~ Static fields/initializers /////////////////////////////////////////////
35

36     private static final Log log = LogFactory.getLog(RemoteEJBFunctionProvider.class);
37
38     //~ Methods ////////////////////////////////////////////////////////////////
39

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