1 package org.objectweb.celtix.context; 2 3 import java.util.ArrayList ; 4 import java.util.Collection ; 5 import java.util.HashSet ; 6 import java.util.Iterator ; 7 import java.util.Map ; 8 import java.util.Set ; 9 10 import javax.xml.ws.handler.MessageContext; 11 import javax.xml.ws.handler.MessageContext.Scope; 12 13 public class ProviderMessageContext implements Map <String , Object > { 14 15 private static final long serialVersionUID = 1L; 16 private final MessageContext context; 17 18 public ProviderMessageContext(MessageContext ctx) { 19 context = ctx; 20 } 21 22 public void clear() { 23 Iterator <String > it = context.keySet().iterator(); 24 while (it.hasNext()) { 25 String k = it.next(); 26 if (context.getScope(k) == Scope.APPLICATION) { 27 context.remove(k); 28 } 29 } 30 } 31 32 public boolean containsKey(Object key) { 33 return context.containsKey(key) && context.getScope((String )key) == Scope.APPLICATION; 34 } 35 36 public boolean containsValue(Object value) { 37 if (!context.containsValue(value)) { 38 return false; 39 } 40 Iterator <String > it = context.keySet().iterator(); 41 while (it.hasNext()) { 42 String k = it.next(); 43 if (context.get(k) == value && context.getScope(k) == Scope.APPLICATION) { 44 return true; 45 } 46 } 47 return false; 48 } 49 50 public Set <Entry<String , Object >> entrySet() { 51 return null; 53 } 54 55 public Object get(Object key) { 56 Object o = context.get(key); 57 if (context.getScope((String )key) == Scope.HANDLER) { 58 return null; 59 } 60 return o; 61 } 62 63 public boolean isEmpty() { 64 return size() == 0; 65 } 66 67 public Set <String > keySet() { 68 Set <String > allKeys = context.keySet(); 69 Set <String > keys = new HashSet <String >(); 70 Iterator <String > it = allKeys.iterator(); 71 while (it.hasNext()) { 72 String k = it.next(); 73 if (context.getScope(k) == Scope.APPLICATION) { 74 keys.add(k); 75 } 76 } 77 return keys; 78 } 79 80 public Object put(String key, Object value) { 81 if (context.containsKey(key) && context.getScope(key) == Scope.HANDLER) { 82 throw new IllegalArgumentException ( 83 "Attempt to set property with scope HANDLER in provider context."); 84 } 85 Object o = context.put(key, value); 86 context.setScope(key, Scope.APPLICATION); 87 return o; 88 } 89 90 public void putAll(Map <? extends String , ? extends Object > t) { 91 Iterator <? extends String > it = t.keySet().iterator(); 92 while (it.hasNext()) { 93 String k = it.next(); 94 put(k, t.get(k)); 95 } 96 } 97 98 public Object remove(Object key) { 99 if (context.containsKey(key) && context.getScope((String )key) == Scope.HANDLER) { 100 throw new IllegalArgumentException ( 101 "Attempt to remove property with scope HANDLER from provider context."); 102 } 103 return context.remove(key); 104 } 105 106 public int size() { 107 return values().size(); 108 } 109 110 public Collection <Object > values() { 111 Collection <Object > values = new ArrayList <Object >(); 112 Iterator <? extends String > it = context.keySet().iterator(); 113 while (it.hasNext()) { 114 String k = it.next(); 115 if (context.getScope(k) == Scope.APPLICATION) { 116 values.add(context.get(k)); 117 } 118 } 119 return values; 120 } 121 } 122 | Popular Tags |