Whiteboard notes for Chain of Responsibility Package

Agility

Agility is a working project name for a business applications framework based on the Commons Chain package.

The core idea behind Agility that is as much work as possible should be pushed up to the business layer. Input and output is encapsulated with a Context object that is passed to and from Agility using a ProtocolAdaptor. Depending on its implementation, a ProtocolAdaptor may collect input and deliver output directly from the native platform or from a presentation framework.

Agility is a Request/Response framework: for each request there is a response. The request is encapsulated in a Context object, which includes a Command identifier. Each request must correspond to a Command, which may also be a Chain of Commands. Commands may nest or chain other Commands as needed. The request Command is referred to as the “Action”.

When a request comes in from the presentation layer (or a presentation framework), it is received by a ProtocolAdaptor. The ProtocolAdaptor extracts the Action Command name from the native request and consults with a ContextFactory to generate a Context for the request. The request Context is then passed to the RequestProcessor for the given protocol.

The RequestProcessor is a Command Chain which includes (at a minimum) an Action Command. Each protocol can have its own RequestProcessor, which may be a combination of protocol-specific and generic commands. The Action Command (or Chain) is the core unit of work for the request.

The Action Command may consult business rules and the persistence layer to complete the unit of work. Any output or messages generated by the Action may be added to the Context under predetermined keys. If the Action completes normally, an attribute is added to the Context to signify the outcome of the Action. The value of the outcome attribute is arbitrary and defined by application implementing the framework (“success”, “failure”, “xylophone”).

When the RequestProcessor Chain completes, the Context is returned to the ProtocolAdaptor. Agility defines the ProtocolAdaptor interface but does not provide an implementation. If the ProtocolAdaptor is a simple Servlet, it may forward to a server page by munging the outcome value. If the ProtocolAdaptor is a presentation layer framework, it may pass the value to an internal mechanism that selects or assembles a server page, or generates a dynamic response. A ProtocolAdaptor might even utilitize its own “ResponseProcessor” to execute a series of Commands to assemble an approriate response.