jaxp/src/com/sun/org/apache/xerces/internal/impl/dv/DatatypeException.java
author joehw
Mon, 18 Feb 2013 11:33:35 -0800
changeset 16953 a44e04deb948
parent 12457 c348e06f0e82
child 25264 040625ce9b72
permissions -rw-r--r--
6657673: Issues with JAXP Reviewed-by: alanb, lancea, ahgross, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 2001, 2002,2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xerces.internal.impl.dv;
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    23
import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import java.util.ResourceBundle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import java.util.PropertyResourceBundle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.util.MissingResourceException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 * Base class for datatype exceptions. For DTD types, the exception can be
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 * created from an error message. For Schema types, it needs an error code
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * (as defined in Appendix C of the structure spec), plus an array of arguents,
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * for error message substitution.
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 * @xerces.internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * @author Sandy Gao, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 *
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    38
 * @version $Id: DatatypeException.java,v 1.6 2010-11-01 04:39:43 joehw Exp $
6
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
}