You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2006/01/21 01:21:00 UTC
svn commit: r370938 [12/50] - in /struts: action/trunk/
action/trunk/conf/java/ action/trunk/src/java/org/apache/struts/
action/trunk/src/java/org/apache/struts/action/
action/trunk/src/java/org/apache/struts/chain/
action/trunk/src/java/org/apache/str...
Modified: struts/action/trunk/src/java/org/apache/struts/config/FormBeanConfig.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/FormBeanConfig.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/FormBeanConfig.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/FormBeanConfig.java Fri Jan 20 16:19:02 2006
@@ -15,45 +15,38 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.config;
-
-import java.util.HashMap;
-import java.lang.reflect.InvocationTargetException;
-
+import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.MutableDynaClass;
-import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.action.DynaActionFormClass;
-import org.apache.struts.action.ActionServlet;
-import org.apache.struts.action.ActionForm;
import org.apache.struts.chain.commands.util.ClassUtils;
import org.apache.struts.chain.contexts.ActionContext;
import org.apache.struts.chain.contexts.ServletActionContext;
-import org.apache.struts.validator.BeanValidatorForm;
import org.apache.struts.util.RequestUtils;
+import org.apache.struts.validator.BeanValidatorForm;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
/**
* <p>A JavaBean representing the configuration information of a
- * <code><form-bean></code> element in a Struts
- * configuration file.<p>
+ * <code><form-bean></code> element in a Struts configuration file.<p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2006-01-17 07:26:20 -0500 (Tue, 17 Jan 2006)
+ * $
* @since Struts 1.1
*/
-
public class FormBeanConfig extends BaseConfig {
-
private static final Log log = LogFactory.getLog(FormBeanConfig.class);
- // ----------------------------------------------------- Instance Variables
-
+ // ----------------------------------------------------- Instance Variables
/**
* The set of FormProperty elements defining dynamic form properties for
@@ -61,57 +54,80 @@
*/
protected HashMap formProperties = new HashMap();
-
/**
- * <p>The lockable object we can synchronize on when creating DynaActionFormClass.</p>
+ * <p>The lockable object we can synchronize on when creating
+ * DynaActionFormClass.</p>
*/
protected String lock = "";
-
// ------------------------------------------------------------- Properties
-
/**
* The DynaActionFormClass associated with a DynaActionForm.
*/
protected transient DynaActionFormClass dynaActionFormClass;
/**
- * <p>Return the DynaActionFormClass associated with a DynaActionForm.</p>
+ * Is the form bean class an instance of DynaActionForm with dynamic
+ * properties?
+ */
+ protected boolean dynamic = false;
+
+ /**
+ * The name of the FormBeanConfig that this config inherits configuration
+ * information from.
+ */
+ protected String inherit = null;
+
+ /**
+ * Have the inheritance values for this class been applied?
+ */
+ protected boolean extensionProcessed = false;
+
+ /**
+ * The unique identifier of this form bean, which is used to reference
+ * this bean in <code>ActionMapping</code> instances as well as for the
+ * name of the request or session attribute under which the corresponding
+ * form bean instance is created or accessed.
+ */
+ protected String name = null;
+
+ /**
+ * The fully qualified Java class name of the implementation class to be
+ * used or generated.
+ */
+ protected String type = null;
+
+ /**
+ * Is this DynaClass currently restricted (for DynaBeans with a
+ * MutableDynaClass).
+ */
+ protected boolean restricted = false;
+
+ /**
+ * <p>Return the DynaActionFormClass associated with a
+ * DynaActionForm.</p>
*
- * @exception IllegalArgumentException if the ActionForm is not dynamic
+ * @throws IllegalArgumentException if the ActionForm is not dynamic
*/
public DynaActionFormClass getDynaActionFormClass() {
-
if (dynamic == false) {
throw new IllegalArgumentException("ActionForm is not dynamic");
}
+
synchronized (lock) {
if (dynaActionFormClass == null) {
dynaActionFormClass = new DynaActionFormClass(this);
}
}
+
return dynaActionFormClass;
}
-
- /**
- * Is the form bean class an instance of DynaActionForm with dynamic
- * properties?
- */
- protected boolean dynamic = false;
-
public boolean getDynamic() {
return (this.dynamic);
}
-
- /**
- * The name of the FormBeanConfig that this config inherits configuration
- * information from.
- */
- protected String inherit = null;
-
public String getExtends() {
return (this.inherit);
}
@@ -121,25 +137,10 @@
this.inherit = extend;
}
-
- /**
- * Have the inheritance values for this class been applied?
- */
- protected boolean extensionProcessed = false;
-
public boolean isExtensionProcessed() {
return extensionProcessed;
}
-
- /**
- * The unique identifier of this form bean, which is used to reference this
- * bean in <code>ActionMapping</code> instances as well as for the name of
- * the request or session attribute under which the corresponding form bean
- * instance is created or accessed.
- */
- protected String name = null;
-
public String getName() {
return (this.name);
}
@@ -149,13 +150,6 @@
this.name = name;
}
-
- /**
- * The fully qualified Java class name of the implementation class
- * to be used or generated.
- */
- protected String type = null;
-
public String getType() {
return (this.type);
}
@@ -163,8 +157,10 @@
public void setType(String type) {
throwIfConfigured();
this.type = type;
+
Class dynaBeanClass = DynaActionForm.class;
Class formBeanClass = formBeanClass();
+
if (formBeanClass != null) {
if (dynaBeanClass.isAssignableFrom(formBeanClass)) {
this.dynamic = true;
@@ -177,43 +173,35 @@
}
/**
- * Is this DynaClass currently restricted (for DynaBeans with a MutableDynaClass).
- */
- protected boolean restricted = false;
-
- /**
* <p>Indicates whether a MutableDynaClass is currently restricted.</p>
* <p>If so, no changes to the existing registration of property names,
- * data types, readability, or writeability are allowed.</p>
+ * data types, readability, or writeability are allowed.</p>
*/
public boolean isRestricted() {
return restricted;
}
/**
- * <p>Set whether a MutableDynaClass is currently restricted.</p>
- * <p>If so, no changes to the existing registration of property names,
- * data types, readability, or writeability are allowed.</p>
+ * <p>Set whether a MutableDynaClass is currently restricted.</p> <p>If
+ * so, no changes to the existing registration of property names, data
+ * types, readability, or writeability are allowed.</p>
*/
public void setRestricted(boolean restricted) {
this.restricted = restricted;
}
-
// ------------------------------------------------------ Protected Methods
-
/**
* <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.
- *
+ * @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)) {
@@ -223,76 +211,71 @@
// get our ancestor's ancestor
FormBeanConfig ancestor =
moduleConfig.findFormBeanConfig(ancestorName);
+
ancestorName = ancestor.getExtends();
}
return false;
}
-
/**
* <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.
- *
+ * @param config The form bean config to copy properties from.
* @see #inheritFrom(FormBeanConfig)
*/
protected void inheritFormProperties(FormBeanConfig config)
- throws ClassNotFoundException,
- IllegalAccessException,
- InstantiationException,
- InvocationTargetException {
-
+ 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());
+ 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());
+ .applicationInstance(baseFpc.getClass()
+ .getName());
BeanUtils.copyProperties(prop, baseFpc);
this.addFormPropertyConfig(prop);
prop.setProperties(baseFpc.copyProperties());
}
-
}
}
-
// --------------------------------------------------------- Public Methods
-
/**
- * <p>Create and return an <code>ActionForm</code> instance appropriate
- * to the information in this <code>FormBeanConfig</code>.</p>
+ * <p>Create and return an <code>ActionForm</code> instance appropriate to
+ * the information in this <code>FormBeanConfig</code>.</p>
*
- * <p>Although this method is not formally deprecated yet, where possible, the
- * form which accepts an <code>ActionContext</code> as an argument is preferred,
- * to help sever direct dependencies on the Servlet API. As the ActionContext becomes
- * more familiar in Struts, this method will almost certainly be deprecated.</p>
+ * <p>Although this method is not formally deprecated yet, where possible,
+ * the form which accepts an <code>ActionContext</code> as an argument is
+ * preferred, to help sever direct dependencies on the Servlet API. As
+ * the ActionContext becomes more familiar in Struts, this method will
+ * almost certainly be deprecated.</p>
*
* @param servlet The action servlet
* @return ActionForm instance
- * @exception IllegalAccessException if the Class or the appropriate
- * constructor is not accessible
- * @exception InstantiationException if this Class represents an abstract
- * class, an array class, a primitive type, or void; or if instantiation
- * fails for some other reason
+ * @throws IllegalAccessException if the Class or the appropriate
+ * constructor is not accessible
+ * @throws InstantiationException if this Class represents an abstract
+ * class, an array class, a primitive type,
+ * or void; or if instantiation fails for
+ * some other reason
*/
public ActionForm createActionForm(ActionServlet servlet)
- throws IllegalAccessException, InstantiationException {
-
+ throws IllegalAccessException, InstantiationException {
Object obj = null;
// Create a new form bean instance
@@ -303,172 +286,179 @@
}
ActionForm form = null;
+
if (obj instanceof ActionForm) {
- form = (ActionForm)obj;
- } else {
+ form = (ActionForm) obj;
+ } else {
form = new BeanValidatorForm(obj);
}
form.setServlet(servlet);
- if (form instanceof DynaBean &&
- ((DynaBean)form).getDynaClass() instanceof MutableDynaClass) {
- DynaBean dynaBean = (DynaBean)form;
- MutableDynaClass dynaClass = (MutableDynaClass)dynaBean.getDynaClass();
+ if (form instanceof DynaBean
+ && ((DynaBean) form)
+ .getDynaClass() instanceof MutableDynaClass) {
+ DynaBean dynaBean = (DynaBean) form;
+ MutableDynaClass dynaClass = (MutableDynaClass) dynaBean
+ .getDynaClass();
// Add properties
dynaClass.setRestricted(false);
- FormPropertyConfig props[] = findFormPropertyConfigs();
+
+ 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());
+ dynaClass.setRestricted(isRestricted());
}
return form;
-
}
/**
- * <p>Create and return an <code>ActionForm</code> instance appropriate
- * to the information in this <code>FormBeanConfig</code>.</p>
+ * <p>Create and return an <code>ActionForm</code> instance appropriate to
+ * the information in this <code>FormBeanConfig</code>.</p>
* <p><b>NOTE:</b> If the given <code>ActionContext</code> is not of type
- * <code>ServletActionContext</code> (or a subclass), then the form which is
- * returned will have a null <code>servlet</code> property. Some of
- * the subclasses of <code>ActionForm</code> included in Struts will
- * later throw a <code>NullPointerException</code> in this case.
- * </p>
- * <p>TODO: Find a way to control this direct dependency on the Servlet API.</p>
+ * <code>ServletActionContext</code> (or a subclass), then the form which
+ * is returned will have a null <code>servlet</code> property. Some of
+ * the subclasses of <code>ActionForm</code> included in Struts will later
+ * throw a <code>NullPointerException</code> in this case. </p> <p>TODO:
+ * Find a way to control this direct dependency on the Servlet API.</p>
*
* @param context The ActionContext.
* @return ActionForm instance
- * @exception IllegalAccessException if the Class or the appropriate
- * constructor is not accessible
- * @exception InstantiationException if this Class represents an abstract
- * class, an array class, a primitive type, or void; or if instantiation
- * fails for some other reason
+ * @throws IllegalAccessException if the Class or the appropriate
+ * constructor is not accessible
+ * @throws InstantiationException if this Class represents an abstract
+ * class, an array class, a primitive type,
+ * or void; or if instantiation fails for
+ * some other reason
*/
public ActionForm createActionForm(ActionContext context)
- throws IllegalAccessException, InstantiationException {
-
+ throws IllegalAccessException, InstantiationException {
ActionServlet actionServlet = null;
+
if (context instanceof ServletActionContext) {
ServletActionContext saContext = (ServletActionContext) context;
+
actionServlet = saContext.getActionServlet();
}
+
return createActionForm(actionServlet);
}
/**
- * <p>Checks if the given <code>ActionForm</code> instance is suitable for
- * use as an alternative to calling this <code>FormBeanConfig</code>
+ * <p>Checks if the given <code>ActionForm</code> instance is suitable for
+ * use as an alternative to calling this <code>FormBeanConfig</code>
* instance's <code>createActionForm</code> method.</p>
- *
- * @param form an existing form instance that may be reused.
- * @return true if the given form can be reused as the form for this config.
+ *
+ * @param form an existing form instance that may be reused.
+ * @return true if the given form can be reused as the form for this
+ * config.
*/
public boolean canReuse(ActionForm form) {
if (form != null) {
if (this.getDynamic()) {
- String className =
- ((DynaBean) form).getDynaClass().getName();
+ String className = ((DynaBean) form).getDynaClass().getName();
+
if (className.equals(this.getName())) {
log.debug("Can reuse existing instance (dynamic)");
+
return (true);
}
} else {
try {
// check if the form's class is compatible with the class
// we're configured for
- Class formClass = form.getClass();
+ Class formClass = form.getClass();
+
if (form instanceof BeanValidatorForm) {
- // what we really want is to compare against the
+ // what we really want is to compare against the
// BeanValidatorForm's getInstance()
- BeanValidatorForm beanValidatorForm =
+ BeanValidatorForm beanValidatorForm =
(BeanValidatorForm) form;
- formClass = beanValidatorForm.getInstance().getClass();
+
+ formClass =
+ beanValidatorForm.getInstance().getClass();
}
-
- Class configClass =
- ClassUtils.getApplicationClass
- (this.getType());
+
+ Class configClass = ClassUtils.getApplicationClass(this
+ .getType());
+
if (configClass.isAssignableFrom(formClass)) {
log.debug("Can reuse existing instance (non-dynamic)");
+
return (true);
}
- } catch (Exception e) {
- log.debug("Error testing existing instance for reusability; just create a new instance", e);
+ }
+ catch (Exception e) {
+ log.debug(
+ "Error testing existing instance for reusability; just create a new instance",
+ e);
}
}
}
+
return false;
}
/**
- * Add a new <code>FormPropertyConfig</code> instance to the set associated
- * with this module.
+ * Add a new <code>FormPropertyConfig</code> instance to the set
+ * associated with this module.
*
* @param config The new configuration instance to be added
- *
- * @exception IllegalArgumentException if this property name has already
- * been defined
+ * @throws IllegalArgumentException if this property name has already been
+ * defined
*/
public void addFormPropertyConfig(FormPropertyConfig config) {
-
throwIfConfigured();
+
if (formProperties.containsKey(config.getName())) {
- throw new IllegalArgumentException("Property " +
- config.getName() +
- " already defined");
+ throw new IllegalArgumentException("Property " + config.getName()
+ + " already defined");
}
- formProperties.put(config.getName(), config);
+ formProperties.put(config.getName(), config);
}
-
/**
- * Return the form property configuration for the specified property
- * name, if any; otherwise return <code>null</code>.
+ * Return the form property configuration for the specified property name,
+ * if any; otherwise return <code>null</code>.
*
* @param name Form property name to find a configuration for
*/
public FormPropertyConfig findFormPropertyConfig(String name) {
-
return ((FormPropertyConfig) formProperties.get(name));
-
}
-
/**
- * Return the form property configurations for this module. If there
- * are none, a zero-length array is returned.
+ * Return the form property configurations for this module. If there are
+ * none, a zero-length array is returned.
*/
public FormPropertyConfig[] findFormPropertyConfigs() {
+ FormPropertyConfig[] results = new FormPropertyConfig[formProperties
+ .size()];
- FormPropertyConfig results[] =
- new FormPropertyConfig[formProperties.size()];
- return ((FormPropertyConfig[]) formProperties.values().toArray(results));
-
+ return ((FormPropertyConfig[]) formProperties.values()
+ .toArray(results));
}
-
/**
* Freeze the configuration of this component.
*/
public void freeze() {
-
super.freeze();
FormPropertyConfig[] fpconfigs = findFormPropertyConfigs();
+
for (int i = 0; i < fpconfigs.length; i++) {
fpconfigs[i].freeze();
}
-
}
-
/**
* <p>Inherit values that have not been overridden from the provided
* config object. Subclasses overriding this method should verify that
@@ -490,16 +480,13 @@
* extensions should be resolved before it's used as a parameter to this
* method.</p>
*
- * @param config The object that this instance will be inheriting
- * its values from.
+ * @param config The object that this instance will be inheriting its
+ * values from.
* @see #processExtends(ModuleConfig)
*/
public void inheritFrom(FormBeanConfig config)
- throws ClassNotFoundException,
- IllegalAccessException,
- InstantiationException,
- InvocationTargetException {
-
+ throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
throwIfConfigured();
// Inherit values that have not been overridden
@@ -519,27 +506,24 @@
inheritProperties(config);
}
-
/**
* <p>Inherit configuration information from the FormBeanConfig that this
* instance is extending. This method verifies that any form bean config
* object that it inherits from has also had its processExtends() method
* called.</p>
*
- * @param moduleConfig The {@link ModuleConfig} that this bean is from.
- *
+ * @param moduleConfig The {@link ModuleConfig} that this bean is from.
* @see #inheritFrom(FormBeanConfig)
*/
public void processExtends(ModuleConfig moduleConfig)
- throws ClassNotFoundException,
- IllegalAccessException,
- InstantiationException,
- InvocationTargetException {
-
+ throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
String ancestor = getExtends();
+
if ((!extensionProcessed) && (ancestor != null)) {
FormBeanConfig baseConfig =
moduleConfig.findFormBeanConfig(ancestor);
@@ -554,7 +538,7 @@
if (checkCircularInheritance(moduleConfig)) {
throw new IllegalArgumentException(
"Circular inheritance detected for form bean "
- + getName());
+ + getName());
}
// Make sure the ancestor's own extension has been processed.
@@ -569,28 +553,25 @@
extensionProcessed = true;
}
-
/**
* 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());
+ formProperties.remove(config.getName());
}
-
/**
* Return a String representation of this object.
*/
public String toString() {
-
StringBuffer sb = new StringBuffer("FormBeanConfig[");
+
sb.append("name=");
sb.append(this.name);
sb.append(",type=");
@@ -598,14 +579,12 @@
sb.append(",extends=");
sb.append(this.inherit);
sb.append("]");
- return (sb.toString());
+ return (sb.toString());
}
-
// ------------------------------------------------------ Protected Methods
-
/**
* Return the <code>Class</code> instance for the form bean implementation
* configured by this <code>FormBeanConfig</code> instance. This method
@@ -613,19 +592,18 @@
* but is reproduced to avoid a runtime dependence.
*/
protected Class formBeanClass() {
-
ClassLoader classLoader =
- Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().getContextClassLoader();
+
if (classLoader == null) {
classLoader = this.getClass().getClassLoader();
}
+
try {
return (classLoader.loadClass(getType()));
- } catch (Exception e) {
+ }
+ catch (Exception e) {
return (null);
}
-
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/config/FormPropertyConfig.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/FormPropertyConfig.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/FormPropertyConfig.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/FormPropertyConfig.java Fri Jan 20 16:19:02 2006
@@ -15,135 +15,140 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.config;
-
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
/**
* <p>A JavaBean representing the configuration information of a
- * <code><form-property></code> element in a Struts
- * configuration file.<p>
+ * <code><form-property></code> element in a Struts configuration
+ * file.<p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-11-12 11:52:08 -0500 (Sat, 12 Nov 2005)
+ * $
* @since Struts 1.1
*/
-
public class FormPropertyConfig extends BaseConfig {
-
/**
* The logging instance
*/
private static final Log log =
- LogFactory.getLog(FormPropertyConfig.class);
+ LogFactory.getLog(FormPropertyConfig.class);
+ // ----------------------------------------------------- Instance Variables
+ // ------------------------------------------------------------- Properties
- // ----------------------------------------------------------- Constructors
+ /**
+ * String representation of the initial value for this property.
+ */
+ protected String initial = null;
+
+ /**
+ * The JavaBean property name of the property described by this element.
+ */
+ protected String name = null;
+
+ /**
+ * <p>The conditions under which the property described by this element
+ * should be reset to its <code>initial</code> value when the form's
+ * <code>reset</code> method is called.</p> <p>This may be set to true (to
+ * always reset the property) or a comma-separated list of HTTP request
+ * methods.</p>
+ *
+ * @since Struts 1.3
+ */
+ protected String reset = null;
+
+ /**
+ * <p>The size of the array to be created if this property is an array
+ * type and there is no specified <code>initial</code> value. This value
+ * must be non-negative.</p>
+ *
+ * @since Struts 1.1
+ */
+ protected int size = 0;
+ /**
+ * The fully qualified Java class name of the implementation class of this
+ * bean property, optionally followed by <code>[]</code> to indicate that
+ * the property is indexed.
+ */
+ protected String type = null;
+
+ // ----------------------------------------------------------- Constructors
/**
* Standard no-arguments constructor for dynamic instantiation.
*/
public FormPropertyConfig() {
-
super();
-
}
-
/**
* Constructor that preconfigures the relevant properties.
*
- * @param name Name of this property
- * @param type Fully qualified class name of this property
+ * @param name Name of this property
+ * @param type Fully qualified class name of this property
* @param initial Initial value of this property (if any)
*/
public FormPropertyConfig(String name, String type, String initial) {
-
this(name, type, initial, 0);
-
}
-
/**
* Constructor that preconfigures the relevant properties.
*
- * @param name Name of this property
- * @param type Fully qualified class name of this property
+ * @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 reset The conditions under which this property will be reset
- * to its 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) {
-
+ public FormPropertyConfig(String name, String type, String initial,
+ String reset) {
this(name, type, initial, reset, 0);
-
}
-
/**
* Constructor that preconfigures the relevant properties.
*
- * @param name Name of this property
- * @param type Fully qualified class name of this property
+ * @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 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) {
-
+ public FormPropertyConfig(String name, String type, String initial,
+ int size) {
this(name, type, initial, null, size);
-
}
-
-
+
/**
* Constructor that preconfigures the relevant properties.
*
- * @param name Name of this property
- * @param type Fully qualified class name of this property
+ * @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.
+ * @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) {
-
+ public FormPropertyConfig(String name, String type, String initial,
+ String reset, int size) {
super();
setName(name);
setType(type);
setInitial(initial);
setReset(reset);
setSize(size);
-
}
-
- // ----------------------------------------------------- Instance Variables
-
-
-
- // ------------------------------------------------------------- Properties
-
-
- /**
- * String representation of the initial value for this property.
- */
- protected String initial = null;
-
public String getInitial() {
return (this.initial);
}
@@ -152,15 +157,10 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.initial = initial;
}
-
- /**
- * The JavaBean property name of the property described by this element.
- */
- protected String name = null;
-
public String getName() {
return (this.name);
}
@@ -169,20 +169,10 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.name = name;
}
-
- /**
- * <p>The conditions under which the property described by this element
- * should be reset to its <code>initial</code> value when the form's
- * <code>reset</code> method is called.</p>
- * <p>This may be set to true (to always reset the property) or a
- * comma-separated list of HTTP request methods.</p>
- * @since Struts 1.3
- */
- protected String reset = null;
-
public String getReset() {
return (this.reset);
}
@@ -191,20 +181,10 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.reset = reset;
}
-
-
- /**
- * <p>The size of the array to be created if this property is an array
- * type and there is no specified <code>initial</code> value. This
- * value must be non-negative.</p>
- *
- * @since Struts 1.1
- */
- protected int size = 0;
-
public int getSize() {
return (this.size);
}
@@ -213,21 +193,14 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
if (size < 0) {
throw new IllegalArgumentException("size < 0");
}
+
this.size = size;
}
-
-
- /**
- * The fully qualified Java class name of the implementation class
- * of this bean property, optionally followed by <code>[]</code> to
- * indicate that the property is indexed.
- */
- protected String type = null;
-
public String getType() {
return (this.type);
}
@@ -236,20 +209,20 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.type = type;
}
-
/**
* Return a Class corresponds to the value specified for the
- * <code>type</code> property, taking into account the trailing "[]"
- * for arrays (as well as the ability to specify primitive Java types).
+ * <code>type</code> property, taking into account the trailing "[]" for
+ * arrays (as well as the ability to specify primitive Java types).
*/
public Class getTypeClass() {
-
// Identify the base class (in case an array was specified)
String baseType = getType();
boolean indexed = false;
+
if (baseType.endsWith("[]")) {
baseType = baseType.substring(0, baseType.length() - 2);
indexed = true;
@@ -257,6 +230,7 @@
// Construct an appropriate Class instance for the base class
Class baseClass = null;
+
if ("boolean".equals(baseType)) {
baseClass = Boolean.TYPE;
} else if ("byte".equals(baseType)) {
@@ -274,14 +248,17 @@
} else if ("short".equals(baseType)) {
baseClass = Short.TYPE;
} else {
- ClassLoader classLoader =
- Thread.currentThread().getContextClassLoader();
+ ClassLoader classLoader = Thread.currentThread()
+ .getContextClassLoader();
+
if (classLoader == null) {
classLoader = this.getClass().getClassLoader();
}
+
try {
baseClass = classLoader.loadClass(baseType);
- } catch (Throwable t) {
+ }
+ catch (Throwable t) {
baseClass = null;
}
}
@@ -292,67 +269,59 @@
} else {
return (baseClass);
}
-
}
-
// --------------------------------------------------------- Public Methods
-
/**
* <p>Return an object representing the initial value of this property.
- * This is calculated according to the following algorithm:</p>
- * <ul>
- * <li>If the value you have specified for the <code>type</code>
- * property represents an array (i.e. it ends with "[]"):
- * <ul>
- * <li>If you have specified a value for the <code>initial</code>
- * property, <code>ConvertUtils.convert</code> will be
- * called to convert it into an instance of the specified
- * array type.</li>
- * <li>If you have not specified a value for the <code>initial</code>
- * property, an array of the length specified by the
- * <code>size</code> property will be created. Each element
- * of the array will be instantiated via the zero-args constructor
- * on the specified class (if any). Otherwise, <code>null</code>
- * will be returned.</li>
- * </ul></li>
- * <li>If the value you have specified for the <code>type</code>
- * property does not represent an array:
- * <ul>
- * <li>If you have specified a value for the <code>initial</code>
- * property, <code>ConvertUtils.convert</code>
- * will be called to convert it into an object instance.</li>
- * <li>If you have not specified a value for the <code>initial</code>
- * attribute, Struts will instantiate an instance via the
- * zero-args constructor on the specified class (if any).
- * Otherwise, <code>null</code> will be returned.</li>
- * </ul></li>
- * </ul>
+ * This is calculated according to the following algorithm:</p> <ul>
+ * <li>If the value you have specified for the <code>type</code> property
+ * represents an array (i.e. it ends with "[]"): <ul> <li>If you have
+ * specified a value for the <code>initial</code> property,
+ * <code>ConvertUtils.convert</code> will be called to convert it into an
+ * instance of the specified array type.</li> <li>If you have not
+ * specified a value for the <code>initial</code> property, an array of
+ * the length specified by the <code>size</code> property will be created.
+ * Each element of the array will be instantiated via the zero-args
+ * constructor on the specified class (if any). Otherwise,
+ * <code>null</code> will be returned.</li> </ul></li> <li>If the value
+ * you have specified for the <code>type</code> property does not
+ * represent an array: <ul> <li>If you have specified a value for the
+ * <code>initial</code> property, <code>ConvertUtils.convert</code> will
+ * be called to convert it into an object instance.</li> <li>If you have
+ * not specified a value for the <code>initial</code> attribute, Struts
+ * will instantiate an instance via the zero-args constructor on the
+ * specified class (if any). Otherwise, <code>null</code> will be
+ * returned.</li> </ul></li> </ul>
*/
public Object initial() {
-
Object initialValue = null;
+
try {
Class clazz = getTypeClass();
+
if (clazz.isArray()) {
if (initial != null) {
- initialValue =
- ConvertUtils.convert(initial, clazz);
+ initialValue = ConvertUtils.convert(initial, clazz);
} else {
- initialValue =
- Array.newInstance(clazz.getComponentType(), size);
+ initialValue = Array.newInstance(clazz.getComponentType(),
+ size);
+
if (!(clazz.getComponentType().isPrimitive())) {
for (int i = 0; i < size; i++) {
try {
Array.set(initialValue, i,
- clazz.getComponentType().newInstance());
- } catch (Throwable t) {
- log.error("Unable to create instance of " + clazz.getName() +
- " for property=" + name+
- ", type=" + type +
- ", initial=" + initial +
- ", size=" + size + ".");
+ clazz.getComponentType().newInstance());
+ }
+ catch (Throwable t) {
+ log.error("Unable to create instance of "
+ + clazz.getName() + " for property="
+ + name
+ + ", type=" + type + ", initial="
+ + initial
+ + ", size=" + size + ".");
+
//FIXME: Should we just dump the entire application/module ?
}
}
@@ -365,14 +334,14 @@
initialValue = clazz.newInstance();
}
}
- } catch (Throwable t) {
+ }
+ catch (Throwable t) {
initialValue = null;
}
- return (initialValue);
+ return (initialValue);
}
-
/**
* <p>Inherit values that have not been overridden from the provided
* config object. Subclasses overriding this method should verify that
@@ -389,15 +358,12 @@
* }
* </pre>
*
- * @param config The object that this instance will be inheriting
- * its values from.
+ * @param config The object that this instance will be inheriting its
+ * values from.
*/
- public void inheritFrom(FormPropertyConfig config)
- throws IllegalAccessException,
- InvocationTargetException,
- InstantiationException,
- ClassNotFoundException {
-
+ public void inheritFrom(FormPropertyConfig config)
+ throws IllegalAccessException, InvocationTargetException,
+ InstantiationException, ClassNotFoundException {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
@@ -417,7 +383,7 @@
if (getType() == null) {
setType(config.getType());
}
-
+
inheritProperties(config);
}
@@ -425,8 +391,8 @@
* Return a String representation of this object.
*/
public String toString() {
-
StringBuffer sb = new StringBuffer("FormPropertyConfig[");
+
sb.append("name=");
sb.append(this.name);
sb.append(",type=");
@@ -436,9 +402,7 @@
sb.append(",reset=");
sb.append(this.reset);
sb.append("]");
- return (sb.toString());
+ return (sb.toString());
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/config/ForwardConfig.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/ForwardConfig.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/ForwardConfig.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/ForwardConfig.java Fri Jan 20 16:19:02 2006
@@ -15,81 +15,130 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.config;
import java.lang.reflect.InvocationTargetException;
/**
* <p>A JavaBean representing the configuration information of a
- * <code><forward></code> element from a Struts
- * configuration file.</p>
+ * <code><forward></code> element from a Struts configuration file.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-08-14 17:24:39 -0400 (Sun, 14 Aug 2005)
+ * $
* @since Struts 1.1
*/
-
public class ForwardConfig extends BaseConfig {
+ // ------------------------------------------------------------- Properties
+ /**
+ * The name of the ForwardConfig that this object should inherit
+ * properties from.
+ */
+ protected String inherit = null;
- // ----------------------------------------------------------- Constructors
+ /**
+ * Have the inheritance values for this class been applied?
+ */
+ protected boolean extensionProcessed = false;
+
+ /**
+ * The unique identifier of this forward, which is used to reference it in
+ * <code>Action</code> classes.
+ */
+ protected String name = null;
+
+ /**
+ * <p>The URL to which this <code>ForwardConfig</code> entry points, which
+ * must start with a slash ("/") character. It is interpreted according
+ * to the following rules:</p> <ul> <li>If <code>contextRelative</code>
+ * property is <code>true</code>, the path is considered to be
+ * context-relative within the current web application (even if we are in
+ * a named module). It will be prefixed by the context path to create a
+ * server-relative URL.</li> <li>If the <code>contextRelative</code>
+ * property is false, the path is considered to be the module-relative
+ * portion of the URL. It will be used as the replacement for the
+ * <code>$P</code> marker in the <code>forwardPattern</code> property
+ * defined on the {@link ControllerConfig} element for our current module.
+ * For the default <code>forwardPattern</code> value of
+ * <code>$C$M$P</code>, the resulting server-relative URL will be the
+ * concatenation of the context path, the module prefix, and the
+ * <code>path</code> from this <code>ForwardConfig</code>.</li> </ul>
+ */
+ protected String path = null;
+
+ /**
+ * <p>The prefix of the module to which this <code>ForwardConfig</code>
+ * entry points, which must start with a slash ("/") character. </p>
+ * <p>Usage note: If a forward config is used in a hyperlink, and a module
+ * is specified, the path must lead to another action and not directly to
+ * a page. This is in keeping with rule that in a modular application all
+ * links must be to an action rather than a page. </p>
+ */
+ protected String module = null;
+
+ /**
+ * Should a redirect be used to transfer control to the specified path?
+ */
+ protected boolean redirect = false;
+
+ /**
+ * <p>The name of a <code>commons-chain</code> command which should be
+ * looked up and executed before Struts dispatches control to the view
+ * represented by this config.</p>
+ */
+ protected String command = null;
+
+ /**
+ * <p>The name of a <code>commons-chain</code> catalog in which
+ * <code>command</code> should be looked up. If this value is undefined,
+ * then the command will be looked up in the "default" catalog. This
+ * value has no meaning except in the context of the <code>command</code>
+ * property.</p>
+ */
+ protected String catalog = null;
+ // ----------------------------------------------------------- Constructors
/**
* Construct a new instance with default values.
*/
public ForwardConfig() {
-
super();
-
}
-
/**
* Construct a new instance with the specified values.
*
- * @param name Name of this forward
- * @param path Path to which control should be forwarded or redirected
+ * @param name Name of this forward
+ * @param path Path to which control should be forwarded or
+ * redirected
* @param redirect Should we do a redirect?
*/
public ForwardConfig(String name, String path, boolean redirect) {
-
super();
setName(name);
setPath(path);
setRedirect(redirect);
-
}
-
/**
* <p>Construct a new instance with the specified values.</p>
- * @param name Name of this forward
- * @param path Path to which control should be forwarded or redirected
+ *
+ * @param name Name of this forward
+ * @param path Path to which control should be forwarded or
+ * redirected
* @param redirect Should we do a redirect?
- * @param module Module prefix, if any
+ * @param module Module prefix, if any
*/
public ForwardConfig(String name, String path, boolean redirect,
String module) {
-
super();
setName(name);
setPath(path);
setRedirect(redirect);
setModule(module);
-
}
- // ------------------------------------------------------------- Properties
-
-
- /**
- * The name of the ForwardConfig that this object should inherit properties
- * from.
- */
- protected String inherit = null;
-
public String getExtends() {
return (this.inherit);
}
@@ -98,26 +147,14 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.inherit = inherit;
}
-
- /**
- * Have the inheritance values for this class been applied?
- */
- protected boolean extensionProcessed = false;
-
public boolean isExtensionProcessed() {
return extensionProcessed;
}
-
- /**
- * The unique identifier of this forward, which is used to reference it
- * in <code>Action</code> classes.
- */
- protected String name = null;
-
public String getName() {
return (this.name);
}
@@ -126,32 +163,10 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.name = name;
}
-
- /**
- * <p>The URL to which this <code>ForwardConfig</code> entry points,
- * which must start with a slash ("/") character. It is
- * interpreted according to the following rules:</p>
- * <ul>
- * <li>If <code>contextRelative</code> property is <code>true</code>, the
- * path is considered to be context-relative within the current web
- * application (even if we are in a named module). It will be
- * prefixed by the context path to create a server-relative URL.</li>
- * <li>If the <code>contextRelative</code> property is false, the path is
- * considered to be the module-relative portion of the URL.
- * It will be used as the replacement for the <code>$P</code>
- * marker in the <code>forwardPattern</code> property defined on the
- * {@link ControllerConfig} element for our current module.
- * For the default <code>forwardPattern</code> value of
- * <code>$C$M$P</code>, the resulting server-relative URL will be
- * the concatenation of the context path, the module prefix,
- * and the <code>path</code> from this <code>ForwardConfig</code>.</li>
- * </ul>
- */
- protected String path = null;
-
public String getPath() {
return (this.path);
}
@@ -160,22 +175,10 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.path = path;
}
-
- /**
- * <p>The prefix of the module to which this <code>ForwardConfig</code> entry points,
- * which must start with a slash ("/") character. </p>
- * <p>Usage note: If a forward config is used in a hyperlink,
- * and a module is specified, the path must lead to another
- * action and not directly to a page. This is in keeping with
- * rule that in a modular application all links must be to
- * an action rather than a page.
- * </p>
- */
- protected String module = null;
-
public String getModule() {
return (this.module);
}
@@ -184,15 +187,10 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.module = module;
}
-
- /**
- * Should a redirect be used to transfer control to the specified path?
- */
- protected boolean redirect = false;
-
public boolean getRedirect() {
return (this.redirect);
}
@@ -201,17 +199,10 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.redirect = redirect;
}
-
- /**
- * <p>The name of a <code>commons-chain</code> command which should be
- * looked up and executed before Struts dispatches control to the view
- * represented by this config.</p>
- */
- protected String command = null;
-
public String getCommand() {
return (this.command);
}
@@ -220,18 +211,10 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.command = command;
}
-
- /**
- * <p>The name of a <code>commons-chain</code> catalog in which <code>command</code>
- * should be looked up. If this value is undefined, then the command will be
- * looked up in the "default" catalog. This value has no meaning except in
- * the context of the <code>command</code> property.</p>
- */
- protected String catalog = null;
-
public String getCatalog() {
return (this.catalog);
}
@@ -240,27 +223,26 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.catalog = catalog;
}
-
// ------------------------------------------------------ Protected Methods
-
/**
* <p>Traces the hierarchy of this object to check if any of the ancestors
* are extending this instance.</p>
*
- * @param moduleConfig The {@link ModuleConfig} that this config is from.
- * @param actionConfig The {@link ActionConfig} that this config is from,
- * if applicable. This parameter must be null if this
- * forward config is a global forward.
- *
+ * @param moduleConfig The {@link ModuleConfig} that this config is from.
+ * @param actionConfig The {@link ActionConfig} that this config is from,
+ * if applicable. This parameter must be null if this
+ * forward config is a global forward.
* @return true if circular inheritance was detected.
*/
protected boolean checkCircularInheritance(ModuleConfig moduleConfig,
ActionConfig actionConfig) {
String ancestorName = getExtends();
+
if (ancestorName == null) {
return false;
}
@@ -281,6 +263,7 @@
// Then check the global forwards
if (ancestor == null) {
ancestor = moduleConfig.findForwardConfig(ancestorName);
+
if (ancestor != null) {
// If the ancestor is a global forward, set actionConfig
// to null so further searches are only done among
@@ -322,6 +305,7 @@
// Then check the global forwards
if (ancestor == null) {
ancestor = moduleConfig.findForwardConfig(ancestorName);
+
if (ancestor != null) {
// Limit further checks to moduleConfig.
actionConfig = null;
@@ -332,10 +316,8 @@
return false;
}
-
// --------------------------------------------------------- Public Methods
-
/**
* <p>Inherit values that have not been overridden from the provided
* config object. Subclasses overriding this method should verify that
@@ -357,16 +339,13 @@
* extensions should be resolved before it's used as a parameter to this
* method.</p>
*
- * @param config The object that this instance will be inheriting
- * its values from.
+ * @param config The object that this instance will be inheriting its
+ * values from.
* @see #processExtends(ModuleConfig, ActionConfig)
*/
public void inheritFrom(ForwardConfig config)
- throws ClassNotFoundException,
- IllegalAccessException,
- InstantiationException,
- InvocationTargetException {
-
+ throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
@@ -399,31 +378,28 @@
inheritProperties(config);
}
-
/**
* <p>Inherit configuration information from the ForwardConfig that this
* instance is extending. This method verifies that any forward config
* object that it inherits from has also had its processExtends() method
* called.</p>
*
- * @param moduleConfig The {@link ModuleConfig} that this config is from.
- * @param actionConfig The {@link ActionConfig} that this config is from,
- * if applicable. This must be null for global
- * forwards.
- *
+ * @param moduleConfig The {@link ModuleConfig} that this config is from.
+ * @param actionConfig The {@link ActionConfig} that this config is from,
+ * if applicable. This must be null for global
+ * forwards.
* @see #inheritFrom(ForwardConfig)
*/
public void processExtends(ModuleConfig moduleConfig,
ActionConfig actionConfig)
- throws ClassNotFoundException,
- IllegalAccessException,
- InstantiationException,
- InvocationTargetException {
-
+ throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
String ancestorName = getExtends();
+
if ((!extensionProcessed) && (ancestorName != null)) {
ForwardConfig baseConfig = null;
@@ -432,7 +408,7 @@
(this != moduleConfig.findForwardConfig(getName()));
// ... and the action config was provided
- checkActionConfig &= actionConfig != null;
+ checkActionConfig &= (actionConfig != null);
// ... and we're not extending a config with the same name
// (because if we are, that means we're an action-level forward
@@ -450,8 +426,8 @@
}
if (baseConfig == null) {
- throw new NullPointerException("Unable to find "
- + "forward '" + ancestorName + "' to extend.");
+ throw new NullPointerException("Unable to find " + "forward '"
+ + ancestorName + "' to extend.");
}
// Check for circular inheritance and make sure the base config's
@@ -459,7 +435,7 @@
if (checkCircularInheritance(moduleConfig, actionConfig)) {
throw new IllegalArgumentException(
"Circular inheritance detected for forward "
- + getName());
+ + getName());
}
if (!baseConfig.isExtensionProcessed()) {
@@ -477,8 +453,8 @@
* Return a String representation of this object.
*/
public String toString() {
-
StringBuffer sb = new StringBuffer("ForwardConfig[");
+
sb.append("name=");
sb.append(this.name);
sb.append(",path=");
@@ -494,10 +470,7 @@
sb.append(",command=");
sb.append(this.command);
sb.append("]");
- return (sb.toString());
+ return (sb.toString());
}
-
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/config/MessageResourcesConfig.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/MessageResourcesConfig.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/MessageResourcesConfig.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/MessageResourcesConfig.java Fri Jan 20 16:19:02 2006
@@ -15,35 +15,51 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.config;
-
-import java.io.Serializable;
import org.apache.struts.Globals;
-
/**
* <p>A JavaBean representing the configuration information of a
- * <code><message-resources></code> element in a Struts
- * configuration file.</p>
+ * <code><message-resources></code> element in a Struts configuration
+ * file.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-08-29 23:57:50 -0400 (Mon, 29 Aug 2005)
+ * $
* @since Struts 1.1
*/
-
public class MessageResourcesConfig extends BaseConfig {
-
// ------------------------------------------------------------- Properties
-
/**
- * Fully qualified Java class name of the MessageResourcesFactory class
- * we should use.
+ * Fully qualified Java class name of the MessageResourcesFactory class we
+ * should use.
*/
protected String factory =
- "org.apache.struts.util.PropertyMessageResourcesFactory";
+ "org.apache.struts.util.PropertyMessageResourcesFactory";
+
+ /**
+ * The servlet context attributes key under which this MessageResources
+ * instance is stored.
+ */
+ protected String key = Globals.MESSAGES_KEY;
+
+ /**
+ * Should we return <code>null</code> for unknown message keys?
+ */
+ protected boolean nullValue = true;
+
+ /**
+ * Indicates whether 'escape processing' should be performed on the error
+ * message string.
+ */
+ private boolean escape = true;
+
+ /**
+ * Parameter that is passed to the <code>createResources()</code> method
+ * of our MessageResourcesFactory implementation.
+ */
+ protected String parameter = null;
public String getFactory() {
return (this.factory);
@@ -53,16 +69,10 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.factory = factory;
}
-
- /**
- * The servlet context attributes key under which this MessageResources
- * instance is stored.
- */
- protected String key = Globals.MESSAGES_KEY;
-
public String getKey() {
return (this.key);
}
@@ -71,15 +81,10 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.key = key;
}
-
- /**
- * Should we return <code>null</code> for unknown message keys?
- */
- protected boolean nullValue = true;
-
public boolean getNull() {
return (this.nullValue);
}
@@ -88,18 +93,13 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.nullValue = nullValue;
}
/**
- * Indicates whether 'escape processing' should be performed on
- * the error message string.
- */
- private boolean escape = true;
-
- /**
- * Indicates whether 'escape processing' should be performed on
- * the error message string.
+ * Indicates whether 'escape processing' should be performed on the error
+ * message string.
*
* @since Struts 1.2.8
*/
@@ -108,8 +108,8 @@
}
/**
- * Set whether 'escape processing' should be performed on
- * the error message string.
+ * Set whether 'escape processing' should be performed on the error
+ * message string.
*
* @since Struts 1.2.8
*/
@@ -117,12 +117,6 @@
this.escape = escape;
}
- /**
- * Parameter that is passed to the <code>createResources()</code> method
- * of our MessageResourcesFactory implementation.
- */
- protected String parameter = null;
-
public String getParameter() {
return (this.parameter);
}
@@ -131,18 +125,18 @@
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
+
this.parameter = parameter;
}
-
// --------------------------------------------------------- Public Methods
/**
* Return a String representation of this object.
*/
public String toString() {
-
StringBuffer sb = new StringBuffer("MessageResourcesConfig[");
+
sb.append("factory=");
sb.append(this.factory);
sb.append(",null=");
@@ -152,9 +146,7 @@
sb.append(",parameter=");
sb.append(this.parameter);
sb.append("]");
- return (sb.toString());
+ return (sb.toString());
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/config/ModuleConfig.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/ModuleConfig.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/ModuleConfig.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/ModuleConfig.java Fri Jan 20 16:19:02 2006
@@ -17,22 +17,24 @@
*/
package org.apache.struts.config;
+
/**
* <p>The collection of static configuration information that describes a
- * Struts-based module. Multiple modules are identified by
- * a <em>prefix</em> at the beginning of the context
- * relative portion of the request URI. If no module prefix can be
- * matched, the default configuration (with a prefix equal to a zero-length
- * string) is selected, which is elegantly backwards compatible with the
- * previous Struts behavior that only supported one module.</p>
+ * Struts-based module. Multiple modules are identified by a <em>prefix</em>
+ * at the beginning of the context relative portion of the request URI. If no
+ * module prefix can be matched, the default configuration (with a prefix
+ * equal to a zero-length string) is selected, which is elegantly backwards
+ * compatible with the previous Struts behavior that only supported one
+ * module.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-08-06 04:12:10 -0400 (Sat, 06 Aug 2005)
+ * $
* @since Struts 1.1
*/
public interface ModuleConfig {
/**
- * Has this module been completely configured yet. Once this flag
- * has been set, any attempt to modify the configuration will return an
+ * Has this module been completely configured yet. Once this flag has
+ * been set, any attempt to modify the configuration will return an
* IllegalStateException.
*/
boolean getConfigured();
@@ -41,11 +43,12 @@
* The controller configuration object for this module.
*/
ControllerConfig getControllerConfig();
+
/**
* The controller configuration object for this module.
- * @param cc The controller configuration object for this module.
+ *
+ * @param cc The controller configuration object for this module.
*/
-
void setControllerConfig(ControllerConfig cc);
/**
@@ -61,7 +64,9 @@
* select this configuration versus others supported by the controller
* servlet. A configuration with a prefix of a zero-length String is the
* default configuration for this web module.
- * @param prefix The prefix of the context-relative portion of the request URI.
+ *
+ * @param prefix The prefix of the context-relative portion of the request
+ * URI.
*/
public void setPrefix(String prefix);
@@ -76,17 +81,19 @@
* instances.
*
* @param actionFormBeanClass default class name to be used when creating
- * action form bean instances.
+ * action form bean instances.
*/
void setActionFormBeanClass(String actionFormBeanClass);
/**
- * The default class name to be used when creating action mapping instances.
+ * The default class name to be used when creating action mapping
+ * instances.
*/
String getActionMappingClass();
/**
- * The default class name to be used when creating action mapping instances.
+ * The default class name to be used when creating action mapping
+ * instances.
*
* @param actionMappingClass default class name to be used when creating
* action mapping instances.
@@ -94,13 +101,12 @@
void setActionMappingClass(String actionMappingClass);
/**
- * Add a new <code>ActionConfig</code> instance to the set associated
- * with this module.
+ * Add a new <code>ActionConfig</code> instance to the set associated with
+ * this module.
*
* @param config The new configuration instance to be added
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
void addActionConfig(ActionConfig config);
@@ -109,9 +115,8 @@
* with this module.
*
* @param config The new configuration instance to be added
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
void addExceptionConfig(ExceptionConfig config);
@@ -120,19 +125,20 @@
* with this module.
*
* @param config The new configuration instance to be added
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
void addFormBeanConfig(FormBeanConfig config);
/**
- * The default class name to be used when creating action forward instances.
+ * The default class name to be used when creating action forward
+ * instances.
*/
String getActionForwardClass();
/**
- * The default class name to be used when creating action forward instances.
+ * The default class name to be used when creating action forward
+ * instances.
*
* @param actionForwardClass default class name to be used when creating
* action forward instances.
@@ -144,9 +150,8 @@
* forwards associated with this module.
*
* @param config The new configuration instance to be added
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
void addForwardConfig(ForwardConfig config);
@@ -155,14 +160,13 @@
* associated with this module.
*
* @param config The new configuration instance to be added
- *
- * @exception IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
void addMessageResourcesConfig(MessageResourcesConfig config);
/**
- * Add a newly configured {@link org.apache.struts.config.PlugInConfig} instance to the set of
+ * Add a newly configured {@link PlugInConfig} instance to the set of
* plug-in Actions for this module.
*
* @param plugInConfig The new configuration instance to be added
@@ -178,8 +182,8 @@
ActionConfig findActionConfig(String path);
/**
- * Return the action configurations for this module. If there are
- * none, a zero-length array is returned.
+ * Return the action configurations for this module. If there are none, a
+ * zero-length array is returned.
*/
ActionConfig[] findActionConfigs();
@@ -192,20 +196,20 @@
ExceptionConfig findExceptionConfig(String type);
/**
- * Perform a recursive search for an ExceptionConfig registered for this class, or for any
- * superclass. This should only be used in the case when an <code>ActionConfig</code>
- * is not available; otherwise, use <code>ActionConfig.findException(Class)</code>
- * to preserve the search order.
+ * Perform a recursive search for an ExceptionConfig registered for this
+ * class, or for any superclass. This should only be used in the case
+ * when an <code>ActionConfig</code> is not available; otherwise, use
+ * <code>ActionConfig.findException(Class)</code> to preserve the search
+ * order.
*
* @param type Exception class name to find a configuration for
* @see ActionConfig.findException(Class)
*/
ExceptionConfig findException(Class type);
-
/**
- * Return the exception configurations for this module. If there
- * are none, a zero-length array is returned.
+ * Return the exception configurations for this module. If there are
+ * none, a zero-length array is returned.
*/
ExceptionConfig[] findExceptionConfigs();
@@ -218,8 +222,8 @@
FormBeanConfig findFormBeanConfig(String name);
/**
- * Return the form bean configurations for this module. If there
- * are none, a zero-length array is returned.
+ * Return the form bean configurations for this module. If there are
+ * none, a zero-length array is returned.
*/
FormBeanConfig[] findFormBeanConfigs();
@@ -232,35 +236,35 @@
ForwardConfig findForwardConfig(String name);
/**
- * Return the form bean configurations for this module. If there
- * are none, a zero-length array is returned.
+ * Return the form bean configurations for this module. If there are
+ * none, a zero-length array is returned.
*/
ForwardConfig[] findForwardConfigs();
/**
- * Return the message resources configuration for the specified key,
- * if any; otherwise return <code>null</code>.
+ * Return the message resources configuration for the specified key, if
+ * any; otherwise return <code>null</code>.
*
* @param key Key of the data source configuration to return
*/
MessageResourcesConfig findMessageResourcesConfig(String key);
/**
- * Return the message resources configurations for this module.
- * If there are none, a zero-length array is returned.
+ * Return the message resources configurations for this module. If there
+ * are none, a zero-length array is returned.
*/
MessageResourcesConfig[] findMessageResourcesConfigs();
/**
- * Return the configured plug-in actions for this module. If there
- * are none, a zero-length array is returned.
+ * Return the configured plug-in actions for this module. If there are
+ * none, a zero-length array is returned.
*/
PlugInConfig[] findPlugInConfigs();
/**
- * Freeze the configuration of this module. After this method
- * returns, any attempt to modify the configuration will return
- * an IllegalStateException.
+ * Freeze the configuration of this module. After this method returns,
+ * any attempt to modify the configuration will return an
+ * IllegalStateException.
*/
void freeze();
@@ -268,9 +272,8 @@
* Remove the specified action configuration instance.
*
* @param config ActionConfig instance to be removed
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
void removeActionConfig(ActionConfig config);
@@ -278,9 +281,8 @@
* Remove the specified exception configuration instance.
*
* @param config ActionConfig instance to be removed
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
void removeExceptionConfig(ExceptionConfig config);
@@ -288,9 +290,8 @@
* Remove the specified form bean configuration instance.
*
* @param config FormBeanConfig instance to be removed
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
void removeFormBeanConfig(FormBeanConfig config);
@@ -298,9 +299,8 @@
* Remove the specified forward configuration instance.
*
* @param config ForwardConfig instance to be removed
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
void removeForwardConfig(ForwardConfig config);
@@ -308,9 +308,8 @@
* Remove the specified message resources configuration instance.
*
* @param config MessageResourcesConfig instance to be removed
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
void removeMessageResourcesConfig(MessageResourcesConfig config);
}
Modified: struts/action/trunk/src/java/org/apache/struts/config/ModuleConfigFactory.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/ModuleConfigFactory.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/ModuleConfigFactory.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/ModuleConfigFactory.java Fri Jan 20 16:19:02 2006
@@ -15,37 +15,55 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.config;
-import org.apache.struts.util.RequestUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.struts.util.RequestUtils;
/**
* A factory interface for creating {@link ModuleConfig}s.
*
- * @version $Rev$ $Date$
- *
+ * @version $Rev$ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
+ * $
* @see ModuleConfig
*/
public abstract class ModuleConfigFactory {
+ /**
+ * The Java class to be used for <code>ModuleConfigFactory</code>
+ * instances.
+ */
+ protected static Class clazz = null;
+
+ /**
+ * Commons Logging instance.
+ */
+ private static final Log LOG =
+ LogFactory.getLog(ModuleConfigFactory.class);
/**
- * Create and return a newly instansiated {@link ModuleConfig}.
- * This method must be implemented by concrete subclasses.
+ * The fully qualified class name to be used for <code>ModuleConfigFactory</code>
+ * instances.
+ */
+ protected static String factoryClass =
+ "org.apache.struts.config.impl.DefaultModuleConfigFactory";
+
+ /**
+ * Create and return a newly instansiated {@link ModuleConfig}. This
+ * method must be implemented by concrete subclasses.
*
* @param prefix Module prefix for Configuration
*/
public abstract ModuleConfig createModuleConfig(String prefix);
-
// ------------------------------------------------------ Static Properties
+
/**
- * The fully qualified class name that is used for
- * <code>ModuleConfigFactory</code> instances.
- * @return class name that is used for
- * <code>ModuleConfigFactory</code> instances
+ * The fully qualified class name that is used for <code>ModuleConfigFactory</code>
+ * instances.
+ *
+ * @return class name that is used for <code>ModuleConfigFactory</code>
+ * instances
*/
public static String getFactoryClass() {
return (ModuleConfigFactory.factoryClass);
@@ -54,8 +72,9 @@
/**
* Set the fully qualified class name that is used for
* <code>ModuleConfigFactory</code> instances.
- * @param factoryClass name that is used for
- * <code>ModuleConfigFactory</code> instances
+ *
+ * @param factoryClass name that is used for <code>ModuleConfigFactory</code>
+ * instances
*/
public static void setFactoryClass(String factoryClass) {
ModuleConfigFactory.factoryClass = factoryClass;
@@ -64,7 +83,6 @@
// --------------------------------------------------------- Static Methods
-
/**
* Create and return a <code>ModuleConfigFactory</code> instance of the
* appropriate class, which can be used to create customized
@@ -72,7 +90,6 @@
* created, return <code>null</code> instead.
*/
public static ModuleConfigFactory createFactory() {
-
ModuleConfigFactory factory = null;
try {
@@ -81,38 +98,17 @@
}
factory = (ModuleConfigFactory) clazz.newInstance();
-
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e) {
LOG.error("ModuleConfigFactory.createFactory()", e);
- } catch (InstantiationException e) {
+ }
+ catch (InstantiationException e) {
LOG.error("ModuleConfigFactory.createFactory()", e);
- } catch (IllegalAccessException e) {
+ }
+ catch (IllegalAccessException e) {
LOG.error("ModuleConfigFactory.createFactory()", e);
}
return factory;
-
}
-
-
- /**
- * The Java class to be used for
- * <code>ModuleConfigFactory</code> instances.
- */
- protected static Class clazz = null;
-
- /**
- * Commons Logging instance.
- */
- private static final Log LOG = LogFactory.getLog(ModuleConfigFactory.class);
-
-
- /**
- * The fully qualified class name to be used for
- * <code>ModuleConfigFactory</code> instances.
- */
- protected static String factoryClass =
- "org.apache.struts.config.impl.DefaultModuleConfigFactory";
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/config/PlugInConfig.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/PlugInConfig.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/PlugInConfig.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/PlugInConfig.java Fri Jan 20 16:19:02 2006
@@ -15,52 +15,42 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.config;
-
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
-
/**
* <p>A JavaBean representing the configuration information of a
- * <code><plug-in></code> element in a Struts
- * configuration file.</p>
- * <p>Note that this class does not extend <code>BaseConfig</code> because it is more "internal"
- * than the other classes which do, and because this class has an existing "properties" object
- * which collides with the one in <code>BaseConfig</code>. Also, since one always writes a concrete
- * PlugIn implementation, there seems to be less call for an arbitrary property map; one can simply
- * use bean properties instead.</p>
- *
- * @version $Rev$ $Date$
+ * <code><plug-in></code> element in a Struts configuration file.</p>
+ * <p>Note that this class does not extend <code>BaseConfig</code> because it
+ * is more "internal" than the other classes which do, and because this class
+ * has an existing "properties" object which collides with the one in
+ * <code>BaseConfig</code>. Also, since one always writes a concrete PlugIn
+ * implementation, there seems to be less call for an arbitrary property map;
+ * one can simply use bean properties instead.</p>
+ *
+ * @version $Rev$ $Date: 2005-05-12 18:41:19 -0400 (Thu, 12 May 2005)
+ * $
* @since Struts 1.1
*/
-
public class PlugInConfig implements Serializable {
-
-
// ----------------------------------------------------- Instance Variables
-
/**
* Has this component been completely configured?
*/
protected boolean configured = false;
-
/**
* A <code>Map</code> of the name-value pairs that will be used to
* configure the property values of a <code>PlugIn</code> instance.
*/
protected Map properties = new HashMap();
-
// ------------------------------------------------------------- Properties
-
/**
* The fully qualified Java class name of the <code>PlugIn</code>
* implementation class being configured.
@@ -75,46 +65,35 @@
this.className = className;
}
-
// --------------------------------------------------------- Public Methods
-
/**
* Add a new property name and value to the set that will be used to
* configure the <code>PlugIn</code> instance.
*
- * @param name Property name
+ * @param name Property name
* @param value Property value
*/
public void addProperty(String name, String value) {
-
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
- properties.put(name, value);
+ properties.put(name, value);
}
-
/**
* Freeze the configuration of this component.
*/
public void freeze() {
-
configured = true;
-
}
-
/**
* Return the properties that will be used to configure a
* <code>PlugIn</code> instance.
*/
public Map getProperties() {
-
return (properties);
-
}
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org