org.grails.config.NavigableMapConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grails-core Show documentation
Show all versions of grails-core Show documentation
Grails Web Application Framework
/*
* Copyright 2014 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.grails.config;
import grails.config.Config;
import grails.util.GrailsStringUtils;
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.grails.core.exceptions.GrailsConfigurationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.util.ClassUtils;
import java.util.*;
/**
* A {@link Config} implementation that operates against a {@link org.grails.config.NavigableMap}
*
* @author Graeme Rocher
* @since 3.0
*/
public abstract class NavigableMapConfig implements Config {
protected static final Logger LOG = LoggerFactory.getLogger(NavigableMapConfig.class);
protected ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
protected ConfigurableConversionService conversionService = new DefaultConversionService();
protected NavigableMap configMap = new NavigableMap() {
@Override
protected Object mergeMapEntry(NavigableMap targetMap, String sourceKey, Object newValue) {
if(newValue instanceof CharSequence) {
newValue = resolvePlaceholders(newValue.toString());
}
return super.mergeMapEntry(targetMap, sourceKey, newValue);
}
};
@Override
public int hashCode() {
return configMap.hashCode();
}
@Override
public boolean equals(Object obj) {
if(obj instanceof NavigableMapConfig) {
return this.configMap.equals(((NavigableMapConfig)obj).configMap);
}
return false;
}
@Override
public String toString() {
return configMap.toString();
}
@Override
public Object getAt(Object key) {
return get(key);
}
@Override
public void setAt(Object key, Object value) {
configMap.put(key.toString(), value);
}
@Override
public int size() {
return configMap.size();
}
@Override
public boolean isEmpty() {
return configMap.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return containsProperty(key.toString());
}
@Override
public boolean containsValue(Object value) {
return configMap.containsValue(value);
}
@Override
public Object get(Object key) {
return configMap.getProperty(key.toString());
}
@Override
public Object put(String key, Object value) {
return configMap.put(key, value);
}
@Override
public Object remove(Object key) {
return configMap.remove(key);
}
@Override
public void putAll(Map extends String, ?> m) {
configMap.putAll(m);
}
@Override
public void clear() {
configMap.clear();
}
@Override
public Set keySet() {
return configMap.keySet();
}
@Override
public Collection