org.inria.ns.reflex.util.wunit
Class IntrusiveXClient

java.lang.Object
  extended by org.inria.ns.reflex.util.wunit.XClient
      extended by org.inria.ns.reflex.util.wunit.IntrusiveXClient
All Implemented Interfaces:
Unwrappable, XOperable

public class IntrusiveXClient
extends XClient

Extend the capabilities of the client (#wunit:x-client) for handling server-side components.

This class supplies a set of methods for retrieving various server objects. Those objects can be returned only if a Web application is targeted by the underlying URI and that the actual Web application is hosted by the server emulator that has created this client.

Note that it is impossible to differentiate 2 different pages of the client that have the same URI (including the query string). If such pages are supposed to contain different content, this won't be the case.

Thus, retrieving a service is not 100% reliable and should be used with care. Components that only rely on the server (servlet contexts, servlets, and sessions) are safe to use.

Author:
Philippe Poulard
See Also:
ClientFactory.newClient(String)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.structures.Unwrappable
Unwrappable.Unwrapper
 
Field Summary
 
Fields inherited from interface org.inria.ns.reflex.structures.Unwrappable
UNWRAPPER
 
Constructor Summary
IntrusiveXClient(WebClient client)
          Create a new client.
 
Method Summary
 HttpServlet getHttpServlet()
          Get a servlet context managed by the counterpart server emulator.
 HttpServlet getHttpServlet(URI uri)
          Get a servlet context managed by the counterpart server emulator.
 HttpServlet getHttpServlet(WebWindow window)
          Get a servlet context managed by the counterpart server emulator.
 HttpServletRequest getRequest(WebWindow window)
          Get the servlet request that was used by the counterpart server emulator for getting a page in a window.
 HttpServletResponse getResponse(WebWindow window)
          Get the servlet response that was used by the counterpart server emulator for getting a page in a window.
 ServerEmulator getServerEmulator()
          Return the counterpart server emulator.
 ServletContext getServletContext()
          Get a servlet context managed by the counterpart server emulator.
 ServletContext getServletContext(URI uri)
          Get a servlet context managed by the counterpart server emulator.
 ServletContext getServletContext(WebWindow window)
          Get a servlet context managed by the counterpart server emulator.
 HttpSession getSession()
          Get a session stored in the counterpart server emulator.
 HttpSession getSession(URI uri)
          Get a session stored in the counterpart server emulator.
 HttpSession getSession(WebWindow window)
          Get a session stored in the counterpart server emulator.
 
Methods inherited from class org.inria.ns.reflex.util.wunit.XClient
createSession, getClientState, getCookies, getCurrentURI, getHttpClient, getPage, getPage, getSessionID, getXOperator, newRequest, removeSession, unwrap
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntrusiveXClient

public IntrusiveXClient(WebClient client)
Create a new client.

Parameters:
client - The client to wrap.
Method Detail

getServerEmulator

public ServerEmulator getServerEmulator()
Return the counterpart server emulator.

Returns:
The server emulator that has created this client.
See Also:
ClientFactory.newClient(String)

getSession

public HttpSession getSession()
Get a session stored in the counterpart server emulator. If the session doesn't exist, it is created.

Returns:
If this client has a current window, the session stored in the Web application pointed by its URI if it is managed by the server emulator or null, or the session of the main Web application of the counterpart server emulator.

getSession

public HttpSession getSession(WebWindow window)
Get a session stored in the counterpart server emulator. If the session doesn't exist, it is created.

Parameters:
window - The window which has an URI that should point to a Web application managed by the counterpart server emulator.
Returns:
The session pointed by the URI of the window if its Web application is managed by the server emulator, or null.

getSession

public HttpSession getSession(URI uri)
Get a session stored in the counterpart server emulator. If the session doesn't exist, it is created.

Parameters:
uri - The URI that should point to a Web application managed by the counterpart server emulator.
Returns:
The session pointed by the given URI if its Web application is managed by the server emulator, or null.

getServletContext

public ServletContext getServletContext()
Get a servlet context managed by the counterpart server emulator.

Returns:
If this client has a current window, the Web application pointed by its URI if it is managed by the server emulator or null, or the main Web application of the counterpart server emulator.

getServletContext

public ServletContext getServletContext(WebWindow window)
Get a servlet context managed by the counterpart server emulator.

Parameters:
window - The window which has an URI that should point to a Web application managed by the counterpart server emulator.
Returns:
The Web application pointed by the URI of the window if it is managed by the server emulator, or null.

getServletContext

public ServletContext getServletContext(URI uri)
Get a servlet context managed by the counterpart server emulator.

Parameters:
uri - The URI that should point to a Web application managed by the counterpart server emulator.
Returns:
The Web application pointed by the given URI if it is managed by the server emulator, or null.

getHttpServlet

public HttpServlet getHttpServlet()
Get a servlet context managed by the counterpart server emulator.

Returns:
If this client has a current window, the Web application pointed by its URI if it is managed by the server emulator or null, or the main Web application of the counterpart server emulator.

getHttpServlet

public HttpServlet getHttpServlet(WebWindow window)
Get a servlet context managed by the counterpart server emulator.

Parameters:
window - The window which has an URI that should point to a Web application managed by the counterpart server emulator.
Returns:
The Web application pointed by the URI of the window if it is managed by the server emulator, or null.

getHttpServlet

public HttpServlet getHttpServlet(URI uri)
Get a servlet context managed by the counterpart server emulator.

Parameters:
uri - The URI that should point to a Web application managed by the counterpart server emulator.
Returns:
The Web application pointed by the given URI if it is managed by the server emulator, or null.

getRequest

public HttpServletRequest getRequest(WebWindow window)
Get the servlet request that was used by the counterpart server emulator for getting a page in a window.

Parameters:
window - The window that sent a query.
Returns:
The request that was used server-side, or null.

getResponse

public HttpServletResponse getResponse(WebWindow window)
Get the servlet response that was used by the counterpart server emulator for getting a page in a window.

Parameters:
window - The window that sent a query.
Returns:
The response that was used server-side, or null.