Java Code Examples for com.sun.org.apache.xerces.internal.util.DatatypeMessageFormatter#formatMessage()

The following examples show how to use com.sun.org.apache.xerces.internal.util.DatatypeMessageFormatter#formatMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DurationImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example 2
Source File: XMLGregorianCalendarImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void setFractionalSecond(BigDecimal fractional) {
    if (fractional != null) {
        if ((fractional.compareTo(DECIMAL_ZERO) < 0) ||
                (fractional.compareTo(DECIMAL_ONE) > 0)) {
            throw new IllegalArgumentException(DatatypeMessageFormatter.formatMessage(null,
                    "InvalidFractional", new Object[]{fractional}));
        }
    }
    this.fractionalSecond = fractional;
}
 
Example 3
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void setFractionalSecond(BigDecimal fractional) {
    if (fractional != null) {
        if ((fractional.compareTo(DECIMAL_ZERO) < 0) ||
                (fractional.compareTo(DECIMAL_ONE) > 0)) {
            throw new IllegalArgumentException(DatatypeMessageFormatter.formatMessage(null,
                    "InvalidFractional", new Object[]{fractional.toString()}));
        }
    }
    this.fractionalSecond = fractional;
}
 
Example 4
Source File: DurationImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example 5
Source File: DurationImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Constructs a new Duration object by specifying each field individually.</p>
 *
 * <p>All the parameters are optional as long as at least one field is present.
 * If specified, parameters have to be zero or positive.</p>
 *
 * @param isPositive Set to <code>false</code> to create a negative duration. When the length
 *   of the duration is zero, this parameter will be ignored.
 * @param years of this <code>Duration</code>
 * @param months of this <code>Duration</code>
 * @param days of this <code>Duration</code>
 * @param hours of this <code>Duration</code>
 * @param minutes of this <code>Duration</code>
 * @param seconds of this <code>Duration</code>
 *
 * @throws IllegalArgumentException
 *    If years, months, days, hours, minutes and
 *    seconds parameters are all <code>null</code>. Or if any
 *    of those parameters are negative.
 */
protected DurationImpl(
    boolean isPositive,
    BigInteger years,
    BigInteger months,
    BigInteger days,
    BigInteger hours,
    BigInteger minutes,
    BigDecimal seconds) {

    this.years = years;
    this.months = months;
    this.days = days;
    this.hours = hours;
    this.minutes = minutes;
    this.seconds = seconds;

    this.signum = calcSignum(isPositive);

    // sanity check
    if (years == null
        && months == null
        && days == null
        && hours == null
        && minutes == null
        && seconds == null) {
        throw new IllegalArgumentException(
        //"all the fields are null"
        DatatypeMessageFormatter.formatMessage(null, "AllFieldsNull", null)
        );
    }
    testNonNegative(years, DatatypeConstants.YEARS);
    testNonNegative(months, DatatypeConstants.MONTHS);
    testNonNegative(days, DatatypeConstants.DAYS);
    testNonNegative(hours, DatatypeConstants.HOURS);
    testNonNegative(minutes, DatatypeConstants.MINUTES);
    testNonNegative(seconds, DatatypeConstants.SECONDS);
}
 
Example 6
Source File: XMLGregorianCalendarImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public final void setFractionalSecond(BigDecimal fractional) {
    if (fractional != null) {
        if ((fractional.compareTo(DECIMAL_ZERO) < 0) ||
                (fractional.compareTo(DECIMAL_ONE) > 0)) {
            throw new IllegalArgumentException(DatatypeMessageFormatter.formatMessage(null,
                    "InvalidFractional", new Object[]{fractional.toString()}));
        }
    }
    this.fractionalSecond = fractional;
}
 
Example 7
Source File: DurationImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example 8
Source File: XMLGregorianCalendarImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private void invalidFieldValue(int field, int value) {
    throw new IllegalArgumentException(
        DatatypeMessageFormatter.formatMessage(null, "InvalidFieldValue",
            new Object[]{ new Integer(value), FIELD_NAME[field]})
    );
}
 
