public Object createObject(Attributes attributes) { // Identify the name of the class to instantiate String className = attributes.getValue("className"); if (className == null) { ModuleConfig mc = (ModuleConfig) digester.peek(1); className = mc.getActionForwardClass(); } // Instantiate the new object and return it Object actionForward = null; try { actionForward = RequestUtils.applicationInstance(className); } catch (Exception e) { digester.getLogger().error("ActionForwardFactory.createObject: ", e); } return actionForward; }
/** * Instantiate any <code>RuleSet</code> classes defined in the <code>rulesets</code> property and * use them to add rules to our <code>Digester</code>. * * @param digester the Digester instance to add RuleSet objects to. * @throws ServletException */ protected void applyRuleSets(Digester digester) throws ServletException { if ((this.rulesets == null) || (this.rulesets.trim().length() == 0)) { return; } rulesets = rulesets.trim(); String ruleSet = null; while (rulesets.length() > 0) { int comma = rulesets.indexOf(","); if (comma < 0) { ruleSet = rulesets.trim(); rulesets = ""; } else { ruleSet = rulesets.substring(0, comma).trim(); rulesets = rulesets.substring(comma + 1).trim(); } if (log.isDebugEnabled()) { // TODO Internationalize msg log.debug("Configuring custom Digester Ruleset of type " + ruleSet); } try { RuleSet instance = (RuleSet) RequestUtils.applicationInstance(ruleSet); digester.addRuleSet(instance); } catch (Exception e) { // TODO Internationalize msg log.error("Exception configuring custom Digester RuleSet", e); throw new ServletException(e); } } }
/** * Create an appropriate form bean in the appropriate scope, if one does not already exist. * * @param context FacesContext for the current request * @exception IllegalArgumentException if no ActionConfig for the specified action attribute can * be located * @exception IllegalArgumentException if no FormBeanConfig for the specified form bean can be * located * @exception IllegalArgumentException if no ModuleConfig can be located for this application * module */ public void createActionForm(FacesContext context) { // Look up the application module configuration information we need ModuleConfig moduleConfig = lookupModuleConfig(context); // Look up the ActionConfig we are processing String action = getAction(); ActionConfig actionConfig = moduleConfig.findActionConfig(action); if (actionConfig == null) { throw new IllegalArgumentException("Cannot find action '" + action + "' configuration"); } // Does this ActionConfig specify a form bean? String name = actionConfig.getName(); if (name == null) { return; } // Look up the FormBeanConfig we are processing FormBeanConfig fbConfig = moduleConfig.findFormBeanConfig(name); if (fbConfig == null) { throw new IllegalArgumentException("Cannot find form bean '" + name + "' configuration"); } // Does a usable form bean attribute already exist? String attribute = actionConfig.getAttribute(); String scope = actionConfig.getScope(); ActionForm instance = null; if ("request".equals(scope)) { instance = (ActionForm) context.getExternalContext().getRequestMap().get(attribute); } else if ("session".equals(scope)) { HttpSession session = (HttpSession) context.getExternalContext().getSession(true); instance = (ActionForm) context.getExternalContext().getSessionMap().get(attribute); } if (instance != null) { if (fbConfig.getDynamic()) { String className = ((DynaBean) instance).getDynaClass().getName(); if (className.equals(fbConfig.getName())) { if (log.isDebugEnabled()) { log.debug( " Recycling existing DynaActionForm instance " + "of type '" + className + "'"); } return; } } else { try { Class configClass = RequestUtils.applicationClass(fbConfig.getType()); if (configClass.isAssignableFrom(instance.getClass())) { if (log.isDebugEnabled()) { log.debug( " Recycling existing ActionForm instance " + "of class '" + instance.getClass().getName() + "'"); } return; } } catch (Throwable t) { throw new IllegalArgumentException( "Cannot load form bean class '" + fbConfig.getType() + "'"); } } } // Create a new form bean instance if (fbConfig.getDynamic()) { try { DynaActionFormClass dynaClass = DynaActionFormClass.createDynaActionFormClass(fbConfig); instance = (ActionForm) dynaClass.newInstance(); if (log.isDebugEnabled()) { log.debug( " Creating new DynaActionForm instance " + "of type '" + fbConfig.getType() + "'"); log.trace(" --> " + instance); } } catch (Throwable t) { throw new IllegalArgumentException( "Cannot create form bean of type '" + fbConfig.getType() + "'"); } } else { try { instance = (ActionForm) RequestUtils.applicationInstance(fbConfig.getType()); if (log.isDebugEnabled()) { log.debug(" Creating new ActionForm instance " + "of type '" + fbConfig.getType() + "'"); log.trace(" --> " + instance); } } catch (Throwable t) { throw new IllegalArgumentException( "Cannot create form bean of class '" + fbConfig.getType() + "'"); } } // Configure and cache the form bean instance in the correct scope ActionServlet servlet = (ActionServlet) context.getExternalContext().getApplicationMap().get(Globals.ACTION_SERVLET_KEY); instance.setServlet(servlet); if ("request".equals(scope)) { context.getExternalContext().getRequestMap().put(attribute, instance); } else if ("session".equals(scope)) { context.getExternalContext().getSessionMap().put(attribute, instance); } }