org.objectweb.jac.aspects.gui.web
Class WebDisplay

java.lang.Object
  |
  +--org.objectweb.jac.aspects.gui.web.WebDisplay
All Implemented Interfaces:
CustomizedDisplay, Display

public class WebDisplay
extends Object
implements CustomizedDisplay

This class provides a server for web clients using a thin client protocol and implements the Display interface to assume data inputs and outputs between JAC objects and web clients.

This inferface is typically used by Java web clients and more specifically by servlets. The implementation provided by JAC is JacServlet.

Author:
Renaud Pawlak, Laurent Martelli

Field Summary
static String ON_ENTER_ACTION
           
static String REQUEST
           
static String RESPONSE
           
 
Constructor Summary
WebDisplay(ViewFactory factory, String sessionId)
          Create a new web display
 
Method Summary
 void addTimedoutDialog(DialogView dialog)
          Add a dialog to the list of timedout dialogs
 void applicationStarted()
          Notifies the display that a new application has just started.
protected  View buildMessage(String title, String message)
           
 Object[] buildParameterValues(AbstractMethodItem method, String[] params)
           
 void close()
          Closes this display.
 void closeWindow(View window, boolean validate)
          Close a window.
 boolean fillParameters(AbstractMethodItem method, Object[] parameters)
          Called before interactively calling a method with parameters, so that the display can set some of them.
 void fullRefresh()
          Rebuilds all customized GUI windows.
 CustomizedView getCustomizedView(String customizedID)
          Returns a CustomizedView identified by its id
 Collection getCustomizedViews()
          Returns a collection of all CustomizedViews contained in the display.
 String getDisplayID()
          Gets the ID (a unique string identifier) of the current display.
 ViewFactory getFactory()
          Returns the ViewFactory of the display.
static HttpServer getHttpServer()
           
static JacRequest getRequest()
          Returns the current JacRequest contained in the context.
static HttpServletResponse getResponse()
          Returnsx the servlet response of the current collaboration
 String getServletName()
          Returns the name of the servlet
 Session getSession()
           
 View getView(String id)
          Returns the view registered with a given id
 String getViewID(View view)
          Gets the ID of a registered view.
protected static void grabResponse()
           
 boolean isTimedout(String viewID)
          Tells wether a view ID corresponds to a timedout dialog
 void onInvocationReturn(Object substance, AbstractMethodItem method)
          Ensure that we will send any HTML output to the currently connection.
 void openView(Object object)
          Shows the given object on the display by opening a new core view.
static void readValues(DisplayContext editors, JacRequest request, boolean commit)
          Read values of field editors from http request
static void readValuesAndRefresh(DisplayContext editors, JacRequest request, boolean commit)
           
 void refresh()
          Refresh the display.
 String registerView(View view)
          Compute an id for a view and register it.
 void setDisplayID(String displayID)
          Sets the ID (a unique string identifier) of the current display.
static void setRequest(JacRequest request)
          Sets the current JacRequest in the context.
static void setResponse(HttpServletResponse response)
          Set the servlet response for the current collaboration
 void setServletName(String name)
          Set the name of the servlet
 void show(Object object)
          Shows the given object on the display.
protected  void show(Object object, boolean newWindow)
           
 void show(Object object, String viewType, Object[] viewParams)
          Shows a view of an object.
protected  void show(Object object, String viewType, Object[] viewParams, boolean newWindow)
           
 void showCustomized(String id, Object object)
          Show a customized Gui.
 void showCustomized(String id, Object object, Map panels)
          Show a customized Gui.
 void showError(String title, String message)
          Show an error message to the user.
 boolean showInput(Object substance, AbstractMethodItem method, Object[] parameters)
          Asks the user to fill the parameters to prepare the invocation of the given method.
 void showMessage(String title, String message)
          Shows a message to the user.
 boolean showMessage(String message, String title, boolean okButton, boolean cancelButton, boolean closeButton)
          Displays a message to the user.
 boolean showModal(Object object, String viewType, Object[] viewParams, String title, String header, Object parent, boolean okButton, boolean cancelButton, boolean closeButton)
          Shows the given object on the display and waits for a user input.
 boolean showModal(Object object, String title, String header, Object parent, boolean okButton, boolean cancelButton, boolean closeButton)
          Shows the given object on the display and waits for a user input.
 boolean showModal(View objectView, DisplayContext context, String title, String header, Object parent, boolean okButton, boolean cancelButton, boolean closeButton)
           
 Object showRefreshMessage(String title, String message)
          Shows a message to the user.
 void showStatus(String message)
           
