KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bindings > AbstractBindingImpl


1 package org.objectweb.celtix.bindings;
2
3 import java.io.IOException JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7
8 import javax.xml.ws.Binding;
9 import javax.xml.ws.handler.Handler;
10 import javax.xml.ws.handler.LogicalHandler;
11 import javax.xml.ws.handler.MessageContext;
12
13 import org.objectweb.celtix.bus.jaxws.configuration.types.SystemHandlerChainType;
14 import org.objectweb.celtix.common.injection.ResourceInjector;
15 import org.objectweb.celtix.configuration.Configuration;
16 import org.objectweb.celtix.context.InputStreamMessageContext;
17 import org.objectweb.celtix.context.ObjectMessageContext;
18 import org.objectweb.celtix.context.OutputStreamMessageContext;
19 import org.objectweb.celtix.handlers.HandlerChainBuilder;
20 import org.objectweb.celtix.handlers.HandlerInvoker;
21 import org.objectweb.celtix.handlers.StreamHandler;
22
23 public abstract class AbstractBindingImpl implements Binding {
24
25     private static final String JavaDoc SYSTEM_HANDLER_CHAIN_PROPERTY_NAME = "systemHandlerChain";
26     protected List JavaDoc<Handler> handlerChain;
27     protected List JavaDoc<Handler> preLogicalSystemHandlers;
28     protected List JavaDoc<Handler> postLogicalSystemHandlers;
29     protected List JavaDoc<Handler> preProtocolSystemHandlers;
30     protected List JavaDoc<Handler> postProtocolSystemHandlers;
31     
32     
33     /* (non-Javadoc)
34      * @see javax.xml.ws.Binding#getHandlerChain()
35      */

36     public List JavaDoc<Handler> getHandlerChain() {
37         // TODO Auto-generated method stub
38
return handlerChain;
39     }
40     
41     /**
42      * Returns the list of configured JAX-WS and system handlers - used by the
43      * abstract client and server binding implementations in processing outgoing and
44      * incoming messages.
45      *
46      * @param includeSystemHandlers
47      * @return
48      */

49     public List JavaDoc<Handler> getHandlerChain(boolean includeSystemHandlers) {
50         if (!includeSystemHandlers) {
51             return getHandlerChain();
52         }
53         List JavaDoc<Handler> allHandlers = new ArrayList JavaDoc<Handler>();
54         if (null != preLogicalSystemHandlers) {
55             allHandlers.addAll(preLogicalSystemHandlers);
56         }
57         // jaxws handlers are sorted by logical and system handlers
58
List JavaDoc<Handler> userHandlers = handlerChain;
59         if (null == userHandlers) {
60             userHandlers = new ArrayList JavaDoc<Handler>();
61         }
62         Iterator JavaDoc<Handler> it = userHandlers.iterator();
63         while (it.hasNext()) {
64             Handler h = it.next();
65             if (h instanceof LogicalHandler) {
66                 allHandlers.add(h);
67             }
68         }
69         if (null != postLogicalSystemHandlers) {
70             allHandlers.addAll(postLogicalSystemHandlers);
71         }
72         if (null != preProtocolSystemHandlers) {
73             allHandlers.addAll(preProtocolSystemHandlers);
74         }
75         it = userHandlers.iterator();
76         while (it.hasNext()) {
77             Handler h = it.next();
78             if (!(h instanceof StreamHandler || h instanceof LogicalHandler)) {
79                 allHandlers.add(h);
80             }
81         }
82         if (null != postProtocolSystemHandlers) {
83             allHandlers.addAll(postProtocolSystemHandlers);
84         }
85         it = userHandlers.iterator();
86         while (it.hasNext()) {
87             Handler h = it.next();
88             if (h instanceof StreamHandler) {
89                 allHandlers.add(h);
90             }
91         }
92         return allHandlers;
93     }
94
95
96     /* (non-Javadoc)
97      * @see javax.xml.ws.Binding#setHandlerChain(java.util.List)
98      */

99     public void setHandlerChain(List JavaDoc<Handler> chain) {
100         assert chain != null;
101         handlerChain = chain;
102     }
103     
104     
105     
106     /**
107      * Configure the system handlers specified in configuration
108      *
109      */

110     public void configureSystemHandlers(Configuration c) {
111         HandlerChainBuilder builder = new HandlerChainBuilder();
112         SystemHandlerChainType sh =
113             (SystemHandlerChainType)c.getObject(SYSTEM_HANDLER_CHAIN_PROPERTY_NAME);
114         if (null != sh) {
115             preLogicalSystemHandlers = builder.buildHandlerChainFromConfiguration(sh.getPreLogical());
116             postLogicalSystemHandlers = builder.buildHandlerChainFromConfiguration(sh.getPostLogical());
117             preProtocolSystemHandlers = builder.buildHandlerChainFromConfiguration(sh.getPreProtocol());
118             postProtocolSystemHandlers = builder.buildHandlerChainFromConfiguration(sh.getPostProtocol());
119         }
120     }
121     
122     /**
123      * Returns the list of logical system handlers that should be executed
124      * before any user supplied logical handlers. The returned list is NOT a
125      * copy and thus can be modified directly.
126      *
127      * @return the list of logical system handlers.
128      */

129     public List JavaDoc<Handler> getPreLogicalSystemHandlers() {
130         if (null == preLogicalSystemHandlers) {
131             preLogicalSystemHandlers = new ArrayList JavaDoc<Handler>();
132         }
133         return preLogicalSystemHandlers;
134     }
135     
136     /**
137      * Returns the list of logical system handlers that should be
138      * executed after any user supplied logical handlers.
139      * The returned list is NOT a copy and thus can be modified directly.
140      * @return the list of logical system handlers.
141      */

142     public List JavaDoc<Handler> getPostLogicalSystemHandlers() {
143         if (null == postLogicalSystemHandlers) {
144             postLogicalSystemHandlers = new ArrayList JavaDoc<Handler>();
145         }
146         return postLogicalSystemHandlers;
147     }
148     
149     /**
150      * Returns the list of protocol system handlers that should be
151      * executed before any user supplied protocol handlers.
152      * @return the list of protocol system handlers.
153      */

154     public List JavaDoc<Handler> getPreProtocolSystemHandlers() {
155         if (null == preProtocolSystemHandlers) {
156             preProtocolSystemHandlers = new ArrayList JavaDoc<Handler>();
157         }
158         return preProtocolSystemHandlers;
159     }
160     
161     /**
162      * Returns the list of protocl system handlers that should be
163      * executed after any user supplied protocl handlers.
164      * @return the list of protocol system handlers.
165      */

166     public List JavaDoc<Handler> getPostProtocolSystemHandlers() {
167         if (null == postProtocolSystemHandlers) {
168             postProtocolSystemHandlers = new ArrayList JavaDoc<Handler>();
169         }
170         return postProtocolSystemHandlers;
171     }
172     
173     public void injectSystemHandlers(ResourceInjector injector) {
174         if (null != preLogicalSystemHandlers) {
175             for (Handler h : preLogicalSystemHandlers) {
176                 injector.inject(h);
177             }
178         }
179         if (null != postLogicalSystemHandlers) {
180             for (Handler h : postLogicalSystemHandlers) {
181                 injector.inject(h);
182             }
183         }
184         
185         if (null != preProtocolSystemHandlers) {
186             for (Handler h : preProtocolSystemHandlers) {
187                 injector.inject(h);
188             }
189         }
190         
191         if (null != postProtocolSystemHandlers) {
192             for (Handler h : postProtocolSystemHandlers) {
193                 injector.inject(h);
194             }
195         }
196     }
197     
198     public abstract MessageContext createBindingMessageContext(MessageContext orig);
199     
200     public abstract HandlerInvoker createHandlerInvoker();
201     
202     public abstract void marshal(ObjectMessageContext objContext,
203                                     MessageContext msgContext,
204                                     DataBindingCallback callback);
205     
206     public abstract void marshalFault(ObjectMessageContext objContext,
207                                     MessageContext msgContext,
208                                     DataBindingCallback callback);
209     
210     public abstract void unmarshal(MessageContext msgContext,
211                                       ObjectMessageContext objContext,
212                                       DataBindingCallback callback);
213     
214     public abstract void unmarshalFault(MessageContext msgContext,
215                                            ObjectMessageContext objContext,
216                                            DataBindingCallback callback);
217     
218     public abstract void write(MessageContext msgContext, OutputStreamMessageContext outContext)
219         throws IOException JavaDoc;
220     
221     public abstract void read(InputStreamMessageContext inContext, MessageContext msgContext)
222         throws IOException JavaDoc;
223     
224     public abstract boolean hasFault(MessageContext msgContext);
225     
226     public abstract void updateMessageContext(MessageContext msgContext);
227     
228 }
229
Popular Tags