1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.data.provider.spring;
17
18 import java.util.Collection;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.kuali.rice.core.api.util.ClassLoaderUtils;
23 import org.kuali.rice.krad.data.metadata.DataObjectMetadata;
24 import org.kuali.rice.krad.data.metadata.impl.DataObjectMetadataImpl;
25 import org.kuali.rice.krad.data.provider.impl.MetadataProviderBase;
26 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
27 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
28 import org.springframework.core.io.DefaultResourceLoader;
29
30
31
32
33
34
35
36
37
38
39
40
41 public class SpringMetadataProviderImpl extends MetadataProviderBase {
42 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
43 .getLogger(SpringMetadataProviderImpl.class);
44
45
46
47
48 protected List<String> resourceLocations;
49
50
51
52
53 protected DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());
54
55
56
57
58 protected DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
59
60
61
62
63 public SpringMetadataProviderImpl() {
64 LOG.debug("Building SpringMetadataProviderImpl");
65 }
66
67
68
69
70 @Override
71 public synchronized void initializeMetadata(Collection<Class<?>> types) {
72
73 if (LOG.isDebugEnabled()) {
74 LOG.debug("Loading Metadata Bean Definitions from Locations:");
75 for (String loc : resourceLocations) {
76 LOG.debug(loc);
77 }
78 }
79
80 XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(beanFactory);
81 String configFileLocationsArray[] = new String[resourceLocations.size()];
82 configFileLocationsArray = resourceLocations.toArray(configFileLocationsArray);
83 xmlReader.loadBeanDefinitions(configFileLocationsArray);
84
85
86 Map<String, DataObjectMetadata> metadataObjects = beanFactory.getBeansOfType(DataObjectMetadata.class);
87 if (LOG.isInfoEnabled()) {
88 LOG.info(metadataObjects.size() + " DataObjectMetadata objects in Spring configuration files");
89 }
90
91 masterMetadataMap.clear();
92 for (DataObjectMetadata metadata : metadataObjects.values()) {
93 if (metadata.getType() != null) {
94 if (metadata instanceof DataObjectMetadataImpl) {
95 ((DataObjectMetadataImpl) metadata).setProviderName(this.getClass().getSimpleName());
96 }
97 masterMetadataMap.put(metadata.getType(), metadata);
98 } else {
99 LOG.error("Configuration Error. MetadataObject in the Spring context contained a null DataObjectType reference: "
100 + metadata);
101 }
102 }
103 }
104
105
106
107
108
109
110 public List<String> getResourceLocations() {
111 return resourceLocations;
112 }
113
114
115
116
117
118
119 public void setResourceLocations(List<String> resourceLocations) {
120 if (LOG.isDebugEnabled()) {
121 LOG.debug("Resource locations set to: " + resourceLocations);
122 }
123 this.resourceLocations = resourceLocations;
124 }
125
126
127
128
129 @Override
130 public String toString() {
131 return getClass().getName() + " : " + resourceLocations;
132 }
133 }