1 34 35 36 package com.micronova.util; 37 38 import java.util.*; 39 import java.util.regex.*; 40 import java.lang.reflect.*; 41 import java.text.*; 42 import java.io.*; 43 import java.net.*; 44 import javax.xml.parsers.*; 45 import javax.xml.transform.*; 46 import javax.xml.transform.dom.*; 47 import javax.xml.transform.stream.*; 48 import org.w3c.dom.*; 49 50 51 52 public class TypeUtil 53 { 54 55 56 private static final Map PRIMITIVETYPE; 57 private static final Map WRAPPERTYPE; 58 59 static 60 { 61 PRIMITIVETYPE = new HashMap(); 62 63 PRIMITIVETYPE.put("boolean", Boolean.TYPE); 64 PRIMITIVETYPE.put("char", Character.TYPE); 65 PRIMITIVETYPE.put("byte", Byte.TYPE); 66 PRIMITIVETYPE.put("short", Short.TYPE); 67 PRIMITIVETYPE.put("int", Integer.TYPE); 68 PRIMITIVETYPE.put("long", Long.TYPE); 69 PRIMITIVETYPE.put("float", Float.TYPE); 70 PRIMITIVETYPE.put("double", Double.TYPE); 71 72 WRAPPERTYPE = new HashMap(); 73 74 WRAPPERTYPE.put(Boolean.TYPE, Boolean .class); 75 WRAPPERTYPE.put(Character.TYPE, Character .class); 76 WRAPPERTYPE.put(Byte.TYPE, Byte .class); 77 WRAPPERTYPE.put(Short.TYPE, Short .class); 78 WRAPPERTYPE.put(Integer.TYPE, Integer .class); 79 WRAPPERTYPE.put(Long.TYPE, Long .class); 80 WRAPPERTYPE.put(Float.TYPE, Float .class); 81 WRAPPERTYPE.put(Double.TYPE, Double .class); 82 } 83 84 85 86 public static final Double isDouble(Object object) 87 { 88 if (object != null) 89 { 90 if (object instanceof Double ) 91 { 92 return (Double )object; 93 } 94 else 95 { 96 try 97 { 98 return Double.valueOf(object.toString()); 99 } 100 catch (Exception e) 101 { 102 } 103 } 104 } 105 106 return null; 107 } 108 109 110 111 public static final Float isFloat(Object object) 112 { 113 if (object != null) 114 { 115 if (object instanceof Float ) 116 { 117 return (Float )object; 118 } 119 else 120 { 121 try 122 { 123 return Float.valueOf(object.toString()); 124 } 125 catch (Exception e) 126 { 127 } 128 } 129 } 130 131 return null; 132 } 133 134 135 136 public static final Long isLong(Object object) 137 { 138 if (object != null) 139 { 140 if (object instanceof Long ) 141 { 142 return (Long )object; 143 } 144 else 145 { 146 try 147 { 148 return new Long (((Double )isDouble(object)).longValue()); 149 } 150 catch (Exception e) 151 { 152 } 153 } 154 } 155 156 return null; 157 } 158 159 160 161 public static final Integer isInteger(Object object) 162 { 163 if (object != null) 164 { 165 if (object instanceof Integer ) 166 { 167 return (Integer )object; 168 } 169 else 170 { 171 try 172 { 173 return new Integer (((Long )isLong(object)).intValue()); 174 } 175 catch (Exception e) 176 { 177 } 178 } 179 } 180 181 return null; 182 } 183 184 185 186 public static final Short isShort(Object object) 187 { 188 if (object != null) 189 { 190 if (object instanceof Short ) 191 { 192 return (Short )object; 193 } 194 else 195 { 196 try 197 { 198 return new Short (((Long )isLong(object)).shortValue()); 199 } 200 catch (Exception e) 201 { 202 } 203 } 204 } 205 206 return null; 207 } 208 209 210 211 public static final Byte isByte(Object object) 212 { 213 if (object != null) 214 { 215 if (object instanceof Byte ) 216 { 217 return (Byte )object; 218 } 219 else 220 { 221 try 222 { 223 return new Byte (((Long )isLong(object)).byteValue()); 224 } 225 catch (Exception e) 226 { 227 } 228 } 229 } 230 231 return null; 232 } 233 234 235 236 public static final String isString(Object object) 237 { 238 if (object != null) 239 { 240 try 241 { 242 if (object instanceof InputStream) 243 { 244 return StringUtil.toBinaryString(IOUtil.readAll((InputStream)object)); 245 } 246 else if (object instanceof Reader) 247 { 248 return new String (IOUtil.readAll((Reader)object)); 249 } 250 else if (object instanceof Node) 251 { 252 Node node = (Node)object; 253 254 Transformer transformer = TransformerFactory.newInstance().newTransformer(); 255 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); 256 257 StringWriter writer = new StringWriter(); 258 259 Source source = new DOMSource(node); 260 Result result = new StreamResult(writer); 261 262 transformer.transform(source, result); 263 264 return writer.toString(); 265 } 266 else 267 { 268 try 269 { 270 if (object instanceof javax.mail.internet.MimeMessage ) 271 { 272 ByteArrayOutputStream bOut = new ByteArrayOutputStream(); 273 274 ((javax.mail.internet.MimeMessage )object).writeTo(bOut); 275 276 return bOut.toString(); 277 } 278 } 279 catch (Exception ee) 280 { 281 } 282 283 return object.toString(); 284 } 285 } 286 catch (Exception e) 287 { 288 } 289 } 290 291 return null; 292 } 293 294 295 296 public static final Boolean isBoolean(Object object) 297 { 298 if (object != null) 299 { 300 if (object instanceof Boolean ) 301 { 302 return (Boolean )object; 303 } 304 else 305 { 306 try 307 { 308 return Boolean.valueOf(object.toString()); 309 } 310 catch (Exception e) 311 { 312 } 313 } 314 } 315 316 return null; 317 } 318 319 320 321 public static final boolean isTrue(Object object) 322 { 323 Boolean b = isBoolean(object); 324 325 return ((b != null) && (b.booleanValue())); 326 } 327 328 329 330 public static final boolean isFalse(Object object) 331 { 332 Boolean b = isBoolean(object); 333 334 return ((b != null) && (!b.booleanValue())); 335 } 336 337 338 339 public static final Character isCharacter(Object object) 340 { 341 if (object != null) 342 { 343 if (object instanceof Character ) 344 { 345 return (Character )object; 346 } 347 else 348 { 349 String s = object.toString(); 350 351 if (s.length() > 0) 352 { 353 return new Character (s.charAt(0)); 354 } 355 } 356 } 357 358 return null; 359 } 360 361 362 363 public static final Object [] isArray(Object object) 364 { 365 if (object != null) 366 { 367 if (object instanceof Object []) 368 { 369 return (Object [])object; 370 } 371 else if (object instanceof Collection) 372 { 373 return ((Collection)object).toArray(); 374 } 375 else if (object.getClass().isArray()) 376 { 377 int i = Array.getLength(object); 378 379 Object [] array = new Object [i]; 380 381 while (--i >= 0) 382 { 383 array[i] = Array.get(object, i); 384 } 385 386 return array; 387 } 388 } 389 390 return null; 391 } 392 393 394 395 public static final String [] isStringArray(Object object) 396 { 397 String [] s = null; 398 399 if (object != null) 400 { 401 if (object instanceof String []) 402 { 403 s = (String [])object; 404 } 405 else if (object instanceof Object []) 406 { 407 Object [] array = (Object [])object; 408 int arraySize = array.length; 409 410 s = new String [arraySize]; 411 412 for (int i = arraySize; --i >=0; ) 413 { 414 Object a = array[i]; 415 416 s[i] = (a != null) ? a.toString() : null; 417 } 418 } 419 else if (object instanceof List) 420 { 421 List list = (List)object; 422 int listSize = list.size(); 423 424 s = new String [listSize]; 425 426 for (int i = listSize; --i >=0; ) 427 { 428 Object a = list.get(i); 429 430 s[i] = (a != null) ? a.toString() : null; 431 } 432 } 433 } 434 435 return s; 436 } 437 438 439 440 public static final List isList(Object object) 441 { 442 if (object != null) 443 { 444 if (object instanceof List) 445 { 446 return (List)object; 447 } 448 else 449 { 450 Object [] array = isArray(object); 451 452 if (array != null) 453 { 454 return Arrays.asList(array); 455 } 456 } 457 } 458 459 return null; 460 } 461 462 463 464 public static final List isStringList(Object object, char separator, char escape) 465 { 466 List list = null; 467 468 if (object != null) 469 { 470 list = isList(object); 471 472 if (list == null) 473 { 474 list = StringUtil.split(object.toString(), separator, escape); 475 } 476 } 477 478 return list; 479 } 480 481 482 483 public static final Collection isCollection(Object object) 484 { 485 if (object instanceof Collection) 486 { 487 return (Collection)object; 488 } 489 else 490 { 491 return isList(object); 492 } 493 } 494 495 496 497 public static final URI isURI(Object object) 498 { 499 URI uri = null; 500 501 if (object != null) 502 { 503 try 504 { 505 if (object instanceof URI) 506 { 507 uri = (URI)object; 508 } 509 else 510 { 511 uri = new URI(object.toString()); 512 } 513 } 514 catch (Exception e) 515 { 516 uri = null; 517 } 518 } 519 520 return uri; 521 } 522 523 524 525 public static final URL isURL(Object object, URL contextURL) 526 { 527 URL url = null; 528 529 if (object != null) 530 { 531 try 532 { 533 url = new URL(contextURL, object.toString()); 534 } 535 catch (Exception e) 536 { 537 url = null; 538 } 539 } 540 541 return url; 542 } 543 544 545 546 public static final URL isURL(Object object) 547 { 548 URL url = null; 549 550 if (object != null) 551 { 552 try 553 { 554 url = new URL(object.toString()); 555 } 556 catch (Exception e) 557 { 558 url = null; 559 } 560 } 561 562 return url; 563 } 564 565 566 567 public static final File isFile(Object object, Object parentObject) 568 { 569 File file = null; 570 571 if (object != null) 572 { 573 try 574 { 575 if (object instanceof URI) 576 { 577 file = new File((URI)object); 578 } 579 else if (object instanceof File) 580 { 581 file = (File)object; 582 } 583 else 584 { 585 file = new File(object.toString()); 586 } 587 588 if (parentObject != null) 589 { 590 file = new File(isFile(parentObject), file.toString()); 591 } 592 } 593 catch (Exception e) 594 { 595 file = null; 596 } 597 } 598 599 return file; 600 } 601 602 public static final File isFile(Object object) 603 { 604 return isFile(object, null); 605 } 606 607 608 609 public static final NestedMap isNestedMap(Object object) 610 { 611 if (object instanceof NestedMap) 612 { 613 return (NestedMap)object; 614 } 615 else 616 { 617 try 618 { 619 return new NestedMap(object); 620 } 621 catch (Exception e) 622 { 623 return null; 624 } 625 } 626 } 627 628 629 630 public static final Locale isLocale(Object object) 631 { 632 if (object instanceof Locale) 633 { 634 return (Locale)object; 635 } 636 else 637 { 638 NestedMap specMap = isNestedMap(object); 639 640 String language = specMap.getString("language", ""); 641 String country = specMap.getString("country", ""); 642 String variant = specMap.getString("variant", ""); 643 644 return new Locale(language, country, variant); 645 } 646 } 647 648 649 650 public static final TimeZone isTimeZone(Object object) 651 { 652 if (object instanceof TimeZone) 653 { 654 return (TimeZone)object; 655 } 656 else 657 { 658 NestedMap specMap = isNestedMap(object); 659 660 String id = specMap.getString("id", ""); 661 662 if (id == null) 663 { 664 return TimeZone.getDefault(); 665 } 666 else 667 { 668 return TimeZone.getTimeZone(id); 669 } 670 } 671 } 672 673 674 675 676 public static final Calendar isCalendar(Object object, String pattern, Locale locale, TimeZone timeZone) throws Exception 677 { 678 Calendar calendar = null; 679 680 if (object != null) 681 { 682 if (object instanceof Calendar) 683 { 684 calendar = (Calendar)object; 685 } 686 else 687 { 688 if (locale == null) 689 { 690 locale = Locale.getDefault(); 691 } 692 693 calendar = Calendar.getInstance(locale); 694 695 Date date = isDate(object, pattern, locale, timeZone); 696 697 calendar.setTime(date); 698 } 699 } 700 701 return calendar; 702 } 703 704 705 706 public static final Date isDate(Object object, String pattern, Locale locale, TimeZone timeZone) throws Exception 707 { 708 Date date = null; 709 710 if (object != null) 711 { 712 if (object instanceof Date) 713 { 714 date = (Date)object; 715 } 716 else if (object instanceof Calendar) 717 { 718 date = ((Calendar)object).getTime(); 719 } 720 else 721 { 722 if (object instanceof Number ) 723 { 724 Long longObject = (Long )isLong(object); 725 726 date = new Date(); 727 date.setTime(longObject.longValue()); 728 } 729 else 730 { 731 SimpleDateFormat simpleDateFormat; 732 733 if (pattern == null) 734 { 735 simpleDateFormat = new SimpleDateFormat(); 736 } 737 else 738 { 739 simpleDateFormat = new SimpleDateFormat(pattern, locale); 740 } 741 742 if (timeZone != null) 743 { 744 simpleDateFormat.setTimeZone(timeZone); 745 } 746 747 ParsePosition parsePosition = new ParsePosition(0); 748 749 String objectString = object.toString(); 750 751 date = simpleDateFormat.parse(objectString, parsePosition); 752 753 if (parsePosition.getIndex() != objectString.length()) 754 { 755 date = null; 756 } 757 } 758 } 759 } 760 761 return date; 762 } 763 764 765 766 public static final Number isNumber(Object object, String pattern, Locale locale) throws Exception 767 { 768 Number number = null; 769 770 if (object != null) 771 { 772 if (object instanceof Number ) 773 { 774 number = (Number )object; 775 } 776 else 777 { 778 DecimalFormat decimalFormat; 779 780 if (pattern == null) 781 { 782 decimalFormat = new DecimalFormat(); 783 } 784 else 785 { 786 decimalFormat = new DecimalFormat(pattern, new DecimalFormatSymbols(locale)); 787 } 788 789 ParsePosition parsePosition = new ParsePosition(0); 790 791 String objectString = object.toString(); 792 793 number = decimalFormat.parse(objectString, parsePosition); 794 795 if (parsePosition.getIndex() != objectString.length()) 796 { 797 number = null; 798 } 799 } 800 } 801 802 return number; 803 } 804 805 806 807 public static final int length(Object object) 808 { 809 if (object != null) 810 { 811 if (object instanceof String ) 812 { 813 return object.toString().length(); 814 } 815 else if (object instanceof Collection) 816 { 817 return ((Collection)object).size(); 818 } 819 else if (object.getClass().isArray()) 820 { 821 return Array.getLength(object); 822 } 823 } 824 825 return -1; 826 } 827 828 829 830 public static final int size(Object object) 831 { 832 return length(object); 833 } 834 835 836 837 public static final int getActualSize(Object object) 838 { 839 if (object instanceof SparseObject) 840 { 841 return ((SparseObject)object).getActualSize(); 842 } 843 else 844 { 845 return size(object); 846 } 847 } 848 849 850 851 public static final boolean isEmptyString(Object object) 852 { 853 return ((object == null) || ("".equals(object))); 854 } 855 856 857 858 public static final boolean isEmpty(Object object) 859 { 860 if (isEmptyString(object)) 861 { 862 return true; 863 } 864 else if (object instanceof Collection) 865 { 866 return ((Collection)object).isEmpty(); 867 } 868 else if (object.getClass().isArray()) 869 { 870 return (Array.getLength(object) == 0); 871 } 872 else 873 { 874 return false; 875 } 876 } 877 878 879 880 public static final Object isClass(Object object, Class classObject) 881 { 882 if (classObject.isInstance(object)) 883 { 884 return object; 885 } 886 else 887 { 888 try 889 { 890 if ((classObject == Boolean.TYPE) || (classObject == Boolean .class)) 891 { 892 return Boolean.valueOf(object.toString()); 893 } 894 else if ((classObject == Byte.TYPE) || (classObject == Byte .class)) 895 { 896 return Byte.valueOf(object.toString()); 897 } 898 else if ((classObject == Short.TYPE) || (classObject == Short .class)) 899 { 900 return Short.valueOf(object.toString()); 901 } 902 else if ((classObject == Integer.TYPE) || (classObject == Integer .class)) 903 { 904 return Integer.valueOf(object.toString()); 905 } 906 else if ((classObject == Long.TYPE) || (classObject == Long .class)) 907 { 908 return Long.valueOf(object.toString()); 909 } 910 else if ((classObject == Float.TYPE) || (classObject == Float .class)) 911 { 912 return Float.valueOf(object.toString()); 913 } 914 else if ((classObject == Double.TYPE) || (classObject == Double .class)) 915 { 916 return Double.valueOf(object.toString()); 917 } 918 else if ((classObject == Character.TYPE) || (classObject == Character .class)) 919 { 920 return new Character (object.toString().charAt(0)); 921 } 922 else if (classObject == String .class) 923 { 924 return object.toString(); 925 } 926 } 927 catch (Exception e) 928 { 929 } 930 } 931 932 return null; 933 } 934 935 936 937 public static final Object newInstance(Class classObject, Object [] args) throws Exception 938 { 939 if (args == null) 940 { 941 return classObject.newInstance(); 942 } 943 944 Constructor[] constructors = classObject.getConstructors(); 945 946 Object [] cArgs = new Object [args.length]; 947 948 950 for (int i = 0; i < constructors.length; i ++) 951 { 952 Constructor constructor = constructors[i]; 953 Class [] parameterTypes = constructor.getParameterTypes(); 954 955 if (parameterTypes.length == args.length) 956 { 957 boolean isMatching = true; 958 959 for (int j = 0; j < parameterTypes.length; j ++) 960 { 961 Class parameterClass = parameterTypes[j]; 962 Class wrapperClass = (Class )WRAPPERTYPE.get(parameterClass); 963 964 if (wrapperClass != null) 965 { 966 parameterClass = wrapperClass; 967 } 968 969 Object arg = args[j]; 970 971 if (arg != null) 972 { 973 if (!parameterClass.isInstance(arg)) 974 { 975 isMatching = false; 976 break; 977 } 978 } 979 980 cArgs[j] = arg; 981 } 982 983 if (isMatching) 984 { 985 return constructor.newInstance(cArgs); 986 } 987 } 988 } 989 990 992 for (int i = 0; i < constructors.length; i ++) 993 { 994 Constructor constructor = constructors[i]; 995 Class [] parameterTypes = constructor.getParameterTypes(); 996 997 if (parameterTypes.length == args.length) 998 { 999 boolean isMatching = true; 1000 1001 for (int j = 0; j < parameterTypes.length; j ++) 1002 { 1003 Object arg = args[j]; 1004 1005 if (arg != null) 1006 { 1007 arg = isClass(arg, parameterTypes[j]); 1008 1009 if (arg == null) 1010 { 1011 isMatching = false; 1012 break; 1013 } 1014 } 1015 1016 cArgs[j] = arg; 1017 } 1018 1019 if (isMatching) 1020 { 1021 return constructor.newInstance(cArgs); 1022 } 1023 } 1024 } 1025 1026 return null; 1027 } 1028 1029 1030 1031 public static final Pattern isPattern(Object object) 1032 { 1033 Pattern pattern = null; 1034 1035 try 1036 { 1037 if (object instanceof Pattern) 1038 { 1039 pattern = (Pattern)object; 1040 } 1041 else if (!isEmptyString(object)) 1042 { 1043 pattern = Pattern.compile(object.toString()); 1044 } 1045 } 1046 catch (Exception e) 1047 { 1048 } 1049 1050 return pattern; 1051 } 1052 1053 1054 1055 public static final Class forName(String className, String defaultPrefix) throws Exception 1056 { 1057 int dimensions = 0; 1058 1059 for (;;) 1060 { 1061 int arrayIndex = className.lastIndexOf("[]"); 1062 1063 if (arrayIndex == -1) 1064 { 1065 break; 1066 } 1067 else 1068 { 1069 dimensions ++; 1070 className = className.substring(0, arrayIndex); 1071 } 1072 } 1073 1074 Class classObject = null; 1075 1076 if (className.indexOf('.') >= 0) 1077 { 1078 classObject = Class.forName(className); 1079 } 1080 else 1081 { 1082 Class primitiveClass = (Class )(PRIMITIVETYPE.get(className)); 1083 1084 if (primitiveClass != null) 1085 { 1086 classObject = primitiveClass; 1087 } 1088 else 1089 { 1090 classObject = Class.forName(defaultPrefix + className); 1091 } 1092 } 1093 1094 if (dimensions == 0) 1095 { 1096 return classObject; 1097 } 1098 else 1099 { 1100 return (Array.newInstance(classObject, new int[dimensions])).getClass(); 1101 } 1102 } 1103 1104 1105 1106 public static final Class forName(String className) throws Exception 1107 { 1108 return forName(className, "java.lang."); 1109 } 1110 1111 1112 1113 public static final Object invoke(Object object, Class classObject, String methodName, Class [] types, Object [] args) throws Exception 1114 { 1115 if (classObject == null) 1116 { 1117 classObject = object.getClass(); 1118 } 1119 1120 if ("*".equals(methodName)) 1121 { 1122 Constructor c = classObject.getConstructor(types); 1123 1124 return c.newInstance(args); 1125 } 1126 else if (methodName.startsWith(".")) 1127 { 1128 Field field = classObject.getDeclaredField(methodName.substring(1)); 1129 return field.get(object); 1130 } 1131 else 1132 { 1133 Method m = classObject.getMethod(methodName, types); 1134 1135 return m.invoke(object, args); 1136 } 1137 } 1138 1139 1140 1141 public final static String OBJECT = "object"; 1142 public final static String CLASS = "class"; 1143 public final static String METHOD = "method"; 1144 public final static String TYPE = "type"; 1145 public final static String VALUE = "value"; 1146 public final static String OBJECTPROPERTY = "objectProperty"; 1147 1148 public static Object invoke(NestedMap map) throws Exception 1149 { 1150 Object returnValue = null; 1151 1152 Object object = map.get(OBJECT); 1153 List list = map.getSubList(false); 1154 1155 Class [] argTypes = null; 1156 Object [] argValues = null; 1157 1158 if (list != null) 1159 { 1160 int listSize = list.size(); 1161 1162 argTypes = new Class [listSize]; 1163 argValues = new Object [listSize]; 1164 1165 for (int i = 0; i < listSize; i ++) 1166 { 1167 Object argSpec = list.get(i); 1168 1169 Object argType = null; 1170 Object argValue = argSpec; 1171 1172 if (argSpec instanceof Map) 1173 { 1174 Map argMap = (Map)argSpec; 1175 1176 argType = argMap.get(TYPE); 1177 argValue = argMap.get(VALUE); 1178 } 1179 1180 Class argClass = Object .class; 1181 1182 if (argType instanceof String ) 1183 { 1184 argClass = TypeUtil.forName(argType.toString()); 1185 } 1186 else if (argType instanceof Class ) 1187 { 1188 argClass = (Class )argType; 1189 } 1190 else if (argType != null) 1191 { 1192 argClass = argType.getClass(); 1193 } 1194 else if (argValue != null) 1195 { 1196 argClass = argValue.getClass(); 1197 } 1198 1199 argTypes[i] = argClass; 1200 1201 argValues[i] = TypeUtil.isClass(argValue, argClass); 1202 } 1203 } 1204 1205 String methodName = (String )map.get(METHOD); 1206 1207 Class classObject = null; 1208 1209 Object classSpec = map.get(CLASS); 1210 1211 if (classSpec != null) 1212 { 1213 if (classSpec instanceof Class ) 1214 { 1215 classObject = (Class )classSpec; 1216 } 1217 else 1218 { 1219 classObject = TypeUtil.forName(classSpec.toString()); 1220 } 1221 } 1222 1223 return invoke(object, classObject, methodName, argTypes, argValues); 1224 } 1225 1226 1227 1228 public static Object invoke(Object object, NestedMap map, String objectProperty) throws Exception 1229 { 1230 map.put(objectProperty, object); 1231 1232 return invoke(map); 1233 } 1234 1235 1236 1237 public static Object invoke(Object object, NestedMap map) throws Exception 1238 { 1239 return invoke(object, map, map.getString(OBJECTPROPERTY, OBJECT)); 1240 } 1241 1242 1243 1244 public static List subList(List list, int start, int end) 1245 { 1246 if (list != null) 1247 { 1248 int length = list.size(); 1249 1250 if (start < 0) 1251 { 1252 start = length + start; 1253 } 1254 1255 if (end <= 0) 1256 { 1257 end = length + end; 1258 } 1259 1260 if (start < 0) 1261 { 1262 start = 0; 1263 } 1264 1265 if (end > length) 1266 { 1267 end = length; 1268 } 1269 1270 if (end <= start) 1271 { 1272 list = new ArrayList(); 1273 } 1274 else 1275 { 1276 list = list.subList(start, end); 1277 } 1278 } 1279 1280 return list; 1281 } 1282 1283 1284 1285 public static Node isNode(Object object, Document document) throws Exception 1286 { 1287 if (object == null) 1288 { 1289 return null; 1290 } 1291 else if (object instanceof Node) 1292 { 1293 return (Node)object; 1294 } 1295 else 1296 { 1297 return XMLUtil.decodeNodeMap(isNestedMap(object), document); 1298 } 1299 } 1300 1301 public static Node isNode(Object object) throws Exception 1302 { 1303 return isNode(object, null); 1304 } 1305} 1306 | Popular Tags |