For some builders, the order of the builder calls can be important.
For other builders, such as an HTML builder that puts a text input box on a named element in a certain page, the order is irrelevant. In another case, where the builder puts a link on all pages in the model, it is vital that the builder is able to run after all the pages are created.
The developer of the builder has the option of making order important or not. IBM® WebSphere® Portlet Factory builder architecture supports multiple phase generation. Any builder that wants to defer its work, for whatever reason, can invoke a defer operation, specifying the name of the phase in which it would like to be re-invoked.
The following generation phases are supported.
All the builder calls in the model are invoked. In general, any builder that calls other builders should do so in this phase. All builders that construct new elements should do so in this phase.Post-Construction
Builders that modify elements that were constructed in the construction phase are run . The second-phase builder calls do not risk generating an error because the element they are supposed to operate on has not yet been created. Modification
Note: The list of builder calls being invoked is not the list of builder calls from the model. It is only the list of builder calls for which the associated builder specifically asked for the builder call to be deferred to this phase. This can include some builder calls that were in the original list, but it might also include builder calls that were invoked by other builders.
Objects that were created in the first two phases can be further modified. Validation
A builder can check the validity of the finished product, perhaps providing some error or warning messages to be displayed in WebSphere Portlet Factory Designer.Process
Abstract elements are processed, for example, action lists are converted to methods. Externalize
Generated pieces are stored externally.
A builder can defer itself to any other named phase. However, phases with names other than the official ones are not be invoked automatically. Instead, the outside entity that called into WebSphere Portlet Factory requesting a generation has the opportunity to trigger these additional phases. This offers flexibility to embed optional functionality in a builder that can be invoked at generation time by the agent in charge.
The following code can be used to control and determine phase.
/** Generation phases */
/** Initial generation phase when objects are created */
public static final String PHASE_CONSTRUCTION = "Construction";
/** Generation phase for modifying objects that were created in Construction phase */
public static final String PHASE_POSTCONSTRUCTION = "PostConstruction";
/** Generation phase for doing more subtle modification on objects that were created in the first two phases */
public static final String PHASE_MODIFICATION = "Modification";
/** Generation phase for doing validation after all creating/modifying objects has completed in the first two phases */
public static final String PHASE_VALIDATION = "Validation";
/** Generation phase for processing the abstract elements. i.e. Action Lists into methods
* Note that this is called AFTER the Domain-specific AppProcesser */
public static final String PHASE_PROCESS = "Process";
/** Generation phase for externalizing the generated pieces. i.e. Classes, JSP files, etc.
* Note that this is called AFTER the Domain-specific AppExternalizer. */
public static final String PHASE_EXTERNALIZE = "Externalize";
Builders calling builders
When one builder wants to call another builder, the process is to create a new builder call object (the API provides assistance with this) and then to invoke it.
Deferring a builder call to another phase
This is typical sample code that would appear in the doBuilderCall method of a builder class that wants to defer itself to another phase.
Parent topic: Overview of builder architecture