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

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

ohair@286 1 /*
ohair@286 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.api;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.NotNull;
ohair@286 29 import com.sun.istack.internal.Nullable;
ohair@286 30 import com.sun.xml.internal.ws.api.message.Packet;
ohair@286 31 import com.sun.xml.internal.ws.client.RequestContext;
ohair@286 32 import com.sun.xml.internal.ws.client.ResponseContext;
ohair@286 33
ohair@286 34 import javax.xml.soap.SOAPException;
ohair@286 35 import javax.xml.soap.SOAPMessage;
ohair@286 36 import javax.xml.ws.WebServiceContext;
ohair@286 37 import java.util.Map.Entry;
ohair@286 38 import java.util.IdentityHashMap;
ohair@286 39 import java.util.Map;
ohair@286 40 import java.util.Set;
ohair@286 41
ohair@286 42 /**
ohair@286 43 * {@link PropertySet} that combines properties exposed from multiple
ohair@286 44 * {@link PropertySet}s into one.
ohair@286 45 *
ohair@286 46 * <p>
ohair@286 47 * This implementation allows one {@link PropertySet} to assemble
ohair@286 48 * all properties exposed from other "satellite" {@link PropertySet}s.
ohair@286 49 * (A satellite may itself be a {@link DistributedPropertySet}, so
ohair@286 50 * in general this can form a tree.)
ohair@286 51 *
ohair@286 52 * <p>
ohair@286 53 * This is useful for JAX-WS because the properties we expose to the application
ohair@286 54 * are contributed by different pieces, and therefore we'd like each of them
ohair@286 55 * to have a separate {@link PropertySet} implementation that backs up
ohair@286 56 * the properties. For example, this allows FastInfoset to expose its
ohair@286 57 * set of properties to {@link RequestContext} by using a strongly-typed fields.
ohair@286 58 *
ohair@286 59 * <p>
ohair@286 60 * This is also useful for a client-side transport to expose a bunch of properties
ohair@286 61 * into {@link ResponseContext}. It simply needs to create a {@link PropertySet}
ohair@286 62 * object with methods for each property it wants to expose, and then add that
ohair@286 63 * {@link PropertySet} to {@link Packet}. This allows property values to be
ohair@286 64 * lazily computed (when actually asked by users), thus improving the performance
ohair@286 65 * of the typical case where property values are not asked.
ohair@286 66 *
ohair@286 67 * <p>
ohair@286 68 * A similar benefit applies on the server-side, for a transport to expose
ohair@286 69 * a bunch of properties to {@link WebServiceContext}.
ohair@286 70 *
ohair@286 71 * <p>
ohair@286 72 * To achieve these benefits, access to {@link DistributedPropertySet} is slower
ohair@286 73 * compared to {@link PropertySet} (such as get/set), while adding a satellite
ohair@286 74 * object is relatively fast.
ohair@286 75 *
ohair@286 76 * @author Kohsuke Kawaguchi
ohair@286 77 */
ohair@286 78 public abstract class DistributedPropertySet
ohair@286 79 extends PropertySet
ohair@286 80 implements com.sun.xml.internal.org.jvnet.ws.message.DistributedPropertySet
ohair@286 81 {
ohair@286 82 /**
ohair@286 83 * All {@link PropertySet}s that are bundled into this {@link PropertySet}.
ohair@286 84 */
ohair@286 85 private final Map<Class, PropertySet> satellites = new IdentityHashMap<Class, PropertySet>();
ohair@286 86
ohair@286 87 public void addSatellite(@NotNull PropertySet satellite) {
ohair@286 88 addSatellite(satellite.getClass(), satellite);
ohair@286 89 }
ohair@286 90
ohair@286 91 public void addSatellite(@NotNull Class keyClass, @NotNull PropertySet satellite) {
ohair@286 92 satellites.put(keyClass, satellite);
ohair@286 93 }
ohair@286 94
ohair@286 95 public void copySatelliteInto(@NotNull DistributedPropertySet r) {
ohair@286 96 r.satellites.putAll(this.satellites);
ohair@286 97 }
ohair@286 98
ohair@286 99 public @Nullable <T extends com.sun.xml.internal.org.jvnet.ws.message.PropertySet> T getSatellite(Class<T> satelliteClass) {
ohair@286 100 T satellite = (T) satellites.get(satelliteClass);
ohair@286 101 if (satellite != null)
ohair@286 102 return satellite;
ohair@286 103
ohair@286 104 for (PropertySet child : satellites.values()) {
ohair@286 105 if (satelliteClass.isInstance(child)) {
ohair@286 106 return satelliteClass.cast(child);
ohair@286 107 }
ohair@286 108
ohair@286 109 if (DistributedPropertySet.class.isInstance(child)) {
ohair@286 110 satellite = DistributedPropertySet.class.cast(child).getSatellite(satelliteClass);
ohair@286 111 if (satellite != null) {
ohair@286 112 return satellite;
ohair@286 113 }
ohair@286 114 }
ohair@286 115 }
ohair@286 116 return null;
ohair@286 117 }
ohair@286 118
ohair@286 119 @Override
ohair@286 120 public Object get(Object key) {
ohair@286 121 // check satellites
ohair@286 122 for (PropertySet child : satellites.values()) {
ohair@286 123 if(child.supports(key))
ohair@286 124 return child.get(key);
ohair@286 125 }
ohair@286 126
ohair@286 127 // otherwise it must be the master
ohair@286 128 return super.get(key);
ohair@286 129 }
ohair@286 130
ohair@286 131 @Override
ohair@286 132 public Object put(String key, Object value) {
ohair@286 133 // check satellites
ohair@286 134 for (PropertySet child : satellites.values()) {
ohair@286 135 if(child.supports(key))
ohair@286 136 return child.put(key,value);
ohair@286 137 }
ohair@286 138
ohair@286 139 // otherwise it must be the master
ohair@286 140 return super.put(key,value);
ohair@286 141 }
ohair@286 142
ohair@286 143 @Override
ohair@286 144 public boolean supports(Object key) {
ohair@286 145 // check satellites
ohair@286 146 for (PropertySet child : satellites.values()) {
ohair@286 147 if(child.supports(key))
ohair@286 148 return true;
ohair@286 149 }
ohair@286 150
ohair@286 151 return super.supports(key);
ohair@286 152 }
ohair@286 153
ohair@286 154 @Override
ohair@286 155 public Object remove(Object key) {
ohair@286 156 // check satellites
ohair@286 157 for (PropertySet child : satellites.values()) {
ohair@286 158 if(child.supports(key))
ohair@286 159 return child.remove(key);
ohair@286 160 }
ohair@286 161
ohair@286 162 return super.remove(key);
ohair@286 163 }
ohair@286 164
ohair@286 165 @Override
ohair@286 166 /*package*/ void createEntrySet(Set<Entry<String, Object>> core) {
ohair@286 167 super.createEntrySet(core);
ohair@286 168 for (PropertySet child : satellites.values()) {
ohair@286 169 child.createEntrySet(core);
ohair@286 170 }
ohair@286 171 }
ohair@286 172
ohair@286 173 public void addSatellite(com.sun.xml.internal.org.jvnet.ws.message.PropertySet satellite) {
ohair@286 174 addSatellite((PropertySet)satellite);
ohair@286 175 }
ohair@286 176
ohair@286 177 public void addSatellite(@NotNull Class keyClass, @NotNull com.sun.xml.internal.org.jvnet.ws.message.PropertySet satellite) {
ohair@286 178 addSatellite(keyClass, (PropertySet)satellite);
ohair@286 179 }
ohair@286 180
ohair@286 181 public void removeSatellite(com.sun.xml.internal.org.jvnet.ws.message.PropertySet satellite) {
ohair@286 182 removeSatellite((PropertySet)satellite);
ohair@286 183 }
ohair@286 184
ohair@286 185 public void copySatelliteInto(com.sun.xml.internal.org.jvnet.ws.message.MessageContext r) {
ohair@286 186 copySatelliteInto((DistributedPropertySet)r);
ohair@286 187 }
ohair@286 188 }

mercurial