001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.edl.impl; 017 018import org.apache.logging.log4j.Logger; 019import org.apache.logging.log4j.LogManager; 020import org.kuali.rice.core.api.util.xml.XmlJotter; 021import org.kuali.rice.edl.impl.bo.EDocLiteAssociation; 022import org.kuali.rice.kew.api.WorkflowRuntimeException; 023import org.w3c.dom.Document; 024import org.w3c.dom.Element; 025 026import javax.xml.transform.Templates; 027import java.util.Iterator; 028import java.util.Map; 029 030 031/** 032 * Responsible for notifying components associated with a particular EDL definition. 033 * 034 * @author Kuali Rice Team (rice.collab@kuali.org) 035 */ 036public class EDLController { 037 038 private static final Logger LOG = LogManager.getLogger(EDLController.class); 039 040 private EDocLiteAssociation edocLiteAssociation; 041 private Templates style; 042 private Map configProcessors; 043 private Map preProcessors; 044 private Map postProcessors; 045 private Map stateComponents; 046 private EDLGlobalConfig edlGlobalConfig; 047 private Document defaultDOM; 048 private EDLContext edlContext; 049 050 public Document notifyComponents() { 051 052 try { 053 updateDOMWithProcessors(defaultDOM, preProcessors); 054 updateDOMWithProcessors(defaultDOM, stateComponents); 055 updateDOMWithProcessors(defaultDOM, configProcessors); 056 updateDOMWithProcessors(defaultDOM, stateComponents); 057 updateDOMWithProcessors(defaultDOM, postProcessors); 058 } catch (Exception e) { 059 throw new WorkflowRuntimeException(e); 060 } 061 062 063 return defaultDOM; 064 } 065 066 private void updateDOMWithProcessors(Document dom, Map processors) throws Exception { 067 068 for (Iterator iter = processors.entrySet().iterator(); iter.hasNext();) { 069 Map.Entry processorEntry = (Map.Entry) iter.next(); 070 Element configElement = (Element)processorEntry.getKey(); 071 EDLModelComponent eldModelComp = (EDLModelComponent)((Class)processorEntry.getValue()).newInstance(); 072 eldModelComp.updateDOM(dom, configElement, edlContext); 073 if (LOG.isDebugEnabled()) { 074 LOG.debug("Just completed notification to component " + eldModelComp + " doc content looks like. " + XmlJotter.jotNode(dom)); 075 } 076 077 } 078 } 079 080 public Map getConfigProcessors() { 081 return configProcessors; 082 } 083 public void setConfigProcessors(Map configProcessors) { 084 this.configProcessors = configProcessors; 085 } 086 public EDLGlobalConfig getEdlGlobalConfig() { 087 return edlGlobalConfig; 088 } 089 public void setEdlGlobalConfig(EDLGlobalConfig edlConfig) { 090 this.edlGlobalConfig = edlConfig; 091 } 092 public Templates getStyle() { 093 return style; 094 } 095 public void setStyle(Templates style) { 096 this.style = style; 097 } 098 public EDocLiteAssociation getEdocLiteAssociation() { 099 return edocLiteAssociation; 100 } 101 public void setEdocLiteAssociation(EDocLiteAssociation edocLiteAssociation) { 102 this.edocLiteAssociation = edocLiteAssociation; 103 } 104 public Document getDefaultDOM() { 105 return defaultDOM; 106 } 107 public void setDefaultDOM(Document defaultDOM) { 108 this.defaultDOM = defaultDOM; 109 } 110 public EDLContext getEdlContext() { 111 return edlContext; 112 } 113 public void setEdlContext(EDLContext edlContext) { 114 this.edlContext = edlContext; 115 } 116 117 public Map getPostProcessors() { 118 return postProcessors; 119 } 120 121 public void setPostProcessors(Map postProcessors) { 122 this.postProcessors = postProcessors; 123 } 124 125 public Map getPreProcessors() { 126 return preProcessors; 127 } 128 129 public void setPreProcessors(Map preProcessors) { 130 this.preProcessors = preProcessors; 131 } 132 133 public Map getStateComponents() { 134 return stateComponents; 135 } 136 137 public void setStateComponents(Map stateComponents) { 138 this.stateComponents = stateComponents; 139 } 140}