001
014
015 package com.liferay.portal.kernel.settings;
016
017 import com.liferay.portal.kernel.util.ArrayUtil;
018 import com.liferay.portal.kernel.util.Validator;
019
020
024 public abstract class BaseSettings implements Settings {
025
026 public BaseSettings() {
027 }
028
029 public BaseSettings(Settings parentSettings) {
030 this.parentSettings = parentSettings;
031 }
032
033 @Override
034 public ModifiableSettings getModifiableSettings() {
035 if (this instanceof ModifiableSettings) {
036 return (ModifiableSettings)this;
037 }
038 else if (parentSettings == null) {
039 return null;
040 }
041 else {
042 return parentSettings.getModifiableSettings();
043 }
044 }
045
046 @Override
047 public Settings getParentSettings() {
048 return parentSettings;
049 }
050
051 @Override
052 public String getValue(String key, String defaultValue) {
053 if (key == null) {
054 throw new IllegalArgumentException("Key is null");
055 }
056
057 String value = doGetValue(key);
058
059 if ((value == null) && (parentSettings != null)) {
060 value = parentSettings.getValue(key, defaultValue);
061 }
062
063 if (Validator.isNull(value)) {
064 value = defaultValue;
065 }
066
067 return value;
068 }
069
070 @Override
071 public String[] getValues(String key, String[] defaultValue) {
072 if (key == null) {
073 throw new IllegalArgumentException("Key is null");
074 }
075
076 String[] values = doGetValues(key);
077
078 if (ArrayUtil.isEmpty(values) && (parentSettings != null)) {
079 values = parentSettings.getValues(key, defaultValue);
080 }
081
082 if (ArrayUtil.isEmpty(values)) {
083 values = defaultValue;
084 }
085
086 return values;
087 }
088
089 protected abstract String doGetValue(String key);
090
091 protected abstract String[] doGetValues(String key);
092
093 protected Settings parentSettings;
094
095 }