|
ref_send API 2.17 defensive programming in Java |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.waterken.syntax.config.Config
public final class Config
A folder of serialized configuration settings.
This class provides convenient access to a folder of JSON files; each of which represents a particular configuration setting. The class provides methods for initializing and reading these settings.
For example, consider a folder with contents:
config/
- username.json
{ "=" : "tyler.close" }
- port.json
{ "=" : 8088 }
- home.json
{
"class" : [ "org.example.hypertext.Anchor" ],
"icon" : "home.png",
"href" : "http://waterken.sourceforge.net/",
"tooltip" : "Home page"
}
These settings can be read with code:
final Config config = new Config(new File("config/"),
getClass().getClassLoader());
final String username = config.read("username");
final int port = config.read("port");
final Anchor home = config.read("home");
| Constructor Summary | |
|---|---|
Config(java.io.File root,
java.lang.ClassLoader code)
Constructs an instance. |
|
Config(java.io.File root,
java.lang.ClassLoader code,
java.lang.String namespace,
Importer connect,
java.io.File home)
Constructs an instance. |
|
Config(java.io.File root,
java.lang.ClassLoader code,
java.lang.String namespace,
Importer connect,
java.io.File home,
PowerlessArray<Syntax> supported,
Syntax output)
Constructs an instance. |
|
| Method Summary | ||
|---|---|---|
void |
init(java.lang.String name,
java.lang.Object value,
Exporter export)
Initializes a configuration setting. |
|
void |
override(java.lang.String name,
java.lang.Object value)
Creates a temporary override of a configuration setting. |
|
|
read(java.lang.String name)
Reads a configuration setting. |
|
|
read(java.lang.String name,
java.lang.reflect.Type type)
Reads a configuration setting. |
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Config(java.io.File root,
java.lang.ClassLoader code,
java.lang.String namespace,
Importer connect,
java.io.File home,
PowerlessArray<Syntax> supported,
Syntax output)
root - root folder for configuration filescode - class loader for serialized objectsnamespace - global identifier for stored object namespaceconnect - remote reference importer, may be nullhome - root folder for a path beginning with ~supported - each supported input syntaxoutput - output syntax
public Config(java.io.File root,
java.lang.ClassLoader code,
java.lang.String namespace,
Importer connect,
java.io.File home)
root - root folder for configuration filescode - class loader for serialized objectsnamespace - global identifier for stored object namespaceconnect - remote reference importer, may be nullhome - root folder for a path beginning with ~
public Config(java.io.File root,
java.lang.ClassLoader code)
root - root folder for configuration filescode - class loader for serialized objects| Method Detail |
|---|
public <T> T read(java.lang.String name)
throws java.lang.Exception
T - expected value typename - setting name
read(name, Object.class)
java.lang.Exception - any problem connecting to the identified reference
public <T> T read(java.lang.String name,
java.lang.reflect.Type type)
throws java.lang.Exception
Any name argument containing a period is assumed to refer
to a configuration file, rather than the serialized object. For example:
final Config config = …
final String username = config.read("username");
final File usernameFile = config.read("username.json");
The configuration folder itself can be accessed using the code:
final File root = config.read("");
T - expected value typename - setting nametype - expected value type, used as a hint to help deserialization
null if not set
java.lang.Exception - any problem connecting to the identified reference
public void init(java.lang.String name,
java.lang.Object value,
Exporter export)
throws java.lang.Exception
name - setting namevalue - setting valueexport - remote reference exporter, may be null
java.lang.Exception - any problem persisting the value
public void override(java.lang.String name,
java.lang.Object value)
name - setting namevalue - transient setting value
|
ref_send API 2.17 defensive programming in Java |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Copyright 1998-2009 Waterken Inc. under the terms of the MIT X license.