static void startWebServer()
          Start the web server if it is not already started
static void startWebServer(String application, String[] guiIDs, int defaultPort)
          Start JAC's internal webserver.
 void unregisterView(View view)
          Unregister a view.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESPONSE

public static final String RESPONSE
See Also:
Constant Field Values

REQUEST

public static final String REQUEST
See Also:
Constant Field Values

ON_ENTER_ACTION

public static final String ON_ENTER_ACTION
See Also:
Constant Field Values
Constructor Detail

WebDisplay

public WebDisplay(ViewFactory factory,
                  String sessionId)
Create a new web display

Parameters:
factory - the ViewFactory of the display
sessionId - the sessionId of the display
Method Detail

setResponse

public static void setResponse(HttpServletResponse response)
Set the servlet response for the current collaboration

Parameters:
response - the servlet response object

getResponse

public static HttpServletResponse getResponse()
Returnsx the servlet response of the current collaboration

Returns:
the servlet response of the current collaboration

setRequest

public static void setRequest(JacRequest request)
Sets the current JacRequest in the context.

Parameters:
request - the JacRequets

getRequest

public static JacRequest getRequest()
Returns the current JacRequest contained in the context.

Returns:
the current JacRequest contained in the context

grabResponse

protected static void grabResponse()

readValues

public static void readValues(DisplayContext editors,
                              JacRequest request,
                              boolean commit)
Read values of field editors from http request

Parameters:
editors - field editors for which to read the value
request - the http request where to read values from
commit - if true, commit() will be called on the field editors after readValue()
See Also:
HTMLEditor.readValue(Object), HTMLEditor.commit()

readValuesAndRefresh

public static void readValuesAndRefresh(DisplayContext editors,
                                        JacRequest request,
                                        boolean commit)

fullRefresh

public void fullRefresh()
Description copied from interface: Display
Rebuilds all customized GUI windows.

Specified by:
fullRefresh in interface Display

showCustomized

public void showCustomized(String id,
                           Object object)
Description copied from interface: Display
Show a customized Gui.

Specified by:
showCustomized in interface Display
Parameters:
id - the id of the customized GUI to show
object - the CustomizedGUI to show
See Also:
CustomizedGUI

showCustomized

public void showCustomized(String id,
                           Object object,
                           Map panels)
Description copied from interface: Display
Show a customized Gui.

Specified by:
showCustomized in interface Display
Parameters:
id - the id of the customized GUI to show
object - the CustomizedGUI to show
panels - contents of panels ( panelID -> object)
See Also:
CustomizedGUI

show

public void show(Object object)
Description copied from interface: Display
Shows the given object on the display.

The showed object is considered as a result.

On contrary to showModal, this method does not stop the client thread execution.

Specified by:
show in interface Display
Parameters:
object - the object to show

show

public void show(Object object,
                 String viewType,
                 Object[] viewParams)
Description copied from interface: Display
Shows a view of an object.

The showed object is considered as a result.

On contrary to showModal, this method does not stop the client thread execution.

Specified by:
show in interface Display
Parameters:
object - the object to show
viewType - the type of the view to display
viewParams - parameters to give the view constructor

show

protected void show(Object object,
                    boolean newWindow)

show

protected void show(Object object,
                    String viewType,
                    Object[] viewParams,
                    boolean newWindow)

openView

public void openView(Object object)
Description copied from interface: Display
Shows the given object on the display by opening a new core view.

On contrary to showModal, this method does not stop the client thread execution.

Specified by:
openView in interface Display
Parameters:
object - the object to show

