001 /*
002 * $Id: TypeConstraintException.java,v 1.5 2002/11/11 18:58:20 ryans Exp $
003 *
004 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
005 *
006 * This software is the proprietary information of Sun Microsystems, Inc.
007 * Use is subject to license terms.
008 *
009 */
010
011 package javax.xml.bind;
012
013 /**
014 * This exception indicates that a violation of a dynamically checked type
015 * constraint was detected.
016 *
017 * <p>
018 * This exception can be thrown by the generated setter methods of the schema
019 * derived Java content classes. However, since fail-fast validation is
020 * an optional feature for JAXB Providers to support, not all setter methods
021 * will throw this exception when a type constraint is violated.
022 *
023 * <p>
024 * If this exception is throw while invoking a fail-fast setter, the value of
025 * the property is guaranteed to remain unchanged, as if the setter were never
026 * called.
027 *
028 * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li><li>Joe Fialli, Sun Microsystems, Inc.</li></ul>
029 * @version $Revision: 1.5 $
030 * @see ValidationEvent
031 * @since JAXB1.0
032 */
033
034 public class TypeConstraintException extends java.lang.RuntimeException {
035
036 /**
037 * Vendor specific error code
038 *
039 */
040 private String errorCode;
041
042 /**
043 * Exception reference
044 *
045 */
046 private Throwable linkedException;
047
048
049 /**
050 * Construct a TypeConstraintException with the specified detail message. The
051 * errorCode and linkedException will default to null.
052 *
053 * @param message a description of the exception
054 */
055 public TypeConstraintException(String message) {
056 this( message, null, null );
057 }
058
059 /**
060 * Construct a TypeConstraintException with the specified detail message and vendor
061 * specific errorCode. The linkedException will default to null.
062 *
063 * @param message a description of the exception
064 * @param errorCode a string specifying the vendor specific error code
065 */
066 public TypeConstraintException(String message, String errorCode) {
067 this( message, errorCode, null );
068 }
069
070 /**
071 * Construct a TypeConstraintException with a linkedException. The detail message and
072 * vendor specific errorCode will default to null.
073 *
074 * @param exception the linked exception
075 */
076 public TypeConstraintException(Throwable exception) {
077 this( null, null, exception );
078 }
079
080 /**
081 * Construct a TypeConstraintException with the specified detail message and
082 * linkedException. The errorCode will default to null.
083 *
084 * @param message a description of the exception
085 * @param exception the linked exception
086 */
087 public TypeConstraintException(String message, Throwable exception) {
088 this( message, null, exception );
089 }
090
091 /**
092 * Construct a TypeConstraintException with the specified detail message,
093 * vendor specific errorCode, and linkedException.
094 *
095 * @param message a description of the exception
096 * @param errorCode a string specifying the vendor specific error code
097 * @param exception the linked exception
098 */
099 public TypeConstraintException(String message, String errorCode, Throwable exception) {
100 super( message );
101 this.errorCode = errorCode;
102 this.linkedException = exception;
103 }
104
105 /**
106 * Get the vendor specific error code
107 *
108 * @return a string specifying the vendor specific error code
109 */
110 public String getErrorCode() {
111 return this.errorCode;
112 }
113
114 /**
115 * Get the linked exception
116 *
117 * @return the linked Exception, null if none exists
118 */
119 public Throwable getLinkedException() {
120 return linkedException;
121 }
122
123 /**
124 * Add a linked Exception.
125 *
126 * @param exception the linked Exception (A null value is permitted and
127 * indicates that the linked exception does not exist or
128 * is unknown).
129 */
130 public synchronized void setLinkedException( Throwable exception ) {
131 this.linkedException = exception;
132 }
133
134 /**
135 * Returns a short description of this TypeConstraintException.
136 *
137 */
138 public String toString() {
139 return linkedException == null ?
140 super.toString() :
141 super.toString() + "\n - with linked exception:\n[" +
142 linkedException.toString()+ "]";
143 }
144
145 /**
146 * Prints this TypeConstraintException and its stack trace (including the stack trace
147 * of the linkedException if it is non-null) to the PrintStream.
148 *
149 * @param s PrintStream to use for output
150 */
151 public void printStackTrace( java.io.PrintStream s ) {
152 if( linkedException != null ) {
153 linkedException.printStackTrace(s);
154 s.println("--------------- linked to ------------------");
155 }
156
157 super.printStackTrace(s);
158 }
159
160 /**
161 * Prints this TypeConstraintException and its stack trace (including the stack trace
162 * of the linkedException if it is non-null) to <tt>System.err</tt>.
163 *
164 */
165 public void printStackTrace() {
166 printStackTrace(System.err);
167 }
168
169 }