com.threerings.config
Class ConfigManager

java.lang.Object
  extended by com.threerings.config.ConfigManager
All Implemented Interfaces:
Exportable, Copyable

public class ConfigManager
extends Object
implements Copyable, Exportable

Manages the set of loaded configurations.


Constructor Summary
ConfigManager()
          No-arg constructor for deserialization.
ConfigManager(com.threerings.resource.ResourceManager rsrcmgr, com.threerings.util.MessageManager msgmgr, String configPath)
          Creates a new global configuration manager.
 
Method Summary
 void addUpdateListener(ConfigUpdateListener listener)
          Adds a listener that will be notified on all config updates.
 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.
<T extends ManagedConfig>
T
getConfig(Class<T> clazz, ConfigReference<T> ref)
          Retrieves a configuration by class and reference.
<T extends ManagedConfig>
T
getConfig(Class<T> clazz, ConfigReference<T> ref, Scope scope)
          Retrieves a configuration by class and reference.
<T extends ManagedConfig>
T
getConfig(Class<T> clazz, String name)
          Retrieves a configuration by class and name.
<T extends ManagedConfig>
T
getConfig(Class<T> clazz, String name, ArgumentMap args)
          Retrieves a configuration by class, name, and arguments.
<T extends ManagedConfig>
T
getConfig(Class<T> clazz, String name, Scope scope)
          Retrieves a configuration by class, name, and scope.
<T extends ManagedConfig>
T
getConfig(Class<T> clazz, String name, Scope scope, ArgumentMap args)
          Retrieves a configuration by class, name, scope, and arguments.
<T extends ManagedConfig>
T
getConfig(Class<T> clazz, String name, Scope scope, String firstKey, Object firstValue, Object... otherArgs)
          Retrieves a configuration by class, name, and arguments.
<T extends ManagedConfig>
T
getConfig(Class<T> clazz, String name, String firstKey, Object firstValue, Object... otherArgs)
          Retrieves a configuration by class, name, and arguments.
 String getConfigPath()
          Returns the resource path from which configurations are loaded, or null if configurations aren't loaded directly.
<T extends ManagedConfig>
ConfigGroup<T>
getGroup(Class<T> clazz)
          Retrieves the group registered for the specified class.
 ConfigGroup getGroup(String name)
          Returns the configuration group with the specified name.
 ConfigGroup getGroup(String name, boolean forward)
          Returns the configuration group with the specified name.
 Collection<ConfigGroup> getGroups()
          Returns the collection of all registered groups.
<T extends ManagedConfig>
ConfigGroup<T>[]
getGroups(Class<T> clazz)
          Retrieves the groups registered for the specified class in this manager and all of its ancestors.
 ConfigGroup[] getGroups(String name)
          Retrieves the groups with the specified name in this manager and all of its ancestors.
 com.threerings.util.MessageManager getMessageManager()
          Returns a reference to the message manager used to load configurations.
 ConfigManager getParent()
          Returns a reference to the parent of this manager, or null if this is the root.
 Class<?>[] getResourceClasses()
          Returns the array of classes representing configurations loaded from individual resources.
 ManagedConfig getResourceConfig(String name)
          Attempts to fetch a resource config through the cache.
 com.threerings.resource.ResourceManager getResourceManager()
          Returns a reference to the resource manager used to load configurations.
 ConfigManager getRoot()
          Returns a reference to the root of the manager hierarchy.
 String getType()
          Returns the type of this manager.
 void init()
          Initialization method for the global configuration manager.
 void init(String type, ConfigManager parent)
          Initialization method for child configuration managers.
 boolean isInitialized()
          Determines whether the config manager has been initialized.
 boolean isResourceClass(Class<?> clazz)
          Determines whether configurations of the specified class are loaded from individual resources.
 void readFields(Importer in)
          Reads the fields of this object.
 void refresh(Class<? extends ManagedConfig> clazz)
          Refreshes all configurations of the specified class.
 void removeUpdateListener(ConfigUpdateListener listener)
          Removes an update listener.
 void revertAll()
          Reverts the configurations in all groups to their last saved state.
 void saveAll()
          Saves the configurations in all groups.
 ManagedConfig updateResourceConfig(String name, ManagedConfig config)
          Updates a resource-loaded configuration through the cache.
 boolean validateReferences(String where, PrintStream out)
          Validates the references of all configs managed by this manager.
 void writeFields(Exporter out)
          Writes the fields of this object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigManager

public ConfigManager(com.threerings.resource.ResourceManager rsrcmgr,
                     com.threerings.util.MessageManager msgmgr,
                     String configPath)
Creates a new global configuration manager.

Parameters:
configPath - the resource path of the configurations.

ConfigManager

public ConfigManager()
No-arg constructor for deserialization.

Method Detail

isInitialized

public boolean isInitialized()
Determines whether the config manager has been initialized.


init

public void init()
Initialization method for the global configuration manager.


init

public void init(String type,
                 ConfigManager parent)
Initialization method for child configuration managers.


getType

public String getType()
Returns the type of this manager.


getParent

public ConfigManager getParent()
Returns a reference to the parent of this manager, or null if this is the root.


getRoot

public ConfigManager getRoot()
Returns a reference to the root of the manager hierarchy.


getResourceManager

