01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.workflow.util.jndi;
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.util.Map;
15:
16: import javax.naming.InitialContext;
17: import javax.naming.NamingException;
18:
19: /**
20: *
21: *
22: * @author $Author: hani $
23: * @version $Revision: 1.3 $
24: */
25: public class JNDICondition implements Condition {
26: //~ Static fields/initializers /////////////////////////////////////////////
27:
28: private static final Log log = LogFactory
29: .getLog(JNDICondition.class);
30:
31: //~ Methods ////////////////////////////////////////////////////////////////
32:
33: public boolean passesCondition(Map transientVars, Map args,
34: PropertySet ps) throws WorkflowException {
35: String location = (String) args
36: .get(AbstractWorkflow.JNDI_LOCATION);
37: location = location.trim();
38:
39: Condition condition = null;
40:
41: try {
42: try {
43: condition = (Condition) new InitialContext()
44: .lookup(location);
45: } catch (NamingException e) {
46: //ok, couldn't find it, look in env
47: condition = (Condition) new InitialContext()
48: .lookup("java:comp/env/" + location);
49: }
50: } catch (NamingException e) {
51: String message = "Could not lookup JNDI condition at: "
52: + location;
53: throw new WorkflowException(message, e);
54: }
55:
56: return condition.passesCondition(transientVars, args, ps);
57: }
58: }
|