ohair@286: /*
mkos@397: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286: *
ohair@286: * This code is free software; you can redistribute it and/or modify it
ohair@286: * under the terms of the GNU General Public License version 2 only, as
ohair@286: * published by the Free Software Foundation. Oracle designates this
ohair@286: * particular file as subject to the "Classpath" exception as provided
ohair@286: * by Oracle in the LICENSE file that accompanied this code.
ohair@286: *
ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286: * version 2 for more details (a copy is included in the LICENSE file that
ohair@286: * accompanied this code).
ohair@286: *
ohair@286: * You should have received a copy of the GNU General Public License version
ohair@286: * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286: *
ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286: * or visit www.oracle.com if you need additional information or have any
ohair@286: * questions.
ohair@286: */
ohair@286:
ohair@286: package javax.xml.bind;
ohair@286:
ohair@286: /**
ohair@286: * This exception indicates that a violation of a dynamically checked type
ohair@286: * constraint was detected.
ohair@286: *
ohair@286: *
ohair@286: * This exception can be thrown by the generated setter methods of the schema
ohair@286: * derived Java content classes. However, since fail-fast validation is
ohair@286: * an optional feature for JAXB Providers to support, not all setter methods
ohair@286: * will throw this exception when a type constraint is violated.
ohair@286: *
ohair@286: *
ohair@286: * If this exception is throw while invoking a fail-fast setter, the value of
ohair@286: * the property is guaranteed to remain unchanged, as if the setter were never
ohair@286: * called.
ohair@286: *
ohair@286: * @author
- Ryan Shoemaker, Sun Microsystems, Inc.
- Joe Fialli, Sun Microsystems, Inc.
ohair@286: * @see ValidationEvent
ohair@286: * @since JAXB1.0
ohair@286: */
ohair@286:
ohair@286: public class TypeConstraintException extends java.lang.RuntimeException {
ohair@286:
ohair@286: /**
ohair@286: * Vendor specific error code
ohair@286: *
ohair@286: */
ohair@286: private String errorCode;
ohair@286:
ohair@286: /**
ohair@286: * Exception reference
ohair@286: *
ohair@286: */
mkos@408: private volatile Throwable linkedException;
ohair@286:
alanb@449: static final long serialVersionUID = -3059799699420143848L;
ohair@286:
ohair@286: /**
ohair@286: * Construct a TypeConstraintException with the specified detail message. The
ohair@286: * errorCode and linkedException will default to null.
ohair@286: *
ohair@286: * @param message a description of the exception
ohair@286: */
ohair@286: public TypeConstraintException(String message) {
ohair@286: this( message, null, null );
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Construct a TypeConstraintException with the specified detail message and vendor
ohair@286: * specific errorCode. The linkedException will default to null.
ohair@286: *
ohair@286: * @param message a description of the exception
ohair@286: * @param errorCode a string specifying the vendor specific error code
ohair@286: */
ohair@286: public TypeConstraintException(String message, String errorCode) {
ohair@286: this( message, errorCode, null );
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Construct a TypeConstraintException with a linkedException. The detail message and
ohair@286: * vendor specific errorCode will default to null.
ohair@286: *
ohair@286: * @param exception the linked exception
ohair@286: */
ohair@286: public TypeConstraintException(Throwable exception) {
ohair@286: this( null, null, exception );
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Construct a TypeConstraintException with the specified detail message and
ohair@286: * linkedException. The errorCode will default to null.
ohair@286: *
ohair@286: * @param message a description of the exception
ohair@286: * @param exception the linked exception
ohair@286: */
ohair@286: public TypeConstraintException(String message, Throwable exception) {
ohair@286: this( message, null, exception );
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Construct a TypeConstraintException with the specified detail message,
ohair@286: * vendor specific errorCode, and linkedException.
ohair@286: *
ohair@286: * @param message a description of the exception
ohair@286: * @param errorCode a string specifying the vendor specific error code
ohair@286: * @param exception the linked exception
ohair@286: */
ohair@286: public TypeConstraintException(String message, String errorCode, Throwable exception) {
ohair@286: super( message );
ohair@286: this.errorCode = errorCode;
ohair@286: this.linkedException = exception;
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Get the vendor specific error code
ohair@286: *
ohair@286: * @return a string specifying the vendor specific error code
ohair@286: */
ohair@286: public String getErrorCode() {
ohair@286: return this.errorCode;
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Get the linked exception
ohair@286: *
ohair@286: * @return the linked Exception, null if none exists
ohair@286: */
ohair@286: public Throwable getLinkedException() {
ohair@286: return linkedException;
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Add a linked Exception.
ohair@286: *
ohair@286: * @param exception the linked Exception (A null value is permitted and
ohair@286: * indicates that the linked exception does not exist or
ohair@286: * is unknown).
ohair@286: */
mkos@408: public void setLinkedException( Throwable exception ) {
ohair@286: this.linkedException = exception;
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Returns a short description of this TypeConstraintException.
ohair@286: *
ohair@286: */
ohair@286: public String toString() {
ohair@286: return linkedException == null ?
ohair@286: super.toString() :
ohair@286: super.toString() + "\n - with linked exception:\n[" +
ohair@286: linkedException.toString()+ "]";
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Prints this TypeConstraintException and its stack trace (including the stack trace
ohair@286: * of the linkedException if it is non-null) to the PrintStream.
ohair@286: *
ohair@286: * @param s PrintStream to use for output
ohair@286: */
ohair@286: public void printStackTrace( java.io.PrintStream s ) {
ohair@286: if( linkedException != null ) {
ohair@286: linkedException.printStackTrace(s);
ohair@286: s.println("--------------- linked to ------------------");
ohair@286: }
ohair@286:
ohair@286: super.printStackTrace(s);
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Prints this TypeConstraintException and its stack trace (including the stack trace
ohair@286: * of the linkedException if it is non-null) to System.err.
ohair@286: *
ohair@286: */
ohair@286: public void printStackTrace() {
ohair@286: printStackTrace(System.err);
ohair@286: }
ohair@286:
ohair@286: }