The attached patch adds support for the direct use of enums in the
attributes of tags.
Assume there is the enum:
public enum LoginType {
account, manager, reseller;
}
and a setter for a tag called 'page':
public void setLogin_required_type( LoginType login_required_type ) { ...
then the jsp code:
<ez:page login_required_type="account"/>
would result in the generation of the java code:
page_tag_instance.setLogin_required_type(LoginType.account);
Andrew J Snodgrass
Index: java/org/apache/jasper/runtime/JspRuntimeLibrary.java
===================================================================
--- java/org/apache/jasper/runtime/JspRuntimeLibrary.java (revision 575441)
+++ java/org/apache/jasper/runtime/JspRuntimeLibrary.java (working copy)
@@ -175,6 +175,13 @@
return Long.valueOf(s).longValue();
}
+ public static <T extends Enum<T>> T coerceToEnum(String s, Class<T> c) {
+ if (s == null || s.length() == 0)
+ return null;
+ else
+ return Enum.valueOf(c, s);
+ }
+
public static Object coerce(String s, Class target) {
boolean isNullOrEmpty = (s == null || s.length() == 0);
Index: java/org/apache/jasper/compiler/Generator.java
===================================================================
--- java/org/apache/jasper/compiler/Generator.java (revision 575441)
+++ java/org/apache/jasper/compiler/Generator.java (working copy)
@@ -3056,12 +3056,16 @@
} else if (c == Object.class) {
return "new String(" + quoted + ")";
} else {
- String className = JspUtil.getCanonicalName(c);
- return "("
- + className
- + ")org.apache.jasper.runtime.JspRuntimeLibrary.getValueFromPropertyEditorManager("
- + className + ".class, \"" + attrName + "\", " + quoted
- + ")";
+ if (c.isEnum()) {
+ return JspUtil.coerceToEnum(s, c, isNamedAttribute);
+ } else {
+ String className = JspUtil.getCanonicalName(c);
+ return "("
+ + className
+ + ")org.apache.jasper.runtime.JspRuntimeLibrary.getValueFromPropertyEditorManager("
+ + className + ".class, \"" + attrName + "\", " + quoted
+ + ")";
+ }
}
}
Index: java/org/apache/jasper/compiler/JspUtil.java
===================================================================
--- java/org/apache/jasper/compiler/JspUtil.java (revision 575441)
+++ java/org/apache/jasper/compiler/JspUtil.java (working copy)
@@ -825,6 +825,19 @@
}
}
+ public static String coerceToEnum(String s, Class c, boolean isNamedAttribute) {
+ final String className = getCanonicalName(c);
+ if (isNamedAttribute) {
+ return "org.apache.jasper.runtime.JspRuntimeLibrary.coerceToEnum(" + s + ", " + className + ".class)";
+ } else {
+ if (s == null || s.length() == 0) {
+ return "null";
+ } else {
+ return className + "." + Enum.valueOf(c, s).toString();
+ }
+ }
+ }
+
public static InputStream getInputStream(String fname, JarFile jarFile,
JspCompilationContext ctxt,
ErrorDispatcher err)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]