Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.xml.internal.ws.handler;
28 import com.sun.xml.internal.ws.api.message.Attachment;
29 import com.sun.xml.internal.ws.api.message.AttachmentSet;
30 import com.sun.xml.internal.ws.api.message.Packet;
32 import javax.activation.DataHandler;
33 import javax.xml.ws.handler.MessageContext;
34 import java.util.Collection;
35 import java.util.HashMap;
36 import java.util.Map;
37 import java.util.Set;
40 /**
41 *
42 * @author WS Development Team
43 */
45 class MessageContextImpl implements MessageContext {
46 private final Set<String> handlerScopeProps;
47 private final Packet packet;
48 private final Map<String, Object> asMapIncludingInvocationProperties;
50 /** Creates a new instance of MessageContextImpl */
51 public MessageContextImpl(Packet packet) {
52 this.packet = packet;
53 this.asMapIncludingInvocationProperties = packet.asMapIncludingInvocationProperties();
54 this.handlerScopeProps = packet.getHandlerScopePropertyNames(false);
55 }
57 protected void updatePacket() {
58 throw new UnsupportedOperationException("wrong call");
59 }
61 public void setScope(String name, Scope scope) {
62 if(!containsKey(name))
63 throw new IllegalArgumentException("Property " + name + " does not exist.");
64 if(scope == Scope.APPLICATION) {
65 handlerScopeProps.remove(name);
66 } else {
67 handlerScopeProps.add(name);
69 }
70 }
72 public Scope getScope(String name) {
73 if(!containsKey(name))
74 throw new IllegalArgumentException("Property " + name + " does not exist.");
75 if(handlerScopeProps.contains(name)) {
76 return Scope.HANDLER;
77 } else {
78 return Scope.APPLICATION;
79 }
80 }
82 public int size() {
83 return asMapIncludingInvocationProperties.size();
84 }
86 public boolean isEmpty() {
87 return asMapIncludingInvocationProperties.isEmpty();
88 }
90 public boolean containsKey(Object key) {
91 return asMapIncludingInvocationProperties.containsKey(key);
92 }
94 public boolean containsValue(Object value) {
95 return asMapIncludingInvocationProperties.containsValue(value);
96 }
98 public Object put(String key, Object value) {
99 if (!asMapIncludingInvocationProperties.containsKey(key)) {
100 //new property, default to Scope.HANDLER
101 handlerScopeProps.add(key);
102 }
103 return asMapIncludingInvocationProperties.put(key, value);
104 }
105 public Object get(Object key) {
106 if(key == null)
107 return null;
108 Object value = asMapIncludingInvocationProperties.get(key);
109 //add the attachments from the Message to the corresponding attachment property
110 if(key.equals(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS) ||
111 key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){
112 Map<String, DataHandler> atts = (Map<String, DataHandler>) value;
113 if(atts == null)
114 atts = new HashMap<String, DataHandler>();
115 AttachmentSet attSet = packet.getMessage().getAttachments();
116 for(Attachment att : attSet){
117 String cid = att.getContentId();
118 if (cid.indexOf("@jaxws.sun.com") == -1) {
119 Object a = atts.get(cid);
120 if (a == null) {
121 a = atts.get("<" + cid + ">");
122 if (a == null) atts.put(att.getContentId(), att.asDataHandler());
123 }
124 } else {
125 atts.put(att.getContentId(), att.asDataHandler());
126 }
127 }
128 return atts;
129 }
130 return value;
131 }
133 public void putAll(Map<? extends String, ? extends Object> t) {
134 for(String key: t.keySet()) {
135 if(!asMapIncludingInvocationProperties.containsKey(key)) {
136 //new property, default to Scope.HANDLER
137 handlerScopeProps.add(key);
138 }
139 }
140 asMapIncludingInvocationProperties.putAll(t);
141 }
143 public void clear() {
144 asMapIncludingInvocationProperties.clear();
145 }
146 public Object remove(Object key){
147 handlerScopeProps.remove(key);
148 return asMapIncludingInvocationProperties.remove(key);
149 }
150 public Set<String> keySet() {
151 return asMapIncludingInvocationProperties.keySet();
152 }
153 public Set<Map.Entry<String, Object>> entrySet(){
154 return asMapIncludingInvocationProperties.entrySet();
155 }
156 public Collection<Object> values() {
157 return asMapIncludingInvocationProperties.values();
158 }
159 }