001package ezvcard.io.json;
002
003import java.io.IOException;
004
005import com.fasterxml.jackson.core.JsonToken;
006
007import ezvcard.Messages;
008
009/*
010 Copyright (c) 2012-2023, Michael Angstadt
011 All rights reserved.
012
013 Redistribution and use in source and binary forms, with or without
014 modification, are permitted provided that the following conditions are met: 
015
016 1. Redistributions of source code must retain the above copyright notice, this
017 list of conditions and the following disclaimer. 
018 2. Redistributions in binary form must reproduce the above copyright notice,
019 this list of conditions and the following disclaimer in the documentation
020 and/or other materials provided with the distribution. 
021
022 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
023 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
024 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
025 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
026 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
027 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
028 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
029 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
031 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
032
033 The views and conclusions contained in the software and documentation are those
034 of the authors and should not be interpreted as representing official policies, 
035 either expressed or implied, of the FreeBSD Project.
036 */
037
038/**
039 * Thrown during the parsing of a jCard, when a jCard is not formatted in the
040 * correct way (the JSON syntax is valid, but it's not in the correct jCard
041 * format).
042 * @author Michael Angstadt
043 */
044public class JCardParseException extends IOException {
045        private static final long serialVersionUID = 5139480815617303404L;
046        private final JsonToken expected, actual;
047
048        /**
049         * Creates a jCard parse exception.
050         * @param expected the JSON token that the parser was expecting
051         * @param actual the actual JSON token
052         */
053        public JCardParseException(JsonToken expected, JsonToken actual) {
054                super(Messages.INSTANCE.getExceptionMessage(35, expected, actual));
055                this.expected = expected;
056                this.actual = actual;
057        }
058
059        /**
060         * Creates a jCard parse exception.
061         * @param message the detail message
062         * @param expected the JSON token that the parser was expecting
063         * @param actual the actual JSON token
064         */
065        public JCardParseException(String message, JsonToken expected, JsonToken actual) {
066                super(message);
067                this.expected = expected;
068                this.actual = actual;
069        }
070
071        /**
072         * Gets the JSON token that the parser was expected.
073         * @return the expected token
074         */
075        public JsonToken getExpectedToken() {
076                return expected;
077        }
078
079        /**
080         * Gets the JSON token that was read.
081         * @return the actual token
082         */
083        public JsonToken getActualToken() {
084                return actual;
085        }
086}