View Javadoc

1   /*
2    * Copyright 2007-2008 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.core.resourceloader;
17  
18  import java.util.List;
19  
20  import javax.xml.namespace.QName;
21  
22  import org.kuali.rice.core.reflect.ObjectDefinition;
23  
24  /**
25   * This is a description of what this class does - ewestfal don't forget to fill this in.
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   *
29   */
30  public class ParentChildResourceLoader extends BaseResourceLoader {
31  
32      private ResourceLoader parent;
33      private ResourceLoader child;
34  
35      public ParentChildResourceLoader(ResourceLoader parent, ResourceLoader child) {
36  	super(new QName(child.getName().toString() + " to parent " + parent.getName().toString()));
37  	this.parent = parent;
38  	this.child = child;
39      }
40  
41      public Object getObject(ObjectDefinition definition) {
42  	Object object = child.getObject(definition);
43  	if (object == null) {
44  	    object = parent.getObject(definition);
45  	}
46  	return object;
47      }
48  
49      public Object getService(QName qname) {
50  	Object service = child.getService(qname);
51  	if (service == null) {
52  	    service = parent.getService(qname);
53  	}
54  	return service;
55      }
56  
57      public void start() throws Exception {
58  	// just start the child, it will be assumed that parent will be started from it's context
59  	if (!child.isStarted()) {
60  	    child.start();
61  	}
62  	super.start();
63      }
64  
65      public void stop() throws Exception {
66  	child.stop();
67  	super.stop();
68      }
69  
70      public void addResourceLoader(ResourceLoader resourceLoader) {
71  	this.child.addResourceLoader(resourceLoader);
72      }
73  
74      public void addResourceLoaderFirst(ResourceLoader resourceLoader) {
75  	this.child.addResourceLoaderFirst(resourceLoader);
76      }
77  
78   
79      public ResourceLoader getResourceLoader(QName name) {
80      	ResourceLoader resourceLoader = this.child.getResourceLoader(name);
81      	if (resourceLoader == null && parent != null) {
82      		return parent.getResourceLoader(name);
83      	} else {
84      		return resourceLoader;
85      	}
86      }
87    
88      public List<QName> getResourceLoaderNames() {
89  	return this.child.getResourceLoaderNames();
90      }
91  
92      public List<ResourceLoader> getResourceLoaders() {
93  	return this.child.getResourceLoaders();
94      }
95  
96      public void removeResourceLoader(QName name) {
97  	this.child.removeResourceLoader(name);
98      }
99  
100 
101 
102 }