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

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
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 *
55 * @param bindingId The binding ID for which a tubeline will be created,
56 * such as {@link javax.xml.ws.soap.SOAPBinding#SOAP11HTTP_BINDING}.
57 * Must not be null.
58 * @return null if this factory doesn't recognize the given binding ID.
59 */
60 public abstract TubelineAssembler doCreate(BindingID bindingId);
61
62 /**
63 * @deprecated
64 * Use {@link #create(ClassLoader, BindingID, Container)}
65 */
66 public static TubelineAssembler create(ClassLoader classLoader, BindingID bindingId) {
67 return create(classLoader,bindingId,null);
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 }

mercurial