| 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 | 0 | public class EDLGlobalConfig { |
| 41 | |
|
| 42 | 0 | private Map preProcessors = new HashMap(); |
| 43 | 0 | private Map postProcessors = new HashMap(); |
| 44 | 0 | private Map stateComponents = new HashMap(); |
| 45 | 0 | private Map configProcessors = new LinkedHashMap(); |
| 46 | |
|
| 47 | |
public void addPreProcessor(String preProcessorName, Element element) { |
| 48 | |
try { |
| 49 | 0 | preProcessors.put(Class.forName(preProcessorName), element); |
| 50 | 0 | } catch (ClassNotFoundException ce) { |
| 51 | 0 | throw new WorkflowRuntimeException("Class " + preProcessorName + " not found.", ce); |
| 52 | 0 | } |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
public void addPostProcessor(String postProcessorName, Element configElement) { |
| 56 | |
try { |
| 57 | 0 | postProcessors.put(Class.forName(postProcessorName), configElement); |
| 58 | 0 | } catch (ClassNotFoundException ce) { |
| 59 | 0 | throw new WorkflowRuntimeException("Class " + postProcessorName + " not found.", ce); |
| 60 | 0 | } |
| 61 | 0 | } |
| 62 | |
|
| 63 | |
public void addStateComponent(String stateComponentName, Element configElement) { |
| 64 | |
try { |
| 65 | 0 | stateComponents.put(Class.forName(stateComponentName), configElement); |
| 66 | 0 | } catch (ClassNotFoundException ce) { |
| 67 | 0 | throw new WorkflowRuntimeException("Class " + stateComponentName + " not found.", ce); |
| 68 | 0 | } |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
public void addConfigProcessor(String xpathExpression, String configProcessorName) { |
| 72 | |
Class configProcessor; |
| 73 | |
try { |
| 74 | 0 | configProcessor = Class.forName(configProcessorName); |
| 75 | 0 | } catch (ClassNotFoundException ce) { |
| 76 | 0 | throw new WorkflowRuntimeException("Class " + configProcessorName + " not found.", ce); |
| 77 | 0 | } |
| 78 | 0 | if (configProcessors.containsKey(configProcessor)) { |
| 79 | 0 | 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 | 0 | configProcessors.put(configProcessor, xpathExpression); |
| 83 | |
} |
| 84 | 0 | } |
| 85 | |
|
| 86 | |
public Map getPreProcessors() { |
| 87 | 0 | return preProcessors; |
| 88 | |
} |
| 89 | |
|
| 90 | |
public Map getPostProcessors() { |
| 91 | 0 | return postProcessors; |
| 92 | |
} |
| 93 | |
|
| 94 | |
public Map getStateComponents() { |
| 95 | 0 | return stateComponents; |
| 96 | |
} |
| 97 | |
|
| 98 | |
public Class getConfigProcessor(Node configElement) { |
| 99 | 0 | if (configElement instanceof Element) { |
| 100 | |
|
| 101 | 0 | XPath xpath = XPathFactory.newInstance().newXPath(); |
| 102 | 0 | String xpathExpression = ""; |
| 103 | |
try { |
| 104 | 0 | for (Iterator iter = configProcessors.entrySet().iterator(); iter.hasNext();) { |
| 105 | 0 | Map.Entry configProcessor = (Map.Entry) iter.next(); |
| 106 | 0 | xpathExpression = (String) configProcessor.getKey(); |
| 107 | 0 | Boolean match = (Boolean) xpath.evaluate(xpathExpression, configElement, XPathConstants.BOOLEAN); |
| 108 | 0 | if (match.booleanValue()) { |
| 109 | 0 | return (Class) configProcessor.getValue(); |
| 110 | |
} |
| 111 | 0 | } |
| 112 | 0 | return null; |
| 113 | 0 | } catch (XPathExpressionException e) { |
| 114 | 0 | throw new WorkflowRuntimeException("Unable to evaluate xpath expression " + xpathExpression, e); |
| 115 | 0 | } catch (Exception ie) { |
| 116 | 0 | throw new WorkflowRuntimeException(ie); |
| 117 | |
} |
| 118 | |
} |
| 119 | 0 | return null; |
| 120 | |
} |
| 121 | |
|
| 122 | |
public Map getConfigProcessors() { |
| 123 | 0 | return configProcessors; |
| 124 | |
} |
| 125 | |
|
| 126 | |
public void setConfigProcessors(Map configProcessors) { |
| 127 | 0 | this.configProcessors = configProcessors; |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
public void setPostProcessors(Map postProcessors) { |
| 131 | 0 | this.postProcessors = postProcessors; |
| 132 | 0 | } |
| 133 | |
|
| 134 | |
public void setPreProcessors(Map preProcessors) { |
| 135 | 0 | this.preProcessors = preProcessors; |
| 136 | 0 | } |
| 137 | |
|
| 138 | |
public void setStateComponents(Map stateComponents) { |
| 139 | 0 | this.stateComponents = stateComponents; |
| 140 | 0 | } |
| 141 | |
|
| 142 | |
|
| 143 | |
} |