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