public com.threerings.resource.ResourceManager getResourceManager()
Returns a reference to the resource manager used to load configurations.


getMessageManager

public com.threerings.util.MessageManager getMessageManager()
Returns a reference to the message manager used to load configurations.


getConfigPath

public String getConfigPath()
Returns the resource path from which configurations are loaded, or null if configurations aren't loaded directly.


isResourceClass

public boolean isResourceClass(Class<?> clazz)
Determines whether configurations of the specified class are loaded from individual resources.


getResourceClasses

public Class<?>[] getResourceClasses()
Returns the array of classes representing configurations loaded from individual resources.


getConfig

public <T extends ManagedConfig> T getConfig(Class<T> clazz,
                                             ConfigReference<T> ref)
Retrieves a configuration by class and reference. If the configuration is not found in this manager, the request will be forwarded to the parent, and so on.

Returns:
the requested configuration, or null if not found.

getConfig

public <T extends ManagedConfig> T getConfig(Class<T> clazz,
                                             ConfigReference<T> ref,
                                             Scope scope)
Retrieves a configuration by class and reference. If the configuration is not found in this manager, the request will be forwarded to the parent, and so on.

Returns:
the requested configuration, or null if not found.

getConfig

public <T extends ManagedConfig> T getConfig(Class<T> clazz,
                                             String name,
                                             String firstKey,
                                             Object firstValue,
                                             Object... otherArgs)
Retrieves a configuration by class, name, and arguments. If the configuration is not found in this manager, the request will be forwarded to the parent, and so on.

Returns:
the requested configuration, or null if not found.

getConfig

public <T extends ManagedConfig> T getConfig(Class<T> clazz,
                                             String name,
                                             Scope scope,
                                             String firstKey,
                                             Object firstValue,
                                             Object... otherArgs)
Retrieves a configuration by class, name, and arguments. If the configuration is not found in this manager, the request will be forwarded to the parent, and so on.

Returns:
the requested configuration, or null if not found.

getConfig

public <T extends ManagedConfig> T getConfig(Class<T> clazz,
                                             String name,
                                             Scope scope)
Retrieves a configuration by class, name, and scope. If the configuration is not found in this manager, the request will be forwarded to the parent, and so on.

Returns:
the requested configuration, or null if not found.

getConfig

public <T extends ManagedConfig> T getConfig(Class<T> clazz,
                                             String name,
                                             ArgumentMap args)
Retrieves a configuration by class, name, and arguments. If the configuration is not found in this manager, the request will be forwarded to the parent, and so on.

Parameters:
args - the configuration arguments, or null for none.
Returns:
the requested configuration, or null if not found.

getConfig

public <T extends ManagedConfig> T getConfig(Class<T> clazz,
                                             String name,
                                             Scope scope,
                                             ArgumentMap args)
Retrieves a configuration by class, name, scope, and arguments. If the configuration is not found in this manager, the request will be forwarded to the parent, and so on.

Parameters:
scope - the scope in which to create the config, or null for none.
args - the configuration arguments, or null for none.
Returns:
the requested configuration, or null if not found.

getConfig

public <T extends ManagedConfig> T getConfig(Class<T> clazz,
                                             String name)
Retrieves a configuration by class and name. If the configuration is not found in this manager, the request will be forwarded to the parent, and so on.

Returns:
the requested configuration, or null if not found.

getResourceConfig

public ManagedConfig getResourceConfig(String name)
Attempts to fetch a resource config through the cache.


getGroups

public <T extends ManagedConfig> ConfigGroup<T>[] getGroups(Class<T> clazz)
Retrieves the groups registered for the specified class in this manager and all of its ancestors.


getGroup

public <T extends ManagedConfig> ConfigGroup<T> getGroup(Class<T> clazz)
Retrieves the group registered for the specified class.


getGroups

public ConfigGroup[] getGroups(String name)
Retrieves the groups with the specified name in this manager and all of its ancestors.


getGroup

public ConfigGroup getGroup(String name)
Returns the configuration group with the specified name. If the group is not found in this manager, the request will be forwarded to the parent, and so on.


getGroup

public ConfigGroup getGroup(String name,
                            boolean forward)
Returns the configuration group with the specified name.

Parameters:
forward - if true and there's no such group, forward the request to the parent.

getGroups

public Collection<ConfigGroup> getGroups()
Returns the collection of all registered groups.


addUpdateListener

public void addUpdateListener(ConfigUpdateListener listener)
Adds a listener that will be notified on all config updates.


removeUpdateListener

public void removeUpdateListener(ConfigUpdateListener listener)
Removes an update listener.


saveAll

public void saveAll()
Saves the configurations in all groups.


revertAll

public void revertAll()
Reverts the configurations in all groups to their last saved state.


updateResourceConfig

public ManagedConfig updateResourceConfig(String name,
                                          ManagedConfig config)
Updates a resource-loaded configuration through the cache. If the configuration is not in the cache, the provided configuration will be stored under the specified name and returned. Otherwise, the cached version will be updated to reflect the provided configuration and returned.


validateReferences

public boolean validateReferences(String where,
                                  PrintStream out)
Validates the references of all configs managed by this manager.

Returns:
true if the references are valid

refresh

public void refresh(Class<? extends ManagedConfig> clazz)
Refreshes all configurations of the specified class.


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.


Copyright © 2011. All Rights Reserved.