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.AbstractWorkflow;
10: import com.opensymphony.workflow.Register;
11: import com.opensymphony.workflow.WorkflowContext;
12: import com.opensymphony.workflow.WorkflowException;
13: import com.opensymphony.workflow.spi.WorkflowEntry;
14:
15: import java.lang.reflect.Method;
16:
17: import java.util.Map;
18:
19: import javax.ejb.EJBLocalHome;
20:
21: import javax.naming.InitialContext;
22:
23: import javax.rmi.PortableRemoteObject;
24:
25: /**
26: * A register helper that exposes a local session bean as a register.
27: * This register takes in one argument, <code>ejb.location</code> that specifies
28: * the JNDI location of the session bean.
29: *
30: * @author $Author: hani $
31: * @version $Revision: 1.5 $
32: */
33: public class LocalEJBRegister implements Register {
34: //~ Methods ////////////////////////////////////////////////////////////////
35:
36: public Object registerVariable(WorkflowContext context,
37: WorkflowEntry entry, Map args, PropertySet ps)
38: throws WorkflowException {
39: String ejbLocation = (String) args
40: .get(AbstractWorkflow.EJB_LOCATION);
41: Register sessionBean;
42:
43: try {
44: EJBLocalHome home = (EJBLocalHome) PortableRemoteObject
45: .narrow(new InitialContext().lookup(ejbLocation),
46: EJBLocalHome.class);
47: Method create = home.getClass().getMethod("create",
48: new Class[0]);
49: sessionBean = (Register) create.invoke(home, new Object[0]);
50: } catch (Exception e) {
51: String message = "Could not get handle to local EJB register at: "
52: + ejbLocation;
53: throw new WorkflowException(message, e);
54: }
55:
56: return sessionBean.registerVariable(context, entry, args, ps);
57: }
58: }
|