cedric 01/12/27 09:41:35 Added: contrib/tiles/src/share/org/apache/struts/tiles ActionController.java Controller.java ControllerSupport.java TilesException.java UrlController.java contrib/tiles/src/share/org/apache/struts/tiles/actions DefinitionDispatcherAction.java NoOpAction.java ReloadDefinitionsAction.java TilesAction.java ViewDefinitionsAction.java contrib/tiles/src/share/org/apache/struts/tiles/beans MenuItem.java SimpleMenuItem.java contrib/tiles/src/share/org/apache/struts/tiles/definition ReloadableDefinitionsFactory.java Log: Add individual controller and reload capabilities Move actions in separate folder Create a bean folder repository Revision Changes Path 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/ActionController.java Index: ActionController.java =================================================================== //Source file: H:\\TEMP\\generated\\org\\apache\\struts\\tiles\\ActionController.java package org.apache.struts.tiles; import org.apache.struts.action.Action; import org.apache.struts.action.ActionServlet; import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletContext; import javax.servlet.ServletException; /** * Struts wrapper implementation of Controller. * This implementation allows to wrap a Struts Action in a Controller */ public class ActionController implements Controller { /** Struts action wrapped */ private Action action; /** * Constructor. */ public ActionController( Action action ) { this.action = action; } /** * Method associated to a tile and called when immediately before tile is included. * This implementation call a Struts Action. No servlet is set by this method. * * @param tileContext Current tile context. * @param request Current request * @param response Current response * @param servletContext Current servlet context */ public void perform(ComponentContext tileContext, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) throws ServletException, IOException { action.perform(null, null, request, response); } } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/Controller.java Index: Controller.java =================================================================== //Source file: H:\\TEMP\\generated\\org\\apache\\struts\\tiles\\Controller.java package org.apache.struts.tiles; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletContext; /** * A controller is a piece of code called before rendering a jsp page. * A controller can be associated to a tile. See <insert> or <definition> for * association syntax. */ public interface Controller { /** * Method associated to a tile and called when immediately before tile is included. * @param tileContext Current tile context. * @param request Current request * @param response Current response * @param servletContext Current servlet context */ public void perform(ComponentContext tileContext, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) throws ServletException, IOException; } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/ControllerSupport.java Index: ControllerSupport.java =================================================================== //Source file: H:\\TEMP\\generated\\org\\apache\\struts\\tiles\\ControllerSupport.java package org.apache.struts.tiles; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletContext; /** * Basic implementation of Controller. */ public class ControllerSupport implements Controller { /** * Method associated to a tile and called when immediately before tile is included. * This implementation do nothing. * @param tileContext Current tile context. * @param request Current request * @param response Current response * @param servletContext Current servlet context */ public void perform(ComponentContext tileContext, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) throws ServletException, IOException { } } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/TilesException.java Index: TilesException.java =================================================================== //Source file: H:\\TEMP\\generated\\org\\apache\\struts\\tiles\\TilesException.java package org.apache.struts.tiles; /** * Root class of Tiles exception * @author Cedric Dumoulin */ public class TilesException extends Exception { /** * Any "wrapped" exception will be exposed when this is serialized. * @serial */ private Exception exception; /** * Constructor. * Create a new MapperFactoryException. * * @param message The error or warning message. */ public TilesException() { super(); this.exception = null; } /** * Constructor. * Create a new MapperFactoryException. * * @param message The error or warning message. */ public TilesException(String message) { super(message); this.exception = null; } /** * Create a new MapperFactoryException wrapping an existing exception. * * <p>The existing exception will be embedded in the new * one, and its message will become the default message for * the MapperFactoryException.</p> * * @param e The exception to be wrapped in a SAXException. */ public TilesException(Exception e) { super(); this.exception = e; } /** * Create a new MapperFactoryException from an existing exception. * * <p>The existing exception will be embedded in the new * one, but the new exception will have its own message.</p> * * @param message The detail message. * @param e The exception to be wrapped in a MapperFactoryException. * @see org.xml.sax.Parser#setLocale */ public TilesException(String message, Exception e) { super(message); this.exception = e; } /** * Return a detail message for this exception. * * <p>If there is a embedded exception, and if the MapperFactoryException * has no detail message of its own, this method will return * the detail message from the embedded exception.</p> * * @return The error or warning message. */ public String getMessage () { String message = super.getMessage (); if (message == null && exception != null) { return exception.getMessage(); } else { return message; } } /** * Return the embedded exception, if any. * * @return The embedded exception, or null if there is none. */ public Exception getException () { return exception; } } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/UrlController.java Index: UrlController.java =================================================================== package org.apache.struts.tiles; import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.RequestDispatcher; /** * Controller including a local URL * @author Cedric Dumoulin * @version */ public class UrlController implements Controller { /** Url associated to this controller */ protected String url; /** * Constructor. */ public UrlController( String url ) { this.url=url; } /** * Method associated to a tile and called when immediately before tile is included. * This implementation call a Struts Action. No servlet is set by this method. * * @param tileContext Current tile context. * @param request Current request * @param response Current response * @param servletContext Current servlet context */ public void perform(ComponentContext tileContext, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) throws ServletException, IOException { RequestDispatcher rd = servletContext.getRequestDispatcher( url ); if( rd == null ) throw new ServletException( "Controller can't find url '" + url + "'." ); rd.include( request, response ); } } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/actions/DefinitionDispatcherAction.java Index: DefinitionDispatcherAction.java =================================================================== /* */ package org.apache.struts.tiles.actions; import org.apache.struts.tiles.*; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * <p>An <strong>Action</strong> that dispatches to a Tiles Definition * that is named by the request parameter whose name is specified * by the <code>parameter</code> property of the corresponding * ActionMapping. * This action is usefull in following situations : * <li> * <ul>To associate an Url to a definition</ul> * <ul>To use Struts <link> tag on a definition</ul> * </li> * <p>To configure the use of this action in your * <code>struts-config.xml</code> file, create an entry like this:</p> * * <code> * <action path="/saveSubscription" * type="org.apache.struts.tiles.actions.DefinitionDispatcherAction" * name="subscriptionForm" * scope="request" * input="/subscription.jsp" * parameter="def"/> * </code> * * <p>which will use the value of the request parameter named "def" * to pick the appropriate definition name. * * @author Niall Pemberton <[EMAIL PROTECTED]> * @author Craig R. McClanahan * @author Cedric Dumoulin * @version $Revision: 1.1 $ $Date: 2001/12/27 17:41:35 $ */ public final class DefinitionDispatcherAction extends Action { /** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param servlet The ActionServlet making this request * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ public ActionForward perform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Identify the request parameter containing the method name // If none defined, use "def" String parameter = mapping.getParameter(); if (parameter == null) { parameter = "def"; } // Identify the method name to be dispatched to String name = request.getParameter(parameter); if (name == null) { String msg = "Definition dispatcher action : can't get parameter '" + parameter + "'."; printError( response, msg ); return (null); } // Try to dispatch to requested definition try { // Read definition from factory, but we can create it here. ComponentDefinition definition = DefinitionsUtil.getDefinition( name, request, getServlet().getServletContext() ); DefinitionsUtil.setActionDefinition( request, definition); } catch( FactoryNotFoundException ex ) { printError( response, "Error - DefinitionDispatcherAction : Can't get definition factory."); return (mapping.findForward(null)); } catch( NoSuchDefinitionException ex ) { printError( response, "Error - DefinitionDispatcherAction : Can't get definition '" + name +"'."); return (mapping.findForward(null)); } catch( DefinitionsFactoryException ex ) { printError( response, "Error - DefinitionDispatcherAction : General error '" + ex.getMessage() +"'."); return (mapping.findForward(null)); } return (mapping.findForward(null)); } protected void printError( HttpServletResponse response, String msg ) throws IOException { response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); writer.println(msg); writer.flush(); writer.close(); } } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/actions/NoOpAction.java Index: NoOpAction.java =================================================================== /* */ package org.apache.struts.tiles.actions; import java.io.IOException; import java.util.Locale; import java.util.Vector; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionServlet; import org.apache.struts.util.MessageResources; import org.apache.struts.util.RequestUtils; /** * Implementation of <strong>Action</strong> that populates an instance of * <code>SubscriptionForm</code> from the currently specified subscription. * * @author Cedric Dumoulin * @version $Revision: 1.1 $ $Date: 2001/12/27 17:41:35 $ */ public final class NoOpAction extends Action { // --------------------------------------------------------- Public Methods /** * No op action. * Action doing nothing. * * @param servlet The ActionServlet making this request * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ public ActionForward perform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // No op action. return (mapping.findForward("success")); } } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/actions/ReloadDefinitionsAction.java Index: ReloadDefinitionsAction.java =================================================================== /* */ package org.apache.struts.tiles.actions; import org.apache.struts.tiles.DefinitionsUtil; import org.apache.struts.tiles.DefinitionsFactoryException; import org.apache.struts.tiles.definition.ReloadableDefinitionsFactory; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * <p>A standard <strong>Action</strong> that calls the * <code>reload()</code> method of our controller servlet to * reload its configuration information from the configuration * files (which have presumably been updated) dynamically.</p> * * @author Craig R. McClanahan * @author Cedric Dumoulin * @version $Revision: 1.1 $ $Date: 2001/12/27 17:41:35 $ */ public final class ReloadDefinitionsAction extends Action { /** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ public ActionForward perform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); try { ServletContext context = getServlet().getServletContext(); ReloadableDefinitionsFactory factory = (ReloadableDefinitionsFactory)DefinitionsUtil.getDefinitionsFactory(context ); factory.reload(context); writer.println("OK"); } catch (ClassCastException e) { writer.println("FAIL - " + e.toString()); getServlet().log("ReloadAction", e); } catch (DefinitionsFactoryException e) { writer.println("FAIL - " + e.toString()); getServlet().log("ReloadAction", e); } writer.flush(); writer.close(); return (null); } } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/actions/TilesAction.java Index: TilesAction.java =================================================================== package org.apache.struts.tiles.actions; import org.apache.struts.tiles.ComponentContext; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionServlet; /** * Base class for Tiles Actions. * This class as the same role as Struts Action. It provides a method perform(...) * called when action is invoked. The difference is that the perform() method takes * an additional parameter : tile context. * This class extends Struts Action. Subclasses should implements new perform() method * instead of Struts perform() method. * @version $Revision: 1.1 $ $Date: 2001/12/27 17:41:35 $ */ public abstract class TilesAction extends Action { /** * Original Struts Action's method. * Retrieve current Tile context, and call Tile's perform method. * * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ public ActionForward perform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Try to retrieve tile context ComponentContext context = ComponentContext.getContext( request ); if( context == null ) { throw new ServletException( "Can't find Tile context for '" + this.getClass().getName() + "'. TilesAction subclasses must be called from a Tile" ); } return perform( context, mapping, form, request, response ); } /** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed. * This method should be implemented by subclasses. * * @param context The current Tile context, containing Tile attributes * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ abstract public ActionForward perform( ComponentContext context, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException; } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/actions/ViewDefinitionsAction.java Index: ViewDefinitionsAction.java =================================================================== /* */ package org.apache.struts.tiles.actions; import org.apache.struts.tiles.DefinitionsUtil; import org.apache.struts.tiles.DefinitionsFactoryException; import org.apache.struts.tiles.ComponentDefinitionsFactory; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * <p>A standard <strong>Action</strong> that calls the * <code>reload()</code> method of our controller servlet to * reload its configuration information from the configuration * files (which have presumably been updated) dynamically.</p> * * @author Craig R. McClanahan * @author Cedric Dumoulin * @version $Revision: 1.1 $ $Date: 2001/12/27 17:41:35 $ */ public final class ViewDefinitionsAction extends Action { /** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ public ActionForward perform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); try { ServletContext context = getServlet().getServletContext(); ComponentDefinitionsFactory factory = DefinitionsUtil.getDefinitionsFactory(context ); writer.println( factory ); } catch (Exception e) { writer.println("FAIL - " + e.toString()); getServlet().log("ReloadAction", e); } writer.flush(); writer.close(); return (null); } } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/beans/MenuItem.java Index: MenuItem.java =================================================================== package org.apache.struts.tiles.beans; import java.io.Serializable; /** * A bean MenuItem interface. * */ public interface MenuItem extends Serializable { /** * Set value property */ public void setValue(String value); /** * Get value property */ public String getValue(); /** * Set link property */ public void setLink(String link); /** * Get link property */ public String getLink(); /** * Set icon property */ public void setIcon(String link); /** * Get icon property */ public String getIcon(); /** * Set tooltip property */ public void setTooltip(String link); /** * Get tooltip property */ public String getTooltip(); } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/beans/SimpleMenuItem.java Index: SimpleMenuItem.java =================================================================== package org.apache.struts.tiles.beans; import java.io.Serializable; /** * A bean MenuItem implementation. * Used to read menu item in definitions. */ public class SimpleMenuItem implements MenuItem, Serializable { private String value; private String link; private String icon; private String tooltip; /** * Constructor. */ public SimpleMenuItem() { } /** * Set value property */ public void setValue(String value) { this.value = value; } /** * Get value property */ public String getValue() { return value; } /** * Set link property */ public void setLink(String link) { this.link = link; } /** * Get link property */ public String getLink() { return link; } /** * Get icon property */ public void setIcon(String icon) { this.icon = icon; } /** * Get icon property */ public String getIcon() { return icon; } /** * Get tooltip property */ public void setTooltip(String tooltip) { this.tooltip = tooltip; } /** * Get tooltip property */ public String getTooltip() { return tooltip; } } 1.1 jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/definition/ReloadableDefinitionsFactory.java Index: ReloadableDefinitionsFactory.java =================================================================== /* * $Header: /home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/definition/ReloadableDefinitionsFactory.java,v 1.1 2001/12/27 17:41:35 cedric Exp $ * $Revision: 1.1 $ * $Date: 2001/12/27 17:41:35 $ * $Author: cedric $ * */ package org.apache.struts.tiles.definition; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.ServletRequest; import java.util.Map; import java.util.HashMap; import java.util.Enumeration; import org.apache.struts.tiles.*; import org.apache.struts.tiles.xmlDefinition.I18nFactorySet; /** * A reloadable factory. * This factory is the main entrance to any factory implementation. It takes in * charge real implementation instance, and allows reload of it by creating a new * instance. * */ public class ReloadableDefinitionsFactory implements ComponentDefinitionsFactory { /** The real factory instance */ protected ComponentDefinitionsFactory factory; /** Initialization parameters */ protected Map properties; /** Name of init property carrying factory class name */ public static final String DEFINITIONS_FACTORY_CLASSNAME = "definitions-factory-class"; /** * Constructor. * Create a factory according to servlet settings. * @throws DefinitionsFactoryException If factory creation fail. */ public ReloadableDefinitionsFactory( ServletContext servletContext, ServletConfig servletConfig ) throws DefinitionsFactoryException { properties = new ServletPropertiesMap( servletConfig ); factory = createFactory( servletContext, properties); } /** * Constructor. * Create a factory according to servlet settings. * @throws DefinitionsFactoryException If factory creation fail. */ public ReloadableDefinitionsFactory( ServletContext servletContext, Map properties ) throws DefinitionsFactoryException { this.properties = properties; factory = createFactory( servletContext, properties); } /** * Create Definition factory from provided classname. * If a factory class name is provided, a factory of this class is created. Otherwise, * default factory is created. * Factory must have a constructor taking ServletContext and Map as parameter. * @param classname Class name of the factory to create. * @param servletContext Servlet Context passed to newly created factory. * @param properties Map of name/property passed to newly created factory. * @return newly created factory. * @throw DefinitionsFactoryException If an error occur while initializing factory */ public ComponentDefinitionsFactory createFactoryFromClassname(ServletContext servletContext, Map properties, String classname) throws DefinitionsFactoryException { if( classname == null ) return createFactory( servletContext, properties ); // Try to create from classname try { Class factoryClass = Class.forName(classname); ComponentDefinitionsFactory factory = (ComponentDefinitionsFactory)factoryClass.newInstance(); factory.initFactory( servletContext, properties); return factory; } catch( ClassCastException ex ) { // Bad classname throw new DefinitionsFactoryException( "Error - createDefinitionsFactory : Factory class '" + classname +" must implements 'ComponentDefinitionsFactory'.", ex ); } catch( ClassNotFoundException ex ) { // Bad classname throw new DefinitionsFactoryException( "Error - createDefinitionsFactory : Bad class name '" + classname +"'.", ex ); } catch( InstantiationException ex ) { // Bad constructor or error throw new DefinitionsFactoryException( ex ); } catch( IllegalAccessException ex ) { // throw new DefinitionsFactoryException( ex ); } } /** * Create default Definition factory. * Factory must have a constructor taking ServletContext and Map as parameter. * In this implementation, default factory is of class I18nFactorySet * @param servletContext Servlet Context passed to newly created factory. * @param properties Map of name/property passed to newly created factory. * @return newly created factory. * @throw DefinitionsFactoryException If an error occur while initializing factory */ public ComponentDefinitionsFactory createDefaultFactory(ServletContext servletContext, Map properties) throws DefinitionsFactoryException { ComponentDefinitionsFactory factory = new I18nFactorySet(servletContext, properties); ; return factory; } /** * Create Definition factory. * Convenience method. ServletConfig is wrapped into a Map allowing retrieval * of init parameters. Factory classname is also retrieved, as well as debug level. * Finally, approriate createDefinitionsFactory() is called. * @param servletContext Servlet Context passed to newly created factory. * @param servletConfig Servlet config containing parameters to be passed to newly created factory. */ public ComponentDefinitionsFactory createFactory(ServletContext servletContext, Map properties) throws DefinitionsFactoryException { String classname = (String)properties.get(DEFINITIONS_FACTORY_CLASSNAME); return new I18nFactorySet( servletContext, properties ); } /** * Get a definition by its name. * Call appropriate method on underlying factory instance. * Throw appropriate exception if definition or definition factory is not found. * @param name Name of requested definition. * @param request Current servelet request * @param servletContext current servlet context * @throw FactoryNotFoundException Can't find definition factory. * @throw DefinitionsFactoryException General error in factory while getting definition. * @throws NoSuchDefinitionException No definition found for specified name */ public ComponentDefinition getDefinition(String definitionName, ServletRequest request, ServletContext servletContext) throws FactoryNotFoundException, DefinitionsFactoryException { return factory.getDefinition(definitionName, (HttpServletRequest)request, servletContext); } /** * Reload underlying factory. * Reload is done creating a new factory instance, and replacing old instance * by the new one. * @param request Current servelet request * @param servletContext current servlet context * @throws DefinitionsFactoryException If factory creation fail. */ public void reload(ServletContext servletContext) throws DefinitionsFactoryException { ComponentDefinitionsFactory newInstance = createFactory( servletContext, properties); factory = newInstance; } /** * Get underlying factory instance. */ public ComponentDefinitionsFactory getFactory() { return factory; } /** * Init factory. * This method is required by interface ComponentDefinitionsFactory. It is * not used in this implementation, as it manage itself underlying creation * and initialization. * @param servletContext Servlet Context passed to newly created factory. * @param properties Map of name/property passed to newly created factory. * Map can contains more properties than requested. * @throws DefinitionsFactoryException An error occur during initialization. */ public void initFactory(ServletContext servletContext, Map properties) throws DefinitionsFactoryException { // do nothing } /** * Get this object as a String */ public String toString() { return factory.toString(); } /** * Inner class. * Wrapper for ServletContext init parameters. * Object of this class is an hashmap containing parameters and values * defined in the servlet config file (web.xml). */ class ServletPropertiesMap extends HashMap { /** * Constructor. */ ServletPropertiesMap( ServletConfig config ) { // This implementation is very simple. // It is possible to avoid creation of a new structure, but this need // imply writing all Map interface. Enumeration enum = config.getInitParameterNames(); while( enum.hasMoreElements() ) { String key = (String)enum.nextElement(); put( key, config.getInitParameter( key ) ); } } } // end inner class }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>