| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.util; |
| 17 | |
|
| 18 | |
import org.apache.log4j.Logger; |
| 19 | |
import org.apache.ojb.broker.metadata.ConnectionRepository; |
| 20 | |
import org.apache.ojb.broker.metadata.DescriptorRepository; |
| 21 | |
import org.apache.ojb.broker.metadata.MetadataManager; |
| 22 | |
import org.kuali.rice.core.api.util.ClassLoaderUtils; |
| 23 | |
import org.springframework.beans.factory.InitializingBean; |
| 24 | |
import org.springframework.core.io.DefaultResourceLoader; |
| 25 | |
|
| 26 | |
import java.io.InputStream; |
| 27 | |
import java.util.ArrayList; |
| 28 | |
import java.util.List; |
| 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 | |
} |