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 public class OjbMetadataLoader implements InitializingBean {
31
32 private static final Logger LOG = Logger.getLogger(OjbMetadataLoader.class);
33
34 private List<String> repositoryDescriptors = new ArrayList<String>();
35 private List<String> connectionDescriptors = new ArrayList<String>();
36
37 public List<String> getConnectionDescriptors() {
38 return connectionDescriptors;
39 }
40
41 public void setConnectionDescriptors(List<String> connectionDescriptors) {
42 this.connectionDescriptors = connectionDescriptors;
43 }
44
45 public List<String> getRepositoryDescriptors() {
46 return repositoryDescriptors;
47 }
48
49 public void setRepositoryDescriptors(List<String> repositoryDescriptors) {
50 this.repositoryDescriptors = repositoryDescriptors;
51 }
52
53 public void afterPropertiesSet() throws Exception {
54
55 MetadataManager mm = MetadataManager.getInstance();
56 DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());
57
58 for (String repositoryDescriptor : repositoryDescriptors) {
59 InputStream is = resourceLoader.getResource(repositoryDescriptor).getInputStream();
60 DescriptorRepository dr = mm.readDescriptorRepository(is);
61 mm.mergeDescriptorRepository(dr);
62 if (LOG.isDebugEnabled()) {
63 LOG.debug("--------------------------------------------------------------------------");
64 LOG.debug("Merging repository descriptor: " + repositoryDescriptor);
65 LOG.debug("--------------------------------------------------------------------------");
66 }
67 try {
68 is.close();
69 } catch (Exception e) {
70 LOG.warn("Failed to close stream to file " + repositoryDescriptor, e);
71 }
72 }
73
74 for (String connectionDesciptor : connectionDescriptors) {
75 InputStream is = resourceLoader.getResource(connectionDesciptor).getInputStream();
76 ConnectionRepository cr = mm.readConnectionRepository(is);
77 mm.mergeConnectionRepository(cr);
78 if (LOG.isDebugEnabled()) {
79 LOG.debug("--------------------------------------------------------------------------");
80 LOG.debug("Merging connection descriptor: " + connectionDesciptor);
81 LOG.debug("--------------------------------------------------------------------------");
82 }
83 try {
84 is.close();
85 } catch (Exception e) {
86 LOG.warn("Failed to close stream to file " + connectionDesciptor, e);
87 }
88 }
89
90 }
91
92 }