Class JESTContext
java.lang.Object
org.apache.openjpa.persistence.jest.JESTContext
- All Implemented Interfaces:
JPAServletContext
An operational context combines a
This context
persistence context
and a HTTP execution
context expressed as a request
and response
.
This context
parses
the HTTP request URL to identity the command and then
executes
it.- Author:
- Pinaki Poddar
-
Field Summary
Modifier and TypeFieldDescriptionprotected static PrototypeFactory<String,
JESTCommand> static final Localizer
protected Log
protected MetaDataRepository
static final String
static final String
static final char
-
Constructor Summary
ConstructorDescriptionJESTContext
(String unit, OpenJPAEntityManagerFactory emf, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) -
Method Summary
Modifier and TypeMethodDescriptionvoid
execute()
Executes the request.static String
Gets the action from the given path.Gets the persistence context.Gets the name of the persistence unit.javax.servlet.http.HttpServletRequest
Gets the request.Get the requested URI.javax.servlet.http.HttpServletResponse
Gets the response.void
Logging message.Resolve the given alias to meta-data of the persistent type.
-
Field Details
-
_repos
-
_log
-
_cf
-
_loc
-
QUERY_SEPARATOR
public static final char QUERY_SEPARATOR- See Also:
-
CONTEXT_ROOT
- See Also:
-
JEST_TEMPLATE
- See Also:
-
-
Constructor Details
-
JESTContext
public JESTContext(String unit, OpenJPAEntityManagerFactory emf, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
-
-
Method Details
-
getPersistenceUnitName
Gets the name of the persistence unit.- Specified by:
getPersistenceUnitName
in interfaceJPAServletContext
-
getPersistenceContext
Gets the persistence context. The persistence context is lazily constructed because all commands may not need it.- Specified by:
getPersistenceContext
in interfaceJPAServletContext
-
getRequest
public javax.servlet.http.HttpServletRequest getRequest()Gets the request.- Specified by:
getRequest
in interfaceJPAServletContext
-
getRequestURI
Description copied from interface:JPAServletContext
Get the requested URI.- Specified by:
getRequestURI
in interfaceJPAServletContext
-
getResponse
public javax.servlet.http.HttpServletResponse getResponse()Gets the response.- Specified by:
getResponse
in interfaceJPAServletContext
-
execute
Executes the request.
Execution starts with parsing therequest path
. The first path segment is interpreted as action key, and if a action with the given key is registered then the control is delegated to the command. The command parses the entirerequest
for requisite qualifiers and arguments and if the parse is successful then the command is executed in this context.
If path is null, or no command is registered for the action or the command can not parse the request, then a last ditch attempt is made to find a resource. This fallback lookup is important because the response can contain hyperlinks to stylesheets or scripts. The browser will resolve such hyperlinks relative to the original response.
For example, let the original request URL be:
http://host:port/demo/jest/find?type=Actor&Robert
The response to this request is a HTML page that contained a hyperlink tojest.css
stylesheet in its <head> section.
<link ref="jest.css" .....>
The browser will resolve the hyperlink by sending back another request as
http://host:port/demo/jest/find/jest.css
- Throws:
Exception
-
getAction
Gets the action from the given path.- Parameters:
path
- a string- Returns:
- if null, returns context root i.e.
'/'
character. Otherwise, if the path starts with context root, then returns the substring before the next'/'
character or end of the string, whichever is earlier. If the path does not start with context root, returns the substring before the first'/'
character or end of the string, whichever is earlier.
-
resolve
Description copied from interface:JPAServletContext
Resolve the given alias to meta-data of the persistent type.- Specified by:
resolve
in interfaceJPAServletContext
- Parameters:
alias
- a moniker for the Java type. It can be fully qualified type name or entity name or simple name of the actual persistent Java class.- Returns:
- meta-data for the given name.
-
log
Description copied from interface:JPAServletContext
Logging message.- Specified by:
log
in interfaceJPAServletContext
- Parameters:
level
- OpenJPA definedlog levels
. Invalid levels will print the message on console.message
- a printable message.
-