Example 9
Source File: XMLGregorianCalendarImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void invalidFieldValue(int field, int value) {
    throw new IllegalArgumentException(
        DatatypeMessageFormatter.formatMessage(null, "InvalidFieldValue",
            new Object[]{ new Integer(value), FIELD_NAME[field]})
    );
}
 
Example 10
Source File: XMLGregorianCalendarImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a new XMLGregorianCalendar object.
 *
 * String parsing documented by {@link #parse(String)}.
 *
 * Returns a non-null valid XMLGregorianCalendar object that holds the
 * value indicated by the lexicalRepresentation parameter.
 *
 * @param lexicalRepresentation
 *      Lexical representation of one the eight
 *      XML Schema date/time datatypes.
 * @throws IllegalArgumentException
 *      If the given string does not conform as documented in
 *      {@link #parse(String)}.
 * @throws NullPointerException
 *      If the given string is null.
 */
protected XMLGregorianCalendarImpl(String lexicalRepresentation)
        throws IllegalArgumentException {

    // compute format string for this lexical representation.
    String format = null;
    String lexRep = lexicalRepresentation;
    final int NOT_FOUND = -1;
    int lexRepLength = lexRep.length();

    // current parser needs a format string,
    // use following heuristics to figure out what xml schema date/time
    // datatype this lexical string could represent.
    // Fix 4971612: invalid SCCS macro substitution in data string,
    //   no %{alpha}% to avoid SCCS maco substitution
    if (lexRep.indexOf('T') != NOT_FOUND) {
        // found Date Time separater, must be xsd:DateTime
        format = "%Y-%M-%DT%h:%m:%s" + "%z";
    } else if (lexRepLength >= 3 && lexRep.charAt(2) == ':') {
        // found ":", must be xsd:Time
        format = "%h:%m:%s" + "%z";
    } else if (lexRep.startsWith("--")) {
        // check for gDay || gMonth || gMonthDay
        if (lexRepLength >= 3 && lexRep.charAt(2) == '-') {
            // gDay, ---DD(z?)
            format = "---%D" + "%z";
        } else if (lexRepLength == 4     // --MM
                || lexRepLength == 5     // --MMZ
                || lexRepLength == 10) { // --MMSHH:MM
            // gMonth, --MM(z?),
            // per XML Schema Errata, used to be --MM--(z?)
            format = "--%M" + "%z";
        } else {
            // gMonthDay, --MM-DD(z?), (or invalid lexicalRepresentation)
            // length should be:
            //  7: --MM-DD
            //  8: --MM-DDZ
            // 13: --MM-DDSHH:MM
            format = "--%M-%D" + "%z";
        }
    } else {
        // check for Date || GYear | GYearMonth
        int countSeparator = 0;

        // start at index 1 to skip potential negative sign for year.


        int timezoneOffset = lexRep.indexOf(':');
        if (timezoneOffset != NOT_FOUND) {

            // found timezone, strip it off for distinguishing
            // between Date, GYear and GYearMonth so possible
            // negative sign in timezone is not mistaken as
            // a separator.
            lexRepLength -= 6;
        }

        for (int i = 1; i < lexRepLength; i++) {
            if (lexRep.charAt(i) == '-') {
                countSeparator++;
            }
        }
        if (countSeparator == 0) {
            // GYear
            format = "%Y" + "%z";
        } else if (countSeparator == 1) {
            // GYearMonth
            format = "%Y-%M" + "%z";
        } else {
            // Date or invalid lexicalRepresentation
            // Fix 4971612: invalid SCCS macro substitution in data string
            format = "%Y-%M-%D" + "%z";
        }
    }
    Parser p = new Parser(format, lexRep);
    p.parse();

    // check for validity
    if (!isValid()) {
        throw new IllegalArgumentException(
                DatatypeMessageFormatter.formatMessage(null, "InvalidXGCRepresentation", new Object[]{lexicalRepresentation})
                //"\"" + lexicalRepresentation + "\" is not a valid representation of an XML Gregorian Calendar value."
        );
    }
}
 
Example 11
Source File: XMLGregorianCalendarImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * <p>Private constructor allowing for complete value spaces allowed by
 * W3C XML Schema 1.0 recommendation for xsd:dateTime and related
 * builtin datatypes. Note that <code>year</code> parameter supports
 * arbitrarily large numbers and fractionalSecond has infinite
 * precision.</p>
 *
 * @param year of <code>XMLGregorianCalendar</code> to be created.
 * @param month of <code>XMLGregorianCalendar</code> to be created.
 * @param day of <code>XMLGregorianCalendar</code> to be created.
 * @param hour of <code>XMLGregorianCalendar</code> to be created.
 * @param minute of <code>XMLGregorianCalendar</code> to be created.
 * @param second of <code>XMLGregorianCalendar</code> to be created.
 * @param fractionalSecond of <code>XMLGregorianCalendar</code> to be created.
 * @param timezone of <code>XMLGregorianCalendar</code> to be created.
 *
 */
protected XMLGregorianCalendarImpl(
    BigInteger year,
    int month,
    int day,
    int hour,
    int minute,
    int second,
    BigDecimal fractionalSecond,
    int timezone) {

            setYear(year);
    setMonth(month);
    setDay(day);
    setTime(hour, minute, second, fractionalSecond);
            setTimezone(timezone);

            // check for validity
            if (!isValid()) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null,
                "InvalidXGCValue-fractional",
                new Object[] { year, new Integer(month), new Integer(day),
                new Integer(hour), new Integer(minute), new Integer(second),
                fractionalSecond, new Integer(timezone)})
                    );

                    /**
            String yearString = "null";
            if (year != null) {
                yearString = year.toString();
            }
            String fractionalSecondString = "null";
            if (fractionalSecond != null) {
                fractionalSecondString = fractionalSecond.toString();
            }

            throw new IllegalArgumentException(
                "year = " + yearString
                + ", month = " + month
                + ", day = " + day
                + ", hour = " + hour
                + ", minute = " + minute
                + ", second = " + second
                + ", fractionalSecond = " + fractionalSecondString
                + ", timezone = " + timezone
                + ", is not a valid representation of an XML Gregorian Calendar value."
            );
            */

            }

}
 
