1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
40 import javax.xml.stream.XMLStreamException;
41 import javax.xml.stream.XMLStreamWriter;
42
43 /**
44 * This class is the JAXB RI's default implementation of the
45 * {@link DatatypeConverterInterface}.
46 *
47 * <p>
48 * When client applications specify the use of the static print/parse
49 * methods in {@link DatatypeConverter}, it will delegate
50 * to this class.
51 *
52 * <p>
53 * This class is responsible for whitespace normalization.
54 *
55 * @author <ul><li>Ryan Shoemaker, Martin Grebac</li></ul>
56 * @since JAXB1.0
57 * @deprecated in JAXB 2.2.4 - use javax.xml.bind.DatatypeConverterImpl instead
58 * or let us know why you can't
59 */
60 public final class DatatypeConverterImpl {
61
62 protected DatatypeConverterImpl() {
63 // shall not be used
64 }
65
66 public static BigInteger _parseInteger(CharSequence s) {
67 return new BigInteger(removeOptionalPlus(WhiteSpaceProcessor.trim(s)).toString());
68 }
69
70 public static String _printInteger(BigInteger val) {
71 return val.toString();
72 }
73
74 /**
75 * Faster but less robust String->int conversion.
76 *
77 * Note that:
78 * <ol>
79 * <li>XML Schema allows '+', but {@link Integer#valueOf(String)} is not.
80 * <li>XML Schema allows leading and trailing (but not in-between) whitespaces.
857 buf.append('-');
858 offset *= -1;
859 }
860
861 offset /= 60 * 1000; // offset is in milli-seconds
862
863 formatTwoDigits(offset / 60, buf);
864 buf.append(':');
865 formatTwoDigits(offset % 60, buf);
866 }
867
868 /** formats Integer into two-character-wide string. */
869 private static void formatTwoDigits(int n, StringBuilder buf) {
870 // n is always non-negative.
871 if (n < 10) {
872 buf.append('0');
873 }
874 buf.append(n);
875 }
876 }
877 }
|
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
40 import javax.xml.stream.XMLStreamException;
41 import javax.xml.stream.XMLStreamWriter;
42
43 /**
44 * This class is the JAXB RI's default implementation of the
45 * {@link DatatypeConverterInterface}.
46 *
47 * <p>
48 * When client applications specify the use of the static print/parse
49 * methods in {@link DatatypeConverter}, it will delegate
50 * to this class.
51 *
52 * <p>
53 * This class is responsible for whitespace normalization.
54 *
55 * @author <ul><li>Ryan Shoemaker, Martin Grebac</li></ul>
56 * @since JAXB1.0
57 * @deprecated in JAXB 2.2.4 - use javax.xml.bind.DatatypeConverterImpl instead
58 * or let us know why you can't
59 */
60 @Deprecated
61 public final class DatatypeConverterImpl implements DatatypeConverterInterface {
62
63 @Deprecated
64 public static final DatatypeConverterInterface theInstance = new DatatypeConverterImpl();
65
66 protected DatatypeConverterImpl() {
67 // shall not be used
68 }
69
70 public static BigInteger _parseInteger(CharSequence s) {
71 return new BigInteger(removeOptionalPlus(WhiteSpaceProcessor.trim(s)).toString());
72 }
73
74 public static String _printInteger(BigInteger val) {
75 return val.toString();
76 }
77
78 /**
79 * Faster but less robust String->int conversion.
80 *
81 * Note that:
82 * <ol>
83 * <li>XML Schema allows '+', but {@link Integer#valueOf(String)} is not.
84 * <li>XML Schema allows leading and trailing (but not in-between) whitespaces.
861 buf.append('-');
862 offset *= -1;
863 }
864
865 offset /= 60 * 1000; // offset is in milli-seconds
866
867 formatTwoDigits(offset / 60, buf);
868 buf.append(':');
869 formatTwoDigits(offset % 60, buf);
870 }
871
872 /** formats Integer into two-character-wide string. */
873 private static void formatTwoDigits(int n, StringBuilder buf) {
874 // n is always non-negative.
875 if (n < 10) {
876 buf.append('0');
877 }
878 buf.append(n);
879 }
880 }
881
882 // DEPRECATED METHODS, KEPT FOR JAXB1 GENERATED CLASSES COMPATIBILITY, WILL BE REMOVED IN FUTURE
883
884 @Deprecated
885 public String parseString(String lexicalXSDString) {
886 return lexicalXSDString;
887 }
888
889 @Deprecated
890 public BigInteger parseInteger(String lexicalXSDInteger) {
891 return _parseInteger(lexicalXSDInteger);
892 }
893
894 @Deprecated
895 public String printInteger(BigInteger val) {
896 return _printInteger(val);
897 }
898
899 @Deprecated
900 public int parseInt(String s) {
901 return _parseInt(s);
902 }
903
904 @Deprecated
905 public long parseLong(String lexicalXSLong) {
906 return _parseLong(lexicalXSLong);
907 }
908
909 @Deprecated
910 public short parseShort(String lexicalXSDShort) {
911 return _parseShort(lexicalXSDShort);
912 }
913
914 @Deprecated
915 public String printShort(short val) {
916 return _printShort(val);
917 }
918
919 @Deprecated
920 public BigDecimal parseDecimal(String content) {
921 return _parseDecimal(content);
922 }
923
924 @Deprecated
925 public float parseFloat(String lexicalXSDFloat) {
926 return _parseFloat(lexicalXSDFloat);
927 }
928
929 @Deprecated
930 public String printFloat(float v) {
931 return _printFloat(v);
932 }
933
934 @Deprecated
935 public double parseDouble(String lexicalXSDDouble) {
936 return _parseDouble(lexicalXSDDouble);
937 }
938
939 @Deprecated
940 public boolean parseBoolean(String lexicalXSDBoolean) {
941 Boolean b = _parseBoolean(lexicalXSDBoolean);
942 return (b == null) ? false : b.booleanValue();
943 }
944
945 @Deprecated
946 public String printBoolean(boolean val) {
947 return val ? "true" : "false";
948 }
949
950 @Deprecated
951 public byte parseByte(String lexicalXSDByte) {
952 return _parseByte(lexicalXSDByte);
953 }
954
955 @Deprecated
956 public String printByte(byte val) {
957 return _printByte(val);
958 }
959
960 @Deprecated
961 public QName parseQName(String lexicalXSDQName, NamespaceContext nsc) {
962 return _parseQName(lexicalXSDQName, nsc);
963 }
964
965 @Deprecated
966 public Calendar parseDateTime(String lexicalXSDDateTime) {
967 return _parseDateTime(lexicalXSDDateTime);
968 }
969
970 @Deprecated
971 public String printDateTime(Calendar val) {
972 return _printDateTime(val);
973 }
974
975 @Deprecated
976 public byte[] parseBase64Binary(String lexicalXSDBase64Binary) {
977 return _parseBase64Binary(lexicalXSDBase64Binary);
978 }
979
980 @Deprecated
981 public byte[] parseHexBinary(String s) {
982 final int len = s.length();
983
984 // "111" is not a valid hex encoding.
985 if (len % 2 != 0) {
986 throw new IllegalArgumentException("hexBinary needs to be even-length: " + s);
987 }
988
989 byte[] out = new byte[len / 2];
990
991 for (int i = 0; i < len; i += 2) {
992 int h = hexToBin(s.charAt(i));
993 int l = hexToBin(s.charAt(i + 1));
994 if (h == -1 || l == -1) {
995 throw new IllegalArgumentException("contains illegal character for hexBinary: " + s);
996 }
997
998 out[i / 2] = (byte) (h * 16 + l);
999 }
1000
1001 return out;
1002 }
1003
1004 @Deprecated
1005 private static int hexToBin(char ch) {
1006 if ('0' <= ch && ch <= '9') {
1007 return ch - '0';
1008 }
1009 if ('A' <= ch && ch <= 'F') {
1010 return ch - 'A' + 10;
1011 }
1012 if ('a' <= ch && ch <= 'f') {
1013 return ch - 'a' + 10;
1014 }
1015 return -1;
1016 }
1017
1018 @Deprecated
1019 private static final char[] hexCode = "0123456789ABCDEF".toCharArray();
1020
1021 @Deprecated
1022 public String printHexBinary(byte[] data) {
1023 StringBuilder r = new StringBuilder(data.length * 2);
1024 for (byte b : data) {
1025 r.append(hexCode[(b >> 4) & 0xF]);
1026 r.append(hexCode[(b & 0xF)]);
1027 }
1028 return r.toString();
1029 }
1030
1031 @Deprecated
1032 public long parseUnsignedInt(String lexicalXSDUnsignedInt) {
1033 return _parseLong(lexicalXSDUnsignedInt);
1034 }
1035
1036 @Deprecated
1037 public String printUnsignedInt(long val) {
1038 return _printLong(val);
1039 }
1040
1041 @Deprecated
1042 public int parseUnsignedShort(String lexicalXSDUnsignedShort) {
1043 return _parseInt(lexicalXSDUnsignedShort);
1044 }
1045
1046 @Deprecated
1047 public Calendar parseTime(String lexicalXSDTime) {
1048 return datatypeFactory.newXMLGregorianCalendar(lexicalXSDTime).toGregorianCalendar();
1049 }
1050
1051 @Deprecated
1052 public String printTime(Calendar val) {
1053 return CalendarFormatter.doFormat("%h:%m:%s%z", val);
1054 }
1055
1056 @Deprecated
1057 public Calendar parseDate(String lexicalXSDDate) {
1058 return datatypeFactory.newXMLGregorianCalendar(lexicalXSDDate).toGregorianCalendar();
1059 }
1060
1061 @Deprecated
1062 public String printDate(Calendar val) {
1063 return _printDate(val);
1064 }
1065
1066 @Deprecated
1067 public String parseAnySimpleType(String lexicalXSDAnySimpleType) {
1068 return lexicalXSDAnySimpleType;
1069 }
1070
1071 @Deprecated
1072 public String printString(String val) {
1073 return val;
1074 }
1075
1076 @Deprecated
1077 public String printInt(int val) {
1078 return _printInt(val);
1079 }
1080
1081 @Deprecated
1082 public String printLong(long val) {
1083 return _printLong(val);
1084 }
1085
1086 @Deprecated
1087 public String printDecimal(BigDecimal val) {
1088 return _printDecimal(val);
1089 }
1090
1091 @Deprecated
1092 public String printDouble(double v) {
1093 return _printDouble(v);
1094 }
1095
1096 @Deprecated
1097 public String printQName(QName val, NamespaceContext nsc) {
1098 return _printQName(val, nsc);
1099 }
1100
1101 @Deprecated
1102 public String printBase64Binary(byte[] val) {
1103 return _printBase64Binary(val);
1104 }
1105
1106 @Deprecated
1107 public String printUnsignedShort(int val) {
1108 return String.valueOf(val);
1109 }
1110
1111 @Deprecated
1112 public String printAnySimpleType(String val) {
1113 return val;
1114 }
1115
1116 }
|