org.basex.core
Class AProp

java.lang.Object
  extended by org.basex.core.AProp
All Implemented Interfaces:
java.lang.Iterable<java.lang.String>
Direct Known Subclasses:
GUIProp, HTMLProp, MainProp, ParserProp, Prop, SerializerProp

public abstract class AProp
extends java.lang.Object
implements java.lang.Iterable<java.lang.String>

This class assembles properties which are used all around the project. They are initially read from and finally written to disk.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Field Summary
protected  java.util.TreeMap<java.lang.String,java.lang.Object> props
          Properties.
 
Constructor Summary
AProp()
          Constructor.
AProp(java.lang.String suffix)
          Constructor, reading options from a configuration file.
 
Method Summary
 java.lang.String get(java.lang.Object[] key)
          Returns the requested string.
 java.lang.Object get(java.lang.String key)
          Returns the requested object, or null.
static java.lang.String getSystem(java.lang.Object[] key)
          Returns a system property.
static java.lang.String getSystem(java.lang.String key)
          Returns a system property.
 boolean invert(java.lang.Object[] key)
          Inverts a boolean property.
 boolean is(java.lang.Object[] key)
          Returns the requested boolean.
 java.util.Iterator<java.lang.String> iterator()
           
 int num(java.lang.Object[] key)
          Returns the requested integer.
 int[] nums(java.lang.Object[] key)
          Returns the requested integer array.
protected  void parse(java.lang.String s)
          Parses a property string and sets the properties accordingly.
static java.lang.Object[][] props(java.lang.Class<? extends AProp> clz)
          Returns all property objects from the specified property class.
 boolean sameAs(java.lang.Object[] key, java.lang.Object val)
          Checks if the specified property has changed.
 void set(java.lang.Object[] key, boolean val)
          Assigns the specified boolean for the specified key.
 void set(java.lang.Object[] key, int val)
          Assigns the specified integer for the specified key.
 void set(java.lang.Object[] key, int[] val)
          Assigns the specified integer array for the specified key.
 void set(java.lang.Object[] key, java.lang.String val)
          Assigns the specified value for the specified key.
 void set(java.lang.Object[] key, java.lang.String[] val)
          Assigns the specified string array for the specified key.
 java.lang.String set(java.lang.String key, java.lang.String val)
          Sets the specified value after casting it to the correct type.
 void setObject(java.lang.String key, java.lang.Object val)
          Assigns the specified object for the specified key.
 void setSystem()
          Scans the system properties and initializes the project properties.
static void setSystem(java.lang.Object[] key, java.lang.Object val)
          Sets a system property if it has not been set before.
static void setSystem(java.lang.String key, java.lang.Object val)
          Sets a system property if it has not been set before.
 java.lang.String similar(java.lang.String key)
          Returns a key similar to the specified string, or null.
 java.lang.String[] strings(java.lang.Object[] key)
          Returns the requested string array.
 java.lang.String toString()
           
 java.lang.String unknown(java.lang.String key)
          Returns an error string for an unknown key.
 void write()
          Writes the properties to disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

props

protected final java.util.TreeMap<java.lang.String,java.lang.Object> props
Properties.

Constructor Detail

AProp

public AProp()
Constructor.


AProp

public AProp(java.lang.String suffix)
Constructor, reading options from a configuration file.

Parameters:
suffix - if null, file parsing will be skipped
Method Detail

write

public final void write()
Writes the properties to disk.


get

public final java.lang.Object get(java.lang.String key)
Returns the requested object, or null.

Parameters:
key - key to be found
Returns:
value

get

public final java.lang.String get(java.lang.Object[] key)
Returns the requested string.

Parameters:
key - key to be found
Returns:
value

num

public final int num(java.lang.Object[] key)
Returns the requested integer.

Parameters:
key - key to be found
Returns:
value

is

public final boolean is(java.lang.Object[] key)
Returns the requested boolean.

Parameters:
key - key to be found
Returns:
value

strings

public final java.lang.String[] strings(java.lang.Object[] key)
Returns the requested string array.

Parameters:
key - key to be found
Returns:
value

nums

public final int[] nums(java.lang.Object[] key)
Returns the requested integer array.

Parameters:
key - key to be found
Returns:
value

set

public final void set(java.lang.Object[] key,
                      java.lang.String val)
Assigns the specified value for the specified key.

Parameters:
key - key to be found
val - value to be written

set

public final void set(java.lang.Object[] key,
                      int val)
Assigns the specified integer for the specified key.

Parameters:
key - key to be found
val - value to be written

set

public final void set(java.lang.Object[] key,
                      boolean val)
Assigns the specified boolean for the specified key.

Parameters:
key - key to be found
val - value to be written

set

public final void set(java.lang.Object[] key,
                      java.lang.String[] val)
Assigns the specified string array for the specified key.

Parameters:
key - key to be found
val - value to be written

set

public final void set(java.lang.Object[] key,
                      int[] val)
Assigns the specified integer array for the specified key.

Parameters:
key - key to be found
val - value to be written

setObject

public final void setObject(java.lang.String key,
                            java.lang.Object val)
Assigns the specified object for the specified key.

Parameters:
key - key to be found
val - value to be written

set

public final java.lang.String set(java.lang.String key,
                                  java.lang.String val)
Sets the specified value after casting it to the correct type.

Parameters:
key - key
val - value
Returns:
final value, or null if the key has not been found

unknown

public final java.lang.String unknown(java.lang.String key)
Returns an error string for an unknown key.

Parameters:
key - key
Returns:
error string

invert

public final boolean invert(java.lang.Object[] key)
Inverts a boolean property.

Parameters:
key - key
Returns:
new value

sameAs

public final boolean sameAs(java.lang.Object[] key,
                            java.lang.Object val)
Checks if the specified property has changed.

Parameters:
key - key
val - new value
Returns:
result of check

similar

public final java.lang.String similar(java.lang.String key)
Returns a key similar to the specified string, or null.

Parameters:
key - key to be found
Returns:
similar key

setSystem

public final void setSystem()
Scans the system properties and initializes the project properties. All properties starting with org.basex. will be assigned as properties and removed from the global system properties.


iterator

public final java.util.Iterator<java.lang.String> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.String>

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

getSystem

public static java.lang.String getSystem(java.lang.Object[] key)
Returns a system property.

Parameters:
key - Prop key
Returns:
value, or empty string

getSystem

public static java.lang.String getSystem(java.lang.String key)
Returns a system property. If necessary, the key will be converted to lower-case and prefixed with Prop.DBPREFIX.

Parameters:
key - Prop key
Returns:
value, or empty string

setSystem

public static void setSystem(java.lang.Object[] key,
                             java.lang.Object val)
Sets a system property if it has not been set before.

Parameters:
key - Prop key
val - value

setSystem

public static void setSystem(java.lang.String key,
                             java.lang.Object val)
Sets a system property if it has not been set before. If necessary, the key will be converted to lower-case and prefixed with Prop.DBPREFIX.

Parameters:
key - key
val - value

props

public static final java.lang.Object[][] props(java.lang.Class<? extends AProp> clz)
                                        throws java.lang.IllegalAccessException
Returns all property objects from the specified property class.

Parameters:
clz - property class
Returns:
property objects
Throws:
java.lang.IllegalAccessException - exception

parse

protected final void parse(java.lang.String s)
                    throws java.io.IOException
Parses a property string and sets the properties accordingly.

Parameters:
s - property string
Throws:
java.io.IOException - io exception