001: /*
002: * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.soap.jaxws;
031:
032: import java.util.AbstractMap;
033: import java.util.HashMap;
034: import java.util.List;
035: import java.util.Map;
036: import java.util.Set;
037:
038: import java.util.logging.Logger;
039: import java.util.logging.Level;
040:
041: import javax.xml.bind.JAXBContext;
042:
043: import javax.xml.namespace.QName;
044: import javax.xml.soap.SOAPMessage;
045:
046: import javax.xml.ws.*;
047: import javax.xml.ws.handler.*;
048:
049: import com.caucho.util.L10N;
050:
051: public abstract class AbstractMessageContextImpl extends
052: HashMap<String, Object> implements MessageContext {
053: private final Map<String, Scope> _scopes = new HashMap<String, Scope>();
054:
055: protected AbstractMessageContextImpl() {
056: }
057:
058: public Scope getScope(String name) {
059: Scope scope = _scopes.get(name);
060:
061: if (scope == null)
062: throw new IllegalArgumentException();
063:
064: return scope;
065: }
066:
067: public void setScope(String name, Scope scope) {
068: if (!containsKey(name))
069: throw new IllegalArgumentException();
070:
071: _scopes.put(name, scope);
072: }
073:
074: public void clear() {
075: super .clear();
076: _scopes.clear();
077: }
078:
079: public Object put(String key, Object value) {
080: Object previous = super .put(key, value);
081:
082: if (previous == null)
083: _scopes.put(key, Scope.HANDLER);
084:
085: return previous;
086: }
087:
088: public void putAll(Map<? extends String, ? extends Object> m) {
089: if (m instanceof MessageContext) {
090: MessageContext context = (MessageContext) m;
091:
092: for (Map.Entry<? extends String, ? extends Object> entry : m
093: .entrySet()) {
094: super .put(entry.getKey(), entry.getValue());
095: setScope(entry.getKey(), context.getScope(entry
096: .getKey()));
097: }
098: } else {
099: for (Map.Entry<? extends String, ? extends Object> entry : m
100: .entrySet())
101: put(entry.getKey(), entry.getValue());
102: }
103: }
104:
105: public void putAll(Map<? extends String, ? extends Object> m,
106: Scope scope) {
107: for (Map.Entry<? extends String, ? extends Object> entry : m
108: .entrySet()) {
109: super .put(entry.getKey(), entry.getValue());
110: setScope(entry.getKey(), scope);
111: }
112: }
113:
114: public Map<String, Object> getScopedSubMap(Scope scope) {
115: Map<String, Object> map = new HashMap<String, Object>();
116:
117: for (Map.Entry<? extends String, ? extends Object> entry : entrySet()) {
118: if (scope.equals(getScope(entry.getKey())))
119: map.put(entry.getKey(), entry.getValue());
120: }
121:
122: return map;
123: }
124:
125: public Object remove(Object key) {
126: Object previous = super.remove(key);
127:
128: if (previous != null)
129: _scopes.remove(key);
130:
131: return previous;
132: }
133: }
|