throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException { throwIfConfigured(); if (getName() == null) { setName(config.getName()); if (!isRestricted()) { setRestricted(config.isRestricted()); if (getType() == null) { setType(config.getType()); inheritFormProperties(config); inheritProperties(config);
instance = config.createActionForm(servlet); + (config.getDynamic() ? "DynaActionForm" : "ActionForm") + " instance of type '" + config.getType() + "'"); log.trace(" --> " + instance); config.getType()), t);
/** * Freeze the configuration of this component. */ public void freeze() { configured = true; FormPropertyConfig[] fpconfigs = findFormPropertyConfigs(); for (int i = 0; i < fpconfigs.length; i++) { fpconfigs[i].freeze(); } }
/** * <p>Traces the hierarchy of this object to check if any of the ancestors * is extending this instance.</p> * * @param moduleConfig The configuration for the module being configured. * @return true if circular inheritance was detected. */ protected boolean checkCircularInheritance(ModuleConfig moduleConfig) { String ancestorName = getExtends(); while (ancestorName != null) { // check if we have the same name as an ancestor if (getName().equals(ancestorName)) { return true; } // get our ancestor's ancestor FormBeanConfig ancestor = moduleConfig.findFormBeanConfig(ancestorName); ancestorName = ancestor.getExtends(); } return false; }
if (formBean.getType() == null) { handleValueRequiredException("type", formBean.getName(), "form bean"); FormPropertyConfig[] fpcs = formBean.findFormPropertyConfigs(); if (formBean.getDynamic()) { formBean.getDynaActionFormClass();
beanClass = RequestUtils.applicationClass(config.getType()); } catch (Throwable t) { throw new IllegalArgumentException( "Cannot instantiate ActionFormBean class '" + config.getType() + "': " + t); throw new IllegalArgumentException("Class '" + config.getType() + "' is not a subclass of " + "'org.apache.struts.action.DynaActionForm'"); this.name = config.getName(); FormPropertyConfig[] descriptors = config.findFormPropertyConfigs();
String className = null; if (config.getDynamic()) { className = ((DynaBean) instance).getDynaClass().getName(); canReuse = className.equals(config.getName()); formType = "DynaActionForm"; } else { Class configClass = applicationClass(config.getType()); className = instance.getClass().getName(); canReuse = configClass.isAssignableFrom(instance.getClass());
if (getDynamic()) { obj = getDynaActionFormClass().newInstance(); } else { obj = formBeanClass().newInstance(); FormPropertyConfig props[] = findFormPropertyConfigs(); for (int i = 0; i < props.length; i++) { dynaClass.add(props[i].getName(), props[i].getTypeClass()); dynaBean.set(props[i].getName(), props[i].initial()); dynaClass.setRestricted(isRestricted());
/** * Return the <code>Class</code> instance for the form bean implementation * configured by this <code>FormBeanConfig</code> instance. This method * uses the same algorithm as <code>RequestUtils.applicationClass()</code> * but is reproduced to avoid a runtime dependence. */ protected Class formBeanClass() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = this.getClass().getClassLoader(); } try { return (classLoader.loadClass(getType())); } catch (Exception e) { return (null); } } }
String ancestor = getExtends(); if (checkCircularInheritance(moduleConfig)) { throw new IllegalArgumentException( "Circular inheritance detected for form bean " + getName()); if (!baseConfig.isExtensionProcessed()) { baseConfig.processExtends(moduleConfig); inheritFrom(baseConfig);
public FormBeanConfig createFormBeanConfig(ModuleConfig config, Class formClass, String name, StrutsActionFormConfig strutsActionForm) { FormBeanConfig formBeanConfig = (FormBeanConfig) ClassUtil.newInstance(config.getActionFormBeanClass()); formBeanConfig.setType(formClass.getName()); if (!StrutsActionFormConfig.DEFAULT_NAME.equals(strutsActionForm.name())) { formBeanConfig.setName(strutsActionForm.name()); } else { formBeanConfig.setName(name); } if (StrutsActionFormConfig.DEFAULT_RESTRICTED != strutsActionForm.restricted()) { formBeanConfig.setRestricted(strutsActionForm.restricted().booleanValue()); } if (!StrutsActionFormConfig.DEFAULT_INHERIT.equals(strutsActionForm.inherit())) { formBeanConfig.setExtends(strutsActionForm.inherit()); } return formBeanConfig; }
/** * <p>Perform intialization of the ActionForm.</p> * <p>This method is called when the form is created.</p> * * @since Struts 1.3.6 */ public void initialize(FormBeanConfig formBeanConfig) { strutsConfigFormName = formBeanConfig.getName(); }
void addFormBeanConfigByClassName(String className) { if(!isValidClassName(className)) { return; } defreeze(); FormBeanConfig formBeanConfig = new FormBeanConfig(); formBeanConfig.setName(className); formBeanConfig.setType(className); addFormBeanConfig(formBeanConfig); }
/** * <p>Extend the form bean's configuration as necessary.</p> * * @param beanConfig the configuration to process. * @param moduleConfig the module configuration for this module. * @throws ServletException if initialization cannot be performed. */ protected void processFormBeanExtension(FormBeanConfig beanConfig, ModuleConfig moduleConfig) throws ServletException { try { if (!beanConfig.isExtensionProcessed()) { if (log.isDebugEnabled()) { log.debug("Processing extensions for '" + beanConfig.getName() + "'"); } beanConfig = processFormBeanConfigClass(beanConfig, moduleConfig); beanConfig.processExtends(moduleConfig); } } catch (ServletException e) { throw e; } catch (Exception e) { handleGeneralExtensionException("FormBeanConfig", beanConfig.getName(), e); } }
FormBeanConfig beanConfig, ModuleConfig moduleConfig) throws ServletException { String ancestor = beanConfig.getExtends(); beanConfig.findFormPropertyConfigs(); newBeanConfig.addFormPropertyConfig(fpc[i]);
private void registerValidations(ModuleConfig config) { // Create Forms. ValidatorResources currentResources = getValidatorResources(config); FormSet formSet = new FormSet(); FormBeanConfig[] formConfigs = config.findFormBeanConfigs(); for (int i = 0; i < formConfigs.length; i++) { if (!registeredValidation(currentResources, formConfigs[i])) { Class clazz = ClassUtil.forName(formConfigs[i].getType()); String name = formConfigs[i].getName(); Form form = this.validationCreator.createForm(config, clazz, name); if (form != null) { formSet.addForm(form); if (log.isDebugEnabled()) { log.debug("auto register " + form); } } } } // Initialize ValidatorResources if (formSet.getForms().size() != 0) { ValidatorResources resources = new ValidatorResources(); resources.addFormSet(formSet); resources.process(); addValidatorResources(config, resources); } }
/** * <p>Compare the form properties of this bean with that of the given and * copy those that are not present.</p> * * @param config The form bean config to copy properties from. * @see #inheritFrom(FormBeanConfig) */ protected void inheritFormProperties(FormBeanConfig config) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException { throwIfConfigured(); // Inherit form property configs FormPropertyConfig[] baseFpcs = config.findFormPropertyConfigs(); for (int i = 0; i < baseFpcs.length; i++) { FormPropertyConfig baseFpc = baseFpcs[i]; // Do we have this prop? FormPropertyConfig prop = this.findFormPropertyConfig(baseFpc.getName()); if (prop == null) { // We don't have this, so let's copy it prop = (FormPropertyConfig) RequestUtils.applicationInstance(baseFpc.getClass() .getName()); BeanUtils.copyProperties(prop, baseFpc); this.addFormPropertyConfig(prop); prop.setProperties(baseFpc.copyProperties()); } } }
if (fbs[i].getDynamic()) { fbs[i].getDynaActionFormClass();
+ "; test for reusability"); if (formBeanConfig.canReuse(instance)) { return instance; ActionForm form = formBeanConfig.createActionForm(this);