01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.workflow.util.ejb.local;
06:
07: import com.opensymphony.module.propertyset.PropertySet;
08:
09: 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;
15:
16: import java.util.Map;
17:
18: import javax.ejb.EJBLocalHome;
19:
20: import javax.naming.InitialContext;
21:
22: import javax.rmi.PortableRemoteObject;
23:
24: /**
25: *
26: *
27: * @author $Author: hani $
28: * @version $Revision: 1.3 $
29: */
30: public class LocalEJBFunctionProvider implements FunctionProvider {
31: //~ Static fields/initializers /////////////////////////////////////////////
32:
33: private static final Log log = LogFactory
34: .getLog(LocalEJBFunctionProvider.class);
35:
36: //~ Methods ////////////////////////////////////////////////////////////////
37:
38: public void execute(Map transientVars, Map args, PropertySet ps)
39: throws WorkflowException {
40: FunctionProvider sessionBean = null;
41: String ejbLocation = (String) args
42: .get(AbstractWorkflow.EJB_LOCATION);
43:
44: try {
45: EJBLocalHome home = (EJBLocalHome) PortableRemoteObject
46: .narrow(new InitialContext().lookup(ejbLocation),
47: EJBLocalHome.class);
48: Method create = home.getClass().getMethod("create",
49: new Class[0]);
50: sessionBean = (FunctionProvider) create.invoke(home,
51: new Object[0]);
52: } catch (Exception e) {
53: String message = "Could not get handle to local EJB at: "
54: + ejbLocation;
55: log.error(message, e);
56: throw new WorkflowException(message, e);
57: }
58:
59: sessionBean.execute(transientVars, args, ps);
60: }
61: }
|