if (getInitial() == null) { setInitial(config.getInitial()); if (getName() == null) { setName(config.getName()); if (getSize() == 0) { setSize(config.getSize()); if (getType() == null) { setType(config.getType()); inheritProperties(config);
protected void addProperty(String name, String type) { FormPropertyConfig propConfig = new FormPropertyConfig(); propConfig.setName(name); propConfig.setType(type); formBeanConfig.addFormPropertyConfig(propConfig); }
/** * 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(); } }
/** * Constructor that preconfigures the relevant properties. * * @param name Name of this property * @param type Fully qualified class name of this property * @param initial Initial value of this property (if any) * @param size Size of the array to be created if this property is an * array with no defined initial value */ public FormPropertyConfig(String name, String type, String initial, int size) { super(); setName(name); setType(type); setInitial(initial); setSize(size); }
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());
for (int i = 0; i < descriptors.length; i++) { properties[i] = new DynaProperty(descriptors[i].getName(), descriptors[i].getTypeClass()); propertiesMap.put(properties[i].getName(), properties[i]);
/** * Remove the specified form property configuration instance. * * @param config FormPropertyConfig instance to be removed */ public void removeFormPropertyConfig(FormPropertyConfig config) { if (configured) { throw new IllegalStateException("Configuration is frozen"); } formProperties.remove(config.getName()); }
/** * <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()); } } }
String baseType = getType(); boolean indexed = false;
Class clazz = getTypeClass(); if (clazz.isArray()) { if (initial != null) {
new ActionFormBean("dynamic", "org.apache.struts.action.DynaActionForm"); formBean.addFormPropertyConfig(new FormPropertyConfig( "booleanProperty", "boolean", "false")); formBean.addFormPropertyConfig(new FormPropertyConfig( "stringProperty", "java.lang.String", null)); moduleConfig.addFormBeanConfig(formBean); new ActionFormBean("dynamic0", "org.apache.struts.action.DynaActionForm"); formBean.addFormPropertyConfig(new FormPropertyConfig( "booleanProperty", "boolean", "true")); formBean.addFormPropertyConfig(new FormPropertyConfig( "stringProperty", "java.lang.String", "String Property")); formBean.addFormPropertyConfig(new FormPropertyConfig("intArray1", "int[]", "{1,2,3}", 4)); // 4 should be ignored formBean.addFormPropertyConfig(new FormPropertyConfig("intArray2", "int[]", null, 5)); // 5 should be respected formBean.addFormPropertyConfig(new FormPropertyConfig("principal", "org.apache.struts.mock.MockPrincipal", null)); formBean.addFormPropertyConfig(new FormPropertyConfig("stringArray1", "java.lang.String[]", "{aaa,bbb,ccc}", 2)); // 2 should be ignored formBean.addFormPropertyConfig(new FormPropertyConfig("stringArray2", "java.lang.String[]", null, 3)); // 3 should be respected moduleConfig.addFormBeanConfig(formBean);
/** * Constructor that preconfigures the relevant properties. * * @param name Name of this property * @param type Fully qualified class name of this property * @param initial Initial value of this property (if any) * @param size Size of the array to be created if this property is an * array with no defined initial value * @param reset The conditions under which this property will be reset * to its initial value. */ public FormPropertyConfig(String name, String type, String initial, String reset, int size) { super(); setName(name); setType(type); setInitial(initial); setReset(reset); setSize(size); }
/** * <p>Initialize the specified form bean.</p> * * @param config The configuration for the form bean to initialize. */ public void initialize(FormBeanConfig config) { FormPropertyConfig[] props = config.findFormPropertyConfigs(); for (int i = 0; i < props.length; i++) { set(props[i].getName(), props[i].initial()); } }
dynaClass.add(props[i].getName(), props[i].getTypeClass()); dynaBean.set(props[i].getName(), props[i].initial());
new DynaProperty(descriptors[i].getName(), descriptors[i].getTypeClass()); propertiesMap.put(properties[i].getName(), properties[i]);
/** * Remove the specified form property configuration instance. * * @param config FormPropertyConfig instance to be removed */ public void removeFormPropertyConfig(FormPropertyConfig config) { if (configured) { throw new IllegalStateException("Configuration is frozen"); } formProperties.remove(config.getName()); }