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

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     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/TubelineAssemblerFactory.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,141 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2012, 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;
    1.30 +
    1.31 +import com.sun.istack.internal.NotNull;
    1.32 +import com.sun.istack.internal.Nullable;
    1.33 +import com.sun.xml.internal.ws.api.BindingID;
    1.34 +import com.sun.xml.internal.ws.api.pipe.helper.PipeAdapter;
    1.35 +import com.sun.xml.internal.ws.api.server.Container;
    1.36 +import com.sun.xml.internal.ws.assembler.MetroTubelineAssembler;
    1.37 +import com.sun.xml.internal.ws.util.ServiceFinder;
    1.38 +import java.util.logging.Level;
    1.39 +
    1.40 +import java.util.logging.Logger;
    1.41 +
    1.42 +/**
    1.43 + * Creates {@link TubelineAssembler}.
    1.44 + * <p/>
    1.45 + * <p/>
    1.46 + * To create a tubeline,
    1.47 + * the JAX-WS runtime locates {@link TubelineAssemblerFactory}s through
    1.48 + * the <tt>META-INF/services/com.sun.xml.internal.ws.api.pipe.TubelineAssemblerFactory</tt> files.
    1.49 + * Factories found are checked to see if it supports the given binding ID one by one,
    1.50 + * and the first valid {@link TubelineAssembler} returned will be used to create
    1.51 + * a tubeline.
    1.52 + *
    1.53 + * @author Jitendra Kotamraju
    1.54 + */
    1.55 +public abstract class TubelineAssemblerFactory {
    1.56 +    /**
    1.57 +     * Creates a {@link TubelineAssembler} applicable for the given binding ID.
    1.58 +     *
    1.59 +     * @param bindingId The binding ID for which a tubeline will be created,
    1.60 +     *                  such as {@link javax.xml.ws.soap.SOAPBinding#SOAP11HTTP_BINDING}.
    1.61 +     *                  Must not be null.
    1.62 +     * @return null if this factory doesn't recognize the given binding ID.
    1.63 +     */
    1.64 +    public abstract TubelineAssembler doCreate(BindingID bindingId);
    1.65 +
    1.66 +    /**
    1.67 +     * @deprecated
    1.68 +     *      Use {@link #create(ClassLoader, BindingID, Container)}
    1.69 +     */
    1.70 +    public static TubelineAssembler create(ClassLoader classLoader, BindingID bindingId) {
    1.71 +        return create(classLoader,bindingId,null);
    1.72 +    }
    1.73 +
    1.74 +    /**
    1.75 +     * Locates {@link TubelineAssemblerFactory}s and create
    1.76 +     * a suitable {@link TubelineAssembler}.
    1.77 +     *
    1.78 +     * @param bindingId The binding ID string for which the new {@link TubelineAssembler}
    1.79 +     *                  is created. Must not be null.
    1.80 +     * @param container
    1.81 +     *      if specified, the container is given a chance to specify a {@link TubelineAssembler}
    1.82 +     *      instance. This parameter should be always given on the server, but can be null.
    1.83 +     * @return Always non-null, since we fall back to our default {@link TubelineAssembler}.
    1.84 +     */
    1.85 +    public static TubelineAssembler create(ClassLoader classLoader, BindingID bindingId, @Nullable Container container) {
    1.86 +
    1.87 +        if(container!=null) {
    1.88 +            // first allow the container to control pipeline for individual endpoint.
    1.89 +            TubelineAssemblerFactory taf = container.getSPI(TubelineAssemblerFactory.class);
    1.90 +            if(taf!=null) {
    1.91 +                TubelineAssembler a = taf.doCreate(bindingId);
    1.92 +                if (a != null) {
    1.93 +                    return a;
    1.94 +                }
    1.95 +            }
    1.96 +        }
    1.97 +
    1.98 +        for (TubelineAssemblerFactory factory : ServiceFinder.find(TubelineAssemblerFactory.class, classLoader)) {
    1.99 +            TubelineAssembler assembler = factory.doCreate(bindingId);
   1.100 +            if (assembler != null) {
   1.101 +                TubelineAssemblerFactory.logger.log(Level.FINE, "{0} successfully created {1}", new Object[]{factory.getClass(), assembler});
   1.102 +                return assembler;
   1.103 +            }
   1.104 +        }
   1.105 +
   1.106 +        // See if there is a PipelineAssembler out there and use it for compatibility.
   1.107 +        for (PipelineAssemblerFactory factory : ServiceFinder.find(PipelineAssemblerFactory.class,classLoader)) {
   1.108 +            PipelineAssembler assembler = factory.doCreate(bindingId);
   1.109 +            if(assembler!=null) {
   1.110 +                logger.log(Level.FINE, "{0} successfully created {1}", new Object[]{factory.getClass(), assembler});
   1.111 +                return new TubelineAssemblerAdapter(assembler);
   1.112 +            }
   1.113 +        }
   1.114 +
   1.115 +        // default binding IDs that are known
   1.116 +        return new MetroTubelineAssembler(bindingId, MetroTubelineAssembler.JAXWS_TUBES_CONFIG_NAMES);
   1.117 +    }
   1.118 +
   1.119 +    private static class TubelineAssemblerAdapter implements TubelineAssembler {
   1.120 +        private PipelineAssembler assembler;
   1.121 +
   1.122 +        TubelineAssemblerAdapter(PipelineAssembler assembler) {
   1.123 +            this.assembler = assembler;
   1.124 +        }
   1.125 +
   1.126 +        @Override
   1.127 +        public @NotNull Tube createClient(@NotNull ClientTubeAssemblerContext context) {
   1.128 +            ClientPipeAssemblerContext ctxt = new ClientPipeAssemblerContext(
   1.129 +                    context.getAddress(), context.getWsdlModel(), context.getService(),
   1.130 +                    context.getBinding(), context.getContainer());
   1.131 +            return PipeAdapter.adapt(assembler.createClient(ctxt));
   1.132 +        }
   1.133 +
   1.134 +        @Override
   1.135 +        public @NotNull Tube createServer(@NotNull ServerTubeAssemblerContext context) {
   1.136 +            if (!(context instanceof ServerPipeAssemblerContext)) {
   1.137 +                throw new IllegalArgumentException("{0} is not instance of ServerPipeAssemblerContext");
   1.138 +            }
   1.139 +            return PipeAdapter.adapt(assembler.createServer((ServerPipeAssemblerContext) context));
   1.140 +        }
   1.141 +    }
   1.142 +
   1.143 +    private static final Logger logger = Logger.getLogger(TubelineAssemblerFactory.class.getName());
   1.144 +}

mercurial