|
Project Wonder 5.0 | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.webobjects.appserver.WORequestHandler
com.webobjects.appserver._private.WOActionRequestHandler
com.webobjects.appserver._private.WODirectActionRequestHandler
er.rest.routes.ERXRouteRequestHandler
public class ERXRouteRequestHandler
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
Nested Class Summary | |
---|---|
static class |
ERXRouteRequestHandler.NameFormat
NameFormat specifies how routes and controller names should be capitalized by default. |
Field Summary | |
---|---|
static java.lang.String |
ExtensionKey
|
static java.lang.String |
Key
|
static java.lang.String |
KeysKey
|
static org.apache.log4j.Logger |
log
|
static java.lang.String |
PathKey
|
static ERXRouteRequestHandler.NameFormat |
RAILS
A NameFormat that behaves like Rails -- plural entities, plural routes, lowercase underscore names (names_like_this). |
static java.lang.String |
RouteKey
|
static java.lang.String |
TypeKey
|
static ERXRouteRequestHandler.NameFormat |
WO
A NameFormat that behaves like WO -- singular entities, singular routes, camel names (NamesLikeThis). |
static ERXRouteRequestHandler.NameFormat |
WO_LOWER
A NameFormat that behaves like WO -- singular entities, singular routes, lowercase camel names (namesLikeThis). |
Fields inherited from class com.webobjects.appserver._private.WOActionRequestHandler |
---|
actionClassClass, actionClassName, CLASS_NOT_FOUND, defaultActionName, INSTANTIATION, INVALID_PATH, INVOCATION, shouldAddToStatistics |
Fields inherited from class com.webobjects.appserver.WORequestHandler |
---|
DidHandleRequestNotification |
Constructor Summary | |
---|---|
ERXRouteRequestHandler()
Constructs a new ERXRouteRequestHandler with the default entity name format. |
|
ERXRouteRequestHandler(ERXRouteRequestHandler.NameFormat entityNameFormat)
Constructs a new ERXRouteRequestHandler. |
Method Summary | ||
---|---|---|
void |
_clearCaches()
Clears any caches that may exist on ERXRoutes (probably only useful to JRebel, to clear the route parameter method cache). |
|
void |
_putComponentsToSleepInContext(com.webobjects.appserver.WOContext wocontext)
|
|
protected void |
addDeclaredRoutes(java.lang.String entityName,
java.lang.Class<? extends ERXRouteController> routeControllerClass,
boolean addDefaultRoutesIfNoDeclaredRoutesFound)
|
|
void |
addDefaultRoutes(java.lang.String entityName)
Adds default routes and maps them to a controller named "[plural entity name]Controller". |
|
void |
addDefaultRoutes(java.lang.String entityName,
boolean numericPKs,
java.lang.Class<? extends ERXRouteController> controllerClass)
Adds list and view routes for the given entity. |
|
void |
addDefaultRoutes(java.lang.String entityName,
java.lang.Class<? extends ERXRouteController> controllerClass)
Adds list and view routes for the given entity. |
|
void |
addDefaultRoutes(java.lang.String entityName,
java.lang.String entityType,
boolean numericPKs,
java.lang.Class<? extends ERXRouteController> controllerClass)
Adds list and view routes for the given entity. |
|
void |
addRoute(ERXRoute route)
Adds a new route to this request handler. |
|
void |
addRoutes(java.lang.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. |
|
void |
addRoutes(java.lang.String entityName,
java.lang.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. |
|
|
controller(java.lang.Class<T> controllerClass,
com.webobjects.appserver.WOContext context)
Returns the corresponding controller instance (with no request specified). |
|
|
controller(java.lang.Class<T> controllerClass,
com.webobjects.appserver.WORequest request,
com.webobjects.appserver.WOContext context)
Returns the corresponding controller instance. |
|
|
controller(java.lang.String entityName,
com.webobjects.appserver.WORequest request,
com.webobjects.appserver.WOContext context)
Returns the corresponding controller instance. |
|
java.lang.String |
controllerPathForEntityNamed(java.lang.String entityName)
Return the controller path name for an entity name based on the entity name format. |
|
com.webobjects.appserver.WOAction |
getActionInstance(java.lang.Class class1,
java.lang.Class[] aclass,
java.lang.Object[] aobj)
|
|
java.lang.Object[] |
getRequestActionClassAndNameForPath(com.webobjects.foundation.NSArray requestHandlerPath)
|
|
com.webobjects.foundation.NSArray |
getRequestHandlerPathForRequest(com.webobjects.appserver.WORequest request)
|
|
void |
insertRoute(ERXRoute route)
Inserts a route at the beginning of the route list. |
|
static void |
register(ERXRouteRequestHandler requestHandler)
Registers an ERXRestRequestHandler with the WOApplication for the handler key "rest". |
|
void |
removeRoute(ERXRoute route)
Removes the given route from this request handler. |
|
java.lang.Class<? extends ERXRouteController> |
routeControllerClassForEntityNamed(java.lang.String entityName)
Returns the default route controller class for the given entity name. |
|
ERXRoute |
routeForMethodAndPath(java.lang.String method,
java.lang.String path,
com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> userInfo)
Returns the route that matches the request method and path, storing metadata about the route in the given userInfo dictionary. |
|
com.webobjects.foundation.NSArray<ERXRoute> |
routes()
Returns the routes for this request handler. |
|
com.webobjects.foundation.NSArray<ERXRoute> |
routesForControllerClass(java.lang.Class<? extends ERXRouteController> routeController)
Returns the routes for the given controller class. |
|
ERXRoute |
setupRequestWithRouteForMethodAndPath(com.webobjects.appserver.WORequest request,
java.lang.String method,
java.lang.String path)
Sets up the request userInfo for the given request for a request of the given method and path. |
|
void |
setupRouteControllerFromUserInfo(ERXRouteController controller,
com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.Object> userInfo)
Sets up a route controller based on a request userInfo that came from routeForMethodAndPath. |
Methods inherited from class com.webobjects.appserver._private.WODirectActionRequestHandler |
---|
allowsContentInputStream, defaultActionClassName, generateErrorResponse, generateRequestRefusal, handler, nullResponse, registerDidHandleActionRequestWithActionNamed, registerWillHandleActionRequest, setAllowsContentInputStream |
Methods inherited from class com.webobjects.appserver._private.WOActionRequestHandler |
---|
_actionClassForName, _handleRequest, defaultDefaultActionName, defaultShouldAddToStatistics, handleRequest, isSessionIDInRequest, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static ERXRouteRequestHandler.NameFormat RAILS
public static ERXRouteRequestHandler.NameFormat WO
public static ERXRouteRequestHandler.NameFormat WO_LOWER
public static final org.apache.log4j.Logger log
public static final java.lang.String Key
public static final java.lang.String TypeKey
public static final java.lang.String ExtensionKey
public static final java.lang.String PathKey
public static final java.lang.String RouteKey
public static final java.lang.String KeysKey
Constructor Detail |
---|
public ERXRouteRequestHandler()
public ERXRouteRequestHandler(ERXRouteRequestHandler.NameFormat entityNameFormat)
entityNameFormat
- the format to use for entity names in URLsMethod Detail |
---|
public void insertRoute(ERXRoute route)
route
- the route to insertpublic void addRoute(ERXRoute route)
route
- the route to addpublic void removeRoute(ERXRoute route)
route
- the route to removepublic void _clearCaches()
public com.webobjects.foundation.NSArray<ERXRoute> routes()
public com.webobjects.foundation.NSArray<ERXRoute> routesForControllerClass(java.lang.Class<? extends ERXRouteController> routeController)
routeController
- the controller class
public java.lang.Class<? extends ERXRouteController> routeControllerClassForEntityNamed(java.lang.String entityName)
entityName
- the name of the entity
public void addRoutes(java.lang.String entityName)
entityName
- the name of the entitypublic void addRoutes(java.lang.String entityName, java.lang.Class<? extends ERXRouteController> routeControllerClass)
entityName
- the name of the entityrouteControllerClass
- the name of the route controllerprotected void addDeclaredRoutes(java.lang.String entityName, java.lang.Class<? extends ERXRouteController> routeControllerClass, boolean addDefaultRoutesIfNoDeclaredRoutesFound)
public void addDefaultRoutes(java.lang.String entityName)
entityName
- the name of the entity to create routes forpublic void addDefaultRoutes(java.lang.String entityName, java.lang.Class<? extends ERXRouteController> controllerClass)
/reminders /reminders/{action} /reminder/{reminder:Reminder} /reminder/{reminder:Reminder}/{action}
entityName
- the entity name to route withcontrollerClass
- the controller classpublic java.lang.String controllerPathForEntityNamed(java.lang.String entityName)
entityName
- the entity name
public void addDefaultRoutes(java.lang.String entityName, boolean numericPKs, java.lang.Class<? extends ERXRouteController> controllerClass)
/reminders /reminders/{action} /reminder/{reminder:Reminder} /reminder/{reminder:Reminder}/{action}
entityName
- the entity name to route withnumericPKs
- if true, routes can assume numeric PK's and add some extra convenience routescontrollerClass
- the controller classpublic void addDefaultRoutes(java.lang.String entityName, java.lang.String entityType, boolean numericPKs, java.lang.Class<? extends ERXRouteController> controllerClass)
/reminders /reminders/{action} /reminder/{reminder:Reminder} /reminder/{reminder:Reminder}/{action}
entityName
- the entity name to route withentityType
- the type of the enitynumericPKs
- if true, routes can assume numeric PK's and add some extra convenience routescontrollerClass
- the controller classpublic ERXRoute routeForMethodAndPath(java.lang.String method, java.lang.String path, com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> userInfo)
method
- the request methodpath
- the request pathuserInfo
- a mutable userInfo
public ERXRoute setupRequestWithRouteForMethodAndPath(com.webobjects.appserver.WORequest request, java.lang.String method, java.lang.String path)
request
- the request to configure the userInfo onmethod
- the request methodpath
- the request path
public void setupRouteControllerFromUserInfo(ERXRouteController controller, com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.Object> userInfo)
controller
- the controller to setupuserInfo
- the request userInfopublic com.webobjects.foundation.NSArray getRequestHandlerPathForRequest(com.webobjects.appserver.WORequest request)
getRequestHandlerPathForRequest
in class com.webobjects.appserver._private.WODirectActionRequestHandler
public java.lang.Object[] getRequestActionClassAndNameForPath(com.webobjects.foundation.NSArray requestHandlerPath)
getRequestActionClassAndNameForPath
in class com.webobjects.appserver._private.WOActionRequestHandler
public com.webobjects.appserver.WOAction getActionInstance(java.lang.Class class1, java.lang.Class[] aclass, java.lang.Object[] aobj)
getActionInstance
in class com.webobjects.appserver._private.WOActionRequestHandler
public <T extends ERXRouteController> T controller(java.lang.String entityName, com.webobjects.appserver.WORequest request, com.webobjects.appserver.WOContext context)
T
- the type of controller to returnentityName
- the entity name of the controller to lookuprequest
- the current requestcontext
- the current context
public <T extends ERXRouteController> T controller(java.lang.Class<T> controllerClass, com.webobjects.appserver.WOContext context)
T
- the type of controller to returncontrollerClass
- the controller class to lookupcontext
- the current context
public <T extends ERXRouteController> T controller(java.lang.Class<T> controllerClass, com.webobjects.appserver.WORequest request, com.webobjects.appserver.WOContext context)
T
- the type of controller to returncontrollerClass
- the controller class to lookuprequest
- the current requestcontext
- the current context
public void _putComponentsToSleepInContext(com.webobjects.appserver.WOContext wocontext)
_putComponentsToSleepInContext
in class com.webobjects.appserver._private.WOActionRequestHandler
public static void register(ERXRouteRequestHandler requestHandler)
requestHandler
- the rest request handler to register
|
Last updated: Tue, Feb 21, 2017 05:45 PM CET | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |