1. Design Goals and Key Roles
This package provides the Activity
implementation that actually executes programmatic calls initiated from the EmbeddedAspectran
service. This package plays a very similar role to the daemon-activity
package but is adapted to the specific context of an embedded environment.
The design goals of this package are as follows:
- Concretizing the Execution Context of an Embedded Environment: Inherits from the abstract
CoreActivity
to provideAspectranActivity
, which can process requests in an environment embedded within another Java application. - Standardization of Programmatic Calls: Provides adapters that convert
Map
-shaped parameters, attributes, and request bodies passed throughEmbeddedAspectran
’stranslate()
method into standard request/response forms that the Aspectran core engine can understand.
In conclusion, this package acts as a bridge that converts and connects data and call methods between the simplified facade EmbeddedAspectran
and the complex execution engine CoreActivity
.
2. Detailed Class Analysis
AspectranActivity
(Implementation Class)
The final implementation of Activity
for the embedded environment. A new instance is created each time DefaultEmbeddedAspectran
’s translate()
method is called.
Key Responsibilities:
- Inherits
CoreActivity
, thus inheriting all of Aspectran’s standard request processing pipeline (advice, action execution, etc.). - Maintains the request name, method, attribute map, parameter map, and request body passed via the
translate()
method as internal state. - Creates and manages request/response/session adapters specific to the embedded environment.
Key Method Analysis:
adapt()
: The core of adaptation for the embedded environment. It is called at the beginning ofCoreActivity
’sperform()
method to convert programmatic calls into standard interfaces.AspectranRequestAdapter
: Wraps theattributeMap
,parameterMap
, andbody
passed to thetranslate()
method to act as aRequestAdapter
. It is functionally slightly more extended thanDaemonRequestAdapter
in that it can handlebody
, making it easier to programmatically simulate requests like POST/PUT.AspectranResponseAdapter
: Internally wraps anOutputStringWriter
or aWriter
directly provided during thetranslate()
call to act as aResponseAdapter
. All response results are written to thisWriter
.DefaultSessionAdapter
: If session management is enabled in the parentEmbeddedAspectran
service, it creates a session adapter to support state persistence.
Interaction with Other Classes:
DefaultEmbeddedAspectran
: Within itstranslate()
method, it directly createsAspectranActivity
, sets parameters, and then callsprepare()
andperform()
to execute it.CoreActivity
:AspectranActivity
inheritsCoreActivity
and uses its execution pipeline as is.- Classes in
com.aspectran.embed.adapter
package:AspectranRequestAdapter
andAspectranResponseAdapter
are directly created and used within theadapt()
method.
3. Package Summary and Architectural Significance
The com.aspectran.embed.activity
package, along with the activity
packages for daemon
and shell
environments, demonstrates how highly reusable Aspectran’s core execution engine, CoreActivity
, is designed.
AspectranActivity
handles all the heavy lifting of converting actual programmatic calls into Aspectran’s standard execution model, behind the user-friendly facade of EmbeddedAspectran
. Thanks to this adapter layer, the CoreActivity
execution engine does not need to distinguish whether its execution was triggered by an HTTP request, an internal daemon call, or a method call from another Java application.
This perfect decoupling makes it very easy to embed Aspectran into other applications and use it as a service component to perform specific functions (e.g., template rendering, rule-based logic execution). This is a key architectural design that allows Aspectran to not only be a standalone application framework but also to fully function as a high-functionality embedded library.