simple.http.load
Class PrefixMapper

java.lang.Object
  extended by simple.http.load.PrefixMapper
All Implemented Interfaces:
Mapper

public class PrefixMapper
extends java.lang.Object
implements Mapper

The PrefixMapper provides a mapper that is used to perform mapping using prefix paths. This provides a scheme like the Servlet context mapping scheme. This Mapper allows arbitrary path configurations to be mapped directly to a service name, which can be autoloaded to serve content.

This can break the URI path into four components, the prefix, the service name, the class name, and the relative path. The prefix is the path part that is used to acquire the service name. A prefix is a URI directory, such as /path/, which is unique. The relative path is the remaining path, after the prefix is removed. So a path of /path/bin/file has the relative path of /bin/file.

The specification of prefix paths to service instance names is done using the XML configuration file Mapper.xml. This must is used by a MapperEngine to resolve services to be loaded, and can also be used by the services to acquire the location of resources using the relative paths.

Author:
Niall Gallagher
See Also:
MapperEngine

Constructor Summary
PrefixMapper(Context context)
          Constructor for the PrefixMapper.
 
Method Summary
 java.lang.String getClass(java.lang.String name)
          Used to resolve the class name using a service name.
 Configuration getConfiguration(java.lang.String name)
          This method is used retrieve properties for a service by using the service name.
 java.lang.String getName(java.lang.String path)
          This will resolve the service instance name given a URI path.
 java.lang.String getPath(java.lang.String path)
          This method is used to acquire a path relative to the prefix path.
 java.lang.String getPrefix(java.lang.String path)
          This will determine the prefix path that matches the given URI path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrefixMapper

public PrefixMapper(Context context)
Constructor for the PrefixMapper. This is used to create a Mapper that can be used to resolve service instance names given an arbitrary URI path. This uses a configuration file located using the Context object supplied with the context. The configuration file is used to acquire the mappings for URI path to service names.

Parameters:
context - used to find the mapping configuration file
Method Detail

getPath

public java.lang.String getPath(java.lang.String path)
This method is used to acquire a path relative to the prefix path. This will accept all HTTP URI formats, including an absolute URI. However, the relative path is determined with only the path part of the URI. If there is no mapping found for the issued path the normalized path part is returned.

Specified by:
getPath in interface Mapper
Parameters:
path - the HTTP URI to extract a relative path with
Returns:
the URI path relative to the resolved path prefix

getName

public java.lang.String getName(java.lang.String path)
This will resolve the service instance name given a URI path. This will determine the service name by matching the URI with the loaded prefix paths. If no match is found then this will return null, otherwise the service instance name is returned.

Specified by:
getName in interface Mapper
Parameters:
path - the URI path to extract a relative path with
Returns:
this returns the service instance name thats matched

getPrefix

public java.lang.String getPrefix(java.lang.String path)
This will determine the prefix path that matches the given URI path. The relative path is determined using the path part of the URI. If no prefix is matched for the URI path then this will return the root path, /.

Parameters:
path - the URI path to resolve a path prefix for
Returns:
this returns the prefix path that is resolved

getConfiguration

public Configuration getConfiguration(java.lang.String name)
This method is used retrieve properties for a service by using the service name. This will acquire the properties if any for the named service instance. The properties will contain zero or more name value pairs. If no properties are associated with the service the instance returned will be an empty map rather than a null object.

Specified by:
getConfiguration in interface Mapper
Parameters:
name - this is the name of the service instance
Returns:
returns a properties object for configuration

getClass

public java.lang.String getClass(java.lang.String name)
Used to resolve the class name using a service name. This is required to resolve the class name once the service name has been acquired from the getName method. If there is no match for the service name then null is returned.

Specified by:
getClass in interface Mapper
Parameters:
name - this is the service name to get a class name for
Returns:
the class name that matches the service name given