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: import com.opensymphony.workflow.spi.WorkflowEntry;
11:
12: import java.util.Map;
13:
14: import javax.naming.InitialContext;
15: import javax.naming.NamingException;
16:
17: /**
18: * Invoke a register registred in JNDI.
19: * Args must contain a {@link AbstractWorkflow#JNDI_LOCATION} key.
20: * @author $Author: hani $
21: * @version $Revision: 1.5 $
22: */
23: public class JNDIRegister implements Register {
24: //~ Methods ////////////////////////////////////////////////////////////////
25:
26: public Object registerVariable(WorkflowContext context,
27: WorkflowEntry entry, Map args, PropertySet ps)
28: throws WorkflowException {
29: String location = (String) args
30: .get(AbstractWorkflow.JNDI_LOCATION);
31:
32: if (location == null) {
33: throw new WorkflowException(AbstractWorkflow.JNDI_LOCATION
34: + " argument is null");
35: }
36:
37: Register r;
38:
39: try {
40: try {
41: r = (Register) new InitialContext().lookup(location);
42: } catch (NamingException e) {
43: //ok, couldn't find it, look in env
44: r = (Register) new InitialContext()
45: .lookup("java:comp/env/" + location);
46: }
47: } catch (NamingException e) {
48: String message = "Could not look up JNDI register at: "
49: + location;
50: throw new WorkflowException(message, e);
51: }
52:
53: return r.registerVariable(context, entry, args, ps);
54: }
55: }
|