KickJava   Java API By Example, From Geeks To Geeks.

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


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.workflow.*;
8 import com.opensymphony.workflow.spi.WorkflowEntry;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12
13 import java.util.Map JavaDoc;
14
15 import javax.naming.InitialContext JavaDoc;
16 import javax.naming.NamingException JavaDoc;
17
18
19 /**
20  *
21  *
22  * @author $Author: hani $
23  * @version $Revision: 1.4 $
24  */

25 public class JNDIRegister implements Register {
26     //~ Static fields/initializers /////////////////////////////////////////////
27

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

32     public Object JavaDoc registerVariable(WorkflowContext context, WorkflowEntry entry, Map JavaDoc args) throws WorkflowException {
33         String JavaDoc location = (String JavaDoc) args.get(AbstractWorkflow.JNDI_LOCATION);
34
35         if (location == null) {
36             throw new WorkflowException(AbstractWorkflow.JNDI_LOCATION + " argument is null");
37         }
38
39         Register r;
40
41         try {
42             try {
43                 r = (Register) new InitialContext JavaDoc().lookup(location);
44             } catch (NamingException JavaDoc e) {
45                 //ok, couldn't find it, look in env
46
r = (Register) new InitialContext JavaDoc().lookup("java:comp/env/" + location);
47             }
48         } catch (NamingException JavaDoc e) {
49             String JavaDoc message = "Could not look up JNDI register at: " + location;
50             throw new WorkflowException(message, e);
51         }
52
53         return r.registerVariable(context, entry, args);
54     }
55 }
56
Popular Tags