src/share/jaxws_classes/com/sun/xml/internal/ws/api/pipe/helper/AbstractFilterPipeImpl.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/pipe/helper/AbstractFilterPipeImpl.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,121 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.api.pipe.helper;
    1.30 +
    1.31 +import com.sun.xml.internal.ws.api.pipe.Pipe;
    1.32 +import com.sun.xml.internal.ws.api.pipe.PipeCloner;
    1.33 +import com.sun.xml.internal.ws.api.message.Packet;
    1.34 +
    1.35 +/**
    1.36 + * Default implementation of {@link Pipe} that is used as a filter.
    1.37 + *
    1.38 + * <p>
    1.39 + * A filter pipe works on a {@link Packet}, then pass it onto the next pipe.
    1.40 + *
    1.41 + *
    1.42 + * <h2>How do I implement a filter?</h2>
    1.43 + * <p>
    1.44 + * Filter {@link Pipe}s are ideal for those components that wish to
    1.45 + * do some of the followings:
    1.46 + *
    1.47 + * <dl>
    1.48 + * <dt><b>
    1.49 + * To read an incoming message and perform some work before the
    1.50 + * application (or more precisely the next pipe sees it)
    1.51 + * </b>
    1.52 + * <dd>
    1.53 + * Implement the {@link #process} method and do some processing before
    1.54 + * you pass the packet to the next pipe:
    1.55 + * <pre>
    1.56 + * process(request) {
    1.57 + *   doSomethingWith(request);
    1.58 + *   return next.process(request);
    1.59 + * }
    1.60 + * </pre>
    1.61 + *
    1.62 + *
    1.63 + * <dt><b>
    1.64 + * To intercept an incoming message and prevent the next pipe from seeing it.
    1.65 + * </b>
    1.66 + * <dd>
    1.67 + * Implement the {@link #process} method and do some processing,
    1.68 + * then do NOT pass the request onto the next pipe.
    1.69 + * <pre>
    1.70 + * process(request) {
    1.71 + *   if(isSomethingWrongWith(request))
    1.72 + *     return createErrorMessage();
    1.73 + *   else
    1.74 + *     return next.proces(request);
    1.75 + * }
    1.76 + * </pre>
    1.77 + *
    1.78 + * <dt><b>
    1.79 + * To post process a reply and possibly modify a message:
    1.80 + * </b>
    1.81 + * <dd>
    1.82 + * Implement the {@link #process} method and do some processing,
    1.83 + * then do NOT pass the request onto the next pipe.
    1.84 + * <pre>
    1.85 + * process(request) {
    1.86 + *   op = request.getMessage().getOperation();
    1.87 + *   reply = next.proces(request);
    1.88 + *   if(op is something I care) {
    1.89 + *     reply = playWith(reply);
    1.90 + *   }
    1.91 + *   return reply;
    1.92 + * }
    1.93 + * </pre>
    1.94 + *
    1.95 + * </dl>
    1.96 + *
    1.97 + * @author Kohsuke Kawaguchi
    1.98 + */
    1.99 +public abstract class AbstractFilterPipeImpl extends AbstractPipeImpl {
   1.100 +    /**
   1.101 +     * Next pipe to call.
   1.102 +     */
   1.103 +    protected final Pipe next;
   1.104 +
   1.105 +    protected AbstractFilterPipeImpl(Pipe next) {
   1.106 +        this.next = next;
   1.107 +        assert next!=null;
   1.108 +    }
   1.109 +
   1.110 +    protected AbstractFilterPipeImpl(AbstractFilterPipeImpl that, PipeCloner cloner) {
   1.111 +        super(that, cloner);
   1.112 +        this.next = cloner.copy(that.next);
   1.113 +        assert next!=null;
   1.114 +    }
   1.115 +
   1.116 +    public Packet process(Packet packet) {
   1.117 +        return next.process(packet);
   1.118 +    }
   1.119 +
   1.120 +    @Override
   1.121 +    public void preDestroy() {
   1.122 +        next.preDestroy();
   1.123 +    }
   1.124 +}

mercurial