1 package org.oddjob.values.types; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.InputStream ; 5 6 import org.oddjob.arooa.reflect.IntrospectionHelper; 7 8 59 public class ValueType { 60 62 67 private Object value; 68 69 public void setValue(Object value) { 70 this.value = value; 71 } 72 73 80 public Object valueFor(Class required) { 81 if (value == null) { 82 return null; 83 } 84 Object valueFor = IntrospectionHelper.valueFor(value, required); 85 if (valueFor != value) { 86 return valueFor; 87 } 88 89 if (required.isAssignableFrom(Object .class)) { 90 return value; 91 } 92 93 if (required.isAssignableFrom(InputStream .class)) { 94 return new ByteArrayInputStream (value.toString().getBytes()); 95 } 96 97 return value; 98 } 99 100 public void addText(String text) { 101 String t= ""; 102 if (this.value != null) { 103 t = (String ) valueFor(String .class); 104 } 105 t += text; 106 value = t; 107 } 108 109 public String toString() { 110 if (value == null) { 111 return null; 112 } 113 return value.toString(); 114 } 115 } 116 | Popular Tags |