1 19 package jcckit.util; 20 21 101 public abstract class FlatConfigData implements ConfigData { 102 private final String _path; 103 104 105 public FlatConfigData(String path) { 106 _path = path; 107 } 108 109 115 public String getFullKey(String key) { 116 return _path == null ? key : _path + key; 117 } 118 119 125 public String get(String key) { 126 return get(_path, key, 0); 127 } 128 129 133 private String get(String path, String key, int numberOfLevels) { 134 String result = null; 135 if (numberOfLevels < 20) { 136 String fullKey = path == null ? key : path + key; 137 result = getValue(fullKey); 138 if (result == null) { 139 int posAfterDelim = path == null ? -1 : path.length(); 141 String replacement; 142 while (posAfterDelim > 0) { 143 replacement = getValue(path.substring(0, posAfterDelim)); 145 if (replacement != null) { 146 result = get(replacement + path.substring(posAfterDelim), key, 148 numberOfLevels + 1); 149 break; 151 } 152 posAfterDelim = path.lastIndexOf('/', posAfterDelim - 2) + 1; 154 } 155 } 156 } 157 return result; 158 } 159 160 166 public ConfigData getNode(String key) { 167 String path = (_path == null ? key : _path + key) + '/'; 168 return createConfigData(path); 169 } 170 171 177 protected abstract String getValue(String fullKey); 178 179 186 protected abstract ConfigData createConfigData(String path); 187 } 188 | Popular Tags |