org.jscience.util
Class Settings

java.lang.Object
  extended by org.jscience.util.Settings

public final class Settings
extends java.lang.Object

Settings provides access to several properties and resources that are used throughout the classes of this Antelmann.com framework.

The default settings are loaded from a well known location which denotes a file that is commonly distributed along with the antelmann.jar file. The default settings can be overwritten by simply altering the Properties returned by getProperties(), where a subsequent call to that method will reflect the changes (similar to System.getProperties().

If the Settings are used in special environments (such as within an application server), you may need to manually use the setClassLoader(ClassLoader) method to specify a ClassLoader appropriate for the given context, before accessing any resources.

Since:
3/24/2002

Field Summary
static java.lang.String defaultPropertyFile
          denotes the relative location of the file for the default Properties, so that it can be found through the ClassLoader
 
Method Summary
static void checkLicense(java.lang.Object licensee)
          checks whether there is a valid license installed for accessing the given object - a convenience method normally used by an application to check whether access to an object is licensed.
static java.lang.ClassLoader getClassLoader()
          returns the ClassLoader currently used to locate resources
 LicenseHandler getLicenseHandler()
          returns the LicenseHandler currently in place to react if a call to checkLicense(Object) fails initially.
static java.util.Properties getOnlineProperties()
          returns a fresh set of default Properties directly from the Antelmann.com website
static java.util.Properties getProperties()
          This method returns the current application properties; changes to the Properties will be reflected in subsequent calls to this method.
static java.lang.String getProperty(java.lang.String key)
          provides a shortcut for getProperties().getPropterty(key)
static java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          This method will try to find the value for the given key and return it - or return the defaultValue if the property was not found or the default property file could not be opened
static java.net.URL getResource(java.lang.String resource)
          This method encapsulates calls to the embedded ClassLoader to ease dealing with problems when not finding the resource.
static void init(java.util.Properties newProperties)
          sets the properties to be used by Settings; this should not be used unless you need to overwrite the default properties
static void installLicense(License l)
          installs the given license to the LicenseManager - a convenience method.
static void installLicenses(java.io.InputStream stream)
          installs one or more License Objects from the given stream - a convenience method.
static void load(java.io.File fileProperties)
          first, this method tries to initialize with the default properties, but even if that fails, the properties are loaded from the given location.
static void load(java.net.URL urlProperties)
          first, this method tries to initialize with the default properties, but even if that fails, the properties are loaded from the given location.
static void reset()
          This method forces to reload the default settings from file.
static void setClassLoader(java.lang.ClassLoader cl)
          sets the ClassLoader to be used in getResource(String); by default, the system class loader is used
static void setContextClassLoader()
           
static void setLicenseHandler(LicenseHandler handler)
          allows to react on failed license-checks by establishing a proper handler
static java.lang.Object setProperty(java.lang.String key, java.lang.String value)
          sets a property within these settings
static void setSystemClassLoader()
          sets the class loader to be used to the system class loader (used by default)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultPropertyFile

public static java.lang.String defaultPropertyFile
denotes the relative location of the file for the default Properties, so that it can be found through the ClassLoader

Method Detail

setLicenseHandler

public static void setLicenseHandler(LicenseHandler handler)
allows to react on failed license-checks by establishing a proper handler

See Also:
getLicenseHandler(), checkLicense(Object)

getLicenseHandler

public LicenseHandler getLicenseHandler()
returns the LicenseHandler currently in place to react if a call to checkLicense(Object) fails initially.

See Also:
checkLicense(Object), setLicenseHandler(LicenseHandler)

checkLicense

public static void checkLicense(java.lang.Object licensee)
                         throws java.lang.SecurityException
checks whether there is a valid license installed for accessing the given object - a convenience method normally used by an application to check whether access to an object is licensed. The method will only return normally if a valid license is available for the given licensee.

By establishing a LicenseHandler, this method - in the event of the license check initially failing - will not immediately fail by throwing an exception, but will first try to e.g. obtain or renew a license through a call to the LicenseHander. After the LicenseHandler was called, the method will once again check with the LicenseManager, whether a valid license is present.

Parameters:
licensee - any object for wich a license is to be checked
Throws:
java.lang.SecurityException - if the license check failed; the embedded exception will be a LicensingException
See Also:
setLicenseHandler(LicenseHandler), License, LicenseManager, LicensingException

installLicenses

public static void installLicenses(java.io.InputStream stream)
                            throws java.lang.SecurityException
installs one or more License Objects from the given stream - a convenience method.

Throws:
java.lang.SecurityException - if one of the licenses within the stream could not be verified. The embedded cause will be a LicensingException
See Also:
License, LicenseManager, LicensingException

installLicense

public static void installLicense(License l)
                           throws java.lang.SecurityException
installs the given license to the LicenseManager - a convenience method.

Throws:
java.lang.SecurityException - if the licenses could not be verified. The embedded cause will be a LicensingException
See Also:
License, LicenseManager, LicensingException

setClassLoader

public static void setClassLoader(java.lang.ClassLoader cl)
sets the ClassLoader to be used in getResource(String); by default, the system class loader is used

See Also:
getResource(String)

init

public static void init(java.util.Properties newProperties)
sets the properties to be used by Settings; this should not be used unless you need to overwrite the default properties


setSystemClassLoader

public static void setSystemClassLoader()
sets the class loader to be used to the system class loader (used by default)


setContextClassLoader

public static void setContextClassLoader()

getClassLoader

public static java.lang.ClassLoader getClassLoader()
returns the ClassLoader currently used to locate resources


getResource

public static java.net.URL getResource(java.lang.String resource)
                                throws ResourceNotFoundException
This method encapsulates calls to the embedded ClassLoader to ease dealing with problems when not finding the resource. Instead of just returning null if a resource is not found, an exception is thrown (which is particularly helpful for image loading in swing). If you are working in special environments where the system class loader may not find the resource you are looking for, you need to set the class loader of this class to the one you need.

Throws:
ResourceNotFoundException - if the given resource could not be found
See Also:
setClassLoader(ClassLoader)

getProperty

public static java.lang.String getProperty(java.lang.String key,
                                           java.lang.String defaultValue)
This method will try to find the value for the given key and return it - or return the defaultValue if the property was not found or the default property file could not be opened


getProperty

public static java.lang.String getProperty(java.lang.String key)
                                    throws ResourceNotFoundException
provides a shortcut for getProperties().getPropterty(key)

Throws:
ResourceNotFoundException - if the property file could not be located
See Also:
getProperties()

setProperty

public static java.lang.Object setProperty(java.lang.String key,
                                           java.lang.String value)
sets a property within these settings


getProperties

public static java.util.Properties getProperties()
                                          throws ResourceNotFoundException
This method returns the current application properties; changes to the Properties will be reflected in subsequent calls to this method.

Throws:
ResourceNotFoundException - if the property file could not be located
See Also:
reset()

load

public static void load(java.io.File fileProperties)
                 throws java.io.IOException
first, this method tries to initialize with the default properties, but even if that fails, the properties are loaded from the given location.

Throws:
java.io.IOException

load

public static void load(java.net.URL urlProperties)
                 throws java.io.IOException
first, this method tries to initialize with the default properties, but even if that fails, the properties are loaded from the given location.

Throws:
java.io.IOException

reset

public static void reset()
This method forces to reload the default settings from file. Any user settings that were set before are not present anymore when calling getProperties() hereafter.

See Also:
getProperties(), defaultPropertyFile

getOnlineProperties

public static java.util.Properties getOnlineProperties()
returns a fresh set of default Properties directly from the Antelmann.com website