Class AbstractWebComponent

All Implemented Interfaces:
ExecutableComponent

public abstract class AbstractWebComponent extends AbstractWebResourceComponent
Abstract base class for web components implementing a generic request / reply mechanism handling various user signals from the web frontend, like signalling states, etc. It also requires the web frontend to send regular keep-alives and therefore can detect closed browser windows and react appropriately.
  • Field Details

    • DIRECT_SUSPEND

      public static final int DIRECT_SUSPEND
      The component should be directly suspended, that is do not wait for the user timeout. Value is ExecutableComponent.Signals.SUSPEND + 1.
      See Also:
    • resumed

      protected boolean resumed
      Whether the execution of this component has been resumed.
    • savepoint

      protected String savepoint
      The savepoint in case this component has been resumed or null in case of normal execution.
  • Constructor Details

    • AbstractWebComponent

      public AbstractWebComponent(String ecName, ActivityInstance activityInstance, String internalResourcePath)
      Parameters:
      ecName - The executable component name.
      activityInstance - The activity instance.
      internalResourcePath - The path for internal resources, to be used with getClass().getRessourceAsStream(...).
  • Method Details

    • initResume

      public void initResume(String savepointId, SessionContext sc)
      Description copied from class: ExecutionEnvironment
      Does nothing - overwrite this method to support resuming.
      Note that this does neither set the session context nor the logger.

      Initialises and prepares the resuming of the application and provides all necessary data which maybe necessary for this. This method or ExecutableComponent.init(SessionContext) is only called once in the lifetime of an executable component. One of these methods is guaranteed to be called before calling any other method.

      When leaving this method the execution has to be completely prepared for resuming. That is, the state of the application has to be restored. This includes the GUI.

      Usually this method will delegate also call ExecutableComponent.init(SessionContext).

      Specified by:
      initResume in interface ExecutableComponent
      Overrides:
      initResume in class ExecutionEnvironment
      Parameters:
      savepointId - The identifier of the savepoint at which the application should resume. This must not be null, but it may be the empty string.
      sc - The session context in which the component is to be executed.
    • run

      public void run()
      Description copied from interface: ExecutableComponent
      Resembles Runnable.run() except that this method is expected to throw exceptions indicating that the environment was unexpected or an internal failure occurred. Both exceptions as well as RuntimeException will set the corresponding process activity to FAILED.
      Specified by:
      run in interface ExecutableComponent
      Specified by:
      run in class ExecutionEnvironment
    • createResponseForInconsistentSend

      protected abstract HTMLContext.Response createResponseForInconsistentSend(HTMLContext.HTTPReply httpReply)
      Create the response for telling the browser side that the data is not consistent, after the user sent the "send" user signal. The method will be called after handleSendParameters(HTTPReply), and afterwards calling isConsistent() returned false.
      Parameters:
      httpReply - The caller is responsible for closing.
      Returns:
      The caller is responsible for closing.
    • createResponseForInvalidSend

      protected abstract HTMLContext.Response createResponseForInvalidSend(HTMLContext.HTTPReply httpReply, Throwable handlingException)
      Create the response for telling the browser that data submitted with the "send" user signal was invalid, e. g. failed to parse. The method will be called if handling the sent parameters failed. This does not set the parameter values.
      Parameters:
      httpReply - The reply which sent the invalid data. The caller is responsible for closing.
      handlingException - The exception that occurred leading to the sent data being invalid.
      Returns:
      The response to send to the browser that submitted invalid data. The caller is responsible for closing.
    • handleUnknownUserSignal

      protected abstract HTMLContext.Response handleUnknownUserSignal(HTMLContext.HTTPReply httpReply)
      Parameters:
      httpReply - The caller is responsible for closing.
      Returns:
      The caller is responsible for closing.
    • isDirty

      protected abstract boolean isDirty()
      Returns true if any data was already send, so the component has unsaved data which should be stored during suspend.
      Returns:
      True, if unsaved data needs to be stored for suspend.
    • isConsistent

      protected abstract boolean isConsistent()
      Check if the current state of the form is consistent, the data is valid and all required parameters have been set.
      Returns:
      True, if the current state of the form is consistent, the data is valid and all required parameters have been set.
    • handleReload

      protected abstract HTMLContext.Response handleReload(HTMLContext.HTTPReply httpReply)
      Handle the reload request having the given parameters and create an appropriate response to be sent to the browser.
      Parameters:
      httpReply - The HTTP reply sent by the browser to the environment with the reload user signal. The caller is responsible for closing.
      Returns:
      The response to be sent to the browser. The caller is responsible for closing.
    • handleKeepAliveParameters

      protected abstract void handleKeepAliveParameters(HTMLContext.HTTPReply httpReply)
      Handle additional parameters which were sent along the "keep alive" signal. This method allows to save intermediate results the user entered and the browser side sent along with the "keep alive" signal.

      The method will only be called if there is not yet an environment signal for suspending the form pending and there are actually additional parameters or an additional request body.

      Note: Do not use the httpReply to send a response, this will be done by the AbstractWebComponent.

      Parameters:
      httpReply - The parameters sent with "keep alive". The caller is responsible for closing.
    • handleSuspendParameters

      protected abstract void handleSuspendParameters(HTMLContext.HTTPReply httpReply)
      Handle the parameters which were sent along the "suspend" user signal.

      Note: Do not use the httpReply to send a response, this will be done by the AbstractWebComponent.

      Parameters:
      httpReply - The HTTP reply sent by the browser to the environment with the suspend signal. The caller is responsible for closing.
    • handleSendParameters

      protected abstract void handleSendParameters(HTMLContext.HTTPReply httpReply)
      Handle the parameters sent along with the "Send" user signal.

      Note: Do not use the httpReply to send a response, this will be done by the AbstractWebComponent.

      Parameters:
      httpReply - The HTTP reply sent by the browser to the environment with the Send user signal. The caller is responsible for closing.
    • handleCustomResourceSignal

      protected abstract HTMLContext.Response handleCustomResourceSignal(HTMLContext.HTTPReply httpReply)
      A "resource" user signal was sent, but the resource type was none of the default ones and needs to be handled by the implementing sub-class.
      Parameters:
      httpReply - The caller is responsible for closing.
      Returns:
      The caller is responsible for closing.
    • serialiseState

      protected abstract byte[] serialiseState(boolean closing)
      Serialise and return the current state of the component for suspension.
      Parameters:
      closing - Whether this state serialisation takes place while closing. In this case implementations need not serialise state by writing output parameter values since this has already been done in writeOutput() beforehand.
      Returns:
    • deserialiseState

      protected abstract void deserialiseState(byte[] serialisedState)
      Deserialise the component's state from the given byte array.
      Parameters:
      serialisedState -
    • writeOutput

      protected abstract void writeOutput()
      Write the output parameters.
    • createCloseMessage

      protected abstract String createCloseMessage()
      Create a string with HTML content to be displayed as final message to the user, e.g. telling him to close the browser window, for the case the activity was opened in a pop-up which wasn't closed by the client application.
      Returns:
      The HTML code with the final message to the user.
    • signal

      public boolean signal(int signal)
      Description copied from class: ExecutionEnvironment
      Returns false - overwrite this method to support signalling.

      Signals an event to the application.

      Specified by:
      signal in interface ExecutableComponent
      Overrides:
      signal in class ExecutionEnvironment
      Parameters:
      signal - Ignored.
      Returns:
      false
      See Also:
    • suspend

      public boolean suspend()
      Description copied from class: ExecutionEnvironment
      Returns false - overwrite this method to support suspending.

      Instructs the component to store its internal state to the data context and to terminate at once. The application should be able to continue its job later when resuming.

      Specified by:
      suspend in interface ExecutableComponent
      Overrides:
      suspend in class ExecutionEnvironment
      Returns:
      false
    • close

      public boolean close()
      Description copied from class: ExecutionEnvironment
      Returns false - overwrite this method to support closing.

      Instructs the component to terminate. Within this method the component should deallocate all allocated resources.

      Specified by:
      close in interface ExecutableComponent
      Overrides:
      close in class ExecutionEnvironment
      Returns:
      false
    • reset

      public boolean reset()
      Description copied from class: ExecutionEnvironment
      Returns false - overwrite this method to support reset.

      Instructs the component to reset. This is quite similar to ExecutableComponent.kill() but the application does not fail but terminate normally (by calling RuntimeEnvironment.applicationReset(). The component will be re-initialised and executed again later.

      Specified by:
      reset in interface ExecutableComponent
      Overrides:
      reset in class ExecutionEnvironment
      Returns:
      false
    • kill

      public boolean kill()
      Description copied from class: ExecutionEnvironment
      Returns false - overwrite this method to support killing.

      Enforces the application to abort its execution at once. In the case of running a internal transaction application should abort the transaction and should rollback. Within this method the component should deallocate all allocated resources.

      Specified by:
      kill in interface ExecutableComponent
      Overrides:
      kill in class ExecutionEnvironment
      Returns:
      false
    • handleUserSuspend

      protected boolean handleUserSuspend(int actualSignal)
      Handles an existing suspend signal properly and sets the designated signal if no suspend signal is pending. In case of an enquiry or a DIRECT_SUSPEND, immediate suspending will take place instead of the designated signal.
      Parameters:
      actualSignal - The actual signal which to set unless a suspend signal is pending.
      Returns:
      Whether we respond to the designated signal, otherwise a suspend signal is pending.
    • getAgent

      public RichAgent getAgent()
      Returns the agent executing this activity.
      Returns:
      The agent executing this activity.