com.threerings.config
Class ConfigGroup<T extends ManagedConfig>

java.lang.Object
  extended by com.threerings.config.ConfigGroup<T>
All Implemented Interfaces:
Exportable, Copyable

public class ConfigGroup<T extends ManagedConfig>
extends Object
implements Copyable, Exportable

Contains a group of managed configurations, all of the same class.


Field Summary
protected  Class<T> _cclass
          The configuration class.
protected  ConfigManager _cfgmgr
          The configuration manager that created this group.
protected  HashMap<String,T> _configsByName
          Configurations mapped by name.
protected  ObserverList<ConfigGroupListener<T>> _listeners
          Configuration event listeners.
protected  String _name
          The name of this group.
 
Constructor Summary
ConfigGroup()
          No-arg constructor for deserialization.
ConfigGroup(Class<T> clazz)
          Creates a new config group for the specified class.
 
Method Summary
 void addConfig(T config)
          Adds a configuration to the set.
 void addConfigs(Collection<T> configs)
          Adds all of the supplied configurations to the set.
 void addListener(ConfigGroupListener<T> listener)
          Adds a listener for configuration events.
 Object copy(Object dest)
          Creates a copy of this object, (re)populating the supplied destination object if possible.
 Object copy(Object dest, Object outer)
          Creates a copy of this object, (re)populating the supplied destination object if possible.
protected  void fireConfigAdded(T config)
          Fires a configuration added event.
protected  void fireConfigRemoved(T config)
          Fires a configuration removed event.
 T getConfig(String name)
          Retrieves a configuration by name.
 Class<T> getConfigClass()
          Returns the class of the configurations in this group.
protected  File getConfigFile(boolean xml)
          Returns the configuration file.
protected  String getConfigPath(boolean xml)
          Returns the path of the config resource associated with this group.
 Collection<T> getConfigs()
          Returns the collection of all registered configurations.
protected  InputStream getConfigStream(boolean xml)
          Returns the configuration stream, or null if it doesn't exist.
 String getName()
          Returns the name of this group.
static String getName(Class<?> clazz)
          Returns the group name for the specified config class.
 void init(ConfigManager cfgmgr)
          Initializes this group.
protected  void initConfigClass(Class<T> clazz)
          Initializes the configuration class immediately after construction or deserialization.
protected  void initConfigs(T[] configs)
          Sets the initial set of configs.
protected  void load(Collection<T> nconfigs, boolean merge, boolean clone)
          Loads the specified configurations.
 void load(File file)
          Loads the configurations from the specified file.
 void load(File file, boolean merge)
          Loads the configurations from the specified file.
protected  boolean readConfigs(boolean xml)
          Attempts to read the initial set of configurations.
 void readFields(Importer in)
          Reads the fields of this object.
 void removeConfig(T config)
          Removes a configuration from the set.
 void removeListener(ConfigGroupListener<T> listener)
          Removes a configuration event listener.
 void revert()
          Reverts to the last saved configurations.
 void save()
          Saves this group's configurations.
 void save(Collection<T> configs, File file)
          Saves the provided collection of configurations to a file.
 void save(File file)
          Saves this group's configurations to the specified file.
protected  T[] toSortedArray(Collection<T> configs)
          Converts the supplied collection of configs to a sorted array.
protected  void validateOuters(T[] configs)
          Validates the outer object references of the supplied configs.
 void writeFields(Exporter out)
          Writes the fields of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_cfgmgr

protected ConfigManager _cfgmgr
The configuration manager that created this group.


_name

protected String _name
The name of this group.


_cclass

protected Class<T extends ManagedConfig> _cclass
The configuration class.


_configsByName

protected HashMap<String,T extends ManagedConfig> _configsByName
Configurations mapped by name.


_listeners

protected ObserverList<ConfigGroupListener<T extends ManagedConfig>> _listeners
Configuration event listeners.

Constructor Detail

ConfigGroup

public ConfigGroup(Class<T> clazz)
Creates a new config group for the specified class.


ConfigGroup

public ConfigGroup()
No-arg constructor for deserialization.

Method Detail

getName

public static String getName(Class<?> clazz)
Returns the group name for the specified config class.


init

public void init(ConfigManager cfgmgr)
Initializes this group.


getName

public String getName()
Returns the name of this group.


getConfigClass

public Class<T> getConfigClass()
Returns the class of the configurations in this group.


getConfig

public T getConfig(String name)
Retrieves a configuration by name.


getConfigs

public Collection<T> getConfigs()
Returns the collection of all registered configurations.


addListener

public void addListener(ConfigGroupListener<T> listener)
Adds a listener for configuration events.


removeListener

public void removeListener(ConfigGroupListener<T> listener)
Removes a configuration event listener.


addConfigs

public void addConfigs(Collection<T> configs)
Adds all of the supplied configurations to the set.


addConfig

public void addConfig(T config)
Adds a configuration to the set.


removeConfig

public void removeConfig(T config)
Removes a configuration from the set.


save

public void save()
Saves this group's configurations.


save

public void save(File file)
Saves this group's configurations to the specified file.


save

public void save(Collection<T> configs,
                 File file)
Saves the provided collection of configurations to a file.


revert

public void revert()
Reverts to the last saved configurations.


load

public void load(File file)
Loads the configurations from the specified file.


load

public void load(File file,
                 boolean merge)
Loads the configurations from the specified file.

Parameters:
merge - if true, merge with the existing configurations; do not delete configurations that do not exist in the file.

writeFields

public void writeFields(Exporter out)
                 throws IOException
Writes the fields of this object.

Throws:
IOException

readFields

public void readFields(Importer in)
                throws IOException
Reads the fields of this object.

Throws:
IOException

copy

public Object copy(Object dest)
Description copied from interface: Copyable
Creates a copy of this object, (re)populating the supplied destination object if possible.

Specified by:
copy in interface Copyable
Returns:
either a reference to the destination object, if it could be repopulated, or a new object containing the copied state.

copy

public Object copy(Object dest,
                   Object outer)
Description copied from interface: Copyable
Creates a copy of this object, (re)populating the supplied destination object if possible.

Specified by:
copy in interface Copyable
outer - the outer object reference to use for inner object creation, if any.
Returns:
either a reference to the destination object, if it could be repopulated, or a new object containing the copied state.

initConfigClass

protected void initConfigClass(Class<T> clazz)
Initializes the configuration class immediately after construction or deserialization.


readConfigs

protected boolean readConfigs(boolean xml)
Attempts to read the initial set of configurations.

Returns:
true if successful, false otherwise.

getConfigStream

protected InputStream getConfigStream(boolean xml)
Returns the configuration stream, or null if it doesn't exist.


getConfigFile

protected File getConfigFile(boolean xml)
Returns the configuration file.


getConfigPath

protected String getConfigPath(boolean xml)
Returns the path of the config resource associated with this group.


validateOuters

protected void validateOuters(T[] configs)
Validates the outer object references of the supplied configs.


initConfigs

protected void initConfigs(T[] configs)
Sets the initial set of configs.


load

protected void load(Collection<T> nconfigs,
                    boolean merge,
                    boolean clone)
Loads the specified configurations.

Parameters:
merge - if true, merge with the existing configurations; do not delete configurations that do not exist in the collection.
clone - if true, we must clone configurations that do not yet exist in the group.

toSortedArray

protected T[] toSortedArray(Collection<T> configs)
Converts the supplied collection of configs to a sorted array.


fireConfigAdded

protected void fireConfigAdded(T config)
Fires a configuration added event.


fireConfigRemoved

protected void fireConfigRemoved(T config)
Fires a configuration removed event.