You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2003/07/22 20:29:50 UTC
cvs commit: jakarta-velocity-tools/src/java/org/apache/velocity/tools/view DataInfo.java
nbubna 2003/07/22 11:29:50
Modified: src/java/org/apache/velocity/tools/view DataInfo.java
Log:
make implementation more bean-ish and Digester friendly (use set methods instead of complex constructor)
Revision Changes Path
1.4 +43 -20 jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/DataInfo.java
Index: DataInfo.java
===================================================================
RCS file: /home/cvs/jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/DataInfo.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DataInfo.java 28 May 2003 00:17:15 -0000 1.3
+++ DataInfo.java 22 Jul 2003 18:29:50 -0000 1.4
@@ -88,32 +88,54 @@
public class DataInfo implements ToolInfo
{
- public static String TYPE_STRING = "string";
- public static String TYPE_NUMBER = "number";
- public static String TYPE_BOOLEAN = "boolean";
+ public static final String TYPE_STRING = "string";
+ public static final String TYPE_NUMBER = "number";
+ public static final String TYPE_BOOLEAN = "boolean";
+
+ private static final int TYPE_ID_STRING = 0;
+ private static final int TYPE_ID_NUMBER = 1;
+ private static final int TYPE_ID_BOOLEAN = 2;
private String key;
+ private int type_id;
private Object data;
- /**
- * Parses the value string into a recognized type. If
- * the type specified is not supported, the data will
- * be held and returned as a string.
- *
- * @param key the context key for the data
- * @param type the data type
- * @param value the data
- */
- public DataInfo(String key, String type, String value)
- {
+ public DataInfo() {}
+
+
+ /*********************** Mutators *************************/
+
+ public void setKey(String key)
+ {
this.key = key;
+ }
+
+
+ public void setType(String type)
+ {
+ if (TYPE_BOOLEAN.equalsIgnoreCase(type))
+ {
+ this.type_id = TYPE_ID_BOOLEAN;
+ }
+ else if (TYPE_NUMBER.equalsIgnoreCase(type))
+ {
+ this.type_id = TYPE_ID_NUMBER;
+ }
+ else /* if no type or type="string" */
+ {
+ this.type_id = TYPE_ID_STRING;
+ }
+ }
+
- if (type.equalsIgnoreCase(TYPE_BOOLEAN))
+ public void setValue(String value)
+ {
+ if (type_id == TYPE_ID_BOOLEAN)
{
this.data = Boolean.valueOf(value);
}
- else if (type.equalsIgnoreCase(TYPE_NUMBER))
+ else if (type_id == TYPE_ID_NUMBER)
{
if (value.indexOf('.') >= 0)
{
@@ -124,13 +146,15 @@
this.data = new Integer(value);
}
}
- else
+ else /* type is "string" */
{
this.data = value;
}
}
+ /*********************** Accessors *************************/
+
public String getKey()
{
return key;
@@ -153,5 +177,4 @@
return data;
}
-
-}
\ No newline at end of file
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org