001: package org.objectweb.celtix.bindings;
002:
003: import java.io.IOException;
004: import java.util.ArrayList;
005: import java.util.Iterator;
006: import java.util.List;
007:
008: import javax.xml.ws.Binding;
009: import javax.xml.ws.handler.Handler;
010: import javax.xml.ws.handler.LogicalHandler;
011: import javax.xml.ws.handler.MessageContext;
012:
013: import org.objectweb.celtix.bus.jaxws.configuration.types.SystemHandlerChainType;
014: import org.objectweb.celtix.common.injection.ResourceInjector;
015: import org.objectweb.celtix.configuration.Configuration;
016: import org.objectweb.celtix.context.InputStreamMessageContext;
017: import org.objectweb.celtix.context.ObjectMessageContext;
018: import org.objectweb.celtix.context.OutputStreamMessageContext;
019: import org.objectweb.celtix.handlers.HandlerChainBuilder;
020: import org.objectweb.celtix.handlers.HandlerInvoker;
021: import org.objectweb.celtix.handlers.StreamHandler;
022:
023: public abstract class AbstractBindingImpl implements Binding {
024:
025: private static final String SYSTEM_HANDLER_CHAIN_PROPERTY_NAME = "systemHandlerChain";
026: protected List<Handler> handlerChain;
027: protected List<Handler> preLogicalSystemHandlers;
028: protected List<Handler> postLogicalSystemHandlers;
029: protected List<Handler> preProtocolSystemHandlers;
030: protected List<Handler> postProtocolSystemHandlers;
031:
032: /* (non-Javadoc)
033: * @see javax.xml.ws.Binding#getHandlerChain()
034: */
035: public List<Handler> getHandlerChain() {
036: // TODO Auto-generated method stub
037: return handlerChain;
038: }
039:
040: /**
041: * Returns the list of configured JAX-WS and system handlers - used by the
042: * abstract client and server binding implementations in processing outgoing and
043: * incoming messages.
044: *
045: * @param includeSystemHandlers
046: * @return
047: */
048: public List<Handler> getHandlerChain(boolean includeSystemHandlers) {
049: if (!includeSystemHandlers) {
050: return getHandlerChain();
051: }
052: List<Handler> allHandlers = new ArrayList<Handler>();
053: if (null != preLogicalSystemHandlers) {
054: allHandlers.addAll(preLogicalSystemHandlers);
055: }
056: // jaxws handlers are sorted by logical and system handlers
057: List<Handler> userHandlers = handlerChain;
058: if (null == userHandlers) {
059: userHandlers = new ArrayList<Handler>();
060: }
061: Iterator<Handler> it = userHandlers.iterator();
062: while (it.hasNext()) {
063: Handler h = it.next();
064: if (h instanceof LogicalHandler) {
065: allHandlers.add(h);
066: }
067: }
068: if (null != postLogicalSystemHandlers) {
069: allHandlers.addAll(postLogicalSystemHandlers);
070: }
071: if (null != preProtocolSystemHandlers) {
072: allHandlers.addAll(preProtocolSystemHandlers);
073: }
074: it = userHandlers.iterator();
075: while (it.hasNext()) {
076: Handler h = it.next();
077: if (!(h instanceof StreamHandler || h instanceof LogicalHandler)) {
078: allHandlers.add(h);
079: }
080: }
081: if (null != postProtocolSystemHandlers) {
082: allHandlers.addAll(postProtocolSystemHandlers);
083: }
084: it = userHandlers.iterator();
085: while (it.hasNext()) {
086: Handler h = it.next();
087: if (h instanceof StreamHandler) {
088: allHandlers.add(h);
089: }
090: }
091: return allHandlers;
092: }
093:
094: /* (non-Javadoc)
095: * @see javax.xml.ws.Binding#setHandlerChain(java.util.List)
096: */
097: public void setHandlerChain(List<Handler> chain) {
098: assert chain != null;
099: handlerChain = chain;
100: }
101:
102: /**
103: * Configure the system handlers specified in configuration
104: *
105: */
106: public void configureSystemHandlers(Configuration c) {
107: HandlerChainBuilder builder = new HandlerChainBuilder();
108: SystemHandlerChainType sh = (SystemHandlerChainType) c
109: .getObject(SYSTEM_HANDLER_CHAIN_PROPERTY_NAME);
110: if (null != sh) {
111: preLogicalSystemHandlers = builder
112: .buildHandlerChainFromConfiguration(sh
113: .getPreLogical());
114: postLogicalSystemHandlers = builder
115: .buildHandlerChainFromConfiguration(sh
116: .getPostLogical());
117: preProtocolSystemHandlers = builder
118: .buildHandlerChainFromConfiguration(sh
119: .getPreProtocol());
120: postProtocolSystemHandlers = builder
121: .buildHandlerChainFromConfiguration(sh
122: .getPostProtocol());
123: }
124: }
125:
126: /**
127: * Returns the list of logical system handlers that should be executed
128: * before any user supplied logical handlers. The returned list is NOT a
129: * copy and thus can be modified directly.
130: *
131: * @return the list of logical system handlers.
132: */
133: public List<Handler> getPreLogicalSystemHandlers() {
134: if (null == preLogicalSystemHandlers) {
135: preLogicalSystemHandlers = new ArrayList<Handler>();
136: }
137: return preLogicalSystemHandlers;
138: }
139:
140: /**
141: * Returns the list of logical system handlers that should be
142: * executed after any user supplied logical handlers.
143: * The returned list is NOT a copy and thus can be modified directly.
144: * @return the list of logical system handlers.
145: */
146: public List<Handler> getPostLogicalSystemHandlers() {
147: if (null == postLogicalSystemHandlers) {
148: postLogicalSystemHandlers = new ArrayList<Handler>();
149: }
150: return postLogicalSystemHandlers;
151: }
152:
153: /**
154: * Returns the list of protocol system handlers that should be
155: * executed before any user supplied protocol handlers.
156: * @return the list of protocol system handlers.
157: */
158: public List<Handler> getPreProtocolSystemHandlers() {
159: if (null == preProtocolSystemHandlers) {
160: preProtocolSystemHandlers = new ArrayList<Handler>();
161: }
162: return preProtocolSystemHandlers;
163: }
164:
165: /**
166: * Returns the list of protocl system handlers that should be
167: * executed after any user supplied protocl handlers.
168: * @return the list of protocol system handlers.
169: */
170: public List<Handler> getPostProtocolSystemHandlers() {
171: if (null == postProtocolSystemHandlers) {
172: postProtocolSystemHandlers = new ArrayList<Handler>();
173: }
174: return postProtocolSystemHandlers;
175: }
176:
177: public void injectSystemHandlers(ResourceInjector injector) {
178: if (null != preLogicalSystemHandlers) {
179: for (Handler h : preLogicalSystemHandlers) {
180: injector.inject(h);
181: }
182: }
183: if (null != postLogicalSystemHandlers) {
184: for (Handler h : postLogicalSystemHandlers) {
185: injector.inject(h);
186: }
187: }
188:
189: if (null != preProtocolSystemHandlers) {
190: for (Handler h : preProtocolSystemHandlers) {
191: injector.inject(h);
192: }
193: }
194:
195: if (null != postProtocolSystemHandlers) {
196: for (Handler h : postProtocolSystemHandlers) {
197: injector.inject(h);
198: }
199: }
200: }
201:
202: public abstract MessageContext createBindingMessageContext(
203: MessageContext orig);
204:
205: public abstract HandlerInvoker createHandlerInvoker();
206:
207: public abstract void marshal(ObjectMessageContext objContext,
208: MessageContext msgContext, DataBindingCallback callback);
209:
210: public abstract void marshalFault(ObjectMessageContext objContext,
211: MessageContext msgContext, DataBindingCallback callback);
212:
213: public abstract void unmarshal(MessageContext msgContext,
214: ObjectMessageContext objContext,
215: DataBindingCallback callback);
216:
217: public abstract void unmarshalFault(MessageContext msgContext,
218: ObjectMessageContext objContext,
219: DataBindingCallback callback);
220:
221: public abstract void write(MessageContext msgContext,
222: OutputStreamMessageContext outContext) throws IOException;
223:
224: public abstract void read(InputStreamMessageContext inContext,
225: MessageContext msgContext) throws IOException;
226:
227: public abstract boolean hasFault(MessageContext msgContext);
228:
229: public abstract void updateMessageContext(MessageContext msgContext);
230:
231: }
|