Skip to content

Commit 742d469

Browse files
Logging and Class Structure
1 parent 61a93f9 commit 742d469

File tree

1 file changed

+42
-50
lines changed

1 file changed

+42
-50
lines changed

src/main/java/com/github/bordertech/config/DefaultConfiguration.java

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,22 @@
4949
*/
5050
public class DefaultConfiguration implements Configuration {
5151

52-
// Use SimpleLog that writes to System.Err by default.
52+
/**
53+
* Logger for debug information.
54+
*/
5355
private static final Log LOG = new SimpleLog("DefaultConfig");
5456

5557
/**
5658
* If this parameter is defined, it is treated as a comma-separated list of additional resources to load. The
5759
* include is processed immediately.
5860
*/
59-
private static final String INCLUDE = "include";
61+
public static final String INCLUDE = "include";
6062

6163
/**
6264
* If this parameter is defined, it is taken as a (comma-separated) resource to load. The resource is loaded after
6365
* the current (set of) resources is loaded.
6466
*/
65-
private static final String INCLUDE_AFTER = "includeAfter";
67+
public static final String INCLUDE_AFTER = "includeAfter";
6668

6769
/**
6870
* If this parameter is defined and resolves to true as a boolean, then the system properties will be merged at the
@@ -289,10 +291,10 @@ private void load() {
289291
// Do nothing while loop
290292
} while (substitute());
291293

292-
log(getDumpHeader());
294+
LOG.info(getDumpHeader());
293295
if (isDumpProperties()) {
294-
log(getDumpMessages());
295-
log(getDumpPropertyDetails());
296+
LOG.info(getDumpMessages());
297+
LOG.info(getDumpPropertyDetails());
296298
}
297299

298300
// We don't want the StringBuilder hanging around after 'DUMP'.
@@ -343,25 +345,24 @@ private String getDumpHeader() {
343345
ProtectionDomain domain = getClass().getProtectionDomain();
344346
if (domain != null) {
345347
CodeSource codesource = domain.getCodeSource();
346-
codesourceStr = codesource == null ? "" : " code location of Config implementation: " + codesource.getLocation();
348+
codesourceStr = codesource == null ? "" : "Code location of Config implementation: " + codesource.getLocation();
347349
}
348350
} catch (Exception failed) {
349351
codesourceStr = "Could not determine location of Config implementation [" + failed.getMessage() + "].";
350352
}
351353

352354
StringBuilder info = new StringBuilder();
353355

354-
info.append("----Config: Info start----");
356+
info.append("----Config: Info start----\n");
355357
info.append(codesourceStr);
356-
info.append("\nWorking directory is ");
358+
info.append("\nWorking directory is: ");
357359
info.append(workingDir);
358360
info.append("\nTo dump all params set ");
359361
info.append(DUMP);
360-
info.append(" to true; currently value is ");
362+
info.append(" to true; current value is ");
361363
info.append(isDumpProperties());
362-
info.append("\nLOGGING can be controlled by configuring org.apache.commons.logging.impl.SimpleLog.");
363-
info.append("\nSimpleLog writes to System.err by default.");
364-
info.append("\n----Config: Info end------");
364+
info.append("\nLOGGING can be controlled by configuring org.apache.commons.logging.impl.SimpleLog that writes to System.err by default.");
365+
info.append("\n----Config: Info end------\n");
365366

366367
return info.toString();
367368
}
@@ -401,7 +402,7 @@ private String getDumpMessages() {
401402

402403
info.append("----Config: Load messages start----\n");
403404
info.append(messages.toString());
404-
info.append("\n----Config: Load messages end----\n");
405+
info.append("----Config: Load messages end----\n");
405406

406407
return info.toString();
407408
}
@@ -908,12 +909,30 @@ private static void copyStream(final InputStream in, final OutputStream out, fin
908909
}
909910

910911
/**
911-
* Log the message.
912-
*
913-
* @param message the message to log.
912+
* Reload the properties to their initial state.
914913
*/
915-
private static void log(final String message) {
916-
LOG.info(message);
914+
public void refresh() {
915+
synchronized (lockObject) {
916+
// Now reset this object back to its initial state.
917+
initialiseInstanceVariables();
918+
919+
// Load all the parameters from scratch.
920+
load();
921+
922+
// Finally, notify all the listeners that have registered with this object that a change in properties has
923+
// occurred.
924+
Config.notifyListeners();
925+
}
926+
}
927+
928+
/**
929+
* @return a copy of the current properties
930+
*/
931+
public Properties getProperties() {
932+
// Don't return the backing directly; make a copy so that the caller can't change us...
933+
Properties copy = new Properties();
934+
copy.putAll(backing);
935+
return copy;
917936
}
918937

919938
// -----------------------------------------------------------------------------------------------------------------
@@ -1311,24 +1330,14 @@ public Configuration subset(final String prefix) {
13111330
return new MapConfiguration(getSubProperties(prefix, false));
13121331
}
13131332

1314-
/**
1315-
* @return a copy of the current properties
1316-
*/
1317-
public Properties getProperties() {
1318-
// Don't return the backing directly; make a copy so that the caller can't change us...
1319-
Properties copy = new Properties();
1320-
copy.putAll(backing);
1321-
return copy;
1322-
}
1323-
13241333
/**
13251334
* Returns a sub-set of the parameters contained in this configuration.
13261335
*
13271336
* @param prefix the prefix of the parameter keys which should be included.
13281337
* @param truncate if true, the prefix is truncated in the returned properties.
13291338
* @return the properties sub-set, may be empty.
13301339
*/
1331-
public Properties getSubProperties(final String prefix, final boolean truncate) {
1340+
protected Properties getSubProperties(final String prefix, final boolean truncate) {
13321341
String cacheKey = truncate + prefix;
13331342
Properties sub = subcontextCache.get(cacheKey);
13341343

@@ -1374,7 +1383,7 @@ public Properties getSubProperties(final String prefix, final boolean truncate)
13741383
* @param defolt the default value if key not available
13751384
* @return the property value or null
13761385
*/
1377-
public String get(final String key, final String defolt) {
1386+
protected String get(final String key, final String defolt) {
13781387
String result = get(key);
13791388
if (result == null) {
13801389
return defolt;
@@ -1388,7 +1397,7 @@ public String get(final String key, final String defolt) {
13881397
* @param key the property key
13891398
* @return the property value or null
13901399
*/
1391-
public String get(final String key) {
1400+
protected String get(final String key) {
13921401
// Check environment property
13931402
if (useEnvironmentKey(key)) {
13941403
String result = (String) backing.get(getEnvironmentKey(key));
@@ -1399,31 +1408,14 @@ public String get(final String key) {
13991408
return (String) backing.get(key);
14001409
}
14011410

1402-
/**
1403-
* Reload the properties to their initial state.
1404-
*/
1405-
public void refresh() {
1406-
synchronized (lockObject) {
1407-
// Now reset this object back to its initial state.
1408-
initialiseInstanceVariables();
1409-
1410-
// Load all the parameters from scratch.
1411-
load();
1412-
1413-
// Finally, notify all the listeners that have registered with this object that a change in properties has
1414-
// occurred.
1415-
Config.notifyListeners();
1416-
}
1417-
}
1418-
14191411
/**
14201412
* Add or Modify a property at runtime.
14211413
*
14221414
* @param name the property name
14231415
* @param value the property value
14241416
*
14251417
*/
1426-
public void addOrModifyProperty(final String name, final String value) {
1418+
protected void addOrModifyProperty(final String name, final String value) {
14271419
if (name == null) {
14281420
throw new IllegalArgumentException("name parameter can not be null.");
14291421
}

0 commit comments

Comments
 (0)