Here's what I would do:
- grab source from CVS
- located the source for ValidatorPlugin.java (or is it
ValidatorPlugIn.java?)
- read up on the javadoc for the Plugin interface.
(You could just browse CVS over the web and find that file to examine,
if you prefer. I find having the full source handy for consultation is
a big help at times though.)
It's *really* simple. I think the most difficult part will be figuring
out the digester and what you want your graph to look like. Be sure you
look at the digester package javadocs: org.apache.commons.digester (I
believe). There's quite a long explaination of how to use the digester.
If you get stuck, I can possibly give you a pointer or two. I haven't
used it long, but I manage to get it to build heirarchys just fine
(create this, set it's properties, add it to this other object ...)
A skelleton plugin might be:
-------------------------------------------------- BEGIN MyPlugin
import org.apache.struts.action.PlugIn;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.config.ApplicationConfig;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.digester.Digester;
import org.xml.sax.SAXException;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import java.io.IOException;
import java.util.Collection;
import java.util.ArrayList;
public class MyPlugin implements PlugIn
{
private Log log = LogFactory.getLog(MyPlugin.class);
private ActionServlet servlet = null;
private ApplicationConfig config = null;
private String configFile;
public MyPlugin()
{
}
public void destroy()
{
this.servlet = null;
this.config = null;
}
public void init(ActionServlet servlet, ApplicationConfig config)
throws ServletException
{
if (log.isTraceEnabled())
log.trace("Initializing module configuration");
this.servlet = servlet;
this.config = config;
Digester digester = new Digester();
...
java.io.InputStream is =
servlet.getServletContext().getResourceAsStream(configFile);
try
{
digester.push(...);
digester.parse(is);
is.close();
}
catch (IOException ioe)
{
log.fatal("IOException thrown while parsing config: " +
ioe.getMessage(), ioe);
throw new UnavailableException("IOException thrown while parsing
modules config");
}
catch (SAXException saxe)
{
log.fatal("SAXException thrown while parsing config: " +
saxe.getMessage(), saxe);
throw new UnavailableException("SAXException thrown while parsing
config");
}
...
servlet.getServletContext().setAttribute("myTopLevelBean",
myTopLevelBean);
if (log.isTraceEnabled())
log.trace("Finished initializing module configuration");
}
public java.lang.String getConfigFile()
{
return configFile;
}
public void setConfigFile(java.lang.String configFile)
{
if (log.isTraceEnabled())
log.trace("Setting configFile to " + configFile);
this.configFile = configFile;
}
}
-------------------------------------------------- END MyPlugin
Billy Ng wrote:
>Good idea! I won't go for hacking Struts either. By the way, I heard you
>guys talking about plugin so many times (I know, I am a slower learner).
>Any web site I can look at. I am very interested in learnig it.
>
>Billy Ng
>
--
Eddie Bush
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>