001/****************************************************************
002 * Licensed to the Apache Software Foundation (ASF) under one   *
003 * or more contributor license agreements.  See the NOTICE file *
004 * distributed with this work for additional information        *
005 * regarding copyright ownership.  The ASF licenses this file   *
006 * to you under the Apache License, Version 2.0 (the            *
007 * "License"); you may not use this file except in compliance   *
008 * with the License.  You may obtain a copy of the License at   *
009 *                                                              *
010 *   http://www.apache.org/licenses/LICENSE-2.0                 *
011 *                                                              *
012 * Unless required by applicable law or agreed to in writing,   *
013 * software distributed under the License is distributed on an  *
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015 * KIND, either express or implied.  See the License for the    *
016 * specific language governing permissions and limitations      *
017 * under the License.                                           *
018 ****************************************************************/
019
020package org.apache.james.mime4j.stream;
021
022/**
023 * Enumerates events which can be monitored.
024 */
025public final class Event {
026
027    /** Indicates that a body part ended prematurely. */
028    public static final Event MIME_BODY_PREMATURE_END
029        = new Event("Body part ended prematurely. " +
030                "Boundary detected in header or EOF reached.");
031    /** Indicates that unexpected end of headers detected.*/
032    public static final Event HEADERS_PREMATURE_END
033        = new Event("Unexpected end of headers detected. " +
034                "Higher level boundary detected or EOF reached.");
035    /** Indicates that unexpected end of headers detected.*/
036    public static final Event INVALID_HEADER
037        = new Event("Invalid header encountered");
038    /** Indicates that an obsolete syntax header has been detected */
039    public static final Event OBSOLETE_HEADER
040        = new Event("Obsolete header encountered");
041
042    private final String code;
043
044    public Event(final String code) {
045        super();
046        if (code == null) {
047            throw new IllegalArgumentException("Code may not be null");
048        }
049        this.code = code;
050    }
051
052    @Override
053    public int hashCode() {
054        return code.hashCode();
055    }
056
057    @Override
058    public boolean equals(Object obj) {
059        if (obj == null) return false;
060        if (this == obj) return true;
061        if (obj instanceof Event) {
062            Event that = (Event) obj;
063            return this.code.equals(that.code);
064        } else {
065            return false;
066        }
067    }
068
069    @Override
070    public String toString() {
071        return code;
072    }
073
074}