1 16 17 package org.apache.poi.hssf.record.formula; 18 19 import java.util.List ; 20 import java.util.ArrayList ; 21 22 import org.apache.poi.hssf.model.Workbook; 23 24 30 31 public abstract class Ptg 32 { 33 34 35 39 40 87 88 public static Ptg createPtg(byte [] data, int offset) 89 { 90 byte id = data[ offset + 0 ]; 91 Ptg retval = null; 92 93 final byte valueRef = ReferencePtg.sid + 0x20; 94 final byte arrayRef = ReferencePtg.sid + 0x40; 95 final byte valueFunc = FuncPtg.sid + 0x20; 96 final byte arrayFunc = FuncPtg.sid + 0x40; 97 final byte valueFuncVar = FuncVarPtg.sid +0x20; 98 final byte arrayFuncVar = FuncVarPtg.sid+0x40; 99 final byte valueArea = AreaPtg.sid + 0x20; 100 final byte arrayArea = AreaPtg.sid + 0x40; 101 102 switch (id) 103 { 104 case AddPtg.sid : 105 retval = new AddPtg(data, offset); 106 break; 107 108 case SubtractPtg.sid : 109 retval = new SubtractPtg(data, offset); 110 break; 111 112 case BoolPtg.sid: 113 retval = new BoolPtg(data, offset); 114 break; 115 116 case IntPtg.sid : 117 retval = new IntPtg(data, offset); 118 break; 119 120 case DividePtg.sid : 121 retval = new DividePtg(data, offset); 122 break; 123 124 case MultiplyPtg.sid : 125 retval = new MultiplyPtg(data, offset); 126 break; 127 128 case PowerPtg.sid : 129 retval = new PowerPtg(data, offset); 130 break; 131 132 case EqualPtg.sid: 133 retval = new EqualPtg(data, offset); 134 break; 135 136 case GreaterThanPtg.sid: 137 retval = new GreaterThanPtg(data, offset); 138 break; 139 140 case LessThanPtg.sid: 141 retval = new LessThanPtg(data, offset); 142 break; 143 144 case LessEqualPtg.sid: 145 retval = new LessEqualPtg(data, offset); 146 break; 147 148 case GreaterEqualPtg.sid: 149 retval = new GreaterEqualPtg(data, offset); 150 break; 151 152 case NotEqualPtg.sid: 153 retval = new NotEqualPtg(data, offset); 154 break; 155 156 case ConcatPtg.sid : 157 retval = new ConcatPtg(data, offset); 158 break; 159 160 case AreaPtg.sid : 161 retval = new AreaPtg(data, offset); 162 break; 163 case valueArea: 164 retval = new AreaPtg(data, offset); 165 break; 166 case arrayArea: 167 retval = new AreaPtg(data, offset); 168 break; 169 case MemErrPtg.sid : case MemErrPtg.sid+0x20 : case MemErrPtg.sid+0x40 : retval = new MemErrPtg(data, offset); 173 break; 174 175 case AttrPtg.sid : 176 retval = new AttrPtg(data, offset); 177 break; 178 179 case ReferencePtg.sid : 180 retval = new ReferencePtg(data, offset); 181 break; 182 case valueRef : 183 retval = new ReferencePtg(data, offset); 184 break; 185 case arrayRef : 186 retval = new ReferencePtg(data, offset); 187 break; 188 189 case ParenthesisPtg.sid : 190 retval = new ParenthesisPtg(data, offset); 191 break; 192 193 case MemFuncPtg.sid : 194 retval = new MemFuncPtg(data, offset); 195 break; 196 197 case UnionPtg.sid : 198 retval = new UnionPtg(data, offset); 199 break; 200 201 case FuncPtg.sid : 202 retval = new FuncPtg(data, offset); 203 break; 204 205 case valueFunc : 206 retval = new FuncPtg(data, offset); 207 break; 208 case arrayFunc : 209 retval = new FuncPtg(data, offset); 210 break; 211 212 case FuncVarPtg.sid : 213 retval = new FuncVarPtg(data, offset); 214 break; 215 216 case valueFuncVar : 217 retval = new FuncVarPtg(data, offset); 218 break; 219 case arrayFuncVar : 220 retval = new FuncVarPtg(data, offset); 221 break; 222 223 case NumberPtg.sid : 224 retval = new NumberPtg(data, offset); 225 break; 226 227 case StringPtg.sid : 228 retval = new StringPtg(data, offset); 229 break; 230 231 case NamePtg.sid : case NamePtg.sid+0x20 : case NamePtg.sid+0x40 : 235 retval = new NamePtg(data, offset); 236 break; 237 238 case NameXPtg.sid : case NameXPtg.sid+0x20 : case NameXPtg.sid+0x40 : 242 retval = new NameXPtg(data, offset); 243 break; 244 245 case ExpPtg.sid : 246 retval = new ExpPtg(data, offset); 247 break; 248 249 case Area3DPtg.sid : case Area3DPtg.sid+0x20 : case Area3DPtg.sid+0x40 : 253 retval = new Area3DPtg(data, offset); 254 break; 255 256 case Ref3DPtg.sid: case Ref3DPtg.sid+0x20: case Ref3DPtg.sid+0x40: 260 retval = new Ref3DPtg(data, offset); 261 break; 262 263 case MissingArgPtg.sid: 264 retval = new MissingArgPtg(data,offset); 265 break; 266 case UnaryPlusPtg.sid: 267 retval=new UnaryPlusPtg(data,offset); 268 break; 269 case UnaryMinusPtg.sid: 270 retval=new UnaryMinusPtg(data,offset); 271 break; 272 273 default : 274 275 throw new java.lang.UnsupportedOperationException ( 277 Integer.toHexString(( int ) id) + " (" + ( int ) id + ")"); 278 } 279 280 if (id > 0x60) { 281 retval.setClass(CLASS_ARRAY); 282 } else if (id > 0x40) { 283 retval.setClass(CLASS_VALUE); 284 } else 285 retval.setClass(CLASS_REF); 286 return retval; 287 288 } 289 290 public abstract int getSize(); 291 292 public final byte [] getBytes() 293 { 294 int size = getSize(); 295 byte[] bytes = new byte[ size ]; 296 297 writeBytes(bytes, 0); 298 return bytes; 299 } 300 301 public abstract void writeBytes(byte [] array, int offset); 302 303 306 public abstract String toFormulaString(Workbook book); 307 310 public String toDebugString() { 311 byte[] ba = new byte[getSize()]; 312 String retval=null; 313 writeBytes(ba,0); 314 try { 315 retval = org.apache.poi.util.HexDump.dump(ba,0,0); 316 } catch (Exception e) { 317 e.printStackTrace(); 318 } 319 return retval; 320 } 321 322 326 public String toString(){ 327 return this.getClass().toString(); 328 } 329 330 public static final byte CLASS_REF = 0x00; 331 public static final byte CLASS_VALUE = 0x20; 332 public static final byte CLASS_ARRAY = 0x40; 333 334 protected byte ptgClass = CLASS_REF; 336 public void setClass(byte thePtgClass) { 337 ptgClass = thePtgClass; 338 } 339 340 341 public byte getPtgClass() { 342 return ptgClass; 343 } 344 345 public abstract byte getDefaultOperandClass(); 346 347 public abstract Object clone(); 348 349 350 351 } 352 | Popular Tags |