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