Class AbstractWebComponent
- java.lang.Object
-
- de.aristaflow.adept2.core.runtimemanager.executionenvironments.ExecutionEnvironment
-
- de.aristaflow.adept2.ui.htmlgui.executionenvironments.AbstractWebResourceComponent
-
- de.aristaflow.adept2.ui.htmlgui.executionenvironments.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface de.aristaflow.adept2.model.runtimeenvironment.ExecutableComponent
ExecutableComponent.Signals
-
-
Field Summary
Fields Modifier and Type Field Description static int
DIRECT_SUSPEND
The component should be directly suspended, that is do not wait for the user timeout.protected boolean
resumed
Whether the execution of this component has been resumed.protected String
savepoint
The savepoint in case this component has been resumed ornull
in case of normal execution.-
Fields inherited from class de.aristaflow.adept2.ui.htmlgui.executionenvironments.AbstractWebResourceComponent
CONF_EXT_RESOURCE_DIR, extCssFiles, extScripts, GLOBAL_EXT_RESOURCE_DIR, htmlContext, url, USER_SIGNAL_EXT_FILE, USER_SIGNAL_FILE
-
Fields inherited from class de.aristaflow.adept2.core.runtimemanager.executionenvironments.ExecutionEnvironment
actData, activityInstance, cleanup, localisedActInst, logger, sessionContext, SUSPEND_SAVEPOINT
-
Fields inherited from interface de.aristaflow.adept2.model.runtimeenvironment.ExecutableComponent
CONF_DATA_DIRECTORY, CONF_LIB_DIRECTORY, CONF_LOG_DIRECTORY, UNLOADING_CLASS_METHOD
-
-
Constructor Summary
Constructors Constructor Description AbstractWebComponent(String ecName, ActivityInstance activityInstance, String internalResourcePath)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
close()
Returns false - overwrite this method to support closing.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.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.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.protected abstract void
deserialiseState(byte[] serialisedState)
Deserialise the component's state from the given byte array.RichAgent
getAgent()
Returns the agent executing this activity.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.protected abstract void
handleKeepAliveParameters(HTMLContext.HTTPReply httpReply)
Handle additional parameters which were sent along the "keep alive" signal.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.protected abstract void
handleSendParameters(HTMLContext.HTTPReply httpReply)
Handle the parameters sent along with the "Send" user signal.protected abstract void
handleSuspendParameters(HTMLContext.HTTPReply httpReply)
Handle the parameters which were sent along the "suspend" user signal.protected abstract HTMLContext.Response
handleUnknownUserSignal(HTMLContext.HTTPReply httpReply)
protected boolean
handleUserSuspend(int actualSignal)
Handles an existing suspend signal properly and sets the designated signal if no suspend signal is pending.void
initResume(String savepointId, SessionContext sc)
Does nothing - overwrite this method to support resuming.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.protected abstract boolean
isDirty()
Returns true if any data was already send, so the component has unsaved data which should be stored during suspend.boolean
kill()
Returns false - overwrite this method to support killing.boolean
reset()
Returns false - overwrite this method to support reset.void
run()
Resembles
except that this method is expected to throw exceptions indicating that the environment was unexpected or an internal failure occurred.Runnable.run()
protected abstract byte[]
serialiseState(boolean closing)
Serialise and return the current state of the component for suspension.boolean
signal(int signal)
Returns false - overwrite this method to support signalling.boolean
suspend()
Returns false - overwrite this method to support suspending.protected abstract void
writeOutput()
Write the output parameters.-
Methods inherited from class de.aristaflow.adept2.ui.htmlgui.executionenvironments.AbstractWebResourceComponent
getMimeType, getResourceAsStream, getResourceAsString, getResourceLink, init, initialiseAndGetInitialContent
-
Methods inherited from class de.aristaflow.adept2.core.runtimemanager.executionenvironments.ExecutionEnvironment
cleanup, commit, createActivityData, getApplicationState, getApplicationState, getRawApplicationState, getRawApplicationState, prepareCommit, requireGUIContext, rollback, setApplicationState, setApplicationState, setRawApplicationState, setRawApplicationState
-
-
-
-
Field Detail
-
DIRECT_SUSPEND
public static final int DIRECT_SUSPEND
The component should be directly suspended, that is do not wait for the user timeout. Value isExecutableComponent.Signals.SUSPEND
+ 1.- See Also:
- Constant Field Values
-
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 ornull
in case of normal execution.
-
-
Constructor Detail
-
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 Detail
-
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 interfaceExecutableComponent
- Overrides:
initResume
in classExecutionEnvironment
- Parameters:
savepointId
- The identifier of the savepoint at which the application should resume. This must not benull
, 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
except that this method is expected to throw exceptions indicating that the environment was unexpected or an internal failure occurred. Both exceptions as well asRunnable.run()
will set the corresponding process activity toRuntimeException
FAILED
.- Specified by:
run
in interfaceExecutableComponent
- Specified by:
run
in classExecutionEnvironment
-
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 afterhandleSendParameters(HTTPReply)
, and afterwards callingisConsistent()
returned false.
-
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)
-
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.
-
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 theAbstractWebComponent
.- 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 theAbstractWebComponent
.- 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 theAbstractWebComponent
.- 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.
-
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 inwriteOutput()
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 interfaceExecutableComponent
- Overrides:
signal
in classExecutionEnvironment
- Parameters:
signal
- Ignored.- Returns:
false
- See Also:
for possible signals. Usually the ones that have corresponding methods, e. g. or , will not be signaled via this method.
-
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 interfaceExecutableComponent
- Overrides:
suspend
in classExecutionEnvironment
- 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 interfaceExecutableComponent
- Overrides:
close
in classExecutionEnvironment
- 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 callingRuntimeEnvironment.applicationReset()
. The component will be re-initialised and executed again later.- Specified by:
reset
in interfaceExecutableComponent
- Overrides:
reset
in classExecutionEnvironment
- 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 interfaceExecutableComponent
- Overrides:
kill
in classExecutionEnvironment
- 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 aDIRECT_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.
-
-