1 /* 2 * Copyright (c) 1997, 2010, 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; 27 28 import com.sun.istack.internal.NotNull; 29 import com.sun.istack.internal.Nullable; 30 import com.sun.xml.internal.ws.api.BindingID; 31 import com.sun.xml.internal.ws.api.pipe.helper.PipeAdapter; 32 import com.sun.xml.internal.ws.api.server.Container; 33 import com.sun.xml.internal.ws.util.ServiceFinder; 34 import com.sun.xml.internal.ws.util.pipe.StandaloneTubeAssembler; 35 36 import java.util.logging.Logger; 37 38 /** 39 * Creates {@link TubelineAssembler}. 40 * <p/> 41 * <p/> 42 * To create a tubeline, 43 * the JAX-WS runtime locates {@link TubelineAssemblerFactory}s through 44 * the <tt>META-INF/services/com.sun.xml.internal.ws.api.pipe.TubelineAssemblerFactory</tt> files. 45 * Factories found are checked to see if it supports the given binding ID one by one, 46 * and the first valid {@link TubelineAssembler} returned will be used to create 47 * a tubeline. 48 * 49 * @author Jitendra Kotamraju 50 */ 51 public abstract class TubelineAssemblerFactory { 52 /** 53 * Creates a {@link TubelineAssembler} applicable for the given binding ID. 54 * 68 } 69 70 /** 71 * Locates {@link TubelineAssemblerFactory}s and create 72 * a suitable {@link TubelineAssembler}. 73 * 74 * @param bindingId The binding ID string for which the new {@link TubelineAssembler} 75 * is created. Must not be null. 76 * @param container 77 * if specified, the container is given a chance to specify a {@link TubelineAssembler} 78 * instance. This parameter should be always given on the server, but can be null. 79 * @return Always non-null, since we fall back to our default {@link TubelineAssembler}. 80 */ 81 public static TubelineAssembler create(ClassLoader classLoader, BindingID bindingId, @Nullable Container container) { 82 83 if(container!=null) { 84 // first allow the container to control pipeline for individual endpoint. 85 TubelineAssemblerFactory taf = container.getSPI(TubelineAssemblerFactory.class); 86 if(taf!=null) { 87 TubelineAssembler a = taf.doCreate(bindingId); 88 if(a!=null) 89 return a; 90 } 91 } 92 93 for (TubelineAssemblerFactory factory : ServiceFinder.find(TubelineAssemblerFactory.class, classLoader)) { 94 TubelineAssembler assembler = factory.doCreate(bindingId); 95 if (assembler != null) { 96 TubelineAssemblerFactory.logger.fine(factory.getClass() + " successfully created " + assembler); 97 return assembler; 98 } 99 } 100 101 // See if there is a PipelineAssembler out there and use it for compatibility. 102 for (PipelineAssemblerFactory factory : ServiceFinder.find(PipelineAssemblerFactory.class,classLoader)) { 103 PipelineAssembler assembler = factory.doCreate(bindingId); 104 if(assembler!=null) { 105 logger.fine(factory.getClass()+" successfully created "+assembler); 106 return new TubelineAssemblerAdapter(assembler); 107 } 108 } 109 110 // default binding IDs that are known 111 return new StandaloneTubeAssembler(); 112 } 113 114 private static class TubelineAssemblerAdapter implements TubelineAssembler { 115 private PipelineAssembler assembler; 116 117 TubelineAssemblerAdapter(PipelineAssembler assembler) { 118 this.assembler = assembler; 119 } 120 121 public @NotNull Tube createClient(@NotNull ClientTubeAssemblerContext context) { 122 ClientPipeAssemblerContext ctxt = new ClientPipeAssemblerContext( 123 context.getAddress(), context.getWsdlModel(), context.getService(), 124 context.getBinding(), context.getContainer()); 125 return PipeAdapter.adapt(assembler.createClient(ctxt)); 126 } 127 128 public @NotNull Tube createServer(@NotNull ServerTubeAssemblerContext context) { 129 return PipeAdapter.adapt(assembler.createServer((ServerPipeAssemblerContext) context)); 130 } 131 } 132 133 private static final Logger logger = Logger.getLogger(TubelineAssemblerFactory.class.getName()); 134 } | 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; 27 28 import com.sun.istack.internal.NotNull; 29 import com.sun.istack.internal.Nullable; 30 import com.sun.xml.internal.ws.api.BindingID; 31 import com.sun.xml.internal.ws.api.pipe.helper.PipeAdapter; 32 import com.sun.xml.internal.ws.api.server.Container; 33 import com.sun.xml.internal.ws.assembler.MetroTubelineAssembler; 34 import com.sun.xml.internal.ws.util.ServiceFinder; 35 import java.util.logging.Level; 36 37 import java.util.logging.Logger; 38 39 /** 40 * Creates {@link TubelineAssembler}. 41 * <p/> 42 * <p/> 43 * To create a tubeline, 44 * the JAX-WS runtime locates {@link TubelineAssemblerFactory}s through 45 * the <tt>META-INF/services/com.sun.xml.internal.ws.api.pipe.TubelineAssemblerFactory</tt> files. 46 * Factories found are checked to see if it supports the given binding ID one by one, 47 * and the first valid {@link TubelineAssembler} returned will be used to create 48 * a tubeline. 49 * 50 * @author Jitendra Kotamraju 51 */ 52 public abstract class TubelineAssemblerFactory { 53 /** 54 * Creates a {@link TubelineAssembler} applicable for the given binding ID. 55 * 69 } 70 71 /** 72 * Locates {@link TubelineAssemblerFactory}s and create 73 * a suitable {@link TubelineAssembler}. 74 * 75 * @param bindingId The binding ID string for which the new {@link TubelineAssembler} 76 * is created. Must not be null. 77 * @param container 78 * if specified, the container is given a chance to specify a {@link TubelineAssembler} 79 * instance. This parameter should be always given on the server, but can be null. 80 * @return Always non-null, since we fall back to our default {@link TubelineAssembler}. 81 */ 82 public static TubelineAssembler create(ClassLoader classLoader, BindingID bindingId, @Nullable Container container) { 83 84 if(container!=null) { 85 // first allow the container to control pipeline for individual endpoint. 86 TubelineAssemblerFactory taf = container.getSPI(TubelineAssemblerFactory.class); 87 if(taf!=null) { 88 TubelineAssembler a = taf.doCreate(bindingId); 89 if (a != null) { 90 return a; 91 } 92 } 93 } 94 95 for (TubelineAssemblerFactory factory : ServiceFinder.find(TubelineAssemblerFactory.class, classLoader)) { 96 TubelineAssembler assembler = factory.doCreate(bindingId); 97 if (assembler != null) { 98 TubelineAssemblerFactory.logger.log(Level.FINE, "{0} successfully created {1}", new Object[]{factory.getClass(), assembler}); 99 return assembler; 100 } 101 } 102 103 // See if there is a PipelineAssembler out there and use it for compatibility. 104 for (PipelineAssemblerFactory factory : ServiceFinder.find(PipelineAssemblerFactory.class,classLoader)) { 105 PipelineAssembler assembler = factory.doCreate(bindingId); 106 if(assembler!=null) { 107 logger.log(Level.FINE, "{0} successfully created {1}", new Object[]{factory.getClass(), assembler}); 108 return new TubelineAssemblerAdapter(assembler); 109 } 110 } 111 112 // default binding IDs that are known 113 return new MetroTubelineAssembler(bindingId, MetroTubelineAssembler.JAXWS_TUBES_CONFIG_NAMES); 114 } 115 116 private static class TubelineAssemblerAdapter implements TubelineAssembler { 117 private PipelineAssembler assembler; 118 119 TubelineAssemblerAdapter(PipelineAssembler assembler) { 120 this.assembler = assembler; 121 } 122 123 @Override 124 public @NotNull Tube createClient(@NotNull ClientTubeAssemblerContext context) { 125 ClientPipeAssemblerContext ctxt = new ClientPipeAssemblerContext( 126 context.getAddress(), context.getWsdlModel(), context.getService(), 127 context.getBinding(), context.getContainer()); 128 return PipeAdapter.adapt(assembler.createClient(ctxt)); 129 } 130 131 @Override 132 public @NotNull Tube createServer(@NotNull ServerTubeAssemblerContext context) { 133 if (!(context instanceof ServerPipeAssemblerContext)) { 134 throw new IllegalArgumentException("{0} is not instance of ServerPipeAssemblerContext"); 135 } 136 return PipeAdapter.adapt(assembler.createServer((ServerPipeAssemblerContext) context)); 137 } 138 } 139 140 private static final Logger logger = Logger.getLogger(TubelineAssemblerFactory.class.getName()); 141 } |