1 2 12 package com.versant.core.jdo.query; 13 14 import com.versant.core.metadata.FieldMetaData; 15 import com.versant.core.metadata.ClassMetaData; 16 import com.versant.core.common.Debug; 17 import com.versant.core.common.OID; 18 20 import javax.jdo.spi.PersistenceCapable; 21 import java.util.ArrayList ; 22 import java.math.BigDecimal ; 23 24 26 public class Field implements Comparable { 27 public static final int TYPE_COLLECTION=1; 28 public static final int TYPE_ARRAY=2; 29 public static final int TYPE_STRING=3; 30 public static final int TYPE_PC=4; 31 public static final int TYPE_BOOLEAN=5; 32 public static final int TYPE_DECIMAL=6; 33 public static final int TYPE_CHAR=12; 34 public static final int TYPE_MAP=13; 35 public static final int TYPE_REF=14; 36 public static final int TYPE_TX=15; 37 public static final int TYPE_BOUND_VAR=16; 38 public static final int TYPE_UNBOUND_VAR=17; 39 public static final int TYPE_CAST=19; 40 public static final int TYPE_OBJECT=20; 41 43 44 public int type; 45 public FieldMetaData fieldMetaData; 46 public ClassMetaData classMetaData; 47 public PersistenceCapable pcValue; 48 public Object value; 50 public boolean bValue; 51 public BigDecimal dValue; 52 public String sValue; 53 public char cValue; 54 public ArrayList collection; 55 public String name; 56 57 public Field(FieldMetaData fieldMetaData) { 58 this.fieldMetaData = fieldMetaData; 59 } 60 61 public Field(int type) { 62 this.type = type; 63 } 64 65 public Field() { 66 } 67 68 public String getType(){ 69 switch(type){ 70 case TYPE_COLLECTION: 71 return "collection"; 72 case TYPE_OBJECT: 73 return "object"; 74 case TYPE_ARRAY: 77 return "array"; 78 case TYPE_STRING: 79 return "string"; 80 case TYPE_PC: 81 return "PersistenceCapable"; 82 case TYPE_BOOLEAN: 83 return "boolean"; 84 case TYPE_DECIMAL: 85 return "decimal"; 86 case TYPE_CHAR: 87 return "char"; 88 case TYPE_MAP: 89 return "map"; 90 case TYPE_TX: 91 return "transactional"; 92 case TYPE_REF: 93 return "reference"; 94 case TYPE_UNBOUND_VAR: 95 return "unbound variable"; 96 case TYPE_BOUND_VAR: 97 return "bound variable"; 98 case TYPE_CAST: 99 return "cast"; 100 default: 101 return null; 102 } 103 } 104 105 public Object getValue(){ 106 switch(type){ 107 case TYPE_MAP: 108 case TYPE_ARRAY: 109 case TYPE_TX: 110 case TYPE_REF: 111 case TYPE_CAST: 112 case TYPE_OBJECT: 113 return value; 114 case TYPE_PC: 117 return pcValue; 118 case TYPE_BOOLEAN: 119 return new Boolean (bValue); 120 case TYPE_DECIMAL: 121 return dValue; 122 case TYPE_CHAR: 123 return new Character (cValue); 124 case TYPE_STRING: 125 return sValue; 126 case TYPE_BOUND_VAR: 127 case TYPE_COLLECTION: 128 return collection; 129 default: 130 return null; 131 } 132 } 133 public String toString(){ 134 StringBuffer buffer = new StringBuffer (); 135 buffer.append("Type = "); 136 buffer.append(getType()); 137 buffer.append(" value = "); 138 switch(type){ 139 case TYPE_MAP: 140 case TYPE_ARRAY: 141 case TYPE_TX: 142 case TYPE_REF: 143 case TYPE_CAST: 144 case TYPE_OBJECT: 145 buffer.append(value); 146 break; 147 case TYPE_PC: 148 buffer.append(pcValue); 149 case TYPE_BOOLEAN: 152 buffer.append(bValue); 153 break; 154 case TYPE_DECIMAL: 155 buffer.append(dValue); 156 break; 157 case TYPE_CHAR: 158 buffer.append(cValue); 159 break; 160 case TYPE_STRING: 161 buffer.append(sValue); 162 break; 163 case TYPE_BOUND_VAR: 164 case TYPE_COLLECTION: 165 buffer.append(collection); 166 default: 167 buffer.append(" --- "); 168 break; 169 } 170 buffer.append(" FieldMetaData = "); 171 buffer.append(fieldMetaData); 172 return buffer.toString(); 173 } 174 public void dump(String indent){ 175 if (Debug.DEBUG) { 176 Debug.OUT.println(indent+ this.toString()); 177 } 178 } 179 180 public void clear(){ 181 fieldMetaData = null; 182 collection = null; 183 classMetaData = null; 184 name = null; 185 dValue = null; 186 sValue = null; 187 pcValue = null; 188 } 190 191 public int compareTo(Object o) { 192 Comparable a = (Comparable )getValue(); 193 Comparable b = null; 194 if(o instanceof Field){ 195 b = (Comparable )((Field)o).getValue(); 196 }else{ 197 b = (Comparable )o; 198 } 199 if (a == null) { 200 a = ""; 201 } 202 if (b == null) { 203 b = ""; 204 } 205 return a.compareTo(b); 206 } 207 208 209 } 210 | Popular Tags |