1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.config.service;
17
18 import java.io.UnsupportedEncodingException;
19 import java.util.HashMap;
20 import java.util.Map;
21 import java.util.Properties;
22
23 import org.kuali.common.util.PropertyUtils;
24 import org.kuali.common.util.project.KualiUtilProjectConstants;
25 import org.kuali.common.util.project.ProjectService;
26 import org.kuali.common.util.project.ProjectUtils;
27 import org.kuali.common.util.project.model.Project;
28 import org.kuali.common.util.project.model.ProjectIdentifier;
29 import org.kuali.common.util.xml.service.XmlService;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.context.support.GenericXmlApplicationContext;
33 import org.springframework.core.io.ByteArrayResource;
34 import org.springframework.core.io.Resource;
35
36
37
38
39 @Deprecated
40 public class SpringConfigService extends AbstractCachingConfigService {
41
42 public SpringConfigService(ProjectService projectService, XmlService xmlService) {
43 super(projectService, xmlService);
44 }
45
46 private static final Logger logger = LoggerFactory.getLogger(SpringConfigService.class);
47
48 private static final Map<String, org.kuali.common.util.config.ProjectConfigContainer> CACHE = new HashMap<String, org.kuali.common.util.config.ProjectConfigContainer>();
49 private static final String FILE = "metadata-spring.xml";
50 private static final String PROPS = "spring.properties";
51 private static final String BEAN = "projectConfig";
52
53 @Override
54 protected synchronized org.kuali.common.util.config.ProjectConfigContainer getCachedConfig(String groupId, String artifactId) {
55 String cacheKey = groupId + ":" + artifactId;
56 org.kuali.common.util.config.ProjectConfigContainer config = CACHE.get(cacheKey);
57 if (config == null) {
58 config = loadMetadata(groupId, artifactId);
59 logger.debug("Caching [{}]", cacheKey);
60 CACHE.put(cacheKey, config);
61 }
62 return config;
63 }
64
65 @Override
66 protected synchronized void clearCache() {
67 CACHE.clear();
68 }
69
70 @Override
71 protected String getFilename() {
72 return FILE;
73 }
74
75 @Override
76 protected Properties getBaseFilterProperties() {
77 ProjectIdentifier identifier = KualiUtilProjectConstants.PROJECT_ID;
78 Project project = getProjectService().getProject(identifier);
79 String location = getMetadataConfigFilePath(project, PROPS);
80 String encoding = ProjectUtils.getEncoding(project);
81 return PropertyUtils.load(location, encoding);
82 }
83
84 @Override
85 protected org.kuali.common.util.config.ProjectConfigContainer getProjectConfig(String content, String encoding) {
86 GenericXmlApplicationContext context = null;
87 try {
88 Resource resource = new ByteArrayResource(content.getBytes(encoding));
89 context = new GenericXmlApplicationContext();
90 context.load(resource);
91 return (org.kuali.common.util.config.ProjectConfigContainer) context.getBean(BEAN);
92 } catch (UnsupportedEncodingException e) {
93 throw new IllegalStateException(e);
94 } finally {
95 if (context != null) {
96 context.close();
97 }
98 }
99 }
100
101 }