Package java.text

Examples of java.text.ParseException


    {
        Date date = null;

        if (s == null)
        {
            throw new ParseException("Input string was null", -1);
        }

        if (sdf != null) // This implies dateFormats.size() > 0
        {
            // First test the FORMATx patterns. If any of these match, break
            // the loop.
            for (int i = 1 ; i < dateFormats.size() - 1; i++)
            {
                sdf.applyPattern((String) dateFormats.get(i));

                try
                {
                    date = sdf.parse(s);
                    break; // We got a matching date. Break the loop
                }
                catch (ParseException e)
                {
                    // ignore
                }
            }

            // Now test the FORMAT pattern which is the first one in the array.
            // if no format but just FORMATx has been given, all of the patterns
            // have been shifted "one down", e.g. tested as format2, format3, format4, format1
            // in sequence.
            if (date == null)
            {
                sdf.applyPattern((String) dateFormats.get(0));

                try
                {
                    date = sdf.parse(s);
                }
                catch (ParseException e)
                {
                    // ignore
                }
            }
        }

        // Still no match. Either we had no format patterns or no pattern matched.
        // See if we have a DateFormat object around. If there were patterns given
        // and just none matched, that we might have date==null and df==null...
        if (date == null && df != null)
        {
            date = df.parse(s);
        }

        // if the date still has not been parsed at this point, throw
        // a ParseException.
        if (date == null)
        {
            throw new ParseException("Could not parse the date", 0);
        }

        return date;
    }
View Full Code Here


            }
        }

        if (result == null)
        {
            throw new ParseException(stringValue +
                    " could not be converted to a Boolean", 0);
        }
        return result;
    }
View Full Code Here

                        message = "Duplicate options for " + describeDualOption(originalId) + " found.";
                    } else {
                        message = "Incompatible options -" + describeDualOption(id) + " and "
                                + describeDualOption(originalId) + " found.";
                    }
                    throw new ParseException(message, 0);
                }
            }
        }
    }
View Full Code Here

            if (STATE_OPTIONAL_ARG == m_state) {
                m_options.addElement(m_option);
            } else if (STATE_REQUIRE_ARG == m_state) {
                final CLOptionDescriptor descriptor = getDescriptorFor(m_option.getDescriptor().getId());
                final String message = "Missing argument to option " + getOptionDescription(descriptor);
                throw new ParseException(message, 0);
            } else if (STATE_REQUIRE_2ARGS == m_state) {
                if (1 == m_option.getArgumentCount()) {
                    m_option.addArgument("");
                    m_options.addElement(m_option);
                } else {
                    final CLOptionDescriptor descriptor = getDescriptorFor(m_option.getDescriptor().getId());
                    final String message = "Missing argument to option " + getOptionDescription(descriptor);
                    throw new ParseException(message, 0);
                }
            } else {
                throw new ParseException("IllegalState " + m_state + ": " + m_option, 0);
            }
        }
    }
View Full Code Here

    }

    private final void parseOption(final CLOptionDescriptor descriptor, final String optionString)
            throws ParseException {
        if (null == descriptor) {
            throw new ParseException("Unknown option " + optionString, 0);
        }

        m_state = getStateFor(descriptor);
        m_option = new CLOption(descriptor);
View Full Code Here

                if (TOKEN_SEPARATOR == token.getType()) {
                    final CLOptionDescriptor descriptor = getDescriptorFor(m_option.getDescriptor().getId());
                    final String message = "Unable to parse first argument for option "
                            + getOptionDescription(descriptor);
                    throw new ParseException(message, 0);
                } else {
                    m_option.addArgument(token.getValue());
                }
                // Are we about to start a new option?
                if (0 == m_ch && '-' == peekAtChar()) {
View Full Code Here

            m_state = STATE_NORMAL;
        } else {
            getChar(); // strip the -

            if (0 == peekAtChar()) {
                throw new ParseException("Malformed option -", 0);
            } else {
                m_ch = peekAtChar();

                // if it is a short option then parse it else ...
                if ('-' != m_ch) {
View Full Code Here

                return t;
            }

            // parse first char
            if (!skip()) {
                throw new ParseException(msgUnexpectedEOF(), 0);
            }
            ir.mark(1);
            char c = (char)ir.read();
            if (!Character.isJavaIdentifierStart(c)) {
                ir.reset(); // not start of an identifier
View Full Code Here

                return t;
            }

            // parse first char
            if (!skip()) {
                throw new ParseException(msgUnexpectedEOF(), 0);
            }
            ir.mark(1);
            char c = (char)ir.read();
            if (Character.isDigit(c)) {
            } else if (c == '-') {
View Full Code Here

                return t;
            }

            // parse first char
            if (!skip()) {
                throw new ParseException(msgUnexpectedEOF(), 0);
            }
            ir.mark(1);
            char c = (char)ir.read();
            if (c != '\'') {
                ir.reset(); // not start of a char literal
                return null;
            }
                   
            // parse remaining two chars
            final StringBuffer sb = new StringBuffer();
            for (int j = 0; j < 2; j++) {
                sb.append(c);
                int i;
                if ((i = ir.read()) < 0) {
                    throw new ParseException(msgUnexpectedEOF(), 0);
                }
                c = (char)i;
            }
            if (c != '\'') {
                throw new ParseException(msgUnexpectedToken(String.valueOf(c)),
                                         0);
            }
            sb.append(c); // keep '\'' part of a char literal
            return sb.toString();
        }
View Full Code Here

TOP

Related Classes of java.text.ParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.