KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > util > jndi > JNDICondition


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

5 package com.opensymphony.workflow.util.jndi;
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.util.Map JavaDoc;
15
16 import javax.naming.InitialContext JavaDoc;
17 import javax.naming.NamingException JavaDoc;
18
19
20 /**
21  *
22  *
23  * @author $Author: hani $
24  * @version $Revision: 1.3 $
25  */

26 public class JNDICondition implements Condition {
27     //~ Static fields/initializers /////////////////////////////////////////////
28

29     private static final Log log = LogFactory.getLog(JNDICondition.class);
30
31     //~ Methods ////////////////////////////////////////////////////////////////
32

33     public boolean passesCondition(Map JavaDoc transientVars, Map JavaDoc args, PropertySet ps) throws WorkflowException {
34         String JavaDoc location = (String JavaDoc) args.get(AbstractWorkflow.JNDI_LOCATION);
35         location = location.trim();
36
37         Condition condition = null;
38
39         try {
40             try {
41                 condition = (Condition) new InitialContext JavaDoc().lookup(location);
42             } catch (NamingException JavaDoc e) {
43                 //ok, couldn't find it, look in env
44
condition = (Condition) new InitialContext JavaDoc().lookup("java:comp/env/" + location);
45             }
46         } catch (NamingException JavaDoc e) {
47             String JavaDoc message = "Could not lookup JNDI condition at: " + location;
48             throw new WorkflowException(message, e);
49         }
50
51         return condition.passesCondition(transientVars, args, ps);
52     }
53 }
54
Popular Tags