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.4 $
24: */
25: public class JNDIFunctionProvider implements FunctionProvider {
26: //~ Static fields/initializers /////////////////////////////////////////////
27:
28: private static final Log log = LogFactory
29: .getLog(JNDIFunctionProvider.class);
30:
31: //~ Methods ////////////////////////////////////////////////////////////////
32:
33: public void execute(Map transientVars, Map args, PropertySet ps)
34: throws WorkflowException {
35: String location = (String) args
36: .get(AbstractWorkflow.JNDI_LOCATION);
37:
38: if (location == null) {
39: throw new WorkflowException(AbstractWorkflow.JNDI_LOCATION
40: + " argument is null");
41: }
42:
43: location = location.trim();
44:
45: FunctionProvider provider;
46:
47: try {
48: try {
49: provider = (FunctionProvider) new InitialContext()
50: .lookup(location);
51: } catch (NamingException e) {
52: provider = (FunctionProvider) new InitialContext()
53: .lookup("java:comp/env/" + location);
54: }
55: } catch (NamingException e) {
56: String message = "Could not get handle to JNDI FunctionProvider at: "
57: + location;
58: throw new WorkflowException(message, e);
59: }
60:
61: provider.execute(transientVars, args, ps);
62: }
63: }
|