View Javadoc

1   /**
2    * Copyright 2005-2015 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.kew.plugin;
17  
18  import org.kuali.rice.core.api.config.property.Config;
19  import org.kuali.rice.core.impl.config.property.ConfigParserImplConfig;
20  
21  import java.io.File;
22  import java.net.MalformedURLException;
23  import java.net.URL;
24  import java.util.ArrayList;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.Properties;
29  
30  /**
31   * Class representing a plugin's config, containing configuration
32   * settings parsed from the config.
33   *
34   * @see Config
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class PluginConfig extends ConfigParserImplConfig {
39  
40  	private String resourceLoaderClassname;
41  	private List listeners = new ArrayList();
42  	private Properties parentProperties;
43  	private Map parentObjects;
44  	private Config parentConfig;
45  
46  	public PluginConfig(URL url, Config parentConfig) {
47  		super(url.toString());
48  		this.parentProperties = parentConfig.getProperties();
49  		this.parentObjects = parentConfig.getObjects();
50  		this.parentConfig = parentConfig;
51  	}
52  
53  	public PluginConfig(File configFile, Config parentConfig) throws MalformedURLException {
54  		this(configFile.toURI().toURL(), parentConfig);
55  	}
56  
57  	public Properties getBaseProperties() {
58  		return this.parentProperties;
59  	}
60  
61  	public Map getBaseObjects() {
62  		return this.parentObjects;
63  	}
64  
65  	public void addListener(String listenerClass) {
66  		listeners.add(listenerClass);
67  	}
68  
69  	public List getListeners() {
70  		return listeners;
71  	}
72  
73  	public void setResourceLoaderClassname(String resourceLoaderClassname) {
74  		this.resourceLoaderClassname = resourceLoaderClassname;
75  	}
76  
77  	public String getResourceLoaderClassname() {
78  		return resourceLoaderClassname;
79  	}
80  
81      public String toString() {
82          return "[PluginConfig: resourceLoaderClassname: " + getResourceLoaderClassname() + "]";
83      }
84      
85  	 
86  	@Override
87  	public Object getObject(String key) {
88  		Object object = super.getObject(key);
89  		if (object == null && parentConfig != null) {
90  			object = parentConfig.getObject(key);
91  		}
92  		return object;
93  	}
94  
95  	@Override
96  	public Map<String, Object> getObjects() {
97  		Map<String, Object> finalObjects = new HashMap<String, Object>(super.getObjects());
98  		if (parentConfig != null) {
99  			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 }