src/share/jaxws_classes/com/sun/xml/internal/ws/api/server/Container.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 397
b99d7e355d4b
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

     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  */
    26 package com.sun.xml.internal.ws.api.server;
    28 import java.util.Collection;
    29 import java.util.Collections;
    30 import java.util.HashSet;
    31 import java.util.Set;
    32 import java.util.concurrent.CopyOnWriteArraySet;
    34 import com.sun.istack.internal.NotNull;
    35 import com.sun.xml.internal.ws.api.Component;
    36 import com.sun.xml.internal.ws.api.ComponentEx;
    37 import com.sun.xml.internal.ws.api.ComponentRegistry;
    39 /**
    40  * Root of the SPI implemented by the container
    41  * (such as application server.)
    42  *
    43  * <p>
    44  * Often technologies that are built on top of JAX-WS
    45  * (such as Tango) needs to negotiate private contracts between
    46  * them and the container. This interface allows such technologies
    47  * to query the negotiated SPI by using the {@link #getSPI(Class)}.
    48  *
    49  * <p>
    50  * For example, if a security pipe needs to get some information
    51  * from a container, they can do the following:
    52  * <ol>
    53  *  <li>Negotiate an interface with the container and define it.
    54  *      (let's call it <tt>ContainerSecuritySPI</tt>.)
    55  *  <li>The container will implement <tt>ContainerSecuritySPI</tt>.
    56  *  <li>At the runtime, a security pipe gets
    57  *      {@link WSEndpoint} and then to {@link Container}.
    58  *  <li>It calls <tt>container.getSPI(ContainerSecuritySPI.class)</tt>
    59  *  <li>The container returns an instance of <tt>ContainerSecuritySPI</tt>.
    60  *  <li>The security pipe talks to the container through this SPI.
    61  * </ol>
    62  *
    63  * <p>
    64  * This protects JAX-WS from worrying about the details of such contracts,
    65  * while still providing the necessary service of hooking up those parties.
    66  *
    67  * <p>
    68  * Technologies that run inside JAX-WS server runtime can access this object through
    69  * {@link WSEndpoint#getContainer()}. In the client runtime, it can be accessed from
    70  * {@link ContainerResolver#getContainer()}
    71  *
    72  * @author Kohsuke Kawaguchi
    73  * @see WSEndpoint
    74  */
    75 public abstract class Container implements ComponentRegistry, ComponentEx {
    76         private final Set<Component> components = new CopyOnWriteArraySet<Component>();
    78     /**
    79      * For derived classes.
    80      */
    81     protected Container() {
    82     }
    84     /**
    85      * Constant that represents a "no {@link Container}",
    86      * which always returns null from {@link #getSPI(Class)}.
    87      */
    88     public static final Container NONE = new NoneContainer();
    90     private static final class NoneContainer extends Container {
    91     }
    93     public <S> S getSPI(Class<S> spiType) {
    94         for (Component c : components) {
    95                 S s = c.getSPI(spiType);
    96                 if (s != null)
    97                         return s;
    98         }
    99         return null;
   100     }
   102         public Set<Component> getComponents() {
   103                 return components;
   104         }
   106         public @NotNull <E> Iterable<E> getIterableSPI(Class<E> spiType) {
   107         E item = getSPI(spiType);
   108         if (item != null) {
   109                 Collection<E> c = Collections.singletonList(item);
   110                 return c;
   111         }
   112         return Collections.emptySet();
   113     }
   114 }

mercurial