KickJava   Java API By Example, From Geeks To Geeks.

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


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.4 $
25  */

26 public class JNDIValidator implements Validator {
27     //~ Static fields/initializers /////////////////////////////////////////////
28

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

33     public void validate(Map JavaDoc transientVars, Map JavaDoc args, PropertySet ps) throws InvalidInputException, WorkflowException {
34         String JavaDoc location = (String JavaDoc) args.get(AbstractWorkflow.JNDI_LOCATION);
35
36         if (location == null) {
37             throw new WorkflowException(AbstractWorkflow.JNDI_LOCATION + " argument is null");
38         }
39
40         Validator validator;
41
42         try {
43             try {
44                 validator = (Validator) new InitialContext JavaDoc().lookup(location);
45             } catch (NamingException JavaDoc e) {
46                 validator = (Validator) new InitialContext JavaDoc().lookup("java:comp/env/" + location);
47             }
48         } catch (NamingException JavaDoc e) {
49             String JavaDoc message = "Could not look up JNDI Validator at: " + location;
50             throw new WorkflowException(message, e);
51         }
52
53         validator.validate(transientVars, args, ps);
54     }
55 }
56
Popular Tags