ERXRouteRequestHandler Class Reference

Inherits com::webobjects::appserver::_private::WODirectActionRequestHandler.

Collaboration diagram for ERXRouteRequestHandler:

Collaboration graph
[legend]

List of all members.

Classes

class  NameFormat

Public Member Functions

void _clearCaches ()
void _putComponentsToSleepInContext (WOContext wocontext)
void addDefaultRoutes (String entityName, String entityType, boolean numericPKs, Class<?extends ERXRouteController > controllerClass)
void addDefaultRoutes (String entityName, boolean numericPKs, Class<?extends ERXRouteController > controllerClass)
void addDefaultRoutes (String entityName, Class<?extends ERXRouteController > controllerClass)
void addDefaultRoutes (String entityName)
void addRoute (ERXRoute route)
void addRoutes (String entityName, Class<?extends ERXRouteController > routeControllerClass)
void addRoutes (String entityName)
String controllerPathForEntityNamed (String entityName)
 ERXRouteRequestHandler (NameFormat entityNameFormat)
 ERXRouteRequestHandler ()
WOAction getActionInstance (Class class1, Class[] aclass, Object[] aobj)
Object[] getRequestActionClassAndNameForPath (NSArray requestHandlerPath)
NSArray getRequestHandlerPathForRequest (WORequest request)
void insertRoute (ERXRoute route)
void removeRoute (ERXRoute route)
Class<?extends ERXRouteControllerrouteControllerClassForEntityNamed (String entityName)
ERXRoute routeForMethodAndPath (String method, String path, NSMutableDictionary< String, Object > userInfo)
NSArray< ERXRouteroutes ()
NSArray< ERXRouteroutesForControllerClass (Class<?extends ERXRouteController > routeController)
ERXRoute setupRequestWithRouteForMethodAndPath (WORequest request, String method, String path)
void setupRouteControllerFromUserInfo (ERXRouteController controller, NSDictionary< String, Object > userInfo)

Static Public Member Functions

static void register (ERXRouteRequestHandler requestHandler)

Static Public Attributes

static final String ExtensionKey = "ERXRouteRequestHandler.extension"
static final String Key = "ra"
static final String KeysKey = "ERXRouteRequestHandler.keys"
static final Logger log = Logger.getLogger(ERXRouteRequestHandler.class)
static final String PathKey = "ERXRouteRequestHandler.path"
static NameFormat RAILS = new NameFormat(true, true, NameFormat.Case.LowercaseUnderscore)
static final String RouteKey = "ERXRouteRequestHandler.route"
static final String TypeKey = "ERXRouteRequestHandler.type"
static NameFormat WO = new NameFormat(false, false, NameFormat.Case.CamelCase)
static NameFormat WO_LOWER = new NameFormat(false, false, NameFormat.Case.LowerCamelCase)

Protected Member Functions

void addDeclaredRoutes (String entityName, Class<?extends ERXRouteController > routeControllerClass, boolean addDefaultRoutesIfNoDeclaredRoutesFound)

Package Functions

public< T extends
ERXRouteController > T 
controller (Class< T > controllerClass, WORequest request, WOContext context)
public< T extends
ERXRouteController > T 
controller (Class< T > controllerClass, WOContext context)
public< T extends
ERXRouteController > T 
controller (String entityName, WORequest request, WOContext context)

Private Attributes

NameFormat _entityNameFormat
NSMutableArray< ERXRoute_routes


Detailed Description

ERXRouteRequestHandler is the request handler that can process rails-style route mappings and convert them to ERXRestController action methods.

in Application:

 ERXRouteRequestHandler routeRequestHandler = new ERXRouteRequestHandler();
 routeRequestHandler.addDefaultRoutes(Person.ENTITY_NAME);
 ERXRouteRequestHandler.register(routeRequestHandler);
 

or

 ERXRouteRequestHandler routeRequestHandler = new ERXRouteRequestHandler();
 routeRequestHandler.addRoute(new ERXRoute("/people/{action}", PeopleController.class));
 routeRequestHandler.addRoute(new ERXRoute("/person/{person:Person}", PeopleController.class, "show"));
 ...
 ERXRouteRequestHandler.register(routeRequestHandler);
 

Note that addDefaultRoutes sets up many routes automatically (not just the 2 that are shown above), and for most cases should be your starting point for adding new entities rather than manually adding them.

