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 020 package org.apache.james.mime4j.parser; 021 022 /** 023 * Enumerates events which can be monitored. 024 */ 025 public 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 INALID_HEADER 037 = new Event("Invalid header encountered"); 038 039 private final String code; 040 041 public Event(final String code) { 042 super(); 043 if (code == null) { 044 throw new IllegalArgumentException("Code may not be null"); 045 } 046 this.code = code; 047 } 048 049 @Override 050 public int hashCode() { 051 return code.hashCode(); 052 } 053 054 @Override 055 public boolean equals(Object obj) { 056 if (obj == null) return false; 057 if (this == obj) return true; 058 if (obj instanceof Event) { 059 Event that = (Event) obj; 060 return this.code.equals(that.code); 061 } else { 062 return false; 063 } 064 } 065 066 @Override 067 public String toString() { 068 return code; 069 } 070 071 }