showModal

public boolean showModal(Object object,
                         String title,
                         String header,
                         Object parent,
                         boolean okButton,
                         boolean cancelButton,
                         boolean closeButton)
Description copied from interface: Display
Shows the given object on the display and waits for a user input.

On contrary to show, this method stops the client thread execution and waits for a user input to continue (as an OK button click or a key pressing).

Specified by:
showModal in interface Display
Parameters:
object - the object to show
title - the window title if a window is opened
header - a header message
parent - the parent window
okButton - if true, a validation button is added
cancelButton - if true, a cancellation button is added
closeButton - if true, a closing button is added
Returns:
false if the user canceled
See Also:
Display.showModal(Object,String,Object[],String,String,Object,boolean,boolean,boolean)

showModal

public boolean showModal(Object object,
                         String viewType,
                         Object[] viewParams,
                         String title,
                         String header,
                         Object parent,
                         boolean okButton,
                         boolean cancelButton,
                         boolean closeButton)
Description copied from interface: Display
Shows the given object on the display and waits for a user input.

Specified by:
showModal in interface Display
Parameters:
object - the object to show
viewType - the type of view to build or the object
viewParams - parameters to give the view constructor
title - the window title if a window is opened
header - a header message
parent - the parent window
okButton - if true, a validation button is added
cancelButton - if true, a cancellation button is added
closeButton - if true, a closing button is added
Returns:
false if the user canceled
See Also:
Display.showModal(Object,String,String,Object,boolean,boolean,boolean)

showModal

public boolean showModal(View objectView,
                         DisplayContext context,
                         String title,
                         String header,
                         Object parent,
                         boolean okButton,
                         boolean cancelButton,
                         boolean closeButton)

showInput

public boolean showInput(Object substance,
                         AbstractMethodItem method,
                         Object[] parameters)
Description copied from interface: Display
Asks the user to fill the parameters to prepare the invocation of the given method.

This operation stops the client thread.

Specified by:
showInput in interface Display
Parameters:
substance - the object that contains the method (null if a constructor)
method - the method to fill the parameters o
parameters - the parameters values; as an input, they can be set by the client to fill default values for these parameters; as an output, they must be used by the client as the actual parameter values to call the given method
Returns:
false if the user canceled

showMessage

public boolean showMessage(String message,
                           String title,
                           boolean okButton,
                           boolean cancelButton,
                           boolean closeButton)
Description copied from interface: Display
Displays a message to the user.

Specified by:
showMessage in interface Display
Parameters:
title - the window title if a window is opened
message - a header message
okButton - if true, a validation button is added
cancelButton - if true, a cancellation button is added
closeButton - if true, a closing button is added
Returns:
false if the user canceled

buildMessage

protected View buildMessage(String title,
                            String message)

showMessage

public void showMessage(String title,
                        String message)
Description copied from interface: Display
Shows a message to the user.

Specified by:
showMessage in interface Display
Parameters:
title - the title of the window
message - the message
See Also:
Display.showError(String,String)

showRefreshMessage

public Object showRefreshMessage(String title,
                                 String message)
Description copied from interface: Display
Shows a message to the user.

Specified by:
showRefreshMessage in interface Display
Parameters:
title - the title of the window
message - the message
Returns:
the auto-refreshed window
See Also:
Display.showError(String,String)

showError

public void showError(String title,
                      String message)
Description copied from interface: Display
Show an error message to the user.

Specified by:
showError in interface Display
Parameters:
title - the title of the window
message - the error message
See Also:
Display.showMessage(String,String)

showStatus

public void showStatus(String message)

applicationStarted

public void applicationStarted()
Description copied from interface: Display
Notifies the display that a new application has just started.

At this step, all the root objects of the application have been created and it is time to open the main view if any.

Specified by:
applicationStarted in interface Display

getCustomizedView

public CustomizedView getCustomizedView(String customizedID)
Description copied from interface: CustomizedDisplay
Returns a CustomizedView identified by its id

