001/** 002 * Copyright 2005-2016 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.kew.plugin; 017 018import org.kuali.rice.core.api.config.property.Config; 019import org.kuali.rice.core.impl.config.property.ConfigParserImplConfig; 020 021import java.io.File; 022import java.net.MalformedURLException; 023import java.net.URL; 024import java.util.ArrayList; 025import java.util.HashMap; 026import java.util.List; 027import java.util.Map; 028import java.util.Properties; 029 030/** 031 * Class representing a plugin's config, containing configuration 032 * settings parsed from the config. 033 * 034 * @see Config 035 * 036 * @author Kuali Rice Team (rice.collab@kuali.org) 037 */ 038public class PluginConfig extends ConfigParserImplConfig { 039 040 private String resourceLoaderClassname; 041 private List listeners = new ArrayList(); 042 private Properties parentProperties; 043 private Map parentObjects; 044 private Config parentConfig; 045 046 public PluginConfig(URL url, Config parentConfig) { 047 super(url.toString()); 048 this.parentProperties = parentConfig.getProperties(); 049 this.parentObjects = parentConfig.getObjects(); 050 this.parentConfig = parentConfig; 051 } 052 053 public PluginConfig(File configFile, Config parentConfig) throws MalformedURLException { 054 this(configFile.toURI().toURL(), parentConfig); 055 } 056 057 public Properties getBaseProperties() { 058 return this.parentProperties; 059 } 060 061 public Map getBaseObjects() { 062 return this.parentObjects; 063 } 064 065 public void addListener(String listenerClass) { 066 listeners.add(listenerClass); 067 } 068 069 public List getListeners() { 070 return listeners; 071 } 072 073 public void setResourceLoaderClassname(String resourceLoaderClassname) { 074 this.resourceLoaderClassname = resourceLoaderClassname; 075 } 076 077 public String getResourceLoaderClassname() { 078 return resourceLoaderClassname; 079 } 080 081 public String toString() { 082 return "[PluginConfig: resourceLoaderClassname: " + getResourceLoaderClassname() + "]"; 083 } 084 085 086 @Override 087 public Object getObject(String key) { 088 Object object = super.getObject(key); 089 if (object == null && parentConfig != null) { 090 object = parentConfig.getObject(key); 091 } 092 return object; 093 } 094 095 @Override 096 public Map<String, Object> getObjects() { 097 Map<String, Object> finalObjects = new HashMap<String, Object>(super.getObjects()); 098 if (parentConfig != null) { 099 Map<String, Object> parentObjects = parentConfig.getObjects(); 100 for (String key : parentObjects.keySet()) { 101 if (!finalObjects.containsKey(key)) { 102 finalObjects.put(key, parentObjects.get(key)); 103 } 104 } 105 } 106 107 return finalObjects; 108 } 109}