com.tomgibara.pronto.config
Class DefaultConfigPolicy

java.lang.Object
  extended by com.tomgibara.pronto.config.DefaultConfigPolicy
All Implemented Interfaces:
ConfigPolicy

public class DefaultConfigPolicy
extends java.lang.Object
implements ConfigPolicy

If no policy is explicitly specified for a config, an instance of this class is used by default.

Author:
Tom Gibara

Field Summary
static long DEFAULT_MIN_READ_PERIOD
          The value returned by the getMinReadPeriod() method.
 
Constructor Summary
DefaultConfigPolicy()
           
 
Method Summary
 java.lang.Object defaultForClass(java.lang.Class clss)
          Returns -1 for whole number primitives, 0.0 for floating point primitives, false for boolean primitives and \0 for character primitives.
 long getMinReadPeriod()
          This default implementation returns the value of DEFAULT_MIN_READ_PERIOD.
 boolean isCachingEager()
          By default, values from possibly different class loaders are cacheable.
 boolean isDefaultsCached()
          By default, the default values generated by defaultForClass are cached.
 boolean isExceptionLogged()
          By default exceptions are not logged because they are expected to be caught and logged by the client code.
 boolean isExceptionThrown()
          By default exceptions are thrown.
 boolean isTimestampNewer(long newTimestamp, long oldTimestamp)
          The default implementation returns true if and only if the new timestamp is strictly greater than the old timestamp.
 java.lang.String propertyFromMethod(java.lang.String methodName)
          The default implementation drops "get" and "is" prefixes and replaces progressions to upper case into hyphens eg.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MIN_READ_PERIOD

public static final long DEFAULT_MIN_READ_PERIOD
The value returned by the getMinReadPeriod() method.

See Also:
Constant Field Values
Constructor Detail

DefaultConfigPolicy

public DefaultConfigPolicy()
Method Detail

getMinReadPeriod

public long getMinReadPeriod()
This default implementation returns the value of DEFAULT_MIN_READ_PERIOD.

Specified by:
getMinReadPeriod in interface ConfigPolicy
Returns:
DEFAULT_MIN_READ_PERIOD

isTimestampNewer

public boolean isTimestampNewer(long newTimestamp,
                                long oldTimestamp)
The default implementation returns true if and only if the new timestamp is strictly greater than the old timestamp.

Specified by:
isTimestampNewer in interface ConfigPolicy
Parameters:
newTimestamp - the timestamp of a new set of properties
oldTimestamp - the timestamp of the previous set of properties.
Returns:
newTimestamp > oldTimestamp

isExceptionThrown

public boolean isExceptionThrown()
By default exceptions are thrown.

Specified by:
isExceptionThrown in interface ConfigPolicy
Returns:
true

isExceptionLogged

public boolean isExceptionLogged()
By default exceptions are not logged because they are expected to be caught and logged by the client code.

Specified by:
isExceptionLogged in interface ConfigPolicy
Returns:
false

propertyFromMethod

public java.lang.String propertyFromMethod(java.lang.String methodName)
The default implementation drops "get" and "is" prefixes and replaces progressions to upper case into hyphens eg. "getBaseURL" becomes "base-url".

Specified by:
propertyFromMethod in interface ConfigPolicy
Parameters:
methodName - the name of a method which is to be satisfied
Returns:
the name of the property to which the method maps

defaultForClass

public java.lang.Object defaultForClass(java.lang.Class clss)
Returns -1 for whole number primitives, 0.0 for floating point primitives, false for boolean primitives and \0 for character primitives. For the standard collection interfaces (Set, Map and List) empty collections are returned. For arrays, a zero length array is returned. For all other classes null is returned.

Specified by:
defaultForClass in interface ConfigPolicy
Parameters:
clss - the type of value for which a primitive value is needed
Returns:
the default values for primitives, collections and arrays

isDefaultsCached

public boolean isDefaultsCached()
By default, the default values generated by defaultForClass are cached.

Specified by:
isDefaultsCached in interface ConfigPolicy
Returns:
true

isCachingEager

public boolean isCachingEager()
By default, values from possibly different class loaders are cacheable. This provides a very narrow opportunity for class incompatibilities but this is expected to be rare.

Specified by:
isCachingEager in interface ConfigPolicy
Returns:
true;


Copyright © 2006-2007 Tom Gibara. All Rights Reserved.