1 /* 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.xml.internal.org.jvnet.mimepull; 27 28 import java.nio.ByteBuffer; 29 30 /** 31 * @author Jitendra Kotamraju 32 */ 33 abstract class MIMEEvent { 34 35 enum EVENT_TYPE {START_MESSAGE, START_PART, HEADERS, CONTENT, END_PART, END_MESSAGE} 36 37 /** 38 * Returns a event for parser's current cursor location in the MIME message. 39 * 40 * <p> 41 * {@link EVENT_TYPE#START_MESSAGE} and {@link EVENT_TYPE#START_MESSAGE} events 42 * are generated only once. 43 * 44 * <p> 45 * {@link EVENT_TYPE#START_PART}, {@link EVENT_TYPE#END_PART}, {@link EVENT_TYPE#HEADERS} 46 * events are generated only once for each attachment part. 47 * 48 * <p> 49 * {@link EVENT_TYPE#CONTENT} event may be generated more than once for an attachment 50 * part. 51 * 52 * @return event type 53 */ 54 abstract EVENT_TYPE getEventType(); 55 56 static final StartMessage START_MESSAGE = new StartMessage(); 57 static final StartPart START_PART = new StartPart(); 58 static final EndPart END_PART = new EndPart(); 59 static final EndMessage END_MESSAGE = new EndMessage(); 60 61 static final class StartMessage extends MIMEEvent { 62 EVENT_TYPE getEventType() { 63 return EVENT_TYPE.START_MESSAGE; 64 } 65 } 66 67 static final class StartPart extends MIMEEvent { 68 EVENT_TYPE getEventType() { 69 return EVENT_TYPE.START_PART; 70 } 71 } 72 73 static final class EndPart extends MIMEEvent { 74 EVENT_TYPE getEventType () { 75 return EVENT_TYPE.END_PART; 76 } 77 } 78 79 static final class Headers extends MIMEEvent { 80 InternetHeaders ih; 81 82 Headers(InternetHeaders ih) { 83 this.ih = ih; 84 } 85 86 EVENT_TYPE getEventType() { 87 return EVENT_TYPE.HEADERS; 88 } 89 90 InternetHeaders getHeaders() { 91 return ih; 92 } 93 } 94 95 static final class Content extends MIMEEvent { 96 private final ByteBuffer buf; 97 98 Content(ByteBuffer buf) { 99 this.buf = buf; 100 } 101 102 EVENT_TYPE getEventType() { 103 return EVENT_TYPE.CONTENT; 104 } 105 106 ByteBuffer getData() { 107 return buf; 108 } 109 } 110 111 static final class EndMessage extends MIMEEvent { 112 EVENT_TYPE getEventType() { 113 return EVENT_TYPE.END_MESSAGE; 114 } 115 } 116 117 }