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

Print this page


   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.server;
  27 
  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;
  33 
  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;
  38 
  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


  74  */
  75 public abstract class Container implements ComponentRegistry, ComponentEx {
  76         private final Set<Component> components = new CopyOnWriteArraySet<Component>();
  77 
  78     /**
  79      * For derived classes.
  80      */
  81     protected Container() {
  82     }
  83 
  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();
  89 
  90     private static final class NoneContainer extends Container {
  91     }
  92 
  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     }
 101 
 102         public Set<Component> getComponents() {
 103                 return components;
 104         }
 105 
 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     }
   1 /*
   2  * Copyright (c) 1997, 2013, 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.server;
  27 
  28 import java.util.Collection;
  29 import java.util.Collections;

  30 import java.util.Set;
  31 import java.util.concurrent.CopyOnWriteArraySet;
  32 
  33 import com.sun.istack.internal.NotNull;
  34 import com.sun.xml.internal.ws.api.Component;
  35 import com.sun.xml.internal.ws.api.ComponentEx;
  36 import com.sun.xml.internal.ws.api.ComponentRegistry;
  37 
  38 /**
  39  * Root of the SPI implemented by the container
  40  * (such as application server.)
  41  *
  42  * <p>
  43  * Often technologies that are built on top of JAX-WS
  44  * (such as Tango) needs to negotiate private contracts between
  45  * them and the container. This interface allows such technologies
  46  * to query the negotiated SPI by using the {@link #getSPI(Class)}.
  47  *
  48  * <p>
  49  * For example, if a security pipe needs to get some information


  73  */
  74 public abstract class Container implements ComponentRegistry, ComponentEx {
  75         private final Set<Component> components = new CopyOnWriteArraySet<Component>();
  76 
  77     /**
  78      * For derived classes.
  79      */
  80     protected Container() {
  81     }
  82 
  83     /**
  84      * Constant that represents a "no {@link Container}",
  85      * which always returns null from {@link #getSPI(Class)}.
  86      */
  87     public static final Container NONE = new NoneContainer();
  88 
  89     private static final class NoneContainer extends Container {
  90     }
  91 
  92     public <S> S getSPI(Class<S> spiType) {
  93         if (components == null) return null;
  94         for (Component c : components) {
  95                 S s = c.getSPI(spiType);
  96                 if (s != null)
  97                         return s;
  98         }
  99         return null;
 100     }
 101 
 102         public Set<Component> getComponents() {
 103                 return components;
 104         }
 105 
 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     }