Coverage Report - org.kuali.rice.krad.util.OjbMetadataLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
OjbMetadataLoader
0%
0/39
0%
0/8
2.2
 
 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.krad.util;
 17  
 
 18  
 import java.io.InputStream;
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import org.apache.log4j.Logger;
 23  
 import org.apache.ojb.broker.metadata.ConnectionRepository;
 24  
 import org.apache.ojb.broker.metadata.DescriptorRepository;
 25  
 import org.apache.ojb.broker.metadata.MetadataManager;
 26  
 import org.kuali.rice.core.util.ClassLoaderUtils;
 27  
 import org.springframework.beans.factory.InitializingBean;
 28  
 import org.springframework.core.io.DefaultResourceLoader;
 29  
 
 30  0
 public class OjbMetadataLoader implements InitializingBean {
 31  
     
 32  0
     private static final Logger LOG = Logger.getLogger(OjbMetadataLoader.class);
 33  
 
 34  0
     private List<String> repositoryDescriptors = new ArrayList<String>();
 35  0
     private List<String> connectionDescriptors = new ArrayList<String>(); 
 36  
     
 37  
     public List<String> getConnectionDescriptors() {
 38  0
         return connectionDescriptors;
 39  
     }
 40  
 
 41  
     public void setConnectionDescriptors(List<String> connectionDescriptors) {
 42  0
         this.connectionDescriptors = connectionDescriptors;
 43  0
     }
 44  
 
 45  
     public List<String> getRepositoryDescriptors() {
 46  0
         return repositoryDescriptors;
 47  
     }
 48  
 
 49  
     public void setRepositoryDescriptors(List<String> repositoryDescriptors) {
 50  0
         this.repositoryDescriptors = repositoryDescriptors;
 51  0
     }
 52  
 
 53  
     public void afterPropertiesSet() throws Exception {
 54  
         
 55  0
         MetadataManager mm = MetadataManager.getInstance();
 56  0
         DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());
 57  
         
 58  0
         for (String repositoryDescriptor : repositoryDescriptors) {
 59  0
             InputStream is = resourceLoader.getResource(repositoryDescriptor).getInputStream();
 60  0
             DescriptorRepository dr = mm.readDescriptorRepository(is);
 61  0
             mm.mergeDescriptorRepository(dr);
 62  0
             if (LOG.isDebugEnabled()) {
 63  0
                 LOG.debug("--------------------------------------------------------------------------");
 64  0
                 LOG.debug("Merging repository descriptor: " + repositoryDescriptor);
 65  0
                 LOG.debug("--------------------------------------------------------------------------");
 66  
             }
 67  
             try {
 68  0
                 is.close();
 69  0
             } catch (Exception e) {
 70  0
                 LOG.warn("Failed to close stream to file " + repositoryDescriptor, e);
 71  0
             }
 72  0
         }
 73  
         
 74  0
         for (String connectionDesciptor : connectionDescriptors) {
 75  0
             InputStream is = resourceLoader.getResource(connectionDesciptor).getInputStream();
 76  0
             ConnectionRepository cr = mm.readConnectionRepository(is);
 77  0
             mm.mergeConnectionRepository(cr);
 78  0
             if (LOG.isDebugEnabled()) {
 79  0
                 LOG.debug("--------------------------------------------------------------------------");
 80  0
                 LOG.debug("Merging connection descriptor: " + connectionDesciptor);
 81  0
                 LOG.debug("--------------------------------------------------------------------------");
 82  
             }
 83  
             try {
 84  0
                 is.close();
 85  0
             } catch (Exception e) {
 86  0
                 LOG.warn("Failed to close stream to file " + connectionDesciptor, e);
 87  0
             }
 88  0
         }
 89  
         
 90  0
     }
 91  
 
 92  
 }