in PeopleController:

 public class PeopleController extends ERXRouteController {
 	public PeopleController(WORequest request) {
 		super(request);
 	}

 	public Person person() {
 		Person person = (Person) routeObjectForKey("person");
 		return person;
 	}

 	public ERXKeyFilter showFilter() {
 		ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes();
 		filter.include(Person.COMPANY).includeAttributes();
 		return filter;
 	}

 	public ERXKeyFilter updateFilter() {
 		ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes();
 		filter.include(Person.COMPANY);
 		return filter;
 	}

 	public WOActionResults createAction() {
 		Person person = (Person) create(Person.ENTITY_NAME, updateFilter());
 		editingContext().saveChanges();
 		return response(person, showFilter());
 	}

 	public WOActionResults updateAction() {
 		Person person = person();
 		update(person, updateFilter());
 		editingContext().saveChanges();
 		return response(person, showFilter());
 	}

 	public WOActionResults showAction() {
 		return response(person(), showFilter());
 	}

 	public WOActionResults indexAction() {
 		NSArray<Person> people = Person.fetchPersons(editingContext(), null, Person.LAST_NAME.asc().then(Person.FIRST_NAME.asc()));
 		return response(editingContext(), Person.ENTITY_NAME, people, showFilter());
 	}
 }
 

in browser:

 http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/people.xml
 http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/people.json
 http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/people.plist
 http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/person/100.json
 http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/person/100/edit.json
 

Author:
mschrag

Constructor & Destructor Documentation

Constructs a new ERXRouteRequestHandler with the default entity name format.

ERXRouteRequestHandler ( NameFormat  entityNameFormat  ) 

Constructs a new ERXRouteRequestHandler.

Parameters:
entityNameFormat the format to use for entity names in URLs


Member Function Documentation

void _clearCaches (  ) 

Clears any caches that may exist on ERXRoutes (probably only useful to JRebel, to clear the route parameter method cache).

void _putComponentsToSleepInContext ( WOContext  wocontext  ) 

void addDeclaredRoutes ( String  entityName,
Class<?extends ERXRouteController routeControllerClass,
boolean  addDefaultRoutesIfNoDeclaredRoutesFound 
) [protected]

void addDefaultRoutes ( String  entityName,
String  entityType,
boolean  numericPKs,
Class<?extends ERXRouteController controllerClass 
)

Adds list and view routes for the given entity. For instance, if you provide the entity name "Reminder" you will get the routes:

 /reminders
 /reminders/{action}
 /reminder/{reminder:Reminder}
 /reminder/{reminder:Reminder}/{action}
 

Parameters:
entityName the entity name to route with
entityType the type of the enity
numericPKs if true, routes can assume numeric PK's and add some extra convenience routes
controllerClass the controller class

void addDefaultRoutes ( String  entityName,
boolean  numericPKs,
Class<?extends ERXRouteController controllerClass 
)

Adds list and view routes for the given entity. For instance, if you provide the entity name "Reminder" you will get the routes:

 /reminders
 /reminders/{action}
 /reminder/{reminder:Reminder}
 /reminder/{reminder:Reminder}/{action}
 

Parameters:
entityName the entity name to route with
numericPKs if true, routes can assume numeric PK's and add some extra convenience routes
controllerClass the controller class

void addDefaultRoutes ( String  entityName,
Class<?extends ERXRouteController controllerClass 
)

Adds list and view routes for the given entity. For instance, if you provide the entity name "Reminder" you will get the routes:

 /reminders
 /reminders/{action}
 /reminder/{reminder:Reminder}
 /reminder/{reminder:Reminder}/{action}
 

Parameters:
entityName the entity name to route with
controllerClass the controller class

void addDefaultRoutes ( String  entityName  ) 

Adds default routes and maps them to a controller named "[plural entity name]Controller". For instance, if the entity name is "Person" it would make a controller named "PeopleController".

Parameters:
entityName the name of the entity to create routes for

void addRoute ( ERXRoute  route  ) 

Adds a new route to this request handler.

Parameters:
route the route to add

void addRoutes ( String  entityName,
Class<?extends ERXRouteController routeControllerClass 
)

Calls the static method 'addRoutes(entityName, routeRequetHandler)' on the given route controller class, giving it the opportunity to add routes for the given entity. Additionally, this method looks for all methods annotated with or annotations and adds the corresponding routes. If no addRoutes method is found and no

annotated methods exist, it will log a warning and add default routes instead.

Parameters:
entityName the name of the entity
routeControllerClass the name of the route controller

void addRoutes ( String  entityName  ) 

Calls the static method 'addRoutes(entityName, routeRequetHandler)' on the route controller for the given entity name, giving it the opportunity to add routes for this entity. Additionally, this method looks for all methods annotated with or annotations and adds the corresponding routes. If no addRoutes method is found and no

