NASA World Wind

gov.nasa.worldwind
Class BasicFactory

java.lang.Object
  extended by gov.nasa.worldwind.BasicFactory
All Implemented Interfaces:
Factory
Direct Known Subclasses:
BasicElevationModelFactory, BasicLayerFactory

public class BasicFactory
extends Object
implements Factory

A basic implementation of the Factory interface.


Constructor Summary
BasicFactory()
           
 
Method Summary
 Object createFromCapabilities(String capsFileName, AVList params)
          Create an object such as a layer or elevation model given a local OGC capabilities document containing named layer descriptions.
 Object createFromClassName(String className)
          Creates an object given the object's class name.
 Object createFromConfigFile(String fileName)
          A no-op implemenation of the Factory.createFromConfigFile(String) method provided so that this class can be instantiated.
 Object createFromDataConfig(DataConfiguration dataConfig, AVList params)
          A no-op implementation of the Factory.createFromDataConfig(DataConfiguration, gov.nasa.worldwind.avlist.AVList) method provided so that this class can be instantiated.
 Object createFromKeys(String[] sourceKeys)
          Creates an object, determining the method to use from a list of specified keys.
protected  Object doCreateFromCapabilities(Capabilities caps, AVList params)
          Implemented by subclasses to perform the actual object creation.
protected  Object doCreateFromKey(String key)
          Called during createFromKeys(String[]) for each key prior to attempting to create an object by the default mechanisms.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicFactory

public BasicFactory()
Method Detail

createFromCapabilities

public Object createFromCapabilities(String capsFileName,
                                     AVList params)
Create an object such as a layer or elevation model given a local OGC capabilities document containing named layer descriptions.

Parameters:
capsFileName - the path to the capabilities file. The file must be either an absolute path or a relative path available on the classpath. The file contents must be a valid OGC capabilities document.
params - a list of configuration properties. These properties override any specified in the capabilities document. The list should contain the AVKey.LAYER_NAMES property for services that define layer, indicating which named layers described in the capabilities document to create. If this argumet is null or contains no layers, the first named layer is used.
Returns:
the requested object.
Throws:
IllegalArgumentException - if the file name is null.
IllegalStateException - if the capabilites document contains no named layer definitions.
WWRuntimeException - if an error occurs while opening, reading or parsing the capabilities document.

createFromClassName

public Object createFromClassName(String className)
Creates an object given the object's class name. Effectively an argument checking and exception logging wrapper around the statement Class.forName(className.trim()).newInstance().

Specified by:
createFromClassName in interface Factory
Parameters:
className - the fully qualified class name of the class to create.
Returns:
the new object

createFromConfigFile

public Object createFromConfigFile(String fileName)
A no-op implemenation of the Factory.createFromConfigFile(String) method provided so that this class can be instantiated. Not all factories need a createfromConfigFile method; this class is therefore useful as is in these cases.

Specified by:
createFromConfigFile in interface Factory
Parameters:
fileName - normally the path to the configuration file. It must be either an absolute path or a relative path available on the classpath. But this dummy method implementation ignores this argument.
Returns:
this no-op method always returns null.

createFromDataConfig

public Object createFromDataConfig(DataConfiguration dataConfig,
                                   AVList params)
A no-op implementation of the Factory.createFromDataConfig(DataConfiguration, gov.nasa.worldwind.avlist.AVList) method provided so that this class can be instantiated. Not all factories need a createFromDataConfig method; this class is therefore useful as is in these cases.

Specified by:
createFromDataConfig in interface Factory
Parameters:
dataConfig - normally the configuration information describing the component.
params - normally key-value parameters which will override or supplement the information provided in the specified configuration. A null reference is permitted.
Returns:
this no-op method always returns null.

createFromKeys

public Object createFromKeys(String[] sourceKeys)
Creates an object, determining the method to use from a list of specified keys.

The method recognizes keys with terminating characters of "ConfigFile" and "ClassName". The key itself is used to determine from Configuration the actual configuration file name or class name, respectively. A key without recognizable terminating characters is considered to be a class name key, as though its terminating characters are "ClassName".

Each key is tried in the order specified. The method whose key is first recognized and whose corresponding configuration component, e.g., class name or configuration file name, is found is used to create an object. If no mechanism is matched then an exception is thrown. An exception is also thrown when a matched method fails during its attempt to create the object.

Subclasses are given the chance to handle each key before the other mechanisms are tried. For each key, the method doCreateFromKey(String) is called prior to trying the other mechanisms. If that method returns non-null then this method returns immediately. If doCreateFromKey(String) returns null, the other mechanisms are tried before calling it again with the next key.

Specified by:
createFromKeys in interface Factory
Parameters:
sourceKeys - an array of keys identifying which mechanisms to use to create the object.
Returns:
the desired object if a mechanism was found to successfully create it.
Throws:
IllegalArgumentException - if sourceKeys is null or empty.
WWRuntimeException - if no mechanism is matched or the matched mechanism throws an exception or otherwise fails.

doCreateFromCapabilities

protected Object doCreateFromCapabilities(Capabilities caps,
                                          AVList params)
Implemented by subclasses to perform the actual object creation. This default implementation always returns null.

Parameters:
caps - the capabilities document.
params - a list of configuration properties. These properties override any specified in the capabilities document. The list should contain the AVKey.LAYER_NAMES property for services that define layers, indicating which named layers described in the capabilities document to create. If this argumet is null or contains no layers, the first named layer is used.
Returns:
the requested object.

doCreateFromKey

protected Object doCreateFromKey(String key)
Called during createFromKeys(String[]) for each key prior to attempting to create an object by the default mechanisms. This give subclasses the first opportunity to create the object. If this method returns null, the other mechanisms are tried for the indicated key. If those other mechanisms fail, this method is called again with the next key.

Parameters:
key - the key identifying the mechanism to use to create an object and the resource with which to do it.
Returns:
an instance of the desired object if creation is successful, otherwise null. The default instance of this method always returns null.

NASA World Wind