View Javadoc

1   /**
2    * Copyright 2010-2013 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.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  /**
29   * @deprecated
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  }