001: package org.objectweb.celtix.context;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.HashSet;
006: import java.util.Iterator;
007: import java.util.Map;
008: import java.util.Set;
009:
010: import javax.xml.ws.handler.MessageContext;
011: import javax.xml.ws.handler.MessageContext.Scope;
012:
013: public class ProviderMessageContext implements Map<String, Object> {
014:
015: private static final long serialVersionUID = 1L;
016: private final MessageContext context;
017:
018: public ProviderMessageContext(MessageContext ctx) {
019: context = ctx;
020: }
021:
022: public void clear() {
023: Iterator<String> it = context.keySet().iterator();
024: while (it.hasNext()) {
025: String k = it.next();
026: if (context.getScope(k) == Scope.APPLICATION) {
027: context.remove(k);
028: }
029: }
030: }
031:
032: public boolean containsKey(Object key) {
033: return context.containsKey(key)
034: && context.getScope((String) key) == Scope.APPLICATION;
035: }
036:
037: public boolean containsValue(Object value) {
038: if (!context.containsValue(value)) {
039: return false;
040: }
041: Iterator<String> it = context.keySet().iterator();
042: while (it.hasNext()) {
043: String k = it.next();
044: if (context.get(k) == value
045: && context.getScope(k) == Scope.APPLICATION) {
046: return true;
047: }
048: }
049: return false;
050: }
051:
052: public Set<Entry<String, Object>> entrySet() {
053: // TODO Auto-generated method stub
054: return null;
055: }
056:
057: public Object get(Object key) {
058: Object o = context.get(key);
059: if (context.getScope((String) key) == Scope.HANDLER) {
060: return null;
061: }
062: return o;
063: }
064:
065: public boolean isEmpty() {
066: return size() == 0;
067: }
068:
069: public Set<String> keySet() {
070: Set<String> allKeys = context.keySet();
071: Set<String> keys = new HashSet<String>();
072: Iterator<String> it = allKeys.iterator();
073: while (it.hasNext()) {
074: String k = it.next();
075: if (context.getScope(k) == Scope.APPLICATION) {
076: keys.add(k);
077: }
078: }
079: return keys;
080: }
081:
082: public Object put(String key, Object value) {
083: if (context.containsKey(key)
084: && context.getScope(key) == Scope.HANDLER) {
085: throw new IllegalArgumentException(
086: "Attempt to set property with scope HANDLER in provider context.");
087: }
088: Object o = context.put(key, value);
089: context.setScope(key, Scope.APPLICATION);
090: return o;
091: }
092:
093: public void putAll(Map<? extends String, ? extends Object> t) {
094: Iterator<? extends String> it = t.keySet().iterator();
095: while (it.hasNext()) {
096: String k = it.next();
097: put(k, t.get(k));
098: }
099: }
100:
101: public Object remove(Object key) {
102: if (context.containsKey(key)
103: && context.getScope((String) key) == Scope.HANDLER) {
104: throw new IllegalArgumentException(
105: "Attempt to remove property with scope HANDLER from provider context.");
106: }
107: return context.remove(key);
108: }
109:
110: public int size() {
111: return values().size();
112: }
113:
114: public Collection<Object> values() {
115: Collection<Object> values = new ArrayList<Object>();
116: Iterator<? extends String> it = context.keySet().iterator();
117: while (it.hasNext()) {
118: String k = it.next();
119: if (context.getScope(k) == Scope.APPLICATION) {
120: values.add(context.get(k));
121: }
122: }
123: return values;
124: }
125: }
|