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
PlugIn
s 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 ...
Get Programming Jakarta Struts, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.