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