Class prefs

java.lang.Object
  extended by prefs

public class prefs
extends Object

Command-line (and static) utility for working with the omero.prefs Preferences node in order to store Java properties-file like values on a user basis. This simplifies configuration and permits quicker re-installs, and less wrangling with configuration files. A single string value is stored as DEFAULT (which by default is the value DEFAULT, and points to the name of some node under "omero.prefs". This value can be overriden by the "OMERO_CONFIG" environment variable. Almost all commands work on this default node, referred to here as a "profile".

Since:
3.0-Beta3
Author:
Josh Moore, josh at glencoesoftware.com
To do:
USE JSCH FOR PUBKEY ENCRYPTION, backing store sync, test nondispatchable

Field Summary
static boolean DEBUG
          Activated by setting DBEUG=true in the environment.
static String DEFAULT
          Key (and default value) of the property under ROOT which defines which "profile" (subnode} is in effect.
static String ENV
          Environment variable which can be set to override the current, active profile.
static String ROOT
          "omero.prefs", the value of the root Preferences node used for all configuration work.
static Properties STDIN
          Storing the standard in as a Properties instance as early as possible to prevent lost data.
 
Constructor Summary
prefs()
           
 
Method Summary
static String[] all(String[] args)
          Calls Preferences.childrenNames() and returns the array.
static String[] args(String... args)
          Converts varargs to a String-array.
static String[] def(String[] args)
          Returns the current default if no argument is given, or sets the default to the given string (or "" if null) otherwise returing "Default set to: ... ".
static String[] dispatch(String[] args)
          Uses the first string in the argument array to reflectively invoke another method with the same signature on prefs.
static String[] drop(String[] args)
          Drops the entire profile (subnode) via Preferences.removeNode().
static String[] exit(String[] args)
          Uses the length of the argument array as the exit code.
static String[] export(String[] args)
          Exports all properties in the current profile to System.out, or if a single argument is given, that is take to be the name of a target ouput file.
static String[] get(String[] args)
          Returns either the given key=value pairs (or all if no argument is given).
static String[] help(String[] args)
          Returns a help string array.
static String[] join(String... args)
          Joins all the String arguments given into a single String (joined with " "), and returns that String as the first element of a new array.
static String[] keys(String[] args)
          Returns Preferences.keys()
static String[] load_nowarn(String[] args)
          Performs the same actions as load(String[]) but does not throw CONFLICT if a key already exists.
static String[] load(String[] args)
          Loads a profile from Properties files, or properly formatted System.in input if no files are given.
static void main(String[] args)
          Entry point to the prefs command line too.
static String[] notNull(String[] args)
          Returns an empty array if the argument is null.
static String[] pop(String[] args)
          Creates a new subarray from the argument, effectively popping off the first element.
static String[] print(String[] args)
          Prints the arg array and returns an empty array (for exit purposes)
static String[] printDebug(String[] args)
          Delegates to printErr(String[]) iff DEBUG is true.
static String[] printErr(String[] args)
          Prints the arg array and returns the input array (for exit purposes)
static String[] set(String[] args)
          Takes an array of length 2, using args[0] as the key and args[1] as the value to be set.
static String[] sys(String[] args)
          Replaces the user Preferences instance with the system Preferences and continues dispatching.
static String[] test(String[] args)
          Simple test framework, callable from the command line via "java prefs test"
static String[] usage(String[] args)
          Returns a usage string array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STDIN

public static final Properties STDIN
Storing the standard in as a Properties instance as early as possible to prevent lost data.


DEBUG

public static final boolean DEBUG
Activated by setting DBEUG=true in the environment. Various information is printed to System.err.


ROOT

public static final String ROOT
"omero.prefs", the value of the root Preferences node used for all configuration work.

See Also:
Constant Field Values

DEFAULT

public static final String DEFAULT
Key (and default value) of the property under ROOT which defines which "profile" (subnode} is in effect.

See Also:
Constant Field Values

ENV

public static final String ENV
Environment variable which can be set to override the current, active profile.

See Also:
Constant Field Values
Constructor Detail

prefs

public prefs()
Method Detail

main

public static void main(String[] args)
Entry point to the prefs command line too. Uses the dispatch(String[]) method to invoke a public static method which takes a popped String-argument array.

Parameters:
args - Not null. Can be empty.

usage

public static String[] usage(String[] args)
Returns a usage string array.

Parameters:
args - Ignored.
Returns:
Never null.

help

public static String[] help(String[] args)
Returns a help string array. Currently calls usage(String[]) but may eventually return a more man page-like statement.

Parameters:
args - Ignored.
Returns:
Never null.

print

public static String[] print(String[] args)
Prints the arg array and returns an empty array (for exit purposes)


printErr

public static String[] printErr(String[] args)
Prints the arg array and returns the input array (for exit purposes)


printDebug

public static String[] printDebug(String[] args)
Delegates to printErr(String[]) iff DEBUG is true.


exit

public static String[] exit(String[] args)
Uses the length of the argument array as the exit code.


dispatch

public static String[] dispatch(String[] args)
                         throws Throwable
Uses the first string in the argument array to reflectively invoke another method with the same signature on prefs. If the array is null, empty, or begins with an non-extant method, USAGE will be thrown. Otherwise, invokes the named method, returning its return value or returning the cause of any InvocationTargetException.

Throws:
Throwable

sys

public static String[] sys(String[] args)
                    throws Throwable
Replaces the user Preferences instance with the system Preferences and continues dispatching.

Throws:
Throwable

all

public static String[] all(String[] args)
                    throws BackingStoreException
Calls Preferences.childrenNames() and returns the array.

Parameters:
args - Ignored.
Throws:
BackingStoreException

def

public static String[] def(String[] args)
Returns the current default if no argument is given, or sets the default to the given string (or "" if null) otherwise returing "Default set to: ... ".

Parameters:
args - String array of length 0 or 1. Otherwise USAGE is thrown.

drop

public static String[] drop(String[] args)
                     throws BackingStoreException
Drops the entire profile (subnode) via Preferences.removeNode().

Parameters:
args - Ignored.
Throws:
BackingStoreException

keys

public static String[] keys(String[] args)
                     throws BackingStoreException
Returns Preferences.keys()

Parameters:
args - Ignored.
Throws:
BackingStoreException

get

public static String[] get(String[] args)
                    throws BackingStoreException
Returns either the given key=value pairs (or all if no argument is given). When a single key is specified the return format is simply "value".

Throws:
BackingStoreException

set

public static String[] set(String[] args)
                    throws BackingStoreException
Takes an array of length 2, using args[0] as the key and args[1] as the value to be set. For more advanced usage, see load(String[]).

Parameters:
args -
Returns:
Throws:
BackingStoreException

export

public static String[] export(String[] args)
                       throws BackingStoreException,
                              IOException
Exports all properties in the current profile to System.out, or if a single argument is given, that is take to be the name of a target ouput file. Export will fail if the file already exists. This method may be removed in favor of using piping with get(String[]). Properties are in standard Java Properties format.

Throws:
BackingStoreException
IOException

load

public static String[] load(String[] args)
                     throws IOException
Loads a profile from Properties files, or properly formatted System.in input if no files are given. If a key to be loaded already exists in the configuration, CONFLICT will be thrown. Use load_nowarn(String[]) instead, or drop(String[]) the profile before loading.

Throws:
IOException

load_nowarn

public static String[] load_nowarn(String[] args)
                            throws IOException
Performs the same actions as load(String[]) but does not throw CONFLICT if a key already exists.

Throws:
IOException

args

public static String[] args(String... args)
Converts varargs to a String-array.


join

public static String[] join(String... args)
Joins all the String arguments given into a single String (joined with " "), and returns that String as the first element of a new array.


notNull

public static String[] notNull(String[] args)
Returns an empty array if the argument is null.


pop

public static String[] pop(String[] args)
Creates a new subarray from the argument, effectively popping off the first element.


test

public static String[] test(String[] args)
                     throws Throwable
Simple test framework, callable from the command line via "java prefs test"

Throws:
Throwable


OmeroJava Api

Version: Beta4.2.1-r8614-Beta4.2-b41

Copyright © 2009 The University of Dundee. All Rights Reserved.