| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.edl.impl; |
| 18 | |
|
| 19 | |
import java.io.InputStream; |
| 20 | |
import java.util.LinkedHashMap; |
| 21 | |
import java.util.Map; |
| 22 | |
|
| 23 | |
import javax.xml.parsers.DocumentBuilderFactory; |
| 24 | |
import javax.xml.xpath.XPath; |
| 25 | |
import javax.xml.xpath.XPathConstants; |
| 26 | |
import javax.xml.xpath.XPathFactory; |
| 27 | |
|
| 28 | |
import org.kuali.rice.core.util.RiceUtilities; |
| 29 | |
import org.w3c.dom.Document; |
| 30 | |
import org.w3c.dom.Element; |
| 31 | |
import org.w3c.dom.NodeList; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | 0 | public class EDLGlobalConfigFactory { |
| 39 | |
|
| 40 | |
private static final String CONFIG_PROCESSOR_XPATH_XPRSN = "xpathExp"; |
| 41 | |
private static final String CONFIG_PROCESSOR_CLASS_NAME = "className"; |
| 42 | |
|
| 43 | |
|
| 44 | |
public static EDLGlobalConfig createEDLGlobalConfig(String edlConfigLocation) throws Exception { |
| 45 | 0 | EDLGlobalConfig edlConfig = new EDLGlobalConfig(); |
| 46 | 0 | InputStream configStream = RiceUtilities.getResourceAsStream(edlConfigLocation); |
| 47 | 0 | Document configXml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(configStream); |
| 48 | |
|
| 49 | 0 | edlConfig.setPreProcessors(createProcessorMap("//preProcessors/preProcessor", configXml)); |
| 50 | 0 | edlConfig.setPostProcessors(createProcessorMap("//postProcessors/postProcessor", configXml)); |
| 51 | 0 | edlConfig.setStateComponents(createProcessorMap("//stateComponents/stateComponent", configXml)); |
| 52 | 0 | edlConfig.setConfigProcessors(createConfigProcessorMap("//configProcessors/configProcessor", configXml)); |
| 53 | |
|
| 54 | 0 | return edlConfig; |
| 55 | |
} |
| 56 | |
|
| 57 | |
private static Map createProcessorMap(String xpathExpression, Document doc) throws Exception { |
| 58 | 0 | Map processors = new LinkedHashMap(); |
| 59 | 0 | XPath xpath = XPathFactory.newInstance().newXPath(); |
| 60 | 0 | NodeList globalProcessorDeclarations = (NodeList)xpath.evaluate(xpathExpression, doc, XPathConstants.NODESET); |
| 61 | 0 | for (int i = 0; i < globalProcessorDeclarations.getLength(); i++) { |
| 62 | 0 | Element globalProcessorDeclaraion = (Element)globalProcessorDeclarations.item(i); |
| 63 | 0 | processors.put(globalProcessorDeclaraion, Class.forName(globalProcessorDeclaraion.getFirstChild().getNodeValue())); |
| 64 | |
} |
| 65 | 0 | return processors; |
| 66 | |
} |
| 67 | |
|
| 68 | |
private static Map createConfigProcessorMap(String xpathExpression, Document doc) throws Exception { |
| 69 | 0 | Map configProcessors = new LinkedHashMap(); |
| 70 | 0 | XPath xpath = XPathFactory.newInstance().newXPath(); |
| 71 | 0 | NodeList globalConfigProcessorDeclarations = (NodeList)xpath.evaluate(xpathExpression, doc, XPathConstants.NODESET); |
| 72 | 0 | for (int i = 0; i < globalConfigProcessorDeclarations.getLength(); i++) { |
| 73 | 0 | Element globalProcessorDeclaraion = (Element)globalConfigProcessorDeclarations.item(i); |
| 74 | 0 | String xpathEx = (String)xpath.evaluate(CONFIG_PROCESSOR_XPATH_XPRSN, globalProcessorDeclaraion, XPathConstants.STRING); |
| 75 | 0 | String className = (String)xpath.evaluate(CONFIG_PROCESSOR_CLASS_NAME, globalProcessorDeclaraion, XPathConstants.STRING); |
| 76 | 0 | configProcessors.put(xpathEx, Class.forName(className)); |
| 77 | |
} |
| 78 | 0 | return configProcessors; |
| 79 | |
} |
| 80 | |
} |