annotated methods exist, it will log a warning and add default routes instead.

Parameters:
entityName the name of the entity

public<T extends ERXRouteController> T controller ( Class< T >  controllerClass,
WORequest  request,
WOContext  context 
) [package]

Returns the corresponding controller instance.

Parameters:
<T> the type of controller to return
controllerClass the controller class to lookup
request the current request
context the current context
Returns:
the created controller

public<T extends ERXRouteController> T controller ( Class< T >  controllerClass,
WOContext  context 
) [package]

Returns the corresponding controller instance (with no request specified).

Parameters:
<T> the type of controller to return
controllerClass the controller class to lookup
context the current context
Returns:
the created controller

public<T extends ERXRouteController> T controller ( String  entityName,
WORequest  request,
WOContext  context 
) [package]

Returns the corresponding controller instance.

Parameters:
<T> the type of controller to return
entityName the entity name of the controller to lookup
request the current request
context the current context
Returns:
the created controller

String controllerPathForEntityNamed ( String  entityName  ) 

Return the controller path name for an entity name based on the entity name format.

Parameters:
entityName the entity name
Returns:
the controller identifier part of the path (the "companies" part in "/companies/1000");

WOAction getActionInstance ( Class  class1,
Class[]  aclass,
Object[]  aobj 
)

Object [] getRequestActionClassAndNameForPath ( NSArray  requestHandlerPath  ) 

NSArray getRequestHandlerPathForRequest ( WORequest  request  ) 

void insertRoute ( ERXRoute  route  ) 

Inserts a route at the beginning of the route list.

Parameters:
route the route to insert

static void register ( ERXRouteRequestHandler  requestHandler  )  [static]

Registers an ERXRestRequestHandler with the WOApplication for the handler key "rest".

Parameters:
requestHandler the rest request handler to register

void removeRoute ( ERXRoute  route  ) 

Removes the given route from this request handler.

Parameters:
route the route to remove

Class<? extends ERXRouteController> routeControllerClassForEntityNamed ( String  entityName  ) 

Returns the default route controller class for the given entity name.

Parameters:
entityName the name of the entity
Returns:
the corresponding route controller

ERXRoute routeForMethodAndPath ( String  method,
String  path,
NSMutableDictionary< String, Object >  userInfo 
)

Returns the route that matches the request method and path, storing metadata about the route in the given userInfo dictionary.

Parameters:
method the request method
path the request path
userInfo a mutable userInfo
Returns:
the matching route (or null if one is not found)

NSArray<ERXRoute> routes (  ) 

Returns the routes for this request handler.

Returns:
the routes for this request handler.

NSArray<ERXRoute> routesForControllerClass ( Class<?extends ERXRouteController routeController  ) 

Returns the routes for the given controller class.

Parameters:
routeController the controller class
Returns:
the routes for the given controller class

ERXRoute setupRequestWithRouteForMethodAndPath ( WORequest  request,
String  method,
String  path 
)

Sets up the request userInfo for the given request for a request of the given method and path.

Parameters:
request the request to configure the userInfo on
method the request method
path the request path
Returns:
the matching route for this method and path

void setupRouteControllerFromUserInfo ( ERXRouteController  controller,
NSDictionary< String, Object >  userInfo 
)

Sets up a route controller based on a request userInfo that came from routeForMethodAndPath.

Parameters:
controller the controller to setup
userInfo the request userInfo


Member Data Documentation

final String ExtensionKey = "ERXRouteRequestHandler.extension" [static]

final String Key = "ra" [static]

final String KeysKey = "ERXRouteRequestHandler.keys" [static]

final Logger log = Logger.getLogger(ERXRouteRequestHandler.class) [static]

final String PathKey = "ERXRouteRequestHandler.path" [static]

NameFormat RAILS = new NameFormat(true, true, NameFormat.Case.LowercaseUnderscore) [static]

A NameFormat that behaves like Rails -- plural entities, plural routes, lowercase underscore names (names_like_this).

final String RouteKey = "ERXRouteRequestHandler.route" [static]

final String TypeKey = "ERXRouteRequestHandler.type" [static]

NameFormat WO = new NameFormat(false, false, NameFormat.Case.CamelCase) [static]

A NameFormat that behaves like WO -- singular entities, singular routes, camel names (NamesLikeThis).

NameFormat WO_LOWER = new NameFormat(false, false, NameFormat.Case.LowerCamelCase) [static]

A NameFormat that behaves like WO -- singular entities, singular routes, lowercase camel names (namesLikeThis).


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:33 2012 for Project Wonder by  doxygen 1.5.8