aerogear-controller 1.0.0.M1

org.jboss.aerogear.controller.router
Class AbstractRoutingModule

java.lang.Object
  extended by org.jboss.aerogear.controller.router.AbstractRoutingModule
All Implemented Interfaces:
RoutingModule

public abstract class AbstractRoutingModule
extends Object
implements RoutingModule

AbstractRoutingModule simplifies the process of configuring Routes by implementing RoutingModule and providing helper methods.

Example Usage:
 Routes routes = new AbstractRoutingModule() {
     @Override
     public void configuration() {
         route()
                .from("/home")
                .on(RequestMethod.GET)
                .to(SampleController.class).index();
         //... more routes
     }
 }.build();
 


Field Summary
private  List<RouteBuilder> routes
           
 
Constructor Summary
AbstractRoutingModule()
           
 
Method Summary
 Routes build()
          Returns a Routes instance containing all the Routes configured in the application.
abstract  void configuration()
          "Hook" for the template method build(), which subclasses should implement to define the routes of the application.
static
<T> T
param(Class<T> clazz)
          Param is used when a target method takes a argument.
static String pathParam(String id)
          Used to specify that a parameter of a method is expected to be in the request path.
 RouteBuilder route()
          Is the starting point to configuring a single route.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

routes

private final List<RouteBuilder> routes
Constructor Detail

AbstractRoutingModule

public AbstractRoutingModule()
Method Detail

configuration

public abstract void configuration()
                            throws Exception
"Hook" for the template method build(), which subclasses should implement to define the routes of the application. For an example usage see the javadoc for this class.

Throws:
Exception - enables a route to specify a target method that throws an exception. This method is only about configuring routes and not invoking them, but the target methods might still declare that they throw exceptions and configuration() declares this as well, saving end users from having to have try/catch clauses that clutter up their route configurations

route

public RouteBuilder route()
Is the starting point to configuring a single route.

Returns:
RouteBuilder which provides a fluent API for configuring a Route.

build

public Routes build()
Description copied from interface: RoutingModule
Returns a Routes instance containing all the Routes configured in the application.

Specified by:
build in interface RoutingModule
Returns:
Routes populated with all the configured Routes.

param

public static <T> T param(Class<T> clazz)
Param is used when a target method takes a argument.

For example, lets say you have a target method named save, which takes a single argument of type Car.class, the following would enable you to configure the save method:
     .to(SampleController.class).save(param(Car.class));
 

Parameters:
clazz - the type of the parameter that the target method accepts.
Returns:
T reference of type T but will always be null.

pathParam

public static String pathParam(String id)
Used to specify that a parameter of a method is expected to be in the request path.

For example:
.from("/car/{id}")
     .on(RequestMethod.GET)
     .to(SampleController.class).find(pathParam("id"));
 

Parameters:
id - the id/name of the parameter
Returns:
String the same String that was passed in.

aerogear-controller 1.0.0.M1

Copyright © 2012 JBoss, a division of Red Hat, Inc.. All Rights Reserved.