Coverage Report - org.kuali.rice.edl.impl.EDLGlobalConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
EDLGlobalConfig
0%
0/56
0%
0/8
2.462
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * Store global EDL config information parsed from config file.
 35  
  * 
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
 }