1 19 20 package org.netbeans.modules.dbschema.migration.archiver.deserializer; 21 22 import java.lang.*; 23 import java.util.*; 24 25 import java.lang.reflect.Field ; 26 import java.lang.reflect.Array ; 27 28 import org.xml.sax.*; 29 30 public class XMLGraphDeserializer extends BaseSpecificXMLDeserializer implements java.io.Serializable 31 { 32 33 35 38 public static final int XGD_END = 99; 39 public static final int XGD_NEED_ATTRIBUTE = 1; 40 public static final int XGD_NEED_END_ATTR = 2; 41 public static final int XGD_NEED_END_NULLVALUE = 4; 42 public static final int XGD_NEED_END_OBJECT = 5; 43 public static final int XGD_NEED_END_PARAM = 10; 44 public static final int XGD_NEED_END_ROW = 3; 45 public static final int XGD_NEED_END_ROW_ELEMENT = 14; 46 public static final int XGD_NEED_OBJECT = 7; 47 public static final int XGD_NEED_PARAM = 9; 48 public static final int XGD_NEED_ROW = 6; 49 public static final int XGD_NEED_ROW_ELEMENT = 13; 50 public static final int XGD_NEED_ROW_TAG = 12; 51 public static final int XGD_NEED_STRING = 11; 52 public static final int XGD_NEED_VALUE = 8; 53 54 private java.util.HashMap ObjectHash; 57 private ArrayListStack AttrNameStack; 58 public ArrayListStack RowTypeStack; 59 private ArrayListStack RowCountStack; 60 66 67 private HashMap hashedClasses = new HashMap(); 69 70 71 73 public XMLGraphDeserializer(ClassLoader cl) 75 { 76 super(cl); 77 this.AttrNameStack = new ArrayListStack(); 79 this.ObjectHash = new java.util.HashMap (20); 80 this.RowTypeStack = new ArrayListStack(); 81 this.RowCountStack = new ArrayListStack(); 82 88 } 89 90 public XMLGraphDeserializer() 91 { 92 this (null); 93 } 94 95 private Field findField(Object lCurrentObj, 97 final String lCurrentField) 98 { 100 Field lField = null; 101 Class lClass = lCurrentObj.getClass(); 102 HashMap hashedFields = (HashMap)hashedClasses.get(lClass); 103 if (hashedFields == null) { 104 hashedFields = new HashMap(); 105 hashedClasses.put(lClass, hashedFields); 106 } else { 107 lField = (Field )hashedFields.get(lCurrentField); 108 } 109 110 for (; 111 lClass != null && lField == null; 112 lClass = lClass.getSuperclass()) 113 { 114 125 126 final Class tmpClass = lClass; 127 lField = (Field )java.security.AccessController.doPrivileged( 128 new java.security.PrivilegedAction () { 129 public Object run() { 130 try { 131 Field tmpField = tmpClass.getDeclaredField(lCurrentField); 132 if (tmpField != null) { 133 tmpField.setAccessible(true); 134 } 135 return tmpField; 136 } catch (java.lang.NoSuchFieldException ex) { 137 return null; 138 } 139 } 140 } 141 ); 142 if (lField != null) { 143 hashedFields.put(lCurrentField, lField); 144 break; 145 } 146 147 } 148 return lField; 149 } 150 151 public void endDocument() throws org.xml.sax.SAXException 152 { 153 super.endDocument(); 154 155 this.State = new Integer (this.XGD_END); 156 } 157 158 public void endElement(java.lang.String name) throws org.xml.sax.SAXException 159 { 160 int lInitialState = this.State.intValue(); 162 163 try { 164 if ( name.equals("ARRAY") ) 165 this.popRowCount(); 166 167 if (!name.equals("_.ALIAS")) 168 { 169 switch ( this.State.intValue() ) 170 { 171 case XGD_NEED_ATTRIBUTE: 172 this.validateTag(name, "OBJECT", true); 173 this.popState(); 174 175 break; 176 case XGD_NEED_END_ATTR: 177 java.lang.String lFieldName = this.topAttrName(); 178 this.validateTag(this.unescapeName(name), lFieldName, true); 179 java.lang.Object lObj = this.popObject(); 180 this.setCurrentAttribute(lObj); 181 this.popAttrName(); 182 this.popState(); 183 184 break; 185 case XGD_NEED_END_PARAM: 186 this.validateTag(name, "PARAM", true); 187 188 break; 189 case XGD_NEED_END_ROW: 190 this.validateTag(name, "ROW", true); 191 this.popState(); 192 java.lang.Object lRow = this.popObject(); 193 194 Object lArrayRef = this.topObject(); 195 if ( lArrayRef instanceof java.util.Collection ) 196 { 197 java.util.Collection lArray = (java.util.Collection )(lArrayRef); 198 lArray.add(lRow); 199 } 200 else if ( lArrayRef.getClass().isArray() ) 201 { 202 int lRowNo = this.currentRowCount(); 203 Array.set(lArrayRef, lRowNo, lRow); 204 this.incrementRowCount(); 205 } 206 break; 207 case XGD_NEED_END_NULLVALUE: 208 this.validateTag(name, "NULLVALUE", true); 209 this.popState(); 210 211 break; 212 case XGD_NEED_END_OBJECT: 213 this.validateTag(name, "OBJECT", true); 214 this.popState(); 215 216 break; 217 218 case XGD_NEED_PARAM: 219 this.popState(); 221 break; 222 case XGD_NEED_ROW: 223 this.validateTag(name, "ARRAY", true); 224 this.popState(); 225 this.popRowType(); 226 227 break; 228 229 case XGD_NEED_VALUE: 230 this.popState(); 231 232 java.lang.String lValue = null; 233 java.lang.String lSource = this.getCharacters(); 234 235 int lLength = lSource.length(); 236 237 if (lLength != 0 || 238 lLength != 1) 239 { 240 lValue = lSource; 241 } 242 243 switch ( this.State.intValue() ) 244 { 245 case XGD_NEED_END_ROW: 246 this.validateTag(name, "ROW", true); 247 248 java.util.Collection lArray2 = (java.util.Collection )(this.topObject()); 249 250 java.lang.Object lRow2 = null; 251 java.lang.Class lRowType; 252 253 lRowType = this.topRowType(); 254 255 if (lRowType == java.lang.String .class) 256 { 257 java.lang.String lNewString = (lValue); 259 lArray2.add(lNewString); 260 } 261 else 262 { 263 lArray2.add(lRow2); 264 } this.popState(); 266 break; 267 case XGD_NEED_END_ATTR: 268 this.validateTag(this.unescapeName(name), this.topAttrName(), true); 269 this.setCurrentAttribute(lValue); 270 this.popAttrName(); 271 this.popState(); 272 break; 273 case XGD_NEED_END_PARAM: 274 this.popState(); 276 this.pushState(this.XGD_NEED_PARAM); 277 break; 278 } 281 break; 282 case XGD_NEED_STRING: 283 this.popState(); 285 break; 286 case XGD_NEED_END_ROW_ELEMENT: 287 289 this.State = new Integer (this.XGD_NEED_ROW_ELEMENT); 290 break; 291 case XGD_NEED_ROW_ELEMENT: 292 this.State = new Integer (this.XGD_NEED_ROW_TAG); 294 break; 295 case XGD_NEED_ROW_TAG: 296 this.popState(); 298 299 break; 300 case XGD_NEED_OBJECT: 301 this.unexpectedTag(name, "OBJECT", false); 303 304 break; 305 } } 308 super.endElement(name); 309 } catch (SAXException lError) 311 { 312 lError.printStackTrace(); 314 System.out.println("Exception cause in XMLGraphDeserializer.endElement"); 315 System.out.println("Tag being process is " + name + " initial state was " + lInitialState); 316 this.DumpStatus(); 317 throw lError; 319 320 } catch (RuntimeException lError) 322 { 323 lError.printStackTrace(); 325 System.out.println("Exception cause in XMLGraphDeserializer.endElement"); 326 System.out.println("Tag being process is " + name + " initial state was " + lInitialState); 327 this.DumpStatus(); 328 throw lError; 330 331 } 333 } 334 335 public void startDocument() throws org.xml.sax.SAXException 336 { 337 super.startDocument(); 338 339 State = new Integer (this.XGD_END); 340 this.pushState(this.XGD_NEED_OBJECT); 341 } 342 343 public void startElement(java.lang.String name, org.xml.sax.AttributeList atts) throws org.xml.sax.SAXException 344 { 345 346 int lInitialState = this.State.intValue(); 348 349 355 try { 356 357 if ( name.equals("ARRAY") ) 358 this.pushRowCount(); 359 360 if ( name.equals( "_.ALIAS" ) ) 361 { 362 java.lang.String lName = atts.getValue("NAME"); 363 java.lang.String lAlias = atts.getValue("ALIAS"); 364 this.addActiveAlias(lName, lAlias); 365 } 366 else 367 { 368 switch ( this.State.intValue() ) 369 { 370 case XGD_NEED_ATTRIBUTE: 371 this.readAttributeHeader(name, atts); 372 break; 373 case XGD_NEED_ROW_TAG: 374 this.State = new Integer (this.XGD_NEED_ROW_ELEMENT); 376 break; 377 case XGD_NEED_ROW_ELEMENT: 383 this.State = new Integer (this.XGD_NEED_END_ROW_ELEMENT); 385 break; 386 case XGD_NEED_ROW: 393 this.validateTag(name, "ROW", false); 394 395 if ( this.checkSimpleRow(name, atts) ) 396 { 397 this.pushState(XGD_NEED_END_ROW); 398 } 399 else 400 { 401 this.pushState(XGD_NEED_END_ROW); 402 this.pushState(XGD_NEED_VALUE); 403 } 404 break; 405 case XGD_NEED_OBJECT: 406 this.validateTag(name, "OBJECT" , false); 407 this.readObjectHeader(name, atts, false); 408 break; 409 case XGD_NEED_PARAM: 410 this.popState(); 413 this.pushState(this.XGD_NEED_END_PARAM); 414 this.pushState(this.XGD_NEED_VALUE); 415 break; 426 case XGD_NEED_VALUE: 427 if (!name.equals("OBJECT") && 428 !name.equals("ARRAY") && 429 !name.equals("NULLVALUE")) 430 { 431 this.unexpectedTag(name, "OBJECT, ARRAY, NULLVALUE", false); 432 } this.readValue(name, atts); 434 435 break; 436 437 case XGD_NEED_END_ATTR: 438 this.unexpectedTag(name, this.topAttrName(), true); 440 break; 441 case XGD_NEED_END_PARAM: 442 this.unexpectedTag(name, "/PARAM", false); 443 break; 444 case XGD_NEED_END_ROW: 445 446 this.unexpectedTag(name, "/ROW", false); 447 break; 448 case XGD_NEED_END_NULLVALUE: 449 this.unexpectedTag(name, "/NULLVALUE", false); 450 break; 451 case XGD_NEED_END_OBJECT: 452 this.unexpectedTag(name, "/OBJECT", false); 453 break; 454 } } 457 458 super.startElement(name, atts); 459 460 } catch (SAXException lError) 462 { 463 lError.printStackTrace(); 465 System.out.println("Exception cause in XMLGraphDeserializer.startElement"); 466 System.out.println("Tag being process is " + name + " initial state was " + lInitialState); 467 System.out.println("Attribute list is :"); 468 for ( int i = 0; i < atts.getLength(); i++) 469 { 470 System.out.println("Attribute " + atts.getName(i) + " Type " + atts.getType(i) + " value " + atts.getValue(i)); 471 } 472 this.DumpStatus(); 473 throw lError; 475 476 } catch (RuntimeException lError) 478 { 479 lError.printStackTrace(); 481 System.out.println("Exception cause in XMLGraphDeserializer.startElement"); 482 System.out.println("Tag being process is " + name + " initial state was " + lInitialState); 483 System.out.println("Attribute list is :"); 484 for ( int i = 0; i < atts.getLength(); i++) 485 { 486 System.out.println("Attribute " + atts.getName(i) + " Type " + atts.getType(i) + " value " + atts.getValue(i)); 487 } 488 this.DumpStatus(); 489 throw lError; 491 492 } } 494 495 public java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException 496 { 497 return super.findClass(this.lookupAlias(name)); 498 } 499 500 public java.lang.String popAttrName() 501 { 502 return (java.lang.String )(AttrNameStack.pop()); 503 } 504 505 public void processObjectReference(java.lang.String refName) throws org.xml.sax.SAXException 506 { 507 java.lang.Object lObj = this.ObjectHash.get(refName); 509 510 if (lObj == null) 511 { 512 String message = ("Object " + refName + " could not be found"); 514 515 SAXException objError = new SAXException(message); 516 517 throw objError; 518 } 519 this.pushObject(lObj); 520 } 521 522 public void pushAttrName(java.lang.String name) 523 { 524 this.AttrNameStack.push(name); 525 } 526 527 public void readAttributeHeader(java.lang.String name, org.xml.sax.AttributeList atts) 528 { 529 if (name == "_.METHOD" || name == "_.CALLBACK") 531 { 532 this.pushAttrName(atts.getValue("NAME")); 533 this.pushAttrName(name); 534 this.pushState(this.XGD_NEED_PARAM); 535 this.ParameterArray.clear(); 536 } 537 else 538 { 539 this.pushAttrName(this.unescapeName(name)); 540 this.pushState(this.XGD_NEED_END_ATTR); 541 this.pushState(this.XGD_NEED_VALUE); 542 } 543 } 544 545 public void readObjectHeader(java.lang.String name, org.xml.sax.AttributeList atts, boolean refOK) throws org.xml.sax.SAXException 546 { 547 boolean lFirstObj = (this.ObjectStack.size() == 0); 548 Object lObj = null; 549 String lIDName = null; 550 551 if (refOK) 552 { 553 java.lang.String lRefName = atts.getValue("REFERENCE"); 554 if (lRefName != null) 555 { 556 this.processObjectReference(lRefName); 557 State = new Integer (this.XGD_NEED_END_OBJECT); 558 return; 559 } } 562 lIDName = atts.getValue("ID"); 564 565 if (lFirstObj || 566 !this.useExistingAttribute(atts, topAttrName(), lObj) 567 ) 568 { 569 java.lang.String lClassName = atts.getValue("CLASS"); 570 if (lClassName == null) 571 { 572 lObj = null; 573 } 574 else 575 { 576 java.lang.Class lClass = null; 577 try 578 { 579 lClass = this.findClass(lClassName); 580 if (WrapperClassHelper.isWrapperClass(lClass)) 590 lObj = new WrapperClassHelper(lClass, lIDName); 591 else 592 lObj = lClass.newInstance(); 593 } 594 catch (IllegalAccessException e1) 595 { 596 e1.printStackTrace(); 597 java.lang.String message = ("Illegal Access to class " + lClass.getName()); 599 SAXException useError = new SAXException(message); 600 throw useError; 601 } 602 catch (InstantiationException e2) 603 { 604 605 lObj = NewInstanceHelper.newInstance(lClassName, this.topObject()); 606 if ( lObj == null ) 607 { 608 e2.printStackTrace(); 609 610 java.lang.String message = ("Instantiation exception of class " + lClass.getName()); 612 SAXException useError = new SAXException(message); 613 throw useError; 614 } 615 } 616 catch (ClassNotFoundException e3) 617 { 618 e3.printStackTrace(); 619 620 java.lang.String message = ("Class " + lClass.getName() + " could not be found"); 622 SAXException useError = new SAXException(message); 623 throw useError; 624 } 625 } } 628 629 this.pushObject(lObj); 630 631 if (lIDName != null) 633 { 634 this.ObjectHash.put(lIDName, lObj); 635 } 637 if (lFirstObj) 638 { 639 this.MasterDeserializer.setInitialObject(lObj); 640 } 642 if (lObj == null) 643 { 644 State = new Integer (this.XGD_NEED_END_OBJECT); 645 } 646 else 652 { 653 State = new Integer (this.XGD_NEED_ATTRIBUTE); 654 } 655 } 656 657 public java.lang.String topAttrName() 658 { 659 660 return (java.lang.String )(this.AttrNameStack.peek()); 661 } 662 663 public void readValue(java.lang.String name, org.xml.sax.AttributeList atts) throws org.xml.sax.SAXException 664 { 665 boolean lFirstObj = (this.ObjectStack.size() == 0); 666 667 if (name.equals("OBJECT")) 668 { 669 this.readObjectHeader(name, atts, true); 670 } 671 else if (name.equals("ARRAY")) 672 { 673 java.lang.Object lObj = null; 674 java.lang.Class lRowClassType = null; 675 java.lang.Object lArray = null; 676 677 680 String lArrayType = atts.getValue("CLASS"); 681 int lArraySize = Integer.parseInt(atts.getValue("SIZE")); 682 java.lang.String lRowTypeName = atts.getValue("ROWCLASS"); 683 684 if ( !lArrayType.equals("PRIMITIVE") ) 688 { 689 try 690 { 691 Class lArrayTypeClass = this.findClass(lArrayType); 692 lArray = lArrayTypeClass.newInstance(); 693 } 694 catch (ClassNotFoundException e1) 695 { 696 e1.printStackTrace(); 697 java.lang.String message = ("Class " + lArrayType + " could not be found, " + 700 "either it has the wrong name or cannot be found in lookup table"); 701 SAXException classError = new SAXException(message); 702 throw classError; 703 } 704 catch (IllegalAccessException e2) 705 { 706 e2.printStackTrace(); 707 java.lang.String message = ("Illegal Access exception whilst trying to init new instance of " + lArrayType); 709 SAXException accessError = new SAXException(message); 710 throw accessError; 711 } 712 catch (InstantiationException e3) 713 { 714 e3.printStackTrace(); 715 java.lang.String message = ("Instantiation exception whilst trying to init new instance of " + lArrayType); 717 SAXException initError = new SAXException(message); 718 throw initError; 719 } 720 721 } 722 723 if (!lFirstObj && 724 this.useExistingAttribute(atts, this.topAttrName(), lObj)) 725 { 726 lArray = lObj; 728 } 730 735 if (lRowTypeName != null && 736 !lRowTypeName.equals("") 737 ) 738 { 739 try 740 { 741 lRowClassType = this.findClass(lRowTypeName); 742 } 743 catch (ClassNotFoundException e1) 744 { 745 e1.printStackTrace(); 746 java.lang.String message = ("Class " + lRowTypeName + " could not be found, " + 749 "either it has the wrong name or cannot be found in lookup table"); 750 SAXException classError = new SAXException(message); 751 throw classError; 752 } 753 } 754 else 755 { 756 lRowClassType = java.lang.Object .class; 757 } 759 if ( lArrayType.equals("PRIMITIVE") ) 760 { 761 lArray = Array.newInstance(lRowClassType, lArraySize); 762 } 763 764 this.pushRowType(lRowClassType); 765 this.pushObject(lArray); 766 this.State = new Integer (this.XGD_NEED_ROW); 767 } 768 else if (name.equals("NULLVALUE")) 769 { 770 java.lang.Object lCurrentObj = null; 771 Field lField = null; 772 try 773 { 774 lCurrentObj = this.topObject(); 775 783 809 818 lField = findField(lCurrentObj, this.topAttrName()); 820 821 if (lField == null) 822 this.pushObject(new Object ()); 825 else 826 this.pushObject(lField.getType().newInstance()); 827 828 this.State = new Integer (this.XGD_NEED_END_NULLVALUE); 829 } 830 catch (InstantiationException e1) 831 { 832 e1.printStackTrace(); 833 java.lang.String message = ("Could not init instance of " + lField.getType().getName()); 835 SAXException initError = new SAXException(message); 836 throw initError; 837 } 838 catch (IllegalAccessException e2) 839 { 840 e2.printStackTrace(); 841 java.lang.String message = ("Illegal access of field " + this.topAttrName()); 843 SAXException illegalError = new SAXException(message); 844 throw illegalError; 845 } 846 } } 848 849 public void pushRowType(java.lang.Class type) 850 { 851 this.RowTypeStack.push(type); 852 } 853 854 public java.lang.Class popRowType() 855 { 856 return (java.lang.Class )(this.RowTypeStack.pop()); 857 } 858 859 860 public void setCurrentAttribute(java.lang.Object value) throws org.xml.sax.SAXException 861 { 862 java.lang.Object lCurrentObj = this.topObject(); 863 java.lang.String lCurrentField = this.topAttrName(); 864 865 if (lCurrentObj instanceof WrapperClassHelper) { 871 WrapperClassHelper helper = (WrapperClassHelper)lCurrentObj; 872 lCurrentObj = helper.valueOf((String )value); 874 popObject(); 877 pushObject(lCurrentObj); 878 String id = helper.getId(); 882 if (id != null) 883 this.ObjectHash.put(id, lCurrentObj); 884 885 return; 888 } 889 890 Field lField = null; 891 892 try 893 { 894 902 907 978 979 lField = findField(lCurrentObj, lCurrentField); 981 982 if (lField == null) 983 return; 986 987 991 995 998 java.lang.Class lFieldClass = lField.getType(); 999 if (lFieldClass.isPrimitive() && 1000 value instanceof java.lang.String ) 1001 { 1002 if (lFieldClass == int.class) 1004 lField.setInt(lCurrentObj, java.lang.Integer.parseInt((java.lang.String )(value))); 1005 else if (lFieldClass == short.class) 1006 lField.setShort(lCurrentObj, java.lang.Short.parseShort((java.lang.String )(value))); 1007 else if (lFieldClass == long.class) 1008 lField.setLong(lCurrentObj, java.lang.Long.parseLong((java.lang.String )(value))); 1009 else if (lFieldClass == byte.class) 1011 lField.setByte(lCurrentObj, java.lang.Byte.parseByte((java.lang.String )(value))); 1012 else if (lFieldClass == double.class) 1013 lField.setDouble(lCurrentObj, java.lang.Double.parseDouble((java.lang.String )(value))); 1014 else if (lFieldClass == float.class) 1015 lField.setFloat(lCurrentObj, java.lang.Float.parseFloat((java.lang.String )(value))); 1016 else if (lFieldClass == boolean.class) 1017 lField.setBoolean(lCurrentObj, (java.lang.Boolean.valueOf((java.lang.String )(value))).booleanValue()); 1018 else if (lFieldClass == char.class) 1019 lField.setChar(lCurrentObj, ((java.lang.String )(value)).charAt(0)); 1020 } 1021 else if (lFieldClass.isArray() && 1022 value instanceof ArrayList) 1023 { 1024 1027 Class lArrayType = lFieldClass.getComponentType(); 1028 ArrayList lList = (ArrayList)(value); 1029 1030 Object lArray = Array.newInstance(lArrayType, lList.size()); 1031 for ( int i = 0; i < lList.size(); i++) 1032 { 1033 Array.set(lArray, i, lList.get(i)); 1034 } 1035 1036 lField.set(lCurrentObj, lArray); 1037 } 1038 else { 1043 lField.set(lCurrentObj, value); 1044 } 1045 } 1046 catch (IllegalAccessException e1) 1047 { 1048 e1.printStackTrace(); 1049 java.lang.String message = ("Illegal access of field " + lCurrentField); 1051 SAXException accessError = new SAXException(message); 1052 1053 throw accessError; 1054 } 1055 1056 catch (SecurityException e3) 1057 { 1058 e3.printStackTrace(); 1059 java.lang.String message = ("Security Exception accessing fields of" + lCurrentObj.getClass().getName()); 1061 SAXException accessError = new SAXException(message); 1062 1063 throw accessError; 1064 } 1065 catch (RuntimeException e4) 1066 { 1067 e4.printStackTrace(); 1068 throw e4; 1069 } 1070 } 1071 1072 public java.lang.Class topRowType() 1073 { 1074 return (java.lang.Class )(this.RowTypeStack.peek()); 1075 } 1076 1077 1078 private boolean checkSimpleRow(java.lang.String name, org.xml.sax.AttributeList atts) throws org.xml.sax.SAXException 1079 { 1080 boolean isSimple = false; 1081 1082 String lRowType = atts.getValue("ROWCLASS"); 1083 String lRowValue = atts.getValue("VALUE"); 1084 1085 if ( lRowType != null && 1086 !lRowType.equals("") 1087 ) 1088 { 1089 isSimple = true; 1090 1091 if ( lRowType.equals("java.lang.String") ) 1092 this.pushObject(lRowValue); 1093 else if ( lRowType.equals("java.lang.StringBuffer") ) 1094 this.pushObject(new StringBuffer (lRowValue)); 1095 else if (lRowType.equals("int") || lRowType.equals("java.lang.Integer")) 1096 this.pushObject(Integer.valueOf(lRowValue)); 1097 else if (lRowType.equals("short") || lRowType.equals("java.lang.Short")) 1098 this.pushObject(Short.valueOf(lRowValue)); 1099 else if (lRowType.equals("long") || lRowType.equals("java.lang.Long")) 1100 this.pushObject(Long.valueOf(lRowValue)); 1101 else if (lRowType.equals("float") || lRowType.equals("java.lang.Float")) 1102 this.pushObject(Float.valueOf(lRowValue)); 1103 else if (lRowType.equals("double") || lRowType.equals("java.lang.Double")) 1104 this.pushObject(Double.valueOf(lRowValue)); 1105 else if (lRowType.equals("boolean") || lRowType.equals("java.lang.Boolean")) 1106 this.pushObject(Boolean.valueOf(lRowValue)); 1107 else if (lRowType.equals("char") || lRowType.equals("java.lang.Character")) 1108 this.pushObject(new Character (lRowValue.charAt(0))); 1109 else 1110 { 1111 System.out.println("Found and unknow type in a row"); 1112 this.pushObject(null); 1113 } 1114 1115 } 1116 1117 return isSimple; 1118 } 1119 1120 public void DumpStatus() 1121 { 1122 super.DumpStatus(); 1124 1125 System.out.println("Dump Status from class XMLGraphSerializer"); 1126 System.out.println("Row Type stack " + this.RowTypeStack); 1127 System.out.println("Row Counter stack " + this.RowCountStack); 1128 System.out.println("Object hash table " + this.ObjectHash); 1129 System.out.println("Dump Status from class XMLGraphSerializer - END"); 1130 1131 } 1132 1133 private void pushRowCount() 1134 { 1135 Integer lInt = new Integer (0); 1136 this.RowCountStack.push(lInt); 1137 } 1138 1139 private void popRowCount() 1140 { 1141 this.RowCountStack.pop(); 1142 } 1143 1144 private int currentRowCount() 1145 { 1146 Integer lInt = (Integer )(this.RowCountStack.peek()); 1147 return lInt.intValue(); 1148 } 1149 1150 private void incrementRowCount() 1151 { 1152 Integer lInt = (Integer )(this.RowCountStack.pop()); 1153 int lRowCount = lInt.intValue(); 1154 lRowCount++; 1155 this.RowCountStack.push(new Integer (lRowCount)); 1156 } 1157 1158 1160 1167 private static class WrapperClassHelper 1168 { 1169 1173 private static interface Converter { public Object valueOf(String s); } 1174 1175 1176 private static final Map converters; 1177 1178 static 1179 { 1180 converters = new HashMap(8); 1182 converters.put(Boolean .class, 1183 new Converter() { public Object valueOf(String s) 1184 { return Boolean.valueOf(s); } }); 1185 converters.put(Byte .class, 1186 new Converter() { public Object valueOf(String s) 1187 { return Byte.valueOf(s); } }); 1188 converters.put(Short .class, 1189 new Converter() { public Object valueOf(String s) 1190 { return Short.valueOf(s); } }); 1191 converters.put(Character .class, 1192 new Converter() { public Object valueOf(String s) 1193 { return new Character (s.charAt(0)); } }); 1194 converters.put(Integer .class, 1195 new Converter() { public Object valueOf(String s) 1196 { return Integer.valueOf(s); } }); 1197 converters.put(Long .class, 1198 new Converter() { public Object valueOf(String s) 1199 { return Long.valueOf(s); } }); 1200 converters.put(Float .class, 1201 new Converter() { public Object valueOf(String s) 1202 { return Float.valueOf(s); } }); 1203 converters.put(Double .class, 1204 new Converter() { public Object valueOf(String s) 1205 { return Double.valueOf(s); } }); 1206 } 1207 1208 1209 private Class wrapperClass; 1210 1211 1212 private String id; 1213 1214 1219 public WrapperClassHelper(Class wrapperClass, String id) 1220 { 1221 this.wrapperClass = wrapperClass; 1222 this.id = id; 1223 } 1224 1225 1226 public String getId() 1227 { 1228 return id; 1229 } 1230 1231 1240 public Object valueOf(String s) 1241 { 1242 Converter conv = (Converter) converters.get(wrapperClass); 1243 return conv != null ? conv.valueOf(s) : null; 1244 } 1245 1246 1253 public static boolean isWrapperClass(Class clazz) 1254 { 1255 return converters.containsKey(clazz); 1256 } 1257 1258 } 1259 1260} | Popular Tags |