KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > bind > helpers > ValidationEventImpl


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

5 package javax.xml.bind.helpers;
6
7 import java.text.MessageFormat JavaDoc;
8
9 import javax.xml.bind.ValidationEvent;
10 import javax.xml.bind.ValidationEventLocator;
11
12 /**
13  * Default implementation of the ValidationEvent interface.
14  *
15  * <p>
16  * JAXB providers are allowed to use whatever class that implements
17  * the ValidationEvent interface. This class is just provided for a
18  * convenience.
19  *
20  * @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li></ul>
21  * @version $Revision: 1.2 $
22  * @see javax.xml.bind.Validator
23  * @see javax.xml.bind.ValidationEventHandler
24  * @see javax.xml.bind.ValidationEvent
25  * @see javax.xml.bind.ValidationEventLocator
26  * @since JAXB1.0
27  */

28 public class ValidationEventImpl implements ValidationEvent
29 {
30     
31     /**
32      * Create a new ValidationEventImpl.
33      *
34      * @param _severity The severity value for this event. Must be one of
35      * ValidationEvent.WARNING, ValidationEvent.ERROR, or
36      * ValidationEvent.FATAL_ERROR
37      * @param _message The text message for this event - may be null.
38      * @param _locator The locator object for this event - may be null.
39      * @throws IllegalArgumentException if an illegal severity field is supplied
40      */

41     public ValidationEventImpl( int _severity, String JavaDoc _message,
42                                  ValidationEventLocator _locator ) {
43         
44         this(_severity,_message,_locator,null);
45     }
46
47     /**
48      * Create a new ValidationEventImpl.
49      *
50      * @param _severity The severity value for this event. Must be one of
51      * ValidationEvent.WARNING, ValidationEvent.ERROR, or
52      * ValidationEvent.FATAL_ERROR
53      * @param _message The text message for this event - may be null.
54      * @param _locator The locator object for this event - may be null.
55      * @param _linkedException An optional linked exception that may provide
56      * additional information about the event - may be null.
57      * @throws IllegalArgumentException if an illegal severity field is supplied
58      */

59     public ValidationEventImpl( int _severity, String JavaDoc _message,
60                                  ValidationEventLocator _locator,
61                                  Throwable JavaDoc _linkedException ) {
62     
63         setSeverity( _severity );
64         this.message = _message;
65         this.locator = _locator;
66         this.linkedException = _linkedException;
67     }
68     
69     private int severity;
70     private String JavaDoc message;
71     private Throwable JavaDoc linkedException;
72     private ValidationEventLocator locator;
73     
74     public int getSeverity() {
75         return severity;
76     }
77     
78     
79     /**
80      * Set the severity field of this event.
81      *
82      * @param _severity Must be one of ValidationEvent.WARNING,
83      * ValidationEvent.ERROR, or ValidationEvent.FATAL_ERROR.
84      * @throws IllegalArgumentException if an illegal severity field is supplied
85      */

86     public void setSeverity( int _severity ) {
87         
88         if( _severity != ValidationEvent.WARNING &&
89             _severity != ValidationEvent.ERROR &&
90             _severity != ValidationEvent.FATAL_ERROR ) {
91                 throw new IllegalArgumentException JavaDoc(
92                     Messages.format( Messages.ILLEGAL_SEVERITY ) );
93         }
94
95         this.severity = _severity;
96     }
97     
98     public String JavaDoc getMessage() {
99         return message;
100     }
101     /**
102      * Set the message field of this event.
103      *
104      * @param _message String message - may be null.
105      */

106     public void setMessage( String JavaDoc _message ) {
107         this.message = _message;
108     }
109     
110     public Throwable JavaDoc getLinkedException() {
111         return linkedException;
112     }
113     /**
114      * Set the linked exception field of this event.
115      *
116      * @param _linkedException Optional linked exception - may be null.
117      */

118     public void setLinkedException( Throwable JavaDoc _linkedException ) {
119         this.linkedException = _linkedException;
120     }
121     
122     public ValidationEventLocator getLocator() {
123         return locator;
124     }
125     /**
126      * Set the locator object for this event.
127      *
128      * @param _locator The locator - may be null.
129      */

130     public void setLocator( ValidationEventLocator _locator ) {
131         this.locator = _locator;
132     }
133     
134     /**
135      * Returns a string representation of this object in a format
136      * helpful to debugging.
137      *
138      * @see Object#equals(Object)
139      */

140     public String JavaDoc toString() {
141         String JavaDoc s;
142         switch(getSeverity()) {
143         case WARNING: s="WARNING";break;
144         case ERROR: s="ERROR";break;
145         case FATAL_ERROR: s="FATAL_ERROR";break;
146         default: s=String.valueOf(getSeverity());break;
147         }
148         return MessageFormat.format("[severity={0},message={1},locator={2}]",
149             new Object JavaDoc[]{
150                 s,
151                 getMessage(),
152                 getLocator()
153             });
154     }
155 }
156
Popular Tags