us.zuercher.gpx2map.source
Class SourceFactory

java.lang.Object
  extended by us.zuercher.gpx2map.source.SourceFactory
Direct Known Subclasses:
Factory, Factory

public abstract class SourceFactory
extends Object

SourceFactory creates MapSource implementations. It uses the name given to createMapSource(String) as the basis of, or to look up, the name of a package containing a concrete implementation of SourceFactory. The concrete implementation must be named "Factory" and is instantiated through reflection. The method newMapSource() is then called to create a new MapSource.

The package name is generated as follows:

  1. If a system property "gpx2map.source.name" exists, its value is assumed to be the name of the package. If the Factory class is found, it is used.
  2. Otherwise, if the system property doesn't exist or the Factory class is not found, we assume that the name refers to a built-in source implementation. The package name is "us.zuercher.gpx2map.source.name".

SourceFactory is not re-entrant w.r.t. createMapSource(String) and getLastThrown(). Synchronize access to SourceFactory if you require multi-threaded access.

Author:
Stephan Zuercher

Field Summary
private static String BUILT_IN_PKG
           
private static List<String> builtInSources
           
private static String FACTORY_NAME
           
private static String PROP_PREFIX
           
private static Throwable thrown
           
 
Constructor Summary
SourceFactory()
           
 
Method Summary
private static String buildAddOnPackageName(String name)
           
private static String buildBuiltInPackageName(String name)
           
static MapSource createMapSource(String name)
          Create a new MapSource.
private static List<String> generateBuiltInSources()
          Generates an unmodifiable List of Strings that represent the names of the built-in map sources.
static List<MapSourceDescriptor> getAvailableSources()
          Returns a List of known source descriptors.
static Throwable getLastThrown()
          Returns any exception thrown during construction of the implementation's UtmMapSource.
abstract  MapSourceDescriptor getMapSourceDescriptor()
          Returns a MapSourceDescriptor for this SourceFactory.
private static MapSource instantiateMapSource(String name)
           
private static SourceFactory instantiateSourceFactory(String name)
           
protected abstract  MapSource newMapSource()
          Returns a newly instantiated MapSource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_PREFIX

private static final String PROP_PREFIX
See Also:
Constant Field Values

BUILT_IN_PKG

private static final String BUILT_IN_PKG
See Also:
Constant Field Values

FACTORY_NAME

private static final String FACTORY_NAME
See Also:
Constant Field Values

builtInSources

private static final List<String> builtInSources

thrown

private static Throwable thrown
Constructor Detail

SourceFactory

public SourceFactory()
Method Detail

createMapSource

public static MapSource createMapSource(String name)
Create a new MapSource. See the class description for how an implementation's factory class is found.

Parameters:
name - implementation name
Returns:
a new UtmMapSource or null if the implementation cannot be found, or if there is an error instantiating the factory class.
See Also:
getLastThrown()

getLastThrown

public static Throwable getLastThrown()
Returns any exception thrown during construction of the implementation's UtmMapSource. This exception is reset with each call to createMapSource(String).

Returns:
exception thrown during construction of the UtmMapSource

getAvailableSources

public static List<MapSourceDescriptor> getAvailableSources()
Returns a List of known source descriptors.

Returns:
List of known source descriptors.

instantiateSourceFactory

private static SourceFactory instantiateSourceFactory(String name)

instantiateMapSource

private static MapSource instantiateMapSource(String name)

buildAddOnPackageName

private static String buildAddOnPackageName(String name)

buildBuiltInPackageName

private static String buildBuiltInPackageName(String name)

generateBuiltInSources

private static List<String> generateBuiltInSources()
Generates an unmodifiable List of Strings that represent the names of the built-in map sources. If the system property "gpx2map.debug" is set to "true", the dummy map source is included for multi-source testing.

Returns:
an umodifiable String List of built-in source names

getMapSourceDescriptor

public abstract MapSourceDescriptor getMapSourceDescriptor()
Returns a MapSourceDescriptor for this SourceFactory.

Returns:
a MapSourceDescriptor

newMapSource

protected abstract MapSource newMapSource()
Returns a newly instantiated MapSource.

Returns:
a newly instantiated MapSource.