KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > context > ProviderMessageContext


1 package org.objectweb.celtix.context;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5 import java.util.HashSet JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.Map JavaDoc;
8 import java.util.Set JavaDoc;
9
10 import javax.xml.ws.handler.MessageContext;
11 import javax.xml.ws.handler.MessageContext.Scope;
12
13 public class ProviderMessageContext implements Map JavaDoc<String JavaDoc, Object JavaDoc> {
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 JavaDoc<String JavaDoc> it = context.keySet().iterator();
24         while (it.hasNext()) {
25             String JavaDoc k = it.next();
26             if (context.getScope(k) == Scope.APPLICATION) {
27                 context.remove(k);
28             }
29         }
30     }
31
32     public boolean containsKey(Object JavaDoc key) {
33         return context.containsKey(key) && context.getScope((String JavaDoc)key) == Scope.APPLICATION;
34     }
35
36     public boolean containsValue(Object JavaDoc value) {
37         if (!context.containsValue(value)) {
38             return false;
39         }
40         Iterator JavaDoc<String JavaDoc> it = context.keySet().iterator();
41         while (it.hasNext()) {
42             String JavaDoc 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 JavaDoc<Entry<String JavaDoc, Object JavaDoc>> entrySet() {
51         // TODO Auto-generated method stub
52
return null;
53     }
54
55     public Object JavaDoc get(Object JavaDoc key) {
56         Object JavaDoc o = context.get(key);
57         if (context.getScope((String JavaDoc)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 JavaDoc<String JavaDoc> keySet() {
68         Set JavaDoc<String JavaDoc> allKeys = context.keySet();
69         Set JavaDoc<String JavaDoc> keys = new HashSet JavaDoc<String JavaDoc>();
70         Iterator JavaDoc<String JavaDoc> it = allKeys.iterator();
71         while (it.hasNext()) {
72             String JavaDoc k = it.next();
73             if (context.getScope(k) == Scope.APPLICATION) {
74                 keys.add(k);
75             }
76         }
77         return keys;
78     }
79
80     public Object JavaDoc put(String JavaDoc key, Object JavaDoc value) {
81         if (context.containsKey(key) && context.getScope(key) == Scope.HANDLER) {
82             throw new IllegalArgumentException JavaDoc(
83                 "Attempt to set property with scope HANDLER in provider context.");
84         }
85         Object JavaDoc o = context.put(key, value);
86         context.setScope(key, Scope.APPLICATION);
87         return o;
88     }
89
90     public void putAll(Map JavaDoc<? extends String JavaDoc, ? extends Object JavaDoc> t) {
91         Iterator JavaDoc<? extends String JavaDoc> it = t.keySet().iterator();
92         while (it.hasNext()) {
93             String JavaDoc k = it.next();
94             put(k, t.get(k));
95         }
96     }
97
98     public Object JavaDoc remove(Object JavaDoc key) {
99         if (context.containsKey(key) && context.getScope((String JavaDoc)key) == Scope.HANDLER) {
100             throw new IllegalArgumentException JavaDoc(
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 JavaDoc<Object JavaDoc> values() {
111         Collection JavaDoc<Object JavaDoc> values = new ArrayList JavaDoc<Object JavaDoc>();
112         Iterator JavaDoc<? extends String JavaDoc> it = context.keySet().iterator();
113         while (it.hasNext()) {
114             String JavaDoc 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