001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package org.jvnet.mimepull;
037:
038: import java.nio.ByteBuffer;
039:
040: /**
041: * @author Jitendra Kotamraju
042: */
043: abstract class MIMEEvent {
044:
045: enum EVENT_TYPE {
046: START_MESSAGE, START_PART, HEADERS, CONTENT, END_PART, END_MESSAGE
047: }
048:
049: /**
050: * Returns a event for parser's current cursor location in the MIME message.
051: *
052: * <p>
053: * {@link EVENT_TYPE#START_MESSAGE} and {@link EVENT_TYPE#START_MESSAGE} events
054: * are generated only once.
055: *
056: * <p>
057: * {@link EVENT_TYPE#START_PART}, {@link EVENT_TYPE#END_PART}, {@link EVENT_TYPE#HEADERS}
058: * events are generated only once for each attachment part.
059: *
060: * <p>
061: * {@link EVENT_TYPE#CONTENT} event may be generated more than once for an attachment
062: * part.
063: *
064: * @return event type
065: */
066: abstract EVENT_TYPE getEventType();
067:
068: static final StartMessage START_MESSAGE = new StartMessage();
069: static final StartPart START_PART = new StartPart();
070: static final EndPart END_PART = new EndPart();
071: static final EndMessage END_MESSAGE = new EndMessage();
072:
073: static final class StartMessage extends MIMEEvent {
074: EVENT_TYPE getEventType() {
075: return EVENT_TYPE.START_MESSAGE;
076: }
077: }
078:
079: static final class StartPart extends MIMEEvent {
080: EVENT_TYPE getEventType() {
081: return EVENT_TYPE.START_PART;
082: }
083: }
084:
085: static final class EndPart extends MIMEEvent {
086: EVENT_TYPE getEventType() {
087: return EVENT_TYPE.END_PART;
088: }
089: }
090:
091: static final class Headers extends MIMEEvent {
092: InternetHeaders ih;
093:
094: Headers(InternetHeaders ih) {
095: this .ih = ih;
096: }
097:
098: EVENT_TYPE getEventType() {
099: return EVENT_TYPE.HEADERS;
100: }
101:
102: InternetHeaders getHeaders() {
103: return ih;
104: }
105: }
106:
107: static final class Content extends MIMEEvent {
108: private final ByteBuffer buf;
109:
110: Content(ByteBuffer buf) {
111: this .buf = buf;
112: }
113:
114: EVENT_TYPE getEventType() {
115: return EVENT_TYPE.CONTENT;
116: }
117:
118: ByteBuffer getData() {
119: return buf;
120: }
121: }
122:
123: static final class EndMessage extends MIMEEvent {
124: EVENT_TYPE getEventType() {
125: return EVENT_TYPE.END_MESSAGE;
126: }
127: }
128:
129: }
|