View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @deprecated
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  }