You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2002/01/17 22:26:18 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/config FormPropertyConfig.java
craigmcc 02/01/17 13:26:18
Modified: src/share/org/apache/struts/action DynaActionFormClass.java
src/share/org/apache/struts/config FormPropertyConfig.java
Log:
Revision Changes Path
1.2 +5 -15 jakarta-struts/src/share/org/apache/struts/action/DynaActionFormClass.java
Index: DynaActionFormClass.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/DynaActionFormClass.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DynaActionFormClass.java 17 Jan 2002 00:15:05 -0000 1.1
+++ DynaActionFormClass.java 17 Jan 2002 21:26:18 -0000 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/DynaActionFormClass.java,v 1.1 2002/01/17 00:15:05 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2002/01/17 00:15:05 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/DynaActionFormClass.java,v 1.2 2002/01/17 21:26:18 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2002/01/17 21:26:18 $
*
* ====================================================================
*
@@ -82,7 +82,7 @@
* to consult this documentation.</p>
*
* @author Craig McClanahan
- * @version $Revision: 1.1 $ $Date: 2002/01/17 00:15:05 $
+ * @version $Revision: 1.2 $ $Date: 2002/01/17 21:26:18 $
* @since Struts 1.1
*/
@@ -341,19 +341,9 @@
// Create corresponding dynamic property definitions
properties = new DynaProperty[descriptors.length];
for (int i = 0; i < descriptors.length; i++) {
- // FIXME - special handling needed for arrays???
- Class clazz = null;
- try {
- // FIXME - thread context class loader?
- clazz = Class.forName(descriptors[i].getType());
- } catch (Throwable t) {
- throw new IllegalArgumentException
- ("Cannot instantiate property class '" +
- descriptors[i].getType() + "' for property '" +
- descriptors[i].getName() + "'");
- }
properties[i] =
- new DynaProperty(descriptors[i].getName(), clazz);
+ new DynaProperty(descriptors[i].getName(),
+ descriptors[i].getTypeClass());
propertiesMap.put(properties[i].getName(),
properties[i]);
}
1.3 +58 -4 jakarta-struts/src/share/org/apache/struts/config/FormPropertyConfig.java
Index: FormPropertyConfig.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/FormPropertyConfig.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FormPropertyConfig.java 17 Jan 2002 00:15:05 -0000 1.2
+++ FormPropertyConfig.java 17 Jan 2002 21:26:18 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/FormPropertyConfig.java,v 1.2 2002/01/17 00:15:05 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2002/01/17 00:15:05 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/FormPropertyConfig.java,v 1.3 2002/01/17 21:26:18 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/01/17 21:26:18 $
*
* ====================================================================
*
@@ -64,6 +64,7 @@
import java.io.Serializable;
+import java.lang.reflect.Array;
import org.apache.commons.beanutils.ConvertUtils;
@@ -73,7 +74,7 @@
* configuration file.<p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2002/01/17 00:15:05 $
+ * @version $Revision: 1.3 $ $Date: 2002/01/17 21:26:18 $
* @since Struts 1.1
*/
@@ -140,6 +141,59 @@
public void setType(String type) {
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).
+ */
+ 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;
+ }
+
+ // Construct an appropriate Class instance for the base class
+ Class baseClass = null;
+ if ("boolean".equals(baseType)) {
+ baseClass = Boolean.TYPE;
+ } else if ("byte".equals(baseType)) {
+ baseClass = Byte.TYPE;
+ } else if ("char".equals(baseType)) {
+ baseClass = Character.TYPE;
+ } else if ("double".equals(baseType)) {
+ baseClass = Double.TYPE;
+ } else if ("float".equals(baseType)) {
+ baseClass = Float.TYPE;
+ } else if ("int".equals(baseType)) {
+ baseClass = Integer.TYPE;
+ } else if ("long".equals(baseType)) {
+ baseClass = Long.TYPE;
+ } else if ("short".equals(baseType)) {
+ baseClass = Short.TYPE;
+ } else {
+ // FIXME - thread context class loader?
+ try {
+ baseClass = Class.forName(baseType);
+ } catch (Throwable t) {
+ baseClass = null;
+ }
+ }
+
+ // Return the base class or an array appropriately
+ if (indexed) {
+ return (Array.newInstance(baseClass, 0).getClass());
+ } else {
+ return (baseClass);
+ }
+
+ }
+
// --------------------------------------------------------- Public Methods
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit: jakarta-struts/src/share/org/apache/struts/config
FormPropertyConfig.java
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On 17 Jan 2002 craigmcc@apache.org wrote:
> Date: 17 Jan 2002 21:26:18 -0000
> From: craigmcc@apache.org
> Reply-To: Struts Developers List <st...@jakarta.apache.org>
> To: jakarta-struts-cvs@apache.org
> Subject: cvs commit: jakarta-struts/src/share/org/apache/struts/config
> FormPropertyConfig.java
>
> craigmcc 02/01/17 13:26:18
>
> Modified: src/share/org/apache/struts/action DynaActionFormClass.java
> src/share/org/apache/struts/config FormPropertyConfig.java
> Log:
>
Oops ... hit send too quickly.
This patch fixes the exception Matt was encountering when trying to
declare a <form-property> with a type of "java.lang.String[]" -- in other
words, a String array.
The exception doesn't happen now, but we're still not out of the woods -
by default, the array itself is not going to be created, so trying to use
an indexed setter or getter method is going to throw an NPE. We probably
need a mechanism to precreate an array of a specified size ...
Craig
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>