001    /*
002     * $Id: ValidationEventImpl.java,v 1.6 2003/02/13 23:41:06 kk122374 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    package javax.xml.bind.helpers;
011    
012    import javax.xml.bind.ValidationEvent;
013    import javax.xml.bind.ValidationEventLocator;
014    
015    /**
016     * Default implementation of the ValidationEvent interface.
017     * 
018     * <p>
019     * JAXB providers are allowed to use whatever class that implements
020     * the ValidationEvent interface. This class is just provided for a
021     * convenience.
022     *
023     * @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li></ul> 
024     * @version $Revision: 1.6 $
025     * @see javax.xml.bind.Validator
026     * @see javax.xml.bind.ValidationEventHandler
027     * @see javax.xml.bind.ValidationEvent
028     * @see javax.xml.bind.ValidationEventLocator
029     * @since JAXB1.0
030     */
031    public class ValidationEventImpl implements ValidationEvent
032    {
033        
034        /**
035         * Create a new ValidationEventImpl.
036         * 
037         * @param _severity The severity value for this event.  Must be one of
038         * ValidationEvent.WARNING, ValidationEvent.ERROR, or 
039         * ValidationEvent.FATAL_ERROR
040         * @param _message The text message for this event - may be null.
041         * @param _locator The locator object for this event - may be null.
042         * @throws IllegalArgumentException if an illegal severity field is supplied
043         */
044        public ValidationEventImpl( int _severity, String _message, 
045                                     ValidationEventLocator _locator ) {
046            
047            this(_severity,_message,_locator,null);
048        }
049    
050        /**
051         * Create a new ValidationEventImpl.
052         * 
053         * @param _severity The severity value for this event.  Must be one of
054         * ValidationEvent.WARNING, ValidationEvent.ERROR, or 
055         * ValidationEvent.FATAL_ERROR
056         * @param _message The text message for this event - may be null.
057         * @param _locator The locator object for this event - may be null.
058         * @param _linkedException An optional linked exception that may provide
059         * additional information about the event - may be null.
060         * @throws IllegalArgumentException if an illegal severity field is supplied
061         */
062        public ValidationEventImpl( int _severity, String _message, 
063                                     ValidationEventLocator _locator, 
064                                     Throwable _linkedException ) {
065        
066            setSeverity( _severity );
067            this.message = _message;
068            this.locator = _locator;
069            this.linkedException = _linkedException;
070        }
071        
072        private int severity;
073        private String message;
074        private Throwable linkedException;
075        private ValidationEventLocator locator;
076        
077        public int getSeverity() {
078            return severity;
079        }
080        
081        
082        /**
083         * Set the severity field of this event.  
084         * 
085         * @param _severity Must be one of ValidationEvent.WARNING, 
086         * ValidationEvent.ERROR, or ValidationEvent.FATAL_ERROR.
087         * @throws IllegalArgumentException if an illegal severity field is supplied
088         */
089        public void setSeverity( int _severity ) {
090            
091            if( _severity != ValidationEvent.WARNING && 
092                _severity != ValidationEvent.ERROR && 
093                _severity != ValidationEvent.FATAL_ERROR ) {
094                    throw new IllegalArgumentException( 
095                        Messages.format( Messages.ILLEGAL_SEVERITY ) );
096            }
097    
098            this.severity = _severity;
099        }
100        
101        public String getMessage() {
102            return message;
103        }
104        /**
105         * Set the message field of this event.
106         * 
107         * @param _message String message - may be null.
108         */
109        public void setMessage( String _message ) {
110            this.message = _message;
111        }
112        
113        public Throwable getLinkedException() {
114            return linkedException;
115        }
116        /**
117         * Set the linked exception field of this event.
118         * 
119         * @param _linkedException Optional linked exception - may be null.
120         */
121        public void setLinkedException( Throwable _linkedException ) {
122            this.linkedException = _linkedException;
123        }
124        
125        public ValidationEventLocator getLocator() {
126            return locator;
127        }
128        /**
129         * Set the locator object for this event.
130         * 
131         * @param _locator The locator - may be null.
132         */
133        public void setLocator( ValidationEventLocator _locator ) {
134            this.locator = _locator;
135        }
136    }