1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.edl;
18
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.LinkedHashMap;
22 import java.util.Map;
23
24 import javax.xml.xpath.XPath;
25 import javax.xml.xpath.XPathConstants;
26 import javax.xml.xpath.XPathExpressionException;
27 import javax.xml.xpath.XPathFactory;
28
29 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
30 import org.w3c.dom.Element;
31 import org.w3c.dom.Node;
32
33
34
35
36
37
38
39
40 public class EDLGlobalConfig {
41
42 private Map preProcessors = new HashMap();
43 private Map postProcessors = new HashMap();
44 private Map stateComponents = new HashMap();
45 private Map configProcessors = new LinkedHashMap();
46
47 public void addPreProcessor(String preProcessorName, Element element) {
48 try {
49 preProcessors.put(Class.forName(preProcessorName), element);
50 } catch (ClassNotFoundException ce) {
51 throw new WorkflowRuntimeException("Class " + preProcessorName + " not found.", ce);
52 }
53 }
54
55 public void addPostProcessor(String postProcessorName, Element configElement) {
56 try {
57 postProcessors.put(Class.forName(postProcessorName), configElement);
58 } catch (ClassNotFoundException ce) {
59 throw new WorkflowRuntimeException("Class " + postProcessorName + " not found.", ce);
60 }
61 }
62
63 public void addStateComponent(String stateComponentName, Element configElement) {
64 try {
65 stateComponents.put(Class.forName(stateComponentName), configElement);
66 } catch (ClassNotFoundException ce) {
67 throw new WorkflowRuntimeException("Class " + stateComponentName + " not found.", ce);
68 }
69 }
70
71 public void addConfigProcessor(String xpathExpression, String configProcessorName) {
72 Class configProcessor;
73 try {
74 configProcessor = Class.forName(configProcessorName);
75 } catch (ClassNotFoundException ce) {
76 throw new WorkflowRuntimeException("Class " + configProcessorName + " not found.", ce);
77 }
78 if (configProcessors.containsKey(configProcessor)) {
79 throw new WorkflowRuntimeException("Config processor " + configProcessorName + " attempted to register an xpath expression twice. " +
80 "The expression being used is " + configProcessors.get(configProcessor));
81 } else {
82 configProcessors.put(configProcessor, xpathExpression);
83 }
84 }
85
86 public Map getPreProcessors() {
87 return preProcessors;
88 }
89
90 public Map getPostProcessors() {
91 return postProcessors;
92 }
93
94 public Map getStateComponents() {
95 return stateComponents;
96 }
97
98 public Class getConfigProcessor(Node configElement) {
99 if (configElement instanceof Element) {
100
101 XPath xpath = XPathFactory.newInstance().newXPath();
102 String xpathExpression = "";
103 try {
104 for (Iterator iter = configProcessors.entrySet().iterator(); iter.hasNext();) {
105 Map.Entry configProcessor = (Map.Entry) iter.next();
106 xpathExpression = (String) configProcessor.getKey();
107 Boolean match = (Boolean) xpath.evaluate(xpathExpression, configElement, XPathConstants.BOOLEAN);
108 if (match.booleanValue()) {
109 return (Class) configProcessor.getValue();
110 }
111 }
112 return null;
113 } catch (XPathExpressionException e) {
114 throw new WorkflowRuntimeException("Unable to evaluate xpath expression " + xpathExpression, e);
115 } catch (Exception ie) {
116 throw new WorkflowRuntimeException(ie);
117 }
118 }
119 return null;
120 }
121
122 public Map getConfigProcessors() {
123 return configProcessors;
124 }
125
126 public void setConfigProcessors(Map configProcessors) {
127 this.configProcessors = configProcessors;
128 }
129
130 public void setPostProcessors(Map postProcessors) {
131 this.postProcessors = postProcessors;
132 }
133
134 public void setPreProcessors(Map preProcessors) {
135 this.preProcessors = preProcessors;
136 }
137
138 public void setStateComponents(Map stateComponents) {
139 this.stateComponents = stateComponents;
140 }
141
142
143 }