001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package javax.xml.bind.helpers;
018    
019    import javax.xml.bind.ValidationEvent;
020    import javax.xml.bind.ValidationEventLocator;
021    
022    public class ValidationEventImpl implements ValidationEvent {
023    
024        private int severity;
025        private String message;
026        private Throwable linkedException;
027        private ValidationEventLocator locator;
028    
029        public ValidationEventImpl(int severity, String message, ValidationEventLocator locator) {
030            this(severity, message, locator, null);
031        }
032    
033        public ValidationEventImpl(int severity, String message, ValidationEventLocator locator, Throwable linkedException) {
034            setSeverity(severity);
035            this.message = message;
036            this.locator = locator;
037            this.linkedException = linkedException;
038        }
039    
040        public int getSeverity() {
041            return severity;
042        }
043    
044        public void setSeverity(int severity) {
045            if (severity != 0 && severity != 1 && severity != 2) {
046                throw new IllegalArgumentException("Illegal severity");
047            }
048            this.severity = severity;
049        }
050    
051        public String getMessage() {
052            return message;
053        }
054    
055        public void setMessage(String message) {
056            this.message = message;
057        }
058    
059        public Throwable getLinkedException() {
060            return linkedException;
061        }
062    
063        public void setLinkedException(Throwable linkedException) {
064            this.linkedException = linkedException;
065        }
066    
067        public ValidationEventLocator getLocator() {
068            return locator;
069        }
070    
071        public void setLocator(ValidationEventLocator locator) {
072            this.locator = locator;
073        }
074    
075        public String toString() {
076            String s;
077            switch (getSeverity()) {
078                case WARNING:
079                    s = "WARNING";
080                    break;
081                case ERROR:
082                    s = "ERROR";
083                    break;
084                case FATAL_ERROR:
085                    s = "FATAL_ERROR";
086                    break;
087                default:
088                    s = String.valueOf(getSeverity());
089                    break;
090            }
091            return "[severity=" + s + ", message=" + getMessage() + ", locator=" + getLocator() + "]";
092        }
093    
094    }