public Object parseObject()

in modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java [528:685]


        public Object parseObject(String pString, ParsePosition pParsePosition) {
            assert pString != null : "The String argument must not be null.";
            assert pParsePosition != null : "The ParsePosition argument must not be null.";
            int offset = pParsePosition.getIndex();
            int length = pString.length();

            boolean isMinus = false;
            StringBuffer digits = new StringBuffer();
            int year = 0;
            int month = 0;
            int mday = 0;
            if (parseDate) {
                // Sign
                if (offset < length) {
                    char c = pString.charAt(offset);
                    if (c == '+') {
                        ++offset;
                    } else if (c == '-') {
                        ++offset;
                        isMinus = true;
                    }
                }

                offset = parseInt(pString, offset, digits);
                if (digits.length() < 4) {
                    pParsePosition.setErrorIndex(offset);
                    return null;
                }
                year = Integer.parseInt(digits.toString());

                if (offset < length && pString.charAt(offset) == '-') {
                    ++offset;
                } else {
                    pParsePosition.setErrorIndex(offset);
                    return null;
                }

                offset = parseInt(pString, offset, digits);
                if (digits.length() != 2) {
                    pParsePosition.setErrorIndex(offset);
                    return null;
                }
                month = Integer.parseInt(digits.toString());

                if (offset < length && pString.charAt(offset) == '-') {
                    ++offset;
                } else {
                    pParsePosition.setErrorIndex(offset);
                    return null;
                }

                offset = parseInt(pString, offset, digits);
                if (digits.length() != 2) {
                    pParsePosition.setErrorIndex(offset);
                    return null;
                }
                mday = Integer.parseInt(digits.toString());

                if (parseTime) {
                    if (offset < length && pString.charAt(offset) == 'T') {
                        ++offset;
                    } else {
                        pParsePosition.setErrorIndex(offset);
                        return null;
                    }
                }
            } else {
                year = month = mday = 0;
            }

            int hour = 0;
            int minute = 0;
            int second = 0;
            int millis = 0;
            if (parseTime) {
                offset = parseInt(pString, offset, digits);
                if (digits.length() != 2) {
                    pParsePosition.setErrorIndex(offset);
                    return null;
                }
                hour = Integer.parseInt(digits.toString());

                if (offset < length && pString.charAt(offset) == ':') {
                    ++offset;
                } else {
                    pParsePosition.setErrorIndex(offset);
                    return null;
                }

                offset = parseInt(pString, offset, digits);
                if (digits.length() != 2) {
                    pParsePosition.setErrorIndex(offset);
                    return null;
                }
                minute = Integer.parseInt(digits.toString());

                if (offset < length && pString.charAt(offset) == ':') {
                    ++offset;
                } else {
                    pParsePosition.setErrorIndex(offset);
                    return null;
                }

                offset = parseInt(pString, offset, digits);
                if (digits.length() != 2) {
                    pParsePosition.setErrorIndex(offset);
                    return null;
                }
                second = Integer.parseInt(digits.toString());

                if (offset < length && pString.charAt(offset) == '.') {
                    ++offset;
                    offset = parseInt(pString, offset, digits);
                    if (digits.length() > 0) {
                        millis = Integer.parseInt(digits.toString());
                    } else {
                        millis = 0;
                    }
                } else {
                    millis = 0;
                }
            } else {
                hour = minute = second = millis = 0;
            }

            digits.setLength(0);
            digits.append("GMT");
            if (offset < length) {
                char c = pString.charAt(offset);
                if (c == 'Z') {
                    // Ignore UTC, it is the default
                    ++offset;
                } else if (c == '+' || c == '-') {
                    digits.append(c);
                    ++offset;
                    for (int i = 0; i < 5; i++) {
                        if (offset >= length) {
                            pParsePosition.setErrorIndex(offset);
                            return null;
                        }
                        c = pString.charAt(offset);
                        if ((i != 2 && Character.isDigit(c)) || (i == 2 && c == ':')) {
                            digits.append(c);
                        } else {
                            pParsePosition.setErrorIndex(offset);
                            return null;
                        }
                        ++offset;
                    }
                }
            }

            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(digits.toString()));
            cal.set(isMinus ? -year : year, parseDate ? month - 1 : month, mday, hour, minute, second);
            cal.set(Calendar.MILLISECOND, millis);
            pParsePosition.setIndex(offset);
            return cal;
        }