325N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. 325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 325N/A * This code is free software; you can redistribute it and/or modify it 325N/A * under the terms of the GNU General Public License version 2 only, as 325N/A * published by the Free Software Foundation. Oracle designates this 325N/A * particular file as subject to the "Classpath" exception as provided 325N/A * by Oracle in the LICENSE file that accompanied this code. 325N/A * This code is distributed in the hope that it will be useful, but WITHOUT 325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 325N/A * version 2 for more details (a copy is included in the LICENSE file that 325N/A * accompanied this code). 325N/A * You should have received a copy of the GNU General Public License version 325N/A * 2 along with this work; if not, write to the Free Software Foundation, 325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 325N/A * or visit www.oracle.com if you need additional information or have any 325N/A * This class is the JAXB RI's default implementation of the 325N/A * {@link DatatypeConverterInterface}. 325N/A * methods in {@link DatatypeConverter}, it will delegate 325N/A * This class is responsible for whitespace normalization. 325N/A * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li></ul> 325N/A * To avoid re-creating instances, we cache one instance. 325N/A * Faster but less robust String->int conversion. 325N/A * <li>XML Schema allows '+', but {@link Integer#valueOf(String)} is not. 325N/A * <li>XML Schema allows leading and trailing (but not in-between) whitespaces. 325N/A * {@link Integer#valueOf(String)} doesn't allow any. 325N/A // from purely XML Schema perspective, 325N/A // this implementation has a problem, since 325N/A // in xs:decimal "1.0" and "1" is equal whereas the above 325N/A // code will return different values for those two forms. 325N/A // the code was originally using com.sun.msv.datatype.xsd.NumberType.load, 325N/A // but a profiling showed that the process of normalizing "1.0" into "1" 325N/A // could take non-trivial time. 325N/A // also, from the user's point of view, one might be surprised if 325N/A // 1 (not 1.0) is returned from "1.000" 325N/A /* Incompatibilities of XML Schema's float "xfloat" and Java's float "jfloat" 325N/A * jfloat.valueOf ignores leading and trailing whitespaces, 325N/A whereas this is not allowed in xfloat. 325N/A * jfloat.valueOf allows "float type suffix" (f, F) to be 325N/A appended after float literal (e.g., 1.52e-2f), whereare 325N/A this is not the case of xfloat. 325N/A * jfloat allows ".523". And there is no clear statement that mentions 325N/A this case in xfloat. Although probably this is allowed. 325N/A // these screening process is necessary due to the wobble of Float.valueOf method 325N/A // these screening process is necessary due to the wobble of Float.valueOf method 325N/A// throw new IllegalArgumentException("String \"" + literal + "\" is not valid boolean value."); 325N/A// throw new IllegalArgumentException("String \"" + literal + "\" is not valid boolean value."); 325N/A// throw new IllegalArgumentException("String \"" + literal + "\" is not valid boolean value."); 325N/A * @return null if fails to convert. 325N/A int idx =
start +
1;
// no point in searching the first char. that's not valid. 325N/A // Prefix exists, check everything 325N/A // uri can never be null according to javadoc, 325N/A // but some users reported that there are implementations that return null. 325N/A // error: unbound prefix 325N/A // "111" is not a valid hex encoding. 325N/A if (h == -
1 || l == -
1) {
325N/A// return (String)SimpleURType.theInstance._createValue( lexicalXSDAnySimpleType, null ); 325N/A// return StringType.theInstance.convertToLexicalValue( val, null ); 325N/A * Just return the string passed as a parameter but 325N/A * installs an instance of this class as the DatatypeConverter 325N/A * implementation. Used from static fixed value initializers. 325N/A for (i =
0; i <
128; i++) {
325N/A for (i =
'A'; i <=
'Z'; i++) {
325N/A for (i =
'a'; i <=
'z'; i++) {
325N/A for (i =
'0'; i <=
'9'; i++) {
325N/A * computes the length of binary data speculatively. 325N/A * Our requirement is to create byte[] of the exact length to store the binary data. 325N/A * If we do this in a straight-forward way, it takes two passes over the data. 325N/A * Experiments show that this is a non-trivial overhead (35% or so is spent on 325N/A * the first pass in calculating the length.) 325N/A * So the approach here is that we compute the length speculatively, without looking 325N/A * at the whole contents. The obtained speculative value is never less than the 325N/A * actual length of the binary data, but it may be bigger. So if the speculation 325N/A * goes wrong, we'll pay the cost of reallocation and buffer copying. 325N/A * If the base64 text is tightly packed with no indentation nor illegal char 325N/A * (like what most web services produce), then the speculation of this method 325N/A * will be correct, so we get the performance benefit. 325N/A // compute the tail '=' chars 325N/A if (
code == -
1)
// most likely this base64 text is indented. go with the upper bound 325N/A j++;
// text.charAt(j) is now at some base64 char, so +1 to make it the size 325N/A if (
padSize >
2)
// something is wrong with base64. be safe and go with the upper bound 325N/A // so far this base64 looks like it's unindented tightly packed base64. 325N/A // take a chance and create an array with the expected size 325N/A * base64Binary data is likely to be long, and decoding requires 325N/A * each character to be accessed twice (once for counting length, another 325N/A * A benchmark showed that taking {@link String} is faster, presumably 325N/A * because JIT can inline a lot of string access (with data of 1K chars, it was twice as fast) 325N/A // convert each quadruplet to three bytes. 325N/A // quadruplet is now filled. 325N/A // we overestimated, so need to create a new buffer 325N/A for (i =
0; i <
26; i++) {
325N/A for (i =
26; i <
52; i++) {
325N/A for (i =
52; i <
62; i++) {
325N/A * Encodes a byte array into a char array by doing base64 encoding. 325N/A * The caller must supply a big enough buffer. 325N/A * the value of {@code ptr+((len+2)/3)*4}, which is the new offset 325N/A * in the output buffer where the further bytes should be placed. 325N/A // encode elements until only 1 or 2 elements are left to encode 325N/A // encode when exactly 1 element (left) to encode 325N/A // encode when exactly 2 elements (left) to encode 325N/A * Encodes a byte array into another byte array by first doing base64 encoding 325N/A * then encoding the result in ASCII. 325N/A * The caller must supply a big enough buffer. 325N/A * the value of {@code ptr+((len+2)/3)*4}, which is the new offset 325N/A * in the output buffer where the further bytes should be placed. 325N/A // encode when exactly 1 element (left) to encode 325N/A // encode when exactly 2 elements (left) to encode 325N/A if (
fch !=
'%') {
// not a meta character 325N/A // seen meta character. we don't do error check against the format 325N/A case 's':
// parse seconds. 325N/A // illegal meta character. impossible. 325N/A }
else // positive value 325N/A /** formats time zone specifier. */ 325N/A // otherwise print out normally. 325N/A /** formats Integer into two-character-wide string. */ 325N/A // n is always non-negative.