com.ccg.io
Class ConfigAttributes

java.lang.Object
  extended by com.ccg.io.ConfigAttributes
All Implemented Interfaces:
Serializable

public class ConfigAttributes
extends Object
implements Serializable

Tools from "magically" transferring configuration to/from beans.

For an general overview of configuration issues (and how this class fits in to the scheme), refer to the Configuration Files document.

This object makes use of introspection techniques to allow one to save one or more attributes from one or more beans such that the attributes can be restored at a later time.

For example, if you had a GUI panel which had text input fields for "name" and "phone" number fields which you would like to preserve between runs (that is "remember" them the next time the user starts the program - so the user doesn't need to re-enter them), then this is the class for you.

Since:
1.0
Version:
$Revision: 1.1.1.1 $
Author:
$Author: pkb $
See Also:
ConfigSource, Serialized Form

Constructor Summary
ConfigAttributes()
          Construct a empty ConfigAttributes object.
 
Method Summary
 int restoreAttributes(Object o, String[] beanNames)
          Load values back into a object that were previously saved.
 void saveAttributes(Object o, String[] beanNames)
          Register a Object and associated set of attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigAttributes

public ConfigAttributes()
Construct a empty ConfigAttributes object.

You typically construct these objects when you are ready to transfer attribute information from your "beans" into this object (just before you write this object to disk).

When you restore your attributes, you typically do NOT use the constructor directly - you simply deserialized the object from your stream (read it back from the config file using ConfigSource.loadObject()).

Since:
1.0
See Also:
saveAttributes(java.lang.Object, java.lang.String[])
Method Detail

saveAttributes

public void saveAttributes(Object o,
                           String[] beanNames)
                    throws ConfigException
Register a Object and associated set of attributes.

This method is used to transfer one or more "bean" values from a object to the ConfigAttributes object so that it can be serialized and then later restored. Refer to the class overview for more information and pointers to example programs.

Parameters:
o - The Object to register and pull values from - its OK to pass null, but only to register a null entry. Typically you only pass null if you make a new revision that no longer requires ANY attributes to be saved from a object.
bnames - The names of the "bean" methods in your object which you would like to retrieve in the attributes object.
Throws:
ConfigException - If we were unable to locate both a "setXXX(X)" and "getXXX()" or "isXXX()" method for one of the bean names passed (triggered by a NoSuchMethodException). Or, if the security manager comes up and bites you (triggered by a SecurityException). Or, if you pass a bean name which your method doesn't have access rights to (the name of a private method of a parent class for example - triggered by a IllegalAccessException). Or, if an exception is thrown by your object when we try to fetch a value for a particular bean field (triggered by a InvocationTargetException).
Since:
1.0
See Also:
restoreAttributes(java.lang.Object, java.lang.String[])

restoreAttributes

public int restoreAttributes(Object o,
                             String[] beanNames)
                      throws ConfigException
Load values back into a object that were previously saved.

This method is used to transfer one or more "bean" values this objects set of attributes back into a Object (this is the "reverse" of the saveAttributes(java.lang.Object, java.lang.String[]) method). This method is typically called after de-serializing a ConfigAttributes object. Each invocation of "restore" should have a corresponding invocation of "save" and the order is important. Refer to the class overview for more information and pointers to example programs.

Parameters:
o - The Object to register and pull values from - its OK to pass null, but only to register a null entry. Typically you only pass null if you make a new revision that no longer requires ANY attributes to be saved from a object.
bnames - The names of the "bean" methods in your object which you would like to retrieve in the attributes object.
Throws:
ConfigException - If you pass a bean name which your method doesn't have access rights to (the name of a private method of a parent class for example - triggered by a IllegalAccessException). Or, if an exception is thrown by your object when we try to fetch a value for a particular bean field (triggered by a InvocationTargetException).
Since:
1.0
See Also:
saveAttributes(java.lang.Object, java.lang.String[])


Copyright 1998-1998-2006 null. All Rights Reserved.