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