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.helper;
038:
039: import com.sun.xml.ws.api.message.Packet;
040: import com.sun.xml.ws.api.pipe.Fiber;
041: import com.sun.xml.ws.api.pipe.NextAction;
042: import com.sun.xml.ws.api.pipe.Pipe;
043: import com.sun.xml.ws.api.pipe.PipeCloner;
044: import com.sun.xml.ws.api.pipe.Tube;
045: import com.sun.xml.ws.api.pipe.TubeCloner;
046:
047: /**
048: * Base class for {@link Tube} implementation.
049: *
050: * <p>
051: * This can be also used as a {@link Pipe}, and thus effectively
052: * making every {@link Tube} usable as a {@link Pipe}.
053: *
054: * @author Kohsuke Kawaguchi
055: */
056: public abstract class AbstractTubeImpl implements Tube, Pipe {
057:
058: /**
059: * Default constructor.
060: */
061: protected AbstractTubeImpl() {
062: }
063:
064: /**
065: * Copy constructor.
066: */
067: protected AbstractTubeImpl(AbstractTubeImpl that, TubeCloner cloner) {
068: cloner.add(that, this );
069: }
070:
071: protected final NextAction doInvoke(Tube next, Packet packet) {
072: NextAction na = new NextAction();
073: na.invoke(next, packet);
074: return na;
075: }
076:
077: protected final NextAction doInvokeAndForget(Tube next,
078: Packet packet) {
079: NextAction na = new NextAction();
080: na.invokeAndForget(next, packet);
081: return na;
082: }
083:
084: protected final NextAction doReturnWith(Packet response) {
085: NextAction na = new NextAction();
086: na.returnWith(response);
087: return na;
088: }
089:
090: protected final NextAction doSuspend() {
091: NextAction na = new NextAction();
092: na.suspend();
093: return na;
094: }
095:
096: protected final NextAction doThrow(Throwable t) {
097: NextAction na = new NextAction();
098: na.throwException(t);
099: return na;
100: }
101:
102: /**
103: * "Dual stack" compatibility mechanism.
104: * Allows {@link Tube} to be invoked from a {@link Pipe}.
105: */
106: public Packet process(Packet p) {
107: return Fiber.current().runSync(this , p);
108: }
109:
110: /**
111: * Needs to be implemented by the derived class, but we can't make it abstract
112: * without upsetting javac.
113: */
114: public final AbstractTubeImpl copy(PipeCloner cloner) {
115: return copy((TubeCloner) cloner);
116: }
117:
118: public abstract AbstractTubeImpl copy(TubeCloner cloner);
119: }
|