1 16 17 18 package org.apache.velocity.tools.view; 19 20 21 50 public class DataInfo implements ToolInfo 51 { 52 53 public static final String TYPE_STRING = "string"; 54 public static final String TYPE_NUMBER = "number"; 55 public static final String TYPE_BOOLEAN = "boolean"; 56 57 private static final int TYPE_ID_STRING = 0; 58 private static final int TYPE_ID_NUMBER = 1; 59 private static final int TYPE_ID_BOOLEAN = 2; 60 61 private String key; 62 private int type_id; 63 private Object data; 64 65 66 public DataInfo() {} 67 68 69 70 71 public void setKey(String key) 72 { 73 this.key = key; 74 } 75 76 77 public void setType(String type) 78 { 79 if (TYPE_BOOLEAN.equalsIgnoreCase(type)) 80 { 81 this.type_id = TYPE_ID_BOOLEAN; 82 } 83 else if (TYPE_NUMBER.equalsIgnoreCase(type)) 84 { 85 this.type_id = TYPE_ID_NUMBER; 86 } 87 else 88 { 89 this.type_id = TYPE_ID_STRING; 90 } 91 } 92 93 94 public void setValue(String value) 95 { 96 if (type_id == TYPE_ID_BOOLEAN) 97 { 98 this.data = Boolean.valueOf(value); 99 } 100 else if (type_id == TYPE_ID_NUMBER) 101 { 102 if (value.indexOf('.') >= 0) 103 { 104 this.data = new Double (value); 105 } 106 else 107 { 108 this.data = new Integer (value); 109 } 110 } 111 else 112 { 113 this.data = value; 114 } 115 } 116 117 118 119 120 public String getKey() 121 { 122 return key; 123 } 124 125 126 public String getClassname() 127 { 128 return data.getClass().getName(); 129 } 130 131 132 137 public Object getInstance(Object initData) 138 { 139 return data; 140 } 141 142 } 143 | Popular Tags |