1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/DistributedPropertySet.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,188 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.api; 1.30 + 1.31 +import com.sun.istack.internal.NotNull; 1.32 +import com.sun.istack.internal.Nullable; 1.33 +import com.sun.xml.internal.ws.api.message.Packet; 1.34 +import com.sun.xml.internal.ws.client.RequestContext; 1.35 +import com.sun.xml.internal.ws.client.ResponseContext; 1.36 + 1.37 +import javax.xml.soap.SOAPException; 1.38 +import javax.xml.soap.SOAPMessage; 1.39 +import javax.xml.ws.WebServiceContext; 1.40 +import java.util.Map.Entry; 1.41 +import java.util.IdentityHashMap; 1.42 +import java.util.Map; 1.43 +import java.util.Set; 1.44 + 1.45 +/** 1.46 + * {@link PropertySet} that combines properties exposed from multiple 1.47 + * {@link PropertySet}s into one. 1.48 + * 1.49 + * <p> 1.50 + * This implementation allows one {@link PropertySet} to assemble 1.51 + * all properties exposed from other "satellite" {@link PropertySet}s. 1.52 + * (A satellite may itself be a {@link DistributedPropertySet}, so 1.53 + * in general this can form a tree.) 1.54 + * 1.55 + * <p> 1.56 + * This is useful for JAX-WS because the properties we expose to the application 1.57 + * are contributed by different pieces, and therefore we'd like each of them 1.58 + * to have a separate {@link PropertySet} implementation that backs up 1.59 + * the properties. For example, this allows FastInfoset to expose its 1.60 + * set of properties to {@link RequestContext} by using a strongly-typed fields. 1.61 + * 1.62 + * <p> 1.63 + * This is also useful for a client-side transport to expose a bunch of properties 1.64 + * into {@link ResponseContext}. It simply needs to create a {@link PropertySet} 1.65 + * object with methods for each property it wants to expose, and then add that 1.66 + * {@link PropertySet} to {@link Packet}. This allows property values to be 1.67 + * lazily computed (when actually asked by users), thus improving the performance 1.68 + * of the typical case where property values are not asked. 1.69 + * 1.70 + * <p> 1.71 + * A similar benefit applies on the server-side, for a transport to expose 1.72 + * a bunch of properties to {@link WebServiceContext}. 1.73 + * 1.74 + * <p> 1.75 + * To achieve these benefits, access to {@link DistributedPropertySet} is slower 1.76 + * compared to {@link PropertySet} (such as get/set), while adding a satellite 1.77 + * object is relatively fast. 1.78 + * 1.79 + * @author Kohsuke Kawaguchi 1.80 + */ 1.81 +public abstract class DistributedPropertySet 1.82 + extends PropertySet 1.83 + implements com.sun.xml.internal.org.jvnet.ws.message.DistributedPropertySet 1.84 +{ 1.85 + /** 1.86 + * All {@link PropertySet}s that are bundled into this {@link PropertySet}. 1.87 + */ 1.88 + private final Map<Class, PropertySet> satellites = new IdentityHashMap<Class, PropertySet>(); 1.89 + 1.90 + public void addSatellite(@NotNull PropertySet satellite) { 1.91 + addSatellite(satellite.getClass(), satellite); 1.92 + } 1.93 + 1.94 + public void addSatellite(@NotNull Class keyClass, @NotNull PropertySet satellite) { 1.95 + satellites.put(keyClass, satellite); 1.96 + } 1.97 + 1.98 + public void copySatelliteInto(@NotNull DistributedPropertySet r) { 1.99 + r.satellites.putAll(this.satellites); 1.100 + } 1.101 + 1.102 + public @Nullable <T extends com.sun.xml.internal.org.jvnet.ws.message.PropertySet> T getSatellite(Class<T> satelliteClass) { 1.103 + T satellite = (T) satellites.get(satelliteClass); 1.104 + if (satellite != null) 1.105 + return satellite; 1.106 + 1.107 + for (PropertySet child : satellites.values()) { 1.108 + if (satelliteClass.isInstance(child)) { 1.109 + return satelliteClass.cast(child); 1.110 + } 1.111 + 1.112 + if (DistributedPropertySet.class.isInstance(child)) { 1.113 + satellite = DistributedPropertySet.class.cast(child).getSatellite(satelliteClass); 1.114 + if (satellite != null) { 1.115 + return satellite; 1.116 + } 1.117 + } 1.118 + } 1.119 + return null; 1.120 + } 1.121 + 1.122 + @Override 1.123 + public Object get(Object key) { 1.124 + // check satellites 1.125 + for (PropertySet child : satellites.values()) { 1.126 + if(child.supports(key)) 1.127 + return child.get(key); 1.128 + } 1.129 + 1.130 + // otherwise it must be the master 1.131 + return super.get(key); 1.132 + } 1.133 + 1.134 + @Override 1.135 + public Object put(String key, Object value) { 1.136 + // check satellites 1.137 + for (PropertySet child : satellites.values()) { 1.138 + if(child.supports(key)) 1.139 + return child.put(key,value); 1.140 + } 1.141 + 1.142 + // otherwise it must be the master 1.143 + return super.put(key,value); 1.144 + } 1.145 + 1.146 + @Override 1.147 + public boolean supports(Object key) { 1.148 + // check satellites 1.149 + for (PropertySet child : satellites.values()) { 1.150 + if(child.supports(key)) 1.151 + return true; 1.152 + } 1.153 + 1.154 + return super.supports(key); 1.155 + } 1.156 + 1.157 + @Override 1.158 + public Object remove(Object key) { 1.159 + // check satellites 1.160 + for (PropertySet child : satellites.values()) { 1.161 + if(child.supports(key)) 1.162 + return child.remove(key); 1.163 + } 1.164 + 1.165 + return super.remove(key); 1.166 + } 1.167 + 1.168 + @Override 1.169 + /*package*/ void createEntrySet(Set<Entry<String, Object>> core) { 1.170 + super.createEntrySet(core); 1.171 + for (PropertySet child : satellites.values()) { 1.172 + child.createEntrySet(core); 1.173 + } 1.174 + } 1.175 + 1.176 + public void addSatellite(com.sun.xml.internal.org.jvnet.ws.message.PropertySet satellite) { 1.177 + addSatellite((PropertySet)satellite); 1.178 + } 1.179 + 1.180 + public void addSatellite(@NotNull Class keyClass, @NotNull com.sun.xml.internal.org.jvnet.ws.message.PropertySet satellite) { 1.181 + addSatellite(keyClass, (PropertySet)satellite); 1.182 + } 1.183 + 1.184 + public void removeSatellite(com.sun.xml.internal.org.jvnet.ws.message.PropertySet satellite) { 1.185 + removeSatellite((PropertySet)satellite); 1.186 + } 1.187 + 1.188 + public void copySatelliteInto(com.sun.xml.internal.org.jvnet.ws.message.MessageContext r) { 1.189 + copySatelliteInto((DistributedPropertySet)r); 1.190 + } 1.191 +}