ref_send API 2.17
defensive programming in Java

org.waterken.syntax.config
Class Config

java.lang.Object
  extended by org.waterken.syntax.config.Config

public final class Config
extends java.lang.Object

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.
<T> T
read(java.lang.String name)
          Reads a configuration setting.
<T> T
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

Config

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)
Constructs an instance.

Parameters:
root - root folder for configuration files
code - class loader for serialized objects
namespace - global identifier for stored object namespace
connect - remote reference importer, may be null
home - root folder for a path beginning with ~
supported - each supported input syntax
output - output syntax

Config

public Config(java.io.File root,
              java.lang.ClassLoader code,
              java.lang.String namespace,
              Importer connect,
              java.io.File home)
Constructs an instance.

Parameters:
root - root folder for configuration files
code - class loader for serialized objects
namespace - global identifier for stored object namespace
connect - remote reference importer, may be null
home - root folder for a path beginning with ~

Config

public Config(java.io.File root,
              java.lang.ClassLoader code)
Constructs an instance.

Parameters:
root - root folder for configuration files
code - class loader for serialized objects
Method Detail

read

public <T> T read(java.lang.String name)
       throws java.lang.Exception
Reads a configuration setting.

Type Parameters:
T - expected value type
Parameters:
name - setting name
Returns:
read(name, Object.class)
Throws:
java.lang.Exception - any problem connecting to the identified reference

read

public <T> T read(java.lang.String name,
                  java.lang.reflect.Type type)
       throws java.lang.Exception
Reads a configuration setting.

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("");
 

Type Parameters:
T - expected value type
Parameters:
name - setting name
type - expected value type, used as a hint to help deserialization
Returns:
setting value, or null if not set
Throws:
java.lang.Exception - any problem connecting to the identified reference

init

public void init(java.lang.String name,
                 java.lang.Object value,
                 Exporter export)
          throws java.lang.Exception
Initializes a configuration setting.

Parameters:
name - setting name
value - setting value
export - remote reference exporter, may be null
Throws:
java.lang.Exception - any problem persisting the value

override

public void override(java.lang.String name,
                     java.lang.Object value)
Creates a temporary override of a configuration setting.

Parameters:
name - setting name
value - transient setting value

ref_send API 2.17
defensive programming in Java

Submit a bug or feature, or get help

Copyright 1998-2009 Waterken Inc. under the terms of the MIT X license.