simple.http.load
Class MapperEngine

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by simple.http.load.LoaderEngine
                  extended by simple.http.load.MapperEngine
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, LoaderManager, ResourceEngine

public class MapperEngine
extends LoaderEngine

The MapperEngine provides an implementation of the LoaderEngine that does not require administration. It enables Service objects to be loaded and then executed without the need to use manual load invocations. This ability means that byte codes are taken from the class path once they have been referenced.

The MapperEngine makes use of a system wide Mapper to determine what references, that is, what URI references, map to a Service implementation. If a URI maps to a service then this will check to determine if it has been previously loaded, if so then it will simply return that instance. However if it has not been loaded then it will load the object and return a reference to it.

The loaded Service objects have an instance name that is used to reference a specific object, this name is taken from the Mapper.getName method. The service name can also be used to acquire the fully qualified class name of the service, this is useful when a service needs to be loaded. This capability allows multiple instances of the same type to be loaded and referenced individually using the service name.

Author:
Niall Gallagher
See Also:
MapperFactory, Mapper, Serialized Form

Field Summary
protected  java.lang.Object data
          Contains the object that is passed to each service object.
protected  Mapper mapper
          This is the mapper used by this engine to resolve URIs.
 
Fields inherited from class simple.http.load.LoaderEngine
context, delegate, profile, registry, resolver
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
MapperEngine()
          Constructor for the MapperEngine.
MapperEngine(Context context)
          Constructor for the MapperEngine.
MapperEngine(Context context, java.io.File path)
          Constructor for the MapperEngine.
MapperEngine(Context context, java.io.File path, java.lang.Object data)
          Constructor for the MapperEngine.
MapperEngine(Context context, java.lang.Object data)
          Constructor for the MapperEngine.
MapperEngine(Context context, java.lang.String path)
          Constructor for the MapperEngine.
MapperEngine(Context context, java.lang.String path, java.lang.Object data)
          Constructor for the MapperEngine.
 
Method Summary
 Resource lookup(java.lang.String name)
          This will look for and retrieve the requested resource.
 Resource resolve(java.lang.String target)
          This will detetmine whether the URI string issued contains a reference to a service object.
 
Methods inherited from class simple.http.load.LoaderEngine
link, link, load, load, load, remove, unlink, unlink, unload, update
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mapper

protected Mapper mapper
This is the mapper used by this engine to resolve URIs.


data

protected java.lang.Object data
Contains the object that is passed to each service object.

Constructor Detail

MapperEngine

public MapperEngine()
             throws java.io.IOException
Constructor for the MapperEngine. This creates an implementation of the LoaderEngine that does not require manual loading of service instances. This allows URI references that contain a service implementation name to load the byte codes. This constructor uses a context for the current working directory as a CacheContext.

Throws:
java.io.IOException

MapperEngine

public MapperEngine(Context context)
             throws java.io.IOException
Constructor for the MapperEngine. This creates an implementation of the LoaderEngine that does not require manual loading of service instances. This allows URI references that contain a service implementation name to load the byte codes.

This will load the class byte codes from the base path of the supplied Context object. If the byte codes cannot be found using the inherited or system class loader the base path is checked, failing that this will return a service object that can supply an HTTP 404 Not Found.

Parameters:
context - the Context for this instance
Throws:
java.io.IOException

MapperEngine

public MapperEngine(Context context,
                    java.lang.Object data)
             throws java.io.IOException
Constructor for the MapperEngine. This creates an implementation of the LoaderEngine that does not require manual loading of service instances. This allows URI references that contain a service implementation name to load the byte codes.

This will load the class byte codes from the base path of the supplied Context object. If the byte codes cannot be found using the inherided or system class loader the base path is checked, failing that this will return a service object that can supply an HTTP 404 Not Found.

This enables an arbitrary object to be issused, which is what is used by this LoaderEngine to load the Service objects. Each instance that is loaded is given this object via its prepare method.

Parameters:
context - the Context for this instance
data - this is the data that is given to each service
Throws:
java.io.IOException

MapperEngine