Example 12
Source File: XMLGregorianCalendarImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a new XMLGregorianCalendar object.
 *
 * String parsing documented by {@link #parse(String)}.
 *
 * Returns a non-null valid XMLGregorianCalendar object that holds the
 * value indicated by the lexicalRepresentation parameter.
 *
 * @param lexicalRepresentation
 *      Lexical representation of one the eight
 *      XML Schema date/time datatypes.
 * @throws IllegalArgumentException
 *      If the given string does not conform as documented in
 *      {@link #parse(String)}.
 * @throws NullPointerException
 *      If the given string is null.
 */
protected XMLGregorianCalendarImpl(String lexicalRepresentation)
        throws IllegalArgumentException {

    // compute format string for this lexical representation.
    String format = null;
    String lexRep = lexicalRepresentation;
    final int NOT_FOUND = -1;
    int lexRepLength = lexRep.length();

    // current parser needs a format string,
    // use following heuristics to figure out what xml schema date/time
    // datatype this lexical string could represent.
    // Fix 4971612: invalid SCCS macro substitution in data string,
    //   no %{alpha}% to avoid SCCS maco substitution
    if (lexRep.indexOf('T') != NOT_FOUND) {
        // found Date Time separater, must be xsd:DateTime
        format = "%Y-%M-%DT%h:%m:%s" + "%z";
    } else if (lexRepLength >= 3 && lexRep.charAt(2) == ':') {
        // found ":", must be xsd:Time
        format = "%h:%m:%s" + "%z";
    } else if (lexRep.startsWith("--")) {
        // check for gDay || gMonth || gMonthDay
        if (lexRepLength >= 3 && lexRep.charAt(2) == '-') {
            // gDay, ---DD(z?)
            format = "---%D" + "%z";
        } else if (lexRepLength == 4     // --MM
                || lexRepLength == 5     // --MMZ
                || lexRepLength == 10) { // --MMSHH:MM
            // gMonth, --MM(z?),
            // per XML Schema Errata, used to be --MM--(z?)
            format = "--%M" + "%z";
        } else {
            // gMonthDay, --MM-DD(z?), (or invalid lexicalRepresentation)
            // length should be:
            //  7: --MM-DD
            //  8: --MM-DDZ
            // 13: --MM-DDSHH:MM
            format = "--%M-%D" + "%z";
        }
    } else {
        // check for Date || GYear | GYearMonth
        int countSeparator = 0;

        // start at index 1 to skip potential negative sign for year.


        int timezoneOffset = lexRep.indexOf(':');
        if (timezoneOffset != NOT_FOUND) {

            // found timezone, strip it off for distinguishing
            // between Date, GYear and GYearMonth so possible
            // negative sign in timezone is not mistaken as
            // a separator.
            lexRepLength -= 6;
        }

        for (int i = 1; i < lexRepLength; i++) {
            if (lexRep.charAt(i) == '-') {
                countSeparator++;
            }
        }
        if (countSeparator == 0) {
            // GYear
            format = "%Y" + "%z";
        } else if (countSeparator == 1) {
            // GYearMonth
            format = "%Y-%M" + "%z";
        } else {
            // Date or invalid lexicalRepresentation
            // Fix 4971612: invalid SCCS macro substitution in data string
            format = "%Y-%M-%D" + "%z";
        }
    }
    Parser p = new Parser(format, lexRep);
    p.parse();

    // check for validity
    if (!isValid()) {
        throw new IllegalArgumentException(
                DatatypeMessageFormatter.formatMessage(null, "InvalidXGCRepresentation", new Object[]{lexicalRepresentation})
                //"\"" + lexicalRepresentation + "\" is not a valid representation of an XML Gregorian Calendar value."
        );
    }
}
 
Example 13
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void invalidFieldValue(int field, int value) {
    throw new IllegalArgumentException(
        DatatypeMessageFormatter.formatMessage(null, "InvalidFieldValue",
            new Object[]{ new Integer(value), FIELD_NAME[field]})
    );
}
 
Example 14
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * <p>Private constructor allowing for complete value spaces allowed by
 * W3C XML Schema 1.0 recommendation for xsd:dateTime and related
 * builtin datatypes. Note that <code>year</code> parameter supports
 * arbitrarily large numbers and fractionalSecond has infinite
 * precision.</p>
 *
 * @param year of <code>XMLGregorianCalendar</code> to be created.
 * @param month of <code>XMLGregorianCalendar</code> to be created.
 * @param day of <code>XMLGregorianCalendar</code> to be created.
 * @param hour of <code>XMLGregorianCalendar</code> to be created.
 * @param minute of <code>XMLGregorianCalendar</code> to be created.
 * @param second of <code>XMLGregorianCalendar</code> to be created.
 * @param fractionalSecond of <code>XMLGregorianCalendar</code> to be created.
 * @param timezone of <code>XMLGregorianCalendar</code> to be created.
 *
 */
protected XMLGregorianCalendarImpl(
    BigInteger year,
    int month,
    int day,
    int hour,
    int minute,
    int second,
    BigDecimal fractionalSecond,
    int timezone) {

    setYear(year);
    setMonth(month);
    setDay(day);
    setTime(hour, minute, second, fractionalSecond);
    setTimezone(timezone);

    // check for validity
    if (!isValid()) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null,
                "InvalidXGCValue-fractional",
                new Object[] { year, new Integer(month), new Integer(day),
                new Integer(hour), new Integer(minute), new Integer(second),
                fractionalSecond, new Integer(timezone)})
                    );

                    /**
            String yearString = "null";
            if (year != null) {
                yearString = year.toString();
            }
            String fractionalSecondString = "null";
            if (fractionalSecond != null) {
                fractionalSecondString = fractionalSecond.toString();
            }

            throw new IllegalArgumentException(
                "year = " + yearString
                + ", month = " + month
                + ", day = " + day
                + ", hour = " + hour
                + ", minute = " + minute
                + ", second = " + second
                + ", fractionalSecond = " + fractionalSecondString
                + ", timezone = " + timezone
                + ", is not a valid representation of an XML Gregorian Calendar value."
            );
            */

    }

    save();
}
 
