001 /** 002 * Copyright 2005-2014 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 */ 016 package org.kuali.rice.edl.impl; 017 018 import org.apache.log4j.Logger; 019 import org.kuali.rice.core.api.util.xml.XmlJotter; 020 import org.kuali.rice.edl.impl.bo.EDocLiteAssociation; 021 import org.kuali.rice.kew.api.WorkflowRuntimeException; 022 import org.w3c.dom.Document; 023 import org.w3c.dom.Element; 024 025 import javax.xml.transform.Templates; 026 import java.util.Iterator; 027 import java.util.Map; 028 029 030 /** 031 * Responsible for notifying components associated with a particular EDL definition. 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 */ 035 public class EDLController { 036 037 private static final Logger LOG = Logger.getLogger(EDLController.class); 038 039 private EDocLiteAssociation edocLiteAssociation; 040 private Templates style; 041 private Map configProcessors; 042 private Map preProcessors; 043 private Map postProcessors; 044 private Map stateComponents; 045 private EDLGlobalConfig edlGlobalConfig; 046 private Document defaultDOM; 047 private EDLContext edlContext; 048 049 public Document notifyComponents() { 050 051 try { 052 updateDOMWithProcessors(defaultDOM, preProcessors); 053 updateDOMWithProcessors(defaultDOM, stateComponents); 054 updateDOMWithProcessors(defaultDOM, configProcessors); 055 updateDOMWithProcessors(defaultDOM, stateComponents); 056 updateDOMWithProcessors(defaultDOM, postProcessors); 057 } catch (Exception e) { 058 throw new WorkflowRuntimeException(e); 059 } 060 061 062 return defaultDOM; 063 } 064 065 private void updateDOMWithProcessors(Document dom, Map processors) throws Exception { 066 067 for (Iterator iter = processors.entrySet().iterator(); iter.hasNext();) { 068 Map.Entry processorEntry = (Map.Entry) iter.next(); 069 Element configElement = (Element)processorEntry.getKey(); 070 EDLModelComponent eldModelComp = (EDLModelComponent)((Class)processorEntry.getValue()).newInstance(); 071 eldModelComp.updateDOM(dom, configElement, edlContext); 072 if (LOG.isDebugEnabled()) { 073 LOG.debug("Just completed notification to component " + eldModelComp + " doc content looks like. " + XmlJotter.jotNode(dom)); 074 } 075 076 } 077 } 078 079 public Map getConfigProcessors() { 080 return configProcessors; 081 } 082 public void setConfigProcessors(Map configProcessors) { 083 this.configProcessors = configProcessors; 084 } 085 public EDLGlobalConfig getEdlGlobalConfig() { 086 return edlGlobalConfig; 087 } 088 public void setEdlGlobalConfig(EDLGlobalConfig edlConfig) { 089 this.edlGlobalConfig = edlConfig; 090 } 091 public Templates getStyle() { 092 return style; 093 } 094 public void setStyle(Templates style) { 095 this.style = style; 096 } 097 public EDocLiteAssociation getEdocLiteAssociation() { 098 return edocLiteAssociation; 099 } 100 public void setEdocLiteAssociation(EDocLiteAssociation edocLiteAssociation) { 101 this.edocLiteAssociation = edocLiteAssociation; 102 } 103 public Document getDefaultDOM() { 104 return defaultDOM; 105 } 106 public void setDefaultDOM(Document defaultDOM) { 107 this.defaultDOM = defaultDOM; 108 } 109 public EDLContext getEdlContext() { 110 return edlContext; 111 } 112 public void setEdlContext(EDLContext edlContext) { 113 this.edlContext = edlContext; 114 } 115 116 public Map getPostProcessors() { 117 return postProcessors; 118 } 119 120 public void setPostProcessors(Map postProcessors) { 121 this.postProcessors = postProcessors; 122 } 123 124 public Map getPreProcessors() { 125 return preProcessors; 126 } 127 128 public void setPreProcessors(Map preProcessors) { 129 this.preProcessors = preProcessors; 130 } 131 132 public Map getStateComponents() { 133 return stateComponents; 134 } 135 136 public void setStateComponents(Map stateComponents) { 137 this.stateComponents = stateComponents; 138 } 139 }