01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.proxy;
23:
24: import java.io.Externalizable;
25: import java.io.IOException;
26: import java.io.ObjectInput;
27: import java.io.ObjectOutput;
28: import org.jboss.invocation.Invocation;
29:
30: /**
31: * The base class for all interceptors.
32: *
33: * @author <a href="mailto:marc.fleury@jboss.org">Marc Fleury</a>
34: * @version $Revision: 57209 $
35: */
36: public abstract class Interceptor implements Externalizable {
37: /** The serialVersionUID. @since 1.2 */
38: private static final long serialVersionUID = 4358098404672505200L;
39:
40: /** The next interceptor in the chain. */
41: protected Interceptor nextInterceptor;
42:
43: /**
44: * Set the next interceptor in the chain.
45: *
46: * <p>
47: * String together the interceptors
48: * We return the passed interceptor to allow for
49: * interceptor1.setNext(interceptor2).setNext(interceptor3)... constructs.
50: */
51: public Interceptor setNext(final Interceptor interceptor) {
52: // assert interceptor != null
53: nextInterceptor = interceptor;
54: return interceptor;
55: }
56:
57: public Interceptor getNext() {
58: return nextInterceptor;
59: }
60:
61: public abstract Object invoke(Invocation mi) throws Throwable;
62:
63: /**
64: * Writes the next interceptor.
65: */
66: public void writeExternal(final ObjectOutput out)
67: throws IOException {
68: out.writeObject(nextInterceptor);
69: }
70:
71: /**
72: * Reads the next interceptor.
73: */
74: public void readExternal(final ObjectInput in) throws IOException,
75: ClassNotFoundException {
76: nextInterceptor = (Interceptor) in.readObject();
77: }
78: }
|