Example 15
Source File: XMLGregorianCalendarImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * <p>Private constructor allowing for complete value spaces allowed by
 * W3C XML Schema 1.0 recommendation for xsd:dateTime and related
 * builtin datatypes. Note that <code>year</code> parameter supports
 * arbitrarily large numbers and fractionalSecond has infinite
 * precision.</p>
 *
 * @param year of <code>XMLGregorianCalendar</code> to be created.
 * @param month of <code>XMLGregorianCalendar</code> to be created.
 * @param day of <code>XMLGregorianCalendar</code> to be created.
 * @param hour of <code>XMLGregorianCalendar</code> to be created.
 * @param minute of <code>XMLGregorianCalendar</code> to be created.
 * @param second of <code>XMLGregorianCalendar</code> to be created.
 * @param fractionalSecond of <code>XMLGregorianCalendar</code> to be created.
 * @param timezone of <code>XMLGregorianCalendar</code> to be created.
 *
 */
protected XMLGregorianCalendarImpl(
    BigInteger year,
    int month,
    int day,
    int hour,
    int minute,
    int second,
    BigDecimal fractionalSecond,
    int timezone) {

            setYear(year);
    setMonth(month);
    setDay(day);
    setTime(hour, minute, second, fractionalSecond);
            setTimezone(timezone);

            // check for validity
            if (!isValid()) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null,
                "InvalidXGCValue-fractional",
                new Object[] { year, new Integer(month), new Integer(day),
                new Integer(hour), new Integer(minute), new Integer(second),
                fractionalSecond, new Integer(timezone)})
                    );

                    /**
            String yearString = "null";
            if (year != null) {
                yearString = year.toString();
            }
            String fractionalSecondString = "null";
            if (fractionalSecond != null) {
                fractionalSecondString = fractionalSecond.toString();
            }

            throw new IllegalArgumentException(
                "year = " + yearString
                + ", month = " + month
                + ", day = " + day
                + ", hour = " + hour
                + ", minute = " + minute
                + ", second = " + second
                + ", fractionalSecond = " + fractionalSecondString
                + ", timezone = " + timezone
                + ", is not a valid representation of an XML Gregorian Calendar value."
            );
            */

            }

}
 