Specified by:
getCustomizedView in interface CustomizedDisplay
Parameters:
customizedID - the id of the CustomizedView
Returns:
the customized if exists, null otherwise

getCustomizedViews

public Collection getCustomizedViews()
Description copied from interface: CustomizedDisplay
Returns a collection of all CustomizedViews contained in the display.

Specified by:
getCustomizedViews in interface CustomizedDisplay
Returns:
all the customized of the display

getFactory

public ViewFactory getFactory()
Description copied from interface: CustomizedDisplay
Returns the ViewFactory of the display.

A view factory implements the creation methods for different visualisation supports (e.g. SWING, WEB, ...).

Specified by:
getFactory in interface CustomizedDisplay
Returns:
the factory that is used for this display

getDisplayID

public String getDisplayID()
Description copied from interface: Display
Gets the ID (a unique string identifier) of the current display.

Specified by:
getDisplayID in interface Display
Returns:
a string

setDisplayID

public void setDisplayID(String displayID)
Description copied from interface: Display
Sets the ID (a unique string identifier) of the current display.

Specified by:
setDisplayID in interface Display
Parameters:
displayID - a string (should be unique)

close

public void close()
Description copied from interface: Display
Closes this display.

Specified by:
close in interface Display

buildParameterValues

public Object[] buildParameterValues(AbstractMethodItem method,
                                     String[] params)

refresh

public void refresh()
Description copied from interface: Display
Refresh the display.

This method is useful for some kind of displays when the refresh operation cannot be done automatically when the displayed objects states change (e.g. a web display).

Specified by:
refresh in interface Display
See Also:
WebDisplay

getHttpServer

public static HttpServer getHttpServer()

startWebServer

public static void startWebServer(String application,
                                  String[] guiIDs,
                                  int defaultPort)
                           throws IOException,
                                  MultiException
Start JAC's internal webserver. You can then interact with the application through an URL like this: http://://

Parameters:
application - name of the application
guiIDs - name of windows. gui_name[:port]
defaultPort - default TCP port on which to listen
IOException
MultiException

startWebServer

public static void startWebServer()
                           throws MultiException
Start the web server if it is not already started

MultiException

registerView

public String registerView(View view)
Compute an id for a view and register it.

Parameters:
view - the view to register
Returns:
the id of the view
See Also:
unregisterView(View), getView(String)

unregisterView

public void unregisterView(View view)
Unregister a view.

Parameters:
view - the view to register
See Also:
registerView(View)

getView

public View getView(String id)
Returns the view registered with a given id

Parameters:
id - the id of the view
Returns:
the registered view with that id, null if there is none
See Also:
registerView(View)

getViewID

public String getViewID(View view)
Gets the ID of a registered view.

Parameters:
view - the view
Returns:
the ID of the view

addTimedoutDialog

public void addTimedoutDialog(DialogView dialog)
Description copied from interface: CustomizedDisplay
Add a dialog to the list of timedout dialogs

Specified by:
addTimedoutDialog in interface CustomizedDisplay
Parameters:
dialog - the timedout dialog

isTimedout

public boolean isTimedout(String viewID)
Tells wether a view ID corresponds to a timedout dialog


setServletName

public void setServletName(String name)
Set the name of the servlet

Parameters:
name - the name of the servlet

getServletName

public String getServletName()
Returns the name of the servlet


closeWindow

public void closeWindow(View window,
                        boolean validate)
Description copied from interface: CustomizedDisplay
Close a window.

Specified by:
closeWindow in interface CustomizedDisplay
Parameters:
window - view window to close
validate - wether to validate values in editors

getSession

public Session getSession()

fillParameters

public boolean fillParameters(AbstractMethodItem method,
                              Object[] parameters)
Description copied from interface: Display
Called before interactively calling a method with parameters, so that the display can set some of them.

Specified by:
fillParameters in interface Display
Returns:
false if there some parameters are still unassigned

onInvocationReturn

public void onInvocationReturn(Object substance,
                               AbstractMethodItem method)
Ensure that we will send any HTML output to the currently connection.

Specified by:
onInvocationReturn in interface Display