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:
037: package com.sun.xml.ws.api.pipe;
038:
039: import com.sun.xml.ws.api.message.Packet;
040:
041: /**
042: * Indicates what shall happen after {@link Tube#processRequest(Packet)} or
043: * {@link Tube#processResponse(Packet)} returns.
044: *
045: * <p>
046: * To allow reuse of this object, this class is mutable.
047: *
048: * @author Kohsuke Kawaguchi
049: */
050: public final class NextAction {
051: int kind;
052: Tube next;
053: Packet packet;
054: /**
055: * Really either {@link RuntimeException} or {@link Error}.
056: */
057: Throwable throwable;
058:
059: // public enum Kind { INVOKE, INVOKE_AND_FORGET, RETURN, SUSPEND }
060:
061: static final int INVOKE = 0;
062: static final int INVOKE_AND_FORGET = 1;
063: static final int RETURN = 2;
064: static final int THROW = 3;
065: static final int SUSPEND = 4;
066:
067: private void set(int k, Tube v, Packet p, Throwable t) {
068: this .kind = k;
069: this .next = v;
070: this .packet = p;
071: this .throwable = t;
072: }
073:
074: /**
075: * Indicates that the next action should be to
076: * invoke the next tube's {@link Tube#processRequest(Packet)},
077: * then later invoke the current tube's {@link Tube#processResponse(Packet)}
078: * with the response packet.
079: */
080: public void invoke(Tube next, Packet p) {
081: set(INVOKE, next, p, null);
082: }
083:
084: /**
085: * Indicates that the next action should be to
086: * invoke the next tube's {@link Tube#processRequest(Packet)},
087: * but the current tube doesn't want to receive the response packet to
088: * its {@link Tube#processResponse(Packet)}.
089: */
090: public void invokeAndForget(Tube next, Packet p) {
091: set(INVOKE_AND_FORGET, next, p, null);
092: }
093:
094: /**
095: * Indicates that the next action is to flip the processing direction
096: * and starts response processing.
097: */
098: public void returnWith(Packet response) {
099: set(RETURN, null, response, null);
100: }
101:
102: /**
103: * Indicates that the next action is to flip the processing direction
104: * and starts exception processing.
105: *
106: * @param t
107: * Either {@link RuntimeException} or {@link Error}, but defined to
108: * take {@link Throwable} because {@link Tube#processException(Throwable)}
109: * takes {@link Throwable}.
110: */
111: public void throwException(Throwable t) {
112: assert t instanceof RuntimeException || t instanceof Error;
113: set(THROW, null, null, t);
114: }
115:
116: /**
117: * Indicates that the fiber should be suspended.
118: * Once {@link Fiber#resume(Packet) resumed}, return the response processing.
119: */
120: public void suspend() {
121: set(SUSPEND, null, null, null);
122: }
123:
124: /**
125: * Dumps the contents to assist debugging.
126: */
127: public String toString() {
128: StringBuilder buf = new StringBuilder();
129: buf.append(super .toString()).append(" [");
130: buf.append("kind=").append(getKindString()).append(',');
131: buf.append("next=").append(next).append(',');
132: buf.append("packet=").append(packet).append(',');
133: buf.append("throwable=").append(throwable).append(']');
134: return buf.toString();
135: }
136:
137: /**
138: * Returns {@link #kind} in a human readable string, to assist debugging.
139: */
140: public String getKindString() {
141: switch (kind) {
142: case INVOKE:
143: return "INVOKE";
144: case INVOKE_AND_FORGET:
145: return "INVOKE_AND_FORGET";
146: case RETURN:
147: return "RETURN";
148: case THROW:
149: return "THROW";
150: case SUSPEND:
151: return "SUSPEND";
152: default:
153: throw new AssertionError(kind);
154: }
155: }
156: }
|