mmhttp.server
Class ResponderFactory

java.lang.Object
  extended by mmhttp.server.ResponderFactory

public class ResponderFactory
extends java.lang.Object

The spawning place of all Responders.

Every Server will have an instance of a ResponderFactory. The role of the ResponderFactory is to create a Responder based on the resource requested. Users must therefore register their customer Responders along with a regular expresion to describe resources that should be handled by the Responder.

See Also:
Responder, Server

Field Summary
 java.lang.Class defaultResponder
          Used in the event that none of the registered Responders match a request.
 
Constructor Summary
ResponderFactory()
           
 
Method Summary
 void register(java.lang.String regex, java.lang.Class klass)
          Use this method to register your custom Responders.
 java.lang.Class responderClassFor(java.lang.String resource)
          This method is used to retreives the first matching Responder class for a given resource.
 Responder responderFor(java.lang.String resource)
          This will find the correct Responder for the resource and construct it using the default constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultResponder

public java.lang.Class defaultResponder
Used in the event that none of the registered Responders match a request. Default: NotFoundResponder

Constructor Detail

ResponderFactory

public ResponderFactory()
Method Detail

register

public void register(java.lang.String regex,
                     java.lang.Class klass)

Use this method to register your custom Responders. Note: The Server has a convenience method to register Responders so you need not use this menthod directory.

To register a Responder you pass in a regular expression String and a Responder class. For example: server.responderFactory.register("abc\d{3}", AlphaNumericResponder.class) This will cause all incoming requests for 'abc' follow by 3 digits to be handled by an instance of AlphaNumericResponder.

The order in which Responder are registere is important. Since a given request may match multiple regular expressions, the factory will follow a simple 'first come, first served' policy. That is the first registered Responder to match the requested resource will be instantiated to process the request.

Parameters:
regex -
klass -

responderClassFor

public java.lang.Class responderClassFor(java.lang.String resource)
This method is used to retreives the first matching Responder class for a given resource. You may find this method handy to test your registrations.

Parameters:
resource -
Returns:
the matching responder class

responderFor

public Responder responderFor(java.lang.String resource)
                       throws java.lang.NoSuchMethodException,
                              java.lang.IllegalAccessException,
                              java.lang.reflect.InvocationTargetException,
                              java.lang.InstantiationException
This will find the correct Responder for the resource and construct it using the default constructor.

Parameters:
resource -
Returns:
an instance of the matching responder
Throws:
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException


Copyright © 2009 Micah Martin. All Rights Reserved.