Class PropertyLoader
- java.lang.Object
-
- ch.sahits.game.openpatrician.utilities.service.PropertyLoader
-
public abstract class PropertyLoader extends java.lang.Object
A simple class for loading java.util.Properties backed by .properties files deployed as classpath resources. See individual methods for details. The implementation looks the property files at the class root up (default player).- Author:
- (C) Vlad Roubtsov, 2003
-
-
Field Summary
Fields Modifier and Type Field Description private static boolean
LOAD_AS_RESOURCE_BUNDLE
private static java.lang.String
SUFFIX
private static boolean
THROW_ON_LOAD_FAILURE
-
Constructor Summary
Constructors Modifier Constructor Description private
PropertyLoader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Properties
loadProperties(java.lang.String name)
A convenience overload ofloadProperties(String, ClassLoader)
that uses the current thread's context classloader.static java.util.Properties
loadProperties(java.lang.String name, java.lang.ClassLoader loader)
Looks up a resource named 'name' in the classpath.
-
-
-
Field Detail
-
THROW_ON_LOAD_FAILURE
private static final boolean THROW_ON_LOAD_FAILURE
- See Also:
- Constant Field Values
-
LOAD_AS_RESOURCE_BUNDLE
private static final boolean LOAD_AS_RESOURCE_BUNDLE
- See Also:
- Constant Field Values
-
SUFFIX
private static final java.lang.String SUFFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
loadProperties
public static java.util.Properties loadProperties(java.lang.String name, java.lang.ClassLoader loader)
Looks up a resource named 'name' in the classpath. The resource must map to a file with .properties extention. The name is assumed to be absolute and can use either "/" or "." for player segment separation with an optional leading "/" and optional ".properties" suffix. Thus, the following names refer to the same resource:some.pkg.Resource some.pkg.Resource.properties some/pkg/Resource some/pkg/Resource.properties /some/pkg/Resource /some/pkg/Resource.properties
- Parameters:
name
- classpath resource name [may not be null]loader
- classloader through which to load the resource [null is equivalent to the application loader]- Returns:
- resource converted to java.util.Properties [may be null if the resource was not found and THROW_ON_LOAD_FAILURE is false]
- Throws:
java.lang.IllegalArgumentException
- if the resource was not found and THROW_ON_LOAD_FAILURE is true
-
loadProperties
public static java.util.Properties loadProperties(java.lang.String name)
A convenience overload ofloadProperties(String, ClassLoader)
that uses the current thread's context classloader. A better strategy would be to use techniques shown in http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html- Parameters:
name
- of the property file- Returns:
- Properties object.
-
-