001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.api;
038:
039: import com.sun.istack.FinalArrayList;
040: import com.sun.istack.NotNull;
041: import com.sun.xml.ws.api.message.Packet;
042: import com.sun.xml.ws.client.RequestContext;
043: import com.sun.xml.ws.client.ResponseContext;
044:
045: import javax.xml.ws.WebServiceContext;
046: import java.util.Map.Entry;
047: import java.util.Set;
048:
049: /**
050: * {@link PropertySet} that combines properties exposed from multiple
051: * {@link PropertySet}s into one.
052: *
053: * <p>
054: * This implementation allows one {@link PropertySet} to assemble
055: * all properties exposed from other "satellite" {@link PropertySet}s.
056: * (A satellite may itself be a {@link DistributedPropertySet}, so
057: * in general this can form a tree.)
058: *
059: * <p>
060: * This is useful for JAX-WS because the properties we expose to the application
061: * are contributed by different pieces, and therefore we'd like each of them
062: * to have a separate {@link PropertySet} implementation that backs up
063: * the properties. For example, this allows FastInfoset to expose its
064: * set of properties to {@link RequestContext} by using a strongly-typed fields.
065: *
066: * <p>
067: * This is also useful for a client-side transport to expose a bunch of properties
068: * into {@link ResponseContext}. It simply needs to create a {@link PropertySet}
069: * object with methods for each property it wants to expose, and then add that
070: * {@link PropertySet} to {@link Packet}. This allows property values to be
071: * lazily computed (when actually asked by users), thus improving the performance
072: * of the typical case where property values are not asked.
073: *
074: * <p>
075: * A similar benefit applies on the server-side, for a transport to expose
076: * a bunch of properties to {@link WebServiceContext}.
077: *
078: * <p>
079: * To achieve these benefits, access to {@link DistributedPropertySet} is slower
080: * compared to {@link PropertySet} (such as get/set), while adding a satellite
081: * object is relatively fast.
082: *
083: * @author Kohsuke Kawaguchi
084: */
085: public abstract class DistributedPropertySet extends PropertySet {
086: /**
087: * All {@link PropertySet}s that are bundled into this {@link PropertySet}.
088: */
089: private final FinalArrayList<PropertySet> satellites = new FinalArrayList<PropertySet>();
090:
091: public void addSatellite(@NotNull
092: PropertySet satellite) {
093: satellites.add(satellite);
094: }
095:
096: public void removeSatellite(@NotNull
097: PropertySet satellite) {
098: satellites.remove(satellite);
099: }
100:
101: public void copySatelliteInto(@NotNull
102: DistributedPropertySet r) {
103: r.satellites.addAll(this .satellites);
104: }
105:
106: @Override
107: public Object get(Object key) {
108: // check satellites
109: for (PropertySet child : satellites) {
110: if (child.supports(key))
111: return child.get(key);
112: }
113:
114: // otherwise it must be the master
115: return super .get(key);
116: }
117:
118: @Override
119: public Object put(String key, Object value) {
120: // check satellites
121: for (PropertySet child : satellites) {
122: if (child.supports(key))
123: return child.put(key, value);
124: }
125:
126: // otherwise it must be the master
127: return super .put(key, value);
128: }
129:
130: @Override
131: public boolean supports(Object key) {
132: // check satellites
133: for (PropertySet child : satellites) {
134: if (child.supports(key))
135: return true;
136: }
137:
138: return super .supports(key);
139: }
140:
141: @Override
142: public Object remove(Object key) {
143: // check satellites
144: for (PropertySet child : satellites) {
145: if (child.supports(key))
146: return child.remove(key);
147: }
148:
149: return super .remove(key);
150: }
151:
152: @Override
153: /*package*/void createEntrySet(Set<Entry<String, Object>> core) {
154: super .createEntrySet(core);
155: for (PropertySet child : satellites) {
156: child.createEntrySet(core);
157: }
158: }
159: }
|