1 /****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 ****************************************************************/
19
20 package org.apache.james.mime4j.parser;
21
22 /**
23 * Enumerates events which can be monitored.
24 */
25 public final class Event {
26
27 /** Indicates that a body part ended prematurely. */
28 public static final Event MIME_BODY_PREMATURE_END
29 = new Event("Body part ended prematurely. " +
30 "Boundary detected in header or EOF reached.");
31 /** Indicates that unexpected end of headers detected.*/
32 public static final Event HEADERS_PREMATURE_END
33 = new Event("Unexpected end of headers detected. " +
34 "Higher level boundary detected or EOF reached.");
35 /** Indicates that unexpected end of headers detected.*/
36 public static final Event INALID_HEADER
37 = new Event("Invalid header encountered");
38
39 private final String code;
40
41 public Event(final String code) {
42 super();
43 if (code == null) {
44 throw new IllegalArgumentException("Code may not be null");
45 }
46 this.code = code;
47 }
48
49 @Override
50 public int hashCode() {
51 return code.hashCode();
52 }
53
54 @Override
55 public boolean equals(Object obj) {
56 if (obj == null) return false;
57 if (this == obj) return true;
58 if (obj instanceof Event) {
59 Event that = (Event) obj;
60 return this.code.equals(that.code);
61 } else {
62 return false;
63 }
64 }
65
66 @Override
67 public String toString() {
68 return code;
69 }
70
71 }