325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.api;
325N/A
325N/Aimport com.sun.istack.internal.FinalArrayList;
325N/Aimport com.sun.istack.internal.NotNull;
325N/Aimport com.sun.istack.internal.Nullable;
325N/Aimport com.sun.xml.internal.ws.api.message.Packet;
325N/Aimport com.sun.xml.internal.ws.client.RequestContext;
325N/Aimport com.sun.xml.internal.ws.client.ResponseContext;
325N/A
325N/Aimport javax.xml.ws.WebServiceContext;
325N/Aimport java.util.Map.Entry;
325N/Aimport java.util.Set;
325N/A
325N/A/**
325N/A * {@link PropertySet} that combines properties exposed from multiple
325N/A * {@link PropertySet}s into one.
325N/A *
325N/A * <p>
325N/A * This implementation allows one {@link PropertySet} to assemble
325N/A * all properties exposed from other "satellite" {@link PropertySet}s.
325N/A * (A satellite may itself be a {@link DistributedPropertySet}, so
325N/A * in general this can form a tree.)
325N/A *
325N/A * <p>
325N/A * This is useful for JAX-WS because the properties we expose to the application
325N/A * are contributed by different pieces, and therefore we'd like each of them
325N/A * to have a separate {@link PropertySet} implementation that backs up
325N/A * the properties. For example, this allows FastInfoset to expose its
325N/A * set of properties to {@link RequestContext} by using a strongly-typed fields.
325N/A *
325N/A * <p>
325N/A * This is also useful for a client-side transport to expose a bunch of properties
325N/A * into {@link ResponseContext}. It simply needs to create a {@link PropertySet}
325N/A * object with methods for each property it wants to expose, and then add that
325N/A * {@link PropertySet} to {@link Packet}. This allows property values to be
325N/A * lazily computed (when actually asked by users), thus improving the performance
325N/A * of the typical case where property values are not asked.
325N/A *
325N/A * <p>
325N/A * A similar benefit applies on the server-side, for a transport to expose
325N/A * a bunch of properties to {@link WebServiceContext}.
325N/A *
325N/A * <p>
325N/A * To achieve these benefits, access to {@link DistributedPropertySet} is slower
325N/A * compared to {@link PropertySet} (such as get/set), while adding a satellite
325N/A * object is relatively fast.
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A */
325N/Apublic abstract class DistributedPropertySet extends PropertySet {
325N/A /**
325N/A * All {@link PropertySet}s that are bundled into this {@link PropertySet}.
325N/A */
325N/A private final FinalArrayList<PropertySet> satellites = new FinalArrayList<PropertySet>();
325N/A
325N/A public void addSatellite(@NotNull PropertySet satellite) {
325N/A satellites.add(satellite);
325N/A }
325N/A
325N/A public void removeSatellite(@NotNull PropertySet satellite) {
325N/A satellites.remove(satellite);
325N/A }
325N/A
325N/A public void copySatelliteInto(@NotNull DistributedPropertySet r) {
325N/A r.satellites.addAll(this.satellites);
325N/A }
325N/A
325N/A public @Nullable <T extends PropertySet> T getSatellite(Class<T> satelliteClass) {
325N/A for (PropertySet child : satellites) {
325N/A if (satelliteClass.isInstance(child)) {
325N/A return satelliteClass.cast(child);
325N/A }
325N/A
325N/A if (DistributedPropertySet.class.isInstance(child)) {
325N/A T satellite = DistributedPropertySet.class.cast(child).getSatellite(satelliteClass);
325N/A if (satellite != null) {
325N/A return satellite;
325N/A }
325N/A }
325N/A }
325N/A
325N/A return null;
325N/A }
325N/A
325N/A @Override
325N/A public Object get(Object key) {
325N/A // check satellites
325N/A for (PropertySet child : satellites) {
325N/A if(child.supports(key))
325N/A return child.get(key);
325N/A }
325N/A
325N/A // otherwise it must be the master
325N/A return super.get(key);
325N/A }
325N/A
325N/A @Override
325N/A public Object put(String key, Object value) {
325N/A // check satellites
325N/A for (PropertySet child : satellites) {
325N/A if(child.supports(key))
325N/A return child.put(key,value);
325N/A }
325N/A
325N/A // otherwise it must be the master
325N/A return super.put(key,value);
325N/A }
325N/A
325N/A @Override
325N/A public boolean supports(Object key) {
325N/A // check satellites
325N/A for (PropertySet child : satellites) {
325N/A if(child.supports(key))
325N/A return true;
325N/A }
325N/A
325N/A return super.supports(key);
325N/A }
325N/A
325N/A @Override
325N/A public Object remove(Object key) {
325N/A // check satellites
325N/A for (PropertySet child : satellites) {
325N/A if(child.supports(key))
325N/A return child.remove(key);
325N/A }
325N/A
325N/A return super.remove(key);
325N/A }
325N/A
325N/A @Override
325N/A /*package*/ void createEntrySet(Set<Entry<String, Object>> core) {
325N/A super.createEntrySet(core);
325N/A for (PropertySet child : satellites) {
325N/A child.createEntrySet(core);
325N/A }
325N/A }
325N/A}