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.ByteArrayInputStream;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.apache.commons.io.IOUtils;
25 import org.kuali.common.util.project.ProjectService;
26 import org.kuali.common.util.xml.service.XmlService;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30
31
32
33 @Deprecated
34 public class DefaultConfigService extends AbstractCachingConfigService {
35
36 public DefaultConfigService(ProjectService projectService, XmlService xmlService) {
37 super(projectService, xmlService);
38 }
39
40 private static final Logger logger = LoggerFactory.getLogger(DefaultConfigService.class);
41
42 private static final Map<String, org.kuali.common.util.config.ProjectConfigContainer> CACHE = new HashMap<String, org.kuali.common.util.config.ProjectConfigContainer>();
43 private static final String FILE = "metadata.xml";
44
45 @Override
46 protected synchronized org.kuali.common.util.config.ProjectConfigContainer getCachedConfig(String groupId, String artifactId) {
47 String cacheKey = groupId + ":" + artifactId;
48 org.kuali.common.util.config.ProjectConfigContainer config = CACHE.get(cacheKey);
49 if (config == null) {
50 config = loadMetadata(groupId, artifactId);
51 logger.debug("Caching [{}]", cacheKey);
52 CACHE.put(cacheKey, config);
53 }
54 return config;
55 }
56
57 @Override
58 protected synchronized void clearCache() {
59 CACHE.clear();
60 }
61
62 @Override
63 protected String getFilename() {
64 return FILE;
65 }
66
67 @Override
68 protected org.kuali.common.util.config.ProjectConfigContainer getProjectConfig(String content, String encoding) {
69 InputStream in = null;
70 try {
71 in = new ByteArrayInputStream(content.getBytes(encoding));
72 return getXmlService().getObject(in, org.kuali.common.util.config.ProjectConfigContainer.class);
73 } catch (IOException e) {
74 throw new IllegalStateException("Unexpected IO error", e);
75 } finally {
76 IOUtils.closeQuietly(in);
77 }
78 }
79
80 }