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