001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.api.pipe;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.istack.Nullable;
041: import com.sun.xml.ws.api.BindingID;
042: import com.sun.xml.ws.api.pipe.helper.PipeAdapter;
043: import com.sun.xml.ws.api.server.Container;
044: import com.sun.xml.ws.util.ServiceFinder;
045: import com.sun.xml.ws.util.pipe.StandaloneTubeAssembler;
046:
047: import java.util.logging.Logger;
048:
049: /**
050: * Creates {@link TubelineAssembler}.
051: * <p/>
052: * <p/>
053: * To create a tubeline,
054: * the JAX-WS runtime locates {@link TubelineAssemblerFactory}s through
055: * the <tt>META-INF/services/com.sun.xml.ws.api.pipe.TubelineAssemblerFactory</tt> files.
056: * Factories found are checked to see if it supports the given binding ID one by one,
057: * and the first valid {@link TubelineAssembler} returned will be used to create
058: * a tubeline.
059: *
060: * @author Jitendra Kotamraju
061: */
062: public abstract class TubelineAssemblerFactory {
063: /**
064: * Creates a {@link TubelineAssembler} applicable for the given binding ID.
065: *
066: * @param bindingId The binding ID for which a tubeline will be created,
067: * such as {@link javax.xml.ws.soap.SOAPBinding#SOAP11HTTP_BINDING}.
068: * Must not be null.
069: * @return null if this factory doesn't recognize the given binding ID.
070: */
071: public abstract TubelineAssembler doCreate(BindingID bindingId);
072:
073: /**
074: * @deprecated
075: * Use {@link #create(ClassLoader, BindingID, Container)}
076: */
077: public static TubelineAssembler create(ClassLoader classLoader,
078: BindingID bindingId) {
079: return create(classLoader, bindingId, null);
080: }
081:
082: /**
083: * Locates {@link TubelineAssemblerFactory}s and create
084: * a suitable {@link TubelineAssembler}.
085: *
086: * @param bindingId The binding ID string for which the new {@link TubelineAssembler}
087: * is created. Must not be null.
088: * @param container
089: * if specified, the container is given a chance to specify a {@link TubelineAssembler}
090: * instance. This parameter should be always given on the server, but can be null.
091: * @return Always non-null, since we fall back to our default {@link TubelineAssembler}.
092: */
093: public static TubelineAssembler create(ClassLoader classLoader,
094: BindingID bindingId, @Nullable
095: Container container) {
096:
097: if (container != null) {
098: // first allow the container to control pipeline for individual endpoint.
099: TubelineAssemblerFactory taf = container
100: .getSPI(TubelineAssemblerFactory.class);
101: if (taf != null) {
102: TubelineAssembler a = taf.doCreate(bindingId);
103: if (a != null)
104: return a;
105: }
106: }
107:
108: for (TubelineAssemblerFactory factory : ServiceFinder.find(
109: TubelineAssemblerFactory.class, classLoader)) {
110: TubelineAssembler assembler = factory.doCreate(bindingId);
111: if (assembler != null) {
112: TubelineAssemblerFactory.logger.fine(factory.getClass()
113: + " successfully created " + assembler);
114: return assembler;
115: }
116: }
117:
118: // See if there is a PipelineAssembler out there and use it for compatibility.
119: for (PipelineAssemblerFactory factory : ServiceFinder.find(
120: PipelineAssemblerFactory.class, classLoader)) {
121: PipelineAssembler assembler = factory.doCreate(bindingId);
122: if (assembler != null) {
123: logger.fine(factory.getClass()
124: + " successfully created " + assembler);
125: return new TubelineAssemblerAdapter(assembler);
126: }
127: }
128:
129: // default binding IDs that are known
130: return new StandaloneTubeAssembler();
131: }
132:
133: private static class TubelineAssemblerAdapter implements
134: TubelineAssembler {
135: private PipelineAssembler assembler;
136:
137: TubelineAssemblerAdapter(PipelineAssembler assembler) {
138: this .assembler = assembler;
139: }
140:
141: public @NotNull
142: Tube createClient(@NotNull
143: ClientTubeAssemblerContext context) {
144: ClientPipeAssemblerContext ctxt = new ClientPipeAssemblerContext(
145: context.getAddress(), context.getWsdlModel(),
146: context.getService(), context.getBinding(), context
147: .getContainer());
148: return PipeAdapter.adapt(assembler.createClient(ctxt));
149: }
150:
151: public @NotNull
152: Tube createServer(@NotNull
153: ServerTubeAssemblerContext context) {
154: return PipeAdapter
155: .adapt(assembler
156: .createServer((ServerPipeAssemblerContext) context));
157: }
158: }
159:
160: private static final Logger logger = Logger
161: .getLogger(TubelineAssemblerFactory.class.getName());
162: }
|