1 /*
2  * Copyright (c) 1997, 2012, 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.ws.api.pipe.helper;
27 
28 import com.sun.xml.internal.ws.api.message.Packet;
29 import com.sun.xml.internal.ws.api.pipe.Fiber;
30 import com.sun.xml.internal.ws.api.pipe.NextAction;
31 import com.sun.xml.internal.ws.api.pipe.Pipe;
32 import com.sun.xml.internal.ws.api.pipe.PipeCloner;
33 import com.sun.xml.internal.ws.api.pipe.Tube;
34 import com.sun.xml.internal.ws.api.pipe.TubeCloner;
35 
36 /**
37  * Base class for {@link Tube} implementation.
38  *
39  * <p>
40  * This can be also used as a {@link Pipe}, and thus effectively
41  * making every {@link Tube} usable as a {@link Pipe}.
42  *
43  * @author Kohsuke Kawaguchi
44  */
45 public abstract class AbstractTubeImpl implements Tube, Pipe {
46 
47     /**
48      * Default constructor.
49      */
AbstractTubeImpl()50     protected AbstractTubeImpl() {
51     }
52 
53     /**
54      * Copy constructor.
55      */
AbstractTubeImpl(AbstractTubeImpl that, TubeCloner cloner)56     protected AbstractTubeImpl(AbstractTubeImpl that, TubeCloner cloner) {
57         cloner.add(that,this);
58     }
59 
doInvoke(Tube next, Packet packet)60     protected final NextAction doInvoke(Tube next, Packet packet) {
61         NextAction na = new NextAction();
62         na.invoke(next,packet);
63         return na;
64     }
65 
doInvokeAndForget(Tube next, Packet packet)66     protected final NextAction doInvokeAndForget(Tube next, Packet packet) {
67         NextAction na = new NextAction();
68         na.invokeAndForget(next,packet);
69         return na;
70     }
71 
doReturnWith(Packet response)72     protected final NextAction doReturnWith(Packet response) {
73         NextAction na = new NextAction();
74         na.returnWith(response);
75         return na;
76     }
77 
doThrow(Packet response, Throwable t)78     protected final NextAction doThrow(Packet response, Throwable t) {
79         NextAction na = new NextAction();
80         na.throwException(response, t);
81         return na;
82     }
83 
84     @Deprecated
doSuspend()85     protected final NextAction doSuspend() {
86         NextAction na = new NextAction();
87         na.suspend();
88         return na;
89     }
90 
doSuspend(Runnable onExitRunnable)91     protected final NextAction doSuspend(Runnable onExitRunnable) {
92         NextAction na = new NextAction();
93         na.suspend(onExitRunnable);
94         return na;
95     }
96 
97     @Deprecated
doSuspend(Tube next)98     protected final NextAction doSuspend(Tube next) {
99         NextAction na = new NextAction();
100         na.suspend(next);
101         return na;
102     }
103 
doSuspend(Tube next, Runnable onExitRunnable)104     protected final NextAction doSuspend(Tube next, Runnable onExitRunnable) {
105         NextAction na = new NextAction();
106         na.suspend(next, onExitRunnable);
107         return na;
108     }
109 
doThrow(Throwable t)110     protected final NextAction doThrow(Throwable t) {
111         NextAction na = new NextAction();
112         na.throwException(t);
113         return na;
114     }
115 
116     /**
117      * "Dual stack" compatibility mechanism.
118      * Allows {@link Tube} to be invoked from a {@link Pipe}.
119      */
process(Packet p)120     public Packet process(Packet p) {
121         return Fiber.current().runSync(this,p);
122     }
123 
124     /**
125      * Needs to be implemented by the derived class, but we can't make it abstract
126      * without upsetting javac.
127      */
copy(PipeCloner cloner)128     public final AbstractTubeImpl copy(PipeCloner cloner) {
129         return copy((TubeCloner)cloner);
130     }
131 
copy(TubeCloner cloner)132     public abstract AbstractTubeImpl copy(TubeCloner cloner);
133 }
134