com.unitesk.atp.tool
Class DynamicVariablesTable

java.lang.Object
  extended by com.unitesk.atp.tool.DynamicVariablesTable

public class DynamicVariablesTable
extends Object

The table of dynamic variables.

A dynamic variable like usual Java variable has a name and a class. But dynamic variables are defined outside of program. It allows to change a set of defined dynamic variables and use them without program recompilation. For example, it can be used to extend program functionality in plugin-like way.

A table of dynamic variables has a name.

A class instance representing dynamic variable is created using class constructor without parameters.

Parameters are passed to variable using so-called plugin properties. The value of plugin property property.name for variable var of table tab is passed through system property tab.var.property.name.

Version:
$Id: DynamicVariablesTable.java,v 1.2 2004/10/11 15:00:44 all-x Exp $
Author:
Alexey Demakov, Alexander Monakhov, Sophia Zelenova

Constructor Summary
DynamicVariablesTable(String name)
          Creates an empty dynamic variables table with the specified name.
DynamicVariablesTable(String name, InputStream in)
          Creates dynamic variables table with the specified name and loads variables from the specified input stream.
 
Method Summary
 boolean containsName(String name)
          Checks if this table contains a variable with the specified name.
 boolean containsObject(Object var)
          Checks if this table contains the specified variable.
 Object get(String name)
          Returns a variable with the specified name.
 String getName()
          Gets the name of this table.
 String getProperty(Object var, String property_name)
          Gets the value of plugin property with the specified name for the specified variable.
 String getProperty(Object var, String property_name, String default_property_value)
          Gets the value of plugin property with the specified name for the specified variable or default value if this property is not defined.
 String getPropertyName(Object var, String property_name)
          Gets the system property name for plugin property name of the specified variable.
 void load(InputStream in)
          Loads variables from the specified input stream.
 void load(String name, String type)
          Loads a variable of the specified type and associates it with the specified name.
 Set names()
          Returns the names of all defined variables.
 Object put(String name, Object var)
          Puts the new variable with the specifed name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicVariablesTable

public DynamicVariablesTable(String name)
Creates an empty dynamic variables table with the specified name.

Parameters:
name - the name of the table. It must be the name of Java indentifier.
Throws:
IllegalArgumentException - if name is incorrect format

DynamicVariablesTable

public DynamicVariablesTable(String name,
                             InputStream in)
                      throws IOException,
                             ClassNotFoundException
Creates dynamic variables table with the specified name and loads variables from the specified input stream.

Parameters:
name - The table name.
in - The input stream containing dynamic variables definitions.
Throws:
IOException
ClassNotFoundException
See Also:
load(InputStream), load(String,String), Properties.load(InputStream)
Method Detail

names

public Set names()
Returns the names of all defined variables.

Returns:
The set containing names of all variables defined in this table.

get

public Object get(String name)
Returns a variable with the specified name.

Parameters:
name - The variable name.
Returns:
The variable with the specified name or null if no such variable is defined.
See Also:
Map.get(Object)

getPropertyName

public String getPropertyName(Object var,
                              String property_name)
Gets the system property name for plugin property name of the specified variable.

Parameters:
var - The variable from this table.
property_name - The name of var plugin property.
Returns:
The corresponding system property name. For plugin property property.name of variable with name var from table tab system property name is tab.var.property.name.
Throws:
IllegalArgumentException - If table doesn't contain var.

getProperty

public String getProperty(Object var,
                          String property_name)
Gets the value of plugin property with the specified name for the specified variable.

Parameters:
var - The variable from this table.
property_name - The name of var plugin property.
Returns:
The value of the plugin property for the specified variable.
Throws:
IllegalArgumentException - If table doesn't contain var.
See Also:
getPropertyName( var, property_name )

getProperty

public String getProperty(Object var,
                          String property_name,
                          String default_property_value)
Gets the value of plugin property with the specified name for the specified variable or default value if this property is not defined.

Parameters:
var - The variable from this table.
property_name - The name of var plugin property.
default_property_value - A default value is used if for the specified variable there is no plugin property with the specified name.
Returns:
The value of the plugin property for the specified variable.
Throws:
IllegalArgumentException - If table doesn't contain var.
See Also:
getPropertyName( var, property_name )

getName

public String getName()
Gets the name of this table.

Returns:
The name of this table.

containsName

public boolean containsName(String name)
Checks if this table contains a variable with the specified name.

Parameters:
name - The name to check.
Returns:
true if this table contains a variable with specified name, false otherwise.

containsObject

public boolean containsObject(Object var)
Checks if this table contains the specified variable.

Parameters:
var - The object to check.
Returns:
true if this table contains the specified object, false otherwise.

put

public Object put(String name,
                  Object var)
Puts the new variable with the specifed name.

Parameters:
name - The name of variable.
var - The value of variable.
Returns:
The previous value associated with the specified name, or null if there was no variable with such name.

load

public void load(InputStream in)
          throws IOException,
                 ClassNotFoundException
Loads variables from the specified input stream.

Parameters:
in - The input stream containing dynamic variables definitions. The data format is specified in (its structure is described in Properties.load( InputStream ) description. Property name is variable name and property value is variable type (fully-qualified Java class name).
Throws:
IOException - If there was an I/O error during the input stream reading.
IllegalArgumentException - If there was no type defined for a variable. or there is a syntax error in the variable name or in the variable type.
ClassNotFoundException - If the variable type is not found.
IllegalAccessException - If an access to a definition of the variable type is denied.
InstantiationException - If the variable can not be created.
See Also:
load( String, String ), Properties.load( InputStream )

load

public void load(String name,
                 String type)
          throws ClassNotFoundException
Loads a variable of the specified type and associates it with the specified name. A variable is created using class constructor without parameters.

Parameters:
name - The variable name.
type - The fully qualified name of variable's class.
Throws:
IllegalArgumentException - If there is a syntax error in the variable name or in the variable type.
ClassNotFoundException - If the variable type is not found can not be accessed or if the variable can not be created. The exception message contains the class name.


Copyright © 2001-2006 ISP RAS, RedVerst Group. All Rights Reserved.