KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > bind > TypeConstraintException


1 /*
2  * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
3  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4  */

5
6 package javax.xml.bind;
7
8 /**
9  * This exception indicates that a violation of a dynamically checked type
10  * constraint was detected.
11  *
12  * <p>
13  * This exception can be thrown by the generated setter methods of the schema
14  * derived Java content classes. However, since fail-fast validation is
15  * an optional feature for JAXB Providers to support, not all setter methods
16  * will throw this exception when a type constraint is violated.
17  *
18  * <p>
19  * If this exception is throw while invoking a fail-fast setter, the value of
20  * the property is guaranteed to remain unchanged, as if the setter were never
21  * called.
22  *
23  * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li><li>Joe Fialli, Sun Microsystems, Inc.</li></ul>
24  * @version $Revision: 1.2 $
25  * @see ValidationEvent
26  * @since JAXB1.0
27  */

28
29 public class TypeConstraintException extends java.lang.RuntimeException JavaDoc {
30   
31     /**
32      * Vendor specific error code
33      *
34      */

35     private String JavaDoc errorCode;
36
37     /**
38      * Exception reference
39      *
40      */

41     private Throwable JavaDoc linkedException;
42
43
44     /**
45      * Construct a TypeConstraintException with the specified detail message. The
46      * errorCode and linkedException will default to null.
47      *
48      * @param message a description of the exception
49      */

50     public TypeConstraintException(String JavaDoc message) {
51         this( message, null, null );
52     }
53
54     /**
55      * Construct a TypeConstraintException with the specified detail message and vendor
56      * specific errorCode. The linkedException will default to null.
57      *
58      * @param message a description of the exception
59      * @param errorCode a string specifying the vendor specific error code
60      */

61     public TypeConstraintException(String JavaDoc message, String JavaDoc errorCode) {
62         this( message, errorCode, null );
63     }
64
65     /**
66      * Construct a TypeConstraintException with a linkedException. The detail message and
67      * vendor specific errorCode will default to null.
68      *
69      * @param exception the linked exception
70      */

71     public TypeConstraintException(Throwable JavaDoc exception) {
72         this( null, null, exception );
73     }
74     
75     /**
76      * Construct a TypeConstraintException with the specified detail message and
77      * linkedException. The errorCode will default to null.
78      *
79      * @param message a description of the exception
80      * @param exception the linked exception
81      */

82     public TypeConstraintException(String JavaDoc message, Throwable JavaDoc exception) {
83         this( message, null, exception );
84     }
85     
86     /**
87      * Construct a TypeConstraintException with the specified detail message,
88      * vendor specific errorCode, and linkedException.
89      *
90      * @param message a description of the exception
91      * @param errorCode a string specifying the vendor specific error code
92      * @param exception the linked exception
93      */

94     public TypeConstraintException(String JavaDoc message, String JavaDoc errorCode, Throwable JavaDoc exception) {
95         super( message );
96         this.errorCode = errorCode;
97         this.linkedException = exception;
98     }
99     
100     /**
101      * Get the vendor specific error code
102      *
103      * @return a string specifying the vendor specific error code
104      */

105     public String JavaDoc 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 JavaDoc 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 JavaDoc exception ) {
126         this.linkedException = exception;
127     }
128     
129     /**
130      * Returns a short description of this TypeConstraintException.
131      *
132      */

133     public String JavaDoc toString() {
134         return linkedException == null ?
135             super.toString() :
136             super.toString() + "\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 JavaDoc 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 }
Popular Tags