1 18 19 package sync4j.framework.engine.dm; 20 21 import org.apache.commons.lang.builder.ToStringBuilder; 22 23 30 public class TreeNode { 31 32 34 public static final String FORMAT_BINARY = "b64"; 35 public static final String FORMAT_CHR = "chr"; 36 public static final String FORMAT_INT = "int"; 37 public static final String FORMAT_BOOL = "bool"; 38 public static final String FORMAT_NODE = "node"; 39 public static final String FORMAT_XML = "xml"; 40 public static final String FORMAT_NULL = "null"; 41 public static final String FORMAT_DEFAULT_VALUE = FORMAT_CHR; 42 43 public static final String TYPE_DEFAULT_VALUE = "text/plain"; 44 45 46 private String name = null; 48 private String format = null; 49 private String type = null; 50 private Object value = null; 51 52 54 public TreeNode() { 55 this.type = TYPE_DEFAULT_VALUE; 56 } 57 58 public TreeNode(String name) { 59 this(); 60 this.name = name; 61 } 62 63 public TreeNode(String name, Object value) { 64 this(name); 65 setValue(value); 66 } 67 68 public TreeNode(String name, Object value, String format) { 69 this(name, value); 70 this.format = format; 71 } 72 73 public TreeNode(String name, Object value, String format, String type) { 74 this(name, value, format); 75 this.type = type; 76 } 77 78 80 85 public String getName() { 86 return name; 87 } 88 89 94 public void setName(String name) { 95 this.name = name; 96 } 97 98 103 public Object getValue() { 104 return value; 105 } 106 107 112 public void setValue(Object value) { 113 this.value = value; 114 115 if (value != null) { 116 if (value instanceof byte[]) { 117 this.format = FORMAT_BINARY; 118 } else if (value instanceof Boolean ) { 119 this.format = FORMAT_BOOL; 120 } else if (value instanceof Integer ) { 121 this.format = FORMAT_INT; 122 } else { 123 this.format = FORMAT_DEFAULT_VALUE; 124 } 125 } 126 } 127 128 133 public String getFormat() { 134 return format; 135 } 136 137 142 public void setFormat(String format) { 143 this.format = format; 144 } 145 146 147 152 public String getType() { 153 return type; 154 } 155 156 161 public void setType(String type) { 162 this.type = type; 163 } 164 165 169 public String toString() { 170 ToStringBuilder sb = new ToStringBuilder(this); 171 172 sb.append("name" , name); 173 sb.append("value" , value); 174 sb.append("format", format); 175 sb.append("type" , type); 176 177 return sb.toString(); 178 } 179 } | Popular Tags |