001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.rice;
017:
018: import java.io.InputStream;
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.apache.log4j.Logger;
023: import org.apache.ojb.broker.metadata.ConnectionRepository;
024: import org.apache.ojb.broker.metadata.DescriptorRepository;
025: import org.apache.ojb.broker.metadata.MetadataManager;
026: import org.springframework.beans.factory.InitializingBean;
027: import org.springframework.core.io.DefaultResourceLoader;
028:
029: import edu.iu.uis.eden.util.ClassLoaderUtils;
030:
031: public class OjbMetadataLoader implements InitializingBean {
032:
033: private static final Logger LOG = Logger
034: .getLogger(OjbMetadataLoader.class);
035:
036: private List<String> repositoryDescriptors = new ArrayList<String>();
037: private List<String> connectionDescriptors = new ArrayList<String>();
038:
039: public List<String> getConnectionDescriptors() {
040: return connectionDescriptors;
041: }
042:
043: public void setConnectionDescriptors(
044: List<String> connectionDescriptors) {
045: this .connectionDescriptors = connectionDescriptors;
046: }
047:
048: public List<String> getRepositoryDescriptors() {
049: return repositoryDescriptors;
050: }
051:
052: public void setRepositoryDescriptors(
053: List<String> repositoryDescriptors) {
054: this .repositoryDescriptors = repositoryDescriptors;
055: }
056:
057: public void afterPropertiesSet() throws Exception {
058:
059: MetadataManager mm = MetadataManager.getInstance();
060: DefaultResourceLoader resourceLoader = new DefaultResourceLoader(
061: ClassLoaderUtils.getDefaultClassLoader());
062:
063: for (String repositoryDescriptor : repositoryDescriptors) {
064: InputStream is = resourceLoader.getResource(
065: repositoryDescriptor).getInputStream();
066: DescriptorRepository dr = mm.readDescriptorRepository(is);
067: mm.mergeDescriptorRepository(dr);
068: if (LOG.isDebugEnabled()) {
069: LOG
070: .debug("--------------------------------------------------------------------------");
071: LOG.debug("Merging repository descriptor: "
072: + repositoryDescriptor);
073: LOG
074: .debug("--------------------------------------------------------------------------");
075: }
076: try {
077: is.close();
078: } catch (Exception e) {
079: LOG.warn("Failed to close stream to file "
080: + repositoryDescriptor, e);
081: }
082: }
083:
084: for (String connectionDesciptor : connectionDescriptors) {
085: InputStream is = resourceLoader.getResource(
086: connectionDesciptor).getInputStream();
087: ConnectionRepository cr = mm.readConnectionRepository(is);
088: mm.mergeConnectionRepository(cr);
089: if (LOG.isDebugEnabled()) {
090: LOG
091: .debug("--------------------------------------------------------------------------");
092: LOG.debug("Merging connection descriptor: "
093: + connectionDesciptor);
094: LOG
095: .debug("--------------------------------------------------------------------------");
096: }
097: try {
098: is.close();
099: } catch (Exception e) {
100: LOG.warn("Failed to close stream to file "
101: + connectionDesciptor, e);
102: }
103: }
104:
105: }
106:
107: }
|