General Extension Points
This section discusses some
extension points that affect the overall framework, not necessarily
one particular layer. Arguably the most important of these is the
PlugIn mechanism.
Using the PlugIn Mechanism
The Struts framework provides a
mechanism to allow components to be plugged in and loaded
dynamically. This feature was added in Version 1.1 and is supported
through the use of the
org.apache.struts.action.PlugIn interface. Any
Java class can function as a plug-in, as long as it implements the
PlugIn interface.
A plug-in is simply any Java class that you need to initialize when the Struts application starts up, and destroy when the application shuts down.
The PlugIn interface contains two methods, as
shown in Example 9-1.
Example 9-1. The org.apache.struts.action.PlugIn interface
public interface PlugIn {
/**
* Notification that the specified module is being started.
*/
public void init(ActionServlet servlet, ModuleConfig config)
throws ServletException;
/**
* Notification that the module is being shut down.
*/
public void destroy( );
}During startup of a Struts application, the
ActionServlet calls the init()
method for each PlugIn that is configured; the
framework supports configuration of one or more
PlugIns for each application. Initialization
routines that your plug- in needs to perform should be done during
the init() method. This is a good time to
initialize a database connection or establish a connection to a
remote system, for example.[8]
The second ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access