1. Design Goals and Key Roles
This package provides the Activity
implementation that actually executes command-line commands parsed by ShellService
. The design goals of this package are as follows:
- Concretizing the Interactive Execution Environment: Inherits from the abstract
CoreActivity
to provideShellActivity
, which can process requests in an interactive console I/O environment. - Abstraction of Console I/O: Through
ShellRequestAdapter
andShellResponseAdapter
, it converts command-line parameters and console output into standard request/response forms that the Aspectran core engine can understand. - Support for Interactive Features: Provides a prompt function that directly asks the user for input if essential parameters are missing for translet execution, completing the interactive experience.
In conclusion, this package acts as a key bridge between ShellService
and CoreActivity
, and is responsible for adapting user’s command-line input to operate within Aspectran’s standard execution pipeline.
2. Detailed Class Analysis
ShellActivity
(Implementation Class)
The final implementation of Activity
for the interactive shell environment. A new instance is created each time ShellService
’s translate()
method is called.
Key Responsibilities:
- Inherits
CoreActivity
, thus inheriting all of Aspectran’s standard request processing pipeline (advice, action execution, etc.). - Maintains parsed request information from
TransletCommandLine
and a reference toShellConsole
. - Handles shell-specific features such as interactive parameter input and output redirection.
Key Method Analysis:
adapt()
: The core of adaptation for the shell environment. It is called at the beginning ofCoreActivity
’sperform()
method to convert command-line input into standard interfaces.ShellRequestAdapter
: Wraps parameters and attributes contained inTransletCommandLine
to act as aRequestAdapter
.ShellResponseAdapter
: Wraps the outputWriter
specified inShellService
(usually console or redirected file) to act as aResponseAdapter
.
preProcedure()
: A unique logic ofShellActivity
that is called before theperform()
method is executed to handle interactive input. Ifprocedural
mode is enabled and an essential parameter (mandatory="true"
) for translet execution is missing, this method callsShellConsole.prompt()
to display a prompt asking the user to directly input the value.
Interaction with Other Classes:
ShellService
: Within itstranslate()
method, it directly createsShellActivity
, sets parameters, and then callsprepare()
andperform()
to execute it.CoreActivity
:ShellActivity
inheritsCoreActivity
and uses its execution pipeline as is.com.aspectran.shell.console.ShellConsole
: Used for all console I/O, such as displaying interactive prompts inpreProcedure()
or outputting final results viaShellResponseAdapter
.- Classes in
com.aspectran.shell.adapter
package:ShellRequestAdapter
andShellResponseAdapter
are directly created and used within theadapt()
method.
3. Package Summary and Architectural Significance
The com.aspectran.shell.activity
package is another important example demonstrating the flexibility of Aspectran’s architecture. The core architectural significance of this package lies in extending beyond simple adaptation to include environment-specific logic.
While WebActivity
and DaemonActivity
primarily focus on the ‘adapter’ role of converting input/output targets, ShellActivity
integrates a new feature, interactive interaction, into the Activity
’s lifecycle through its unique preProcedure()
stage. This shows that Aspectran’s Activity
model is designed not just to execute a fixed pipeline, but to extend the execution flow itself to meet the unique requirements of each environment.
Thanks to this design, developers can easily build command-line applications that provide rich interaction, as if using a dedicated CLI library, while still leveraging Aspectran’s core functionalities.