src/share/jaxws_classes/com/sun/xml/internal/ws/handler/MessageContextImpl.java

Fri, 14 Feb 2014 11:13:45 +0100

author
mkos
date
Fri, 14 Feb 2014 11:13:45 +0100
changeset 515
6cd506508147
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8026188: Enhance envelope factory
Summary: Avoiding caching data initialized via TCCL in static context; fix also reviewed by Alexander Fomin
Reviewed-by: ahgross, mgrebac, skoivu

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2013, 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.handler;
ohair@286 27
ohair@286 28 import com.sun.xml.internal.ws.api.message.Attachment;
ohair@286 29 import com.sun.xml.internal.ws.api.message.AttachmentSet;
ohair@286 30 import com.sun.xml.internal.ws.api.message.Packet;
ohair@286 31
ohair@286 32 import javax.activation.DataHandler;
ohair@286 33 import javax.xml.ws.handler.MessageContext;
ohair@286 34 import java.util.Collection;
ohair@286 35 import java.util.HashMap;
ohair@286 36 import java.util.Map;
ohair@286 37 import java.util.Set;
ohair@286 38
alanb@368 39
ohair@286 40 /**
ohair@286 41 *
ohair@286 42 * @author WS Development Team
ohair@286 43 */
ohair@286 44
ohair@286 45 class MessageContextImpl implements MessageContext {
alanb@368 46 private final Set<String> handlerScopeProps;
alanb@368 47 private final Packet packet;
alanb@368 48 private final Map<String, Object> asMapIncludingInvocationProperties;
ohair@286 49
ohair@286 50 /** Creates a new instance of MessageContextImpl */
ohair@286 51 public MessageContextImpl(Packet packet) {
ohair@286 52 this.packet = packet;
alanb@368 53 this.asMapIncludingInvocationProperties = packet.asMapIncludingInvocationProperties();
alanb@368 54 this.handlerScopeProps = packet.getHandlerScopePropertyNames(false);
ohair@286 55 }
alanb@368 56
ohair@286 57 protected void updatePacket() {
ohair@286 58 throw new UnsupportedOperationException("wrong call");
ohair@286 59 }
ohair@286 60
ohair@286 61 public void setScope(String name, Scope scope) {
ohair@286 62 if(!containsKey(name))
ohair@286 63 throw new IllegalArgumentException("Property " + name + " does not exist.");
ohair@286 64 if(scope == Scope.APPLICATION) {
ohair@286 65 handlerScopeProps.remove(name);
ohair@286 66 } else {
ohair@286 67 handlerScopeProps.add(name);
ohair@286 68
ohair@286 69 }
ohair@286 70 }
ohair@286 71
ohair@286 72 public Scope getScope(String name) {
ohair@286 73 if(!containsKey(name))
ohair@286 74 throw new IllegalArgumentException("Property " + name + " does not exist.");
ohair@286 75 if(handlerScopeProps.contains(name)) {
ohair@286 76 return Scope.HANDLER;
ohair@286 77 } else {
ohair@286 78 return Scope.APPLICATION;
ohair@286 79 }
ohair@286 80 }
ohair@286 81
ohair@286 82 public int size() {
alanb@368 83 return asMapIncludingInvocationProperties.size();
ohair@286 84 }
ohair@286 85
ohair@286 86 public boolean isEmpty() {
alanb@368 87 return asMapIncludingInvocationProperties.isEmpty();
ohair@286 88 }
ohair@286 89
ohair@286 90 public boolean containsKey(Object key) {
alanb@368 91 return asMapIncludingInvocationProperties.containsKey(key);
ohair@286 92 }
ohair@286 93
ohair@286 94 public boolean containsValue(Object value) {
alanb@368 95 return asMapIncludingInvocationProperties.containsValue(value);
ohair@286 96 }
ohair@286 97
ohair@286 98 public Object put(String key, Object value) {
alanb@368 99 if (!asMapIncludingInvocationProperties.containsKey(key)) {
alanb@368 100 //new property, default to Scope.HANDLER
alanb@368 101 handlerScopeProps.add(key);
ohair@286 102 }
alanb@368 103 return asMapIncludingInvocationProperties.put(key, value);
ohair@286 104 }
ohair@286 105 public Object get(Object key) {
ohair@286 106 if(key == null)
ohair@286 107 return null;
alanb@368 108 Object value = asMapIncludingInvocationProperties.get(key);
ohair@286 109 //add the attachments from the Message to the corresponding attachment property
ohair@286 110 if(key.equals(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS) ||
ohair@286 111 key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){
ohair@286 112 Map<String, DataHandler> atts = (Map<String, DataHandler>) value;
ohair@286 113 if(atts == null)
ohair@286 114 atts = new HashMap<String, DataHandler>();
ohair@286 115 AttachmentSet attSet = packet.getMessage().getAttachments();
ohair@286 116 for(Attachment att : attSet){
alanb@368 117 String cid = att.getContentId();
alanb@368 118 if (cid.indexOf("@jaxws.sun.com") == -1) {
alanb@368 119 Object a = atts.get(cid);
alanb@368 120 if (a == null) {
alanb@368 121 a = atts.get("<" + cid + ">");
alanb@368 122 if (a == null) atts.put(att.getContentId(), att.asDataHandler());
alanb@368 123 }
alanb@368 124 } else {
alanb@368 125 atts.put(att.getContentId(), att.asDataHandler());
alanb@368 126 }
ohair@286 127 }
ohair@286 128 return atts;
ohair@286 129 }
ohair@286 130 return value;
ohair@286 131 }
ohair@286 132
ohair@286 133 public void putAll(Map<? extends String, ? extends Object> t) {
ohair@286 134 for(String key: t.keySet()) {
alanb@368 135 if(!asMapIncludingInvocationProperties.containsKey(key)) {
ohair@286 136 //new property, default to Scope.HANDLER
ohair@286 137 handlerScopeProps.add(key);
ohair@286 138 }
ohair@286 139 }
alanb@368 140 asMapIncludingInvocationProperties.putAll(t);
ohair@286 141 }
ohair@286 142
ohair@286 143 public void clear() {
alanb@368 144 asMapIncludingInvocationProperties.clear();
ohair@286 145 }
ohair@286 146 public Object remove(Object key){
ohair@286 147 handlerScopeProps.remove(key);
alanb@368 148 return asMapIncludingInvocationProperties.remove(key);
ohair@286 149 }
ohair@286 150 public Set<String> keySet() {
alanb@368 151 return asMapIncludingInvocationProperties.keySet();
ohair@286 152 }
ohair@286 153 public Set<Map.Entry<String, Object>> entrySet(){
alanb@368 154 return asMapIncludingInvocationProperties.entrySet();
ohair@286 155 }
ohair@286 156 public Collection<Object> values() {
alanb@368 157 return asMapIncludingInvocationProperties.values();
ohair@286 158 }
ohair@286 159 }

mercurial