Coverage Report - org.kuali.rice.core.api.resourceloader.ParentChildResourceLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
ParentChildResourceLoader
0%
0/43
0%
0/16
1.733
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.api.resourceloader;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import javax.xml.namespace.QName;
 21  
 
 22  
 import org.kuali.rice.core.api.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  
 class ParentChildResourceLoader implements ResourceLoader {
 31  
 
 32  
     private final ResourceLoader parent;
 33  
     private final ResourceLoader child;
 34  
     private QName name;
 35  
 
 36  0
     ParentChildResourceLoader(ResourceLoader parent, ResourceLoader child) {
 37  0
             if (parent == null) {
 38  0
                     throw new IllegalArgumentException("parent resource loader was null");
 39  
             }
 40  0
             if (child == null) {
 41  0
                     throw new IllegalArgumentException("child resource loader was null");
 42  
             }
 43  0
             this.parent = parent;
 44  0
             this.child = child;
 45  0
             this.name = new QName(child.getName().toString() + " to parent " + parent.getName().toString());
 46  0
     }
 47  
 
 48  
         @Override
 49  
         public <T> T getObject(ObjectDefinition definition) {
 50  0
                 T object = child.<T>getObject(definition);
 51  0
             if (object == null) {
 52  0
                     object = parent.<T>getObject(definition);
 53  
             }
 54  0
             return object;
 55  
         }
 56  
 
 57  
         @Override
 58  
         public <T> T getService(QName qname) {
 59  0
                 T service = child.<T>getService(qname);
 60  0
                 if (service == null) {
 61  0
                         service = parent.<T>getService(qname);
 62  
                 }
 63  0
                 return service;
 64  
     }
 65  
 
 66  
         /**
 67  
          * "Starts" this resource loader.  When started, this method will simply
 68  
          * invoke start on the child resource loader.  It's assumed that the
 69  
          * parent will be started from it's context.
 70  
          * 
 71  
          * @see org.kuali.rice.core.api.lifecycle.Lifecycle#start()
 72  
          */
 73  
         @Override
 74  
     public void start() throws Exception {
 75  0
                 if (!child.isStarted()) {
 76  0
                         child.start();
 77  
                 }
 78  0
         }
 79  
 
 80  
         /**
 81  
          * Just stopes the internal child resource loader.
 82  
          * 
 83  
          * @see org.kuali.rice.core.api.lifecycle.Lifecycle#stop()
 84  
          */
 85  
         @Override
 86  
     public void stop() throws Exception {
 87  0
             if (child.isStarted()) {
 88  0
                     child.stop();
 89  
             }
 90  0
     }
 91  
 
 92  
         @Override
 93  
     public void addResourceLoader(ResourceLoader resourceLoader) {
 94  0
             this.child.addResourceLoader(resourceLoader);
 95  0
     }
 96  
 
 97  
         @Override
 98  
     public void addResourceLoaderFirst(ResourceLoader resourceLoader) {
 99  0
             this.child.addResourceLoaderFirst(resourceLoader);
 100  0
     }
 101  
 
 102  
         @Override
 103  
     public ResourceLoader getResourceLoader(QName name) {
 104  0
             ResourceLoader resourceLoader = this.child.getResourceLoader(name);
 105  0
             if (resourceLoader == null && parent != null) {
 106  0
                     return parent.getResourceLoader(name);
 107  
             } else {
 108  0
                     return resourceLoader;
 109  
             }
 110  
     }
 111  
   
 112  
         @Override
 113  
     public List<QName> getResourceLoaderNames() {
 114  0
                 return this.child.getResourceLoaderNames();
 115  
     }
 116  
 
 117  
         @Override
 118  
     public List<ResourceLoader> getResourceLoaders() {
 119  0
                 return this.child.getResourceLoaders();
 120  
     }
 121  
 
 122  
         @Override
 123  
     public void removeResourceLoader(QName name) {
 124  0
                 this.child.removeResourceLoader(name);
 125  0
     }
 126  
 
 127  
         /**
 128  
          * This overridden method ...
 129  
          * 
 130  
          * @see org.kuali.rice.core.api.lifecycle.Lifecycle#isStarted()
 131  
          */
 132  
         @Override
 133  
         public boolean isStarted() {
 134  
                 // TODO ewestfal - THIS METHOD NEEDS JAVADOCS
 135  0
                 return false;
 136  
         }
 137  
 
 138  
         @Override
 139  
         public void setName(QName name) {
 140  0
                 this.name = name;
 141  0
         }
 142  
 
 143  
         @Override
 144  
         public QName getName() {
 145  0
                 return this.name;
 146  
         }
 147  
 
 148  
         /**
 149  
          * This overridden method ...
 150  
          * 
 151  
          * @see org.kuali.rice.core.api.resourceloader.ResourceLoader#getContents(java.lang.String, boolean)
 152  
          */
 153  
         @Override
 154  
         public String getContents(String indent, boolean servicePerLine) {
 155  0
                 StringBuilder contents = new StringBuilder();
 156  0
                 contents.append(parent.getContents(indent, servicePerLine)).append("\n");
 157  0
                 contents.append(child.getContents(indent, servicePerLine));
 158  0
                 return contents.toString();
 159  
         }
 160  
 
 161  
         
 162  
 
 163  
 }