Example 16
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void invalidFieldValue(int field, int value) {
    throw new IllegalArgumentException(
        DatatypeMessageFormatter.formatMessage(null, "InvalidFieldValue",
            new Object[]{ new Integer(value), FIELD_NAME[field]})
    );
}
 
Example 17
Source File: XMLGregorianCalendarImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private void invalidFieldValue(int field, int value) {
    throw new IllegalArgumentException(
        DatatypeMessageFormatter.formatMessage(null, "InvalidFieldValue",
            new Object[]{ new Integer(value), FIELD_NAME[field]})
    );
}
 
Example 18
Source File: XMLGregorianCalendarImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a new XMLGregorianCalendar object.
 *
 * String parsing documented by {@link #parse(String)}.
 *
 * Returns a non-null valid XMLGregorianCalendar object that holds the
 * value indicated by the lexicalRepresentation parameter.
 *
 * @param lexicalRepresentation
 *      Lexical representation of one the eight
 *      XML Schema date/time datatypes.
 * @throws IllegalArgumentException
 *      If the given string does not conform as documented in
 *      {@link #parse(String)}.
 * @throws NullPointerException
 *      If the given string is null.
 */
protected XMLGregorianCalendarImpl(String lexicalRepresentation)
        throws IllegalArgumentException {

    // compute format string for this lexical representation.
    String format = null;
    String lexRep = lexicalRepresentation;
    final int NOT_FOUND = -1;
    int lexRepLength = lexRep.length();

    // current parser needs a format string,
    // use following heuristics to figure out what xml schema date/time
    // datatype this lexical string could represent.
    // Fix 4971612: invalid SCCS macro substitution in data string,
    //   no %{alpha}% to avoid SCCS maco substitution
    if (lexRep.indexOf('T') != NOT_FOUND) {
        // found Date Time separater, must be xsd:DateTime
        format = "%Y-%M-%DT%h:%m:%s" + "%z";
    } else if (lexRepLength >= 3 && lexRep.charAt(2) == ':') {
        // found ":", must be xsd:Time
        format = "%h:%m:%s" + "%z";
    } else if (lexRep.startsWith("--")) {
        // check for gDay || gMonth || gMonthDay
        if (lexRepLength >= 3 && lexRep.charAt(2) == '-') {
            // gDay, ---DD(z?)
            format = "---%D" + "%z";
        } else if (lexRepLength == 4     // --MM
                || lexRepLength == 5     // --MMZ
                || lexRepLength == 10) { // --MMSHH:MM
            // gMonth, --MM(z?),
            // per XML Schema Errata, used to be --MM--(z?)
            format = "--%M" + "%z";
        } else {
            // gMonthDay, --MM-DD(z?), (or invalid lexicalRepresentation)
            // length should be:
            //  7: --MM-DD
            //  8: --MM-DDZ
            // 13: --MM-DDSHH:MM
            format = "--%M-%D" + "%z";
        }
    } else {
        // check for Date || GYear | GYearMonth
        int countSeparator = 0;

        // start at index 1 to skip potential negative sign for year.


        int timezoneOffset = lexRep.indexOf(':');
        if (timezoneOffset != NOT_FOUND) {

            // found timezone, strip it off for distinguishing
            // between Date, GYear and GYearMonth so possible
            // negative sign in timezone is not mistaken as
            // a separator.
            lexRepLength -= 6;
        }

        for (int i = 1; i < lexRepLength; i++) {
            if (lexRep.charAt(i) == '-') {
                countSeparator++;
            }
        }
        if (countSeparator == 0) {
            // GYear
            format = "%Y" + "%z";
        } else if (countSeparator == 1) {
            // GYearMonth
            format = "%Y-%M" + "%z";
        } else {
            // Date or invalid lexicalRepresentation
            // Fix 4971612: invalid SCCS macro substitution in data string
            format = "%Y-%M-%D" + "%z";
        }
    }
    Parser p = new Parser(format, lexRep);
    p.parse();

    // check for validity
    if (!isValid()) {
        throw new IllegalArgumentException(
                DatatypeMessageFormatter.formatMessage(null, "InvalidXGCRepresentation", new Object[]{lexicalRepresentation})
                //"\"" + lexicalRepresentation + "\" is not a valid representation of an XML Gregorian Calendar value."
        );
    }
}
 
Example 19
Source File: XMLGregorianCalendarImpl.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * <p>Private constructor of value spaces that a
 * <code>java.util.GregorianCalendar</code> instance would need to convert to an
 * <code>XMLGregorianCalendar</code> instance.</p>
 *
 * <p><code>XMLGregorianCalendar eon</code> and
 * <code>fractionalSecond</code> are set to <code>null</code></p>
 *
 * @param year of <code>XMLGregorianCalendar</code> to be created.
 * @param month of <code>XMLGregorianCalendar</code> to be created.
 * @param day of <code>XMLGregorianCalendar</code> to be created.
 * @param hour of <code>XMLGregorianCalendar</code> to be created.
 * @param minute of <code>XMLGregorianCalendar</code> to be created.
 * @param second of <code>XMLGregorianCalendar</code> to be created.
 * @param millisecond of <code>XMLGregorianCalendar</code> to be created.
 * @param timezone of <code>XMLGregorianCalendar</code> to be created.
 */
private XMLGregorianCalendarImpl(
    int year,
    int month,
    int day,
    int hour,
    int minute,
    int second,
            int millisecond,
    int timezone) {

            setYear(year);
    setMonth(month);
    setDay(day);
    setTime(hour, minute, second);
            setTimezone(timezone);
            setMillisecond(millisecond);

            if (!isValid()) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null,
            "InvalidXGCValue-milli",
            new Object[] { new Integer(year), new Integer(month), new Integer(day),
            new Integer(hour), new Integer(minute), new Integer(second),
            new Integer(millisecond), new Integer(timezone)})
                    );
            /*
            throw new IllegalArgumentException(
                "year = " + year
                + ", month = " + month
                + ", day = " + day
                + ", hour = " + hour
                + ", minute = " + minute
                + ", second = " + second
                + ", millisecond = " + millisecond
                + ", timezone = " + timezone
                + ", is not a valid representation of an XML Gregorian Calendar value."
                );
             */

            }
}
 
Example 20
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void invalidFieldValue(int field, int value) {
    throw new IllegalArgumentException(
        DatatypeMessageFormatter.formatMessage(null, "InvalidFieldValue",
            new Object[]{ new Integer(value), FIELD_NAME[field]})
    );
}