001 /*
002 * Copyright 2010 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package com.hs.mail.imap.parser;
017
018 import java.util.LinkedList;
019
020 import org.apache.commons.collections.CollectionUtils;
021
022 /**
023 * This exception is thrown when errors are encountered while parsing the IMAP
024 * command.
025 *
026 * @author Won Chul Doh
027 * @since Jan 12, 2010
028 *
029 */
030 public class ParseException extends RuntimeException {
031
032 private static final long serialVersionUID = 1L;
033
034 private String tag;
035
036 public ParseException(String tag, Throwable cause) {
037 super(cause);
038 this.tag = tag;
039 }
040
041 public ParseException(String tag, String message) {
042 super(message);
043 this.tag = tag;
044 }
045
046 public ParseException(LinkedList<Token> tokens, String message) {
047 this(tokens, message, null);
048 }
049
050 public ParseException(LinkedList<Token> tokens, String message,
051 Throwable cause) {
052 super(message, cause);
053 this.tag = CollectionUtils.isNotEmpty(tokens) ? tokens.getFirst().value
054 : "*";
055 }
056
057 public String getTag() {
058 return tag;
059 }
060
061 public String getMessage() {
062 return new StringBuffer(tag).append(" BAD ").append(super.getMessage())
063 .toString();
064 }
065
066 }