2, XWORK component architecture
(1) Write a component class
In xwork, the component class can be anything you want to do. The only restriction is to have a default constructor so that XWORK is instantiated when needed. As an option, the component class can implement intializable and / or disposable interfaces to receive lifecycle events after being created and destroyed, as shown below:
Public class mycomponent imports intializable, disposable {
Public void init () {
// Do INITIALIZATION HERE
}
Public void dispose () {
// Do Any Clean Up Necessary Before Garbage Collection of this Component
}
}
(2) Component dependencies
An unambiguated feature is that the components depend on another component. For example, ExchangeRateService describes a Configuration component, then XWORK passes the Configuration component to the ExchangeRateService instance after ExchangeRateService instantiation. XWork will automatically initialize the components in the correct order.
If A is an action or component, depending on B and C, but B is dependent on C, then ComponentManager will handle the following order:
l Institute C. If Intializable interface is implemented, INTI ();
l Institutionalization B. Set C to B for use using the Enabler method;
l If b is implemented in the intilazable interface, you calls init ();
l Institutionalization A. Use the Enabler method to set B for A.
If B and C need to reuse, use the Enabler method to pass instance instead of a new instance.
(3) Write enablers
Enabler is an interface that contains a method of receiving a single parameter. The parameters can be the component class to be activated or a superclass thereof. Here is an example of ExchangeRateaWare:
Public interface exchangerateaware {
Public void setExchangeRrateService (ExchangeRateService ExchangeRrate);
}
(4) Write "enabler-aware" action
The Action class needs to implement the relevant Enabler interface so that XWork calls the Enabler method to pass the component instance to the action before the action executes, and below is a simple example:
Public class myAction extends actionSupport implements ExchangeRateaWare {
ExchangerateService ERS;
Public void setExchangeRrateService (ExchangeRateService ExchangeRector) {
ERS = ExchangerateService;
}
Public String Execute () throws exception {
System.out.println ("The Base Currency IS" Ers.getBaseCurrency ());
}
}
If the object is not an action or component, you can call ComponentManager. InitializeObject (EnableDObject); Explicitly telling XWork to provide an activated component. (5) Using an external reference parser
You can use an external reference parser in XWork instead of being parsed by xwork. An example is to use an external reference parser in XWork and Spring integration.
You need to write an external reference parser and tell xWork in the package declaration to use it:
Name = "default" ExternalReferenceRereSolver = "com.atlassian.xwork.ext.springservletContextReferenceRereSolver"> You can now use external references: The attribute name is the name of the setter method, and foo is a reference to find.