org.baswell.routes
Class RoutingTable

java.lang.Object
  extended by org.baswell.routes.RoutingTable

public class RoutingTable
extends java.lang.Object

Hub for all routes. Routes can be added to the RoutingTable in the following ways:

1. As class objects. Routes added as class objects are instantiated on each matched HTTP request. Once the HTTP request is processed, the instantiated route object is discarded. Every HTTP request gets its own route object instance. The route class does not have to be thread safe.

2. As instances of the route class. In this case the same route object will get used for every matched HTTP request. The route class must be thread safe as it can process multiple HTTP requests concurrently.

Normally build should be called during application startup after all routes have been added. If there are any errors in route configurations an error will be thrown then. Otherwise this method will be called on the first request that uses the Routes engine.

If the RoutesFilter or RoutesServlet is used in web.xml then this class should be treated as a singleton (only one instance created). If multiple instances of RoutingTable are created then RoutesFilter and RoutesServlet will only have visibly to the last one created.


Constructor Summary
RoutingTable()
          The default RoutesConfiguration will be used.
RoutingTable(RoutesConfiguration routesConfiguration)
           
 
Method Summary
 RoutingTable add(java.lang.Object... instancesOrClasses)
          Adds to the given objects to the routing table.
 void build()
          Builds the routing table from the added route objects.
 void setRoutes(java.util.List<java.lang.Object> routeObjects)
          Calls add(java.lang.Object...) for each object in the given list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RoutingTable

public RoutingTable()
The default RoutesConfiguration will be used.


RoutingTable

public RoutingTable(RoutesConfiguration routesConfiguration)
Method Detail

setRoutes

public void setRoutes(java.util.List<java.lang.Object> routeObjects)
Calls add(java.lang.Object...) for each object in the given list. Can be used in spring XML mappings as:

Parameters:
routeObjects - The list of route objects to add to the routing table.

add

public RoutingTable add(java.lang.Object... instancesOrClasses)
Adds to the given objects to the routing table. Objects can be either the route class object or a route instance object.

Parameters:
instancesOrClasses - Route class or instance objects.
Returns:
This RoutingTable

build

public void build()
           throws RoutesException
Builds the routing table from the added route objects. This will typically only be called once after all route objects have been added in your application's bootstrap.

Throws:
RoutesException - If an added route is configured incorrectly.