simple.http.load
Class PatternMapper

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

public class PatternMapper
extends java.lang.Object
implements Mapper

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

This uses the wild card characters '*' and '?' to specify the patterns used for URI path to service name matching. For example take the pattern "*.html", this will match any URI path that ends with ".html", such as "/index.html" or "/example.html". If the '?' character is used with '*' in the formation '*?' then the match will be all characters up to the first occurance of the following character. For instance "/*?/*.html" will match the path "/pub/index.html" but not "/pub/bin/index.html".

The specification of wild card patterns to service names is done using the XML configuration file Mapper.xml. This must be used by a MapperEngine to resolve services to be loaded by resolving the service instance name.


    <resolve>
       <match path="/*" name="file"/>
       <match path="/*?/*.txt" name="text"/>
       <match path="/???/*" name="three"/>
    </resolve>

 
Taking the above example mappings as entries within the XML configuration file loaded, matches for all URI paths can match the pattern "/*", which signifies anything. However the matches for the "/*?/*.txt" pattern will only match URI paths that end in ".txt" and have only a single path segment, like "/path/README.txt". Any number of wild card characters can be specified and the order they appear in the configuration file is signifigant. The first pattern has the lowest priority and the last has the highest. So taking the above specification, a URI path such as "/1234/README.txt" will match the "/*?/*.txt" pattern, as it is resolved before "/*" pattern. Also "/???/*" matches an initial path segment with only three characters.

See Also:
MapperEngine, Resolver

Constructor Summary
PatternMapper(Context context)
          Constructor for the PatternMapper.
 
Method Summary
 java.lang.String getClass(java.lang.String name)
          This method is used to retrieve the fully qualified class name from the service instance 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 method is used to transform a path to a service name.
 java.lang.String getPath(java.lang.String path)
          This method is used to acquire a path given the unmodified URI path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PatternMapper

public PatternMapper(Context context)
Constructor for the PatternMapper. 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. This 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 given the unmodified URI path. One of the most confusing things about mapping within the Servlet Specification is the combination of pattern mapping such as *.jsp and context mapping such as /context/. When these are used together determining the getPathInfo is not intuitive. So this will simply return the path as is.

Specified by:
getPath in interface Mapper
Parameters:
path - the URI path to extract a relative path with
Returns:
the specified URI path normalized and escaped

getName

public java.lang.String getName(java.lang.String path)
Description copied from interface: Mapper
This method is used to transform a path to a service name. If the path cannot be converted to a service name then a null is returned. The returned service name can then be used to acquire the class name of the service object.

Specified by:
getName in interface Mapper
Parameters:
path - this is the path that is to be converted
Returns:
name of the service instance mapped to the path

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)
This method is used to retrieve the fully qualified class name from the service instance name. This is provided such that if a service has not been loaded, the class name can be retrieved from the service instance name, which will enable the service to be loaded into the system from a URI path provided with a HTTP request. If the service instance name does not exist this method will return null.

Specified by:
getClass in interface Mapper
Parameters:
name - this is the service instance being queried
Returns:
the fully qualified class name for the service