01: package org.concern.controller.jmx;
02:
03: import org.concern.*;
04: import org.concern.Worklist;
05: import org.apache.commons.logging.LogFactory;
06:
07: import javax.naming.*;
08: import java.util.*;
09:
10: public class JndiControllerLookup extends ControllerLookup {
11: private static org.apache.commons.logging.Log LOG = LogFactory
12: .getLog(ControllerLookup.class);
13:
14: private static String jndiRoot = "java:controller";
15:
16: public JndiControllerLookup() {
17: instance = this ;
18: }
19:
20: public String getJndiRoot() {
21: return jndiRoot;
22: }
23:
24: public void setJndiRoot(String jndiRoot) {
25: if (jndiRoot.endsWith("/"))
26: jndiRoot = jndiRoot.substring(0, jndiRoot.length() - 1);
27: JndiControllerLookup.jndiRoot = jndiRoot;
28: }
29:
30: public Controller getController(String processName) {
31: try {
32: return (Controller) new InitialContext()
33: .lookup(getJndiRoot() + "/" + processName);
34: } catch (NamingException e) {
35: LOG.warn("No controller with name " + processName);
36: return null;
37: }
38: }
39:
40: public String[] getControllerNames() {
41: try {
42: List names = new LinkedList();
43: NamingEnumeration enumeration = new InitialContext()
44: .list(getJndiRoot());
45: while (enumeration.hasMoreElements()) {
46: NameClassPair nameClassPair = (NameClassPair) enumeration
47: .nextElement();
48: String name = nameClassPair.getName();
49: if (!"Worklist".equals(name)
50: && !"Collaboration".equals(name))
51: names.add(name);
52: }
53: return (String[]) names.toArray(new String[names.size()]);
54: } catch (NamingException e) {
55: LOG.error("JndiRoot does not exist " + getJndiRoot());
56: throw new RuntimeException(e);
57: }
58: }
59:
60: public Worklist getWorklist() {
61: try {
62: return (Worklist) new InitialContext().lookup(getJndiRoot()
63: + "/Worklist");
64: } catch (NamingException e) {
65: return null;
66: }
67: }
68:
69: public Collaboration getCollaboration() {
70: try {
71: return (Collaboration) new InitialContext()
72: .lookup(getJndiRoot() + "/Collaboration");
73: } catch (NamingException e) {
74: return null;
75: }
76: }
77: }
|