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 LocalEJBCondition implements Condition {
31: //~ Static fields/initializers /////////////////////////////////////////////
32:
33: private static final Log log = LogFactory
34: .getLog(LocalEJBCondition.class);
35:
36: //~ Methods ////////////////////////////////////////////////////////////////
37:
38: public boolean passesCondition(Map transientVars, Map args,
39: PropertySet ps) throws WorkflowException {
40: String ejbLocation = (String) args
41: .get(AbstractWorkflow.EJB_LOCATION);
42:
43: Condition sessionBean = null;
44:
45: try {
46: EJBLocalHome home = (EJBLocalHome) PortableRemoteObject
47: .narrow(new InitialContext().lookup(ejbLocation),
48: EJBLocalHome.class);
49: Method create = home.getClass().getMethod("create",
50: new Class[0]);
51: sessionBean = (Condition) create
52: .invoke(home, new Object[0]);
53: } catch (Exception e) {
54: String message = "Could not get handle to Local Condition: "
55: + ejbLocation;
56: log.error(message, e);
57: throw new WorkflowException(message, e);
58: }
59:
60: return sessionBean.passesCondition(transientVars, args, ps);
61: }
62: }
|