src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/dv/DatatypeException.java
author joehw
Wed, 04 Oct 2017 10:54:18 -0700
changeset 47312 d4f959806fe9
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8187593: Cleanup: removing SecuritySupport files Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Sep 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xerces.internal.impl.dv;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    24
import java.util.MissingResourceException;
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    25
import java.util.PropertyResourceBundle;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.util.ResourceBundle;
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    27
import jdk.xml.internal.SecuritySupport;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 * Base class for datatype exceptions. For DTD types, the exception can be
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * created from an error message. For Schema types, it needs an error code
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * (as defined in Appendix C of the structure spec), plus an array of arguents,
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * for error message substitution.
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * @xerces.internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * @author Sandy Gao, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
public class DatatypeException extends Exception {
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
    /** Serialization version. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
    static final long serialVersionUID = 1940805832730465578L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
    // used to store error code and error substitution arguments
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    protected String key;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    protected Object[] args;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
     * Create a new datatype exception by providing an error code and a list
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
     * of error message substitution arguments.
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
     * @param key  error code
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
     * @param args error arguments
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    public DatatypeException(String key, Object[] args) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
        super(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
        this.key = key;
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
        this.args = args;
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
     * Return the error code
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     * @return  error code
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    public String getKey() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
        return key;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
     * Return the list of error arguments
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
     * @return  error arguments
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    public Object[] getArgs() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        return args;
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
     * Overrides this method to get the formatted&localized error message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
     * REVISIT: the system locale is used to load the property file.
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
     *          do we want to allow the appilcation to specify a
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
     *          different locale?
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
    public String getMessage() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        ResourceBundle resourceBundle = null;
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    89
        resourceBundle = SecuritySupport.getResourceBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        if (resourceBundle == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
            throw new MissingResourceException("Property file not found!", "com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages", key);
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        String msg = resourceBundle.getString(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
        if (msg == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
            msg = resourceBundle.getString("BadMessageKey");
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
            throw new MissingResourceException(msg, "com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages", key);
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
        if (args != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
                msg = java.text.MessageFormat.format(msg, args);
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
            } catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
                msg = resourceBundle.getString("FormatFailed");
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
                msg += " " + resourceBundle.getString(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
        return msg;
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
}