public MapperEngine(Context context,
                    java.lang.String path)
             throws java.io.IOException
Constructor for the MapperEngine. This creates an implementation of the LoaderEngine that does not require manual loading of service instances. This allows URI references that contain a service implementation name to load the byte codes.

This will load the class byte codes from the supplied path, if they cannot be found within the inherited or system class path. Providing a path other than the Context base path can be useful in seperating services from content. If a service cannot be found an HTTP 404 Not Found is used.

Parameters:
context - the Context for this instance
path - this is added to the classpath of the engine
Throws:
java.io.IOException

MapperEngine

public MapperEngine(Context context,
                    java.lang.String path,
                    java.lang.Object data)
             throws java.io.IOException
Constructor for the MapperEngine. This creates an implementation of the LoaderEngine that does not require manual loading of service instances. This allows URI references that contain a service implementation name to load the byte codes.

This will load the class byte codes from the supplied path, if they cannot be found within the inherited or system class path. Providing a path other than the Context base path can be useful in seperating services from content. If a service cannot be found an HTTP 404 Not Found is used.

This enables an arbitrary object to be issused, which is what is used by this LoaderEngine to load the Service objects. Each instance that is loaded is given this object via its prepare method.

Parameters:
context - the Context for this instance
path - this is added to the classpath of the engine
data - this is the data that is given to each service
Throws:
java.io.IOException

MapperEngine

public MapperEngine(Context context,
                    java.io.File path)
             throws java.io.IOException
Constructor for the MapperEngine. This creates an implementation of the LoaderEngine that does not require manual loading of service instances. This allows URI references that contain a service implementation name to load the byte codes.

This will load the class byte codes from the supplied path, if they cannot be found within the inherited or system class path. Providing a path other than the Context base path can be useful in seperating services from content. If a service cannot be found an HTTP 404 Not Found is used.

Parameters:
context - the Context for this instance
path - this is added to the classpath of the engine
Throws:
java.io.IOException

MapperEngine

public MapperEngine(Context context,
                    java.io.File path,
                    java.lang.Object data)
             throws java.io.IOException
Constructor for the MapperEngine. This creates an implementation of the LoaderEngine that does not require manual loading of service instances. This allows URI references that contain a service implementation name to load the byte codes.

This will load the class byte codes from the supplied path, if they cannot be found within the inherited or system class path. Providing a path other than the Context base path can be useful in seperating services from content. If a service cannot be found an HTTP 404 Not Found is used.

This enables an arbitrary object to be issused, which is what is used by this LoaderEngine to load the Service objects. Each instance that is loaded is given this object via its prepare method.

Parameters:
context - the Context for this instance
path - this is added to the classpath of the engine
data - this is the data that is given to each service
Throws:
java.io.IOException
Method Detail

lookup

public Resource lookup(java.lang.String name)
This will look for and retrieve the requested resource. The target given must be the actual name for the resource. This will locate the resource and return the Resource implementation that will handle the target.

This attempts to retrieve a service that has been previously loaded using the load method. If the named service has been previously loaded then the loaded instance is returned from this method. However, if the service name does not corrospond to any previously loaded service then this will attempt to use the given name to acquire a fully qualified class name to load a service implementation. If this does not result in sucess, then a report resource that can display the cause and status of the error is returned.

Overrides:
lookup in class LoaderEngine
Parameters:
name - this is than name of the service to retrieve
Returns:
the service implementation that has been retrieved

resolve

public Resource resolve(java.lang.String target)
This will detetmine whether the URI string issued contains a reference to a service object. This uses the system wide implementation of the Mapper object to check whether a mapping exists. If a service name can be retrieved from the URI then it is used to load the service. If there is a failure loading the service then a report is returned.

Service objects are loaded the first time they are mapped. The instance name of a loaded object is used to acquire an implementation class name. This enables multiple service types to be loaded and referenced individually.

Specified by:
resolve in interface ResourceEngine
Overrides:
resolve in class LoaderEngine
Parameters:
target - this is the request URI to be resolved
Returns:
the service implementation that has been resolved