1 package org.objectweb.celtix.bindings; 2 3 import java.io.IOException ; 4 import java.util.ArrayList ; 5 import java.util.Iterator ; 6 import java.util.List ; 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 SYSTEM_HANDLER_CHAIN_PROPERTY_NAME = "systemHandlerChain"; 26 protected List <Handler> handlerChain; 27 protected List <Handler> preLogicalSystemHandlers; 28 protected List <Handler> postLogicalSystemHandlers; 29 protected List <Handler> preProtocolSystemHandlers; 30 protected List <Handler> postProtocolSystemHandlers; 31 32 33 36 public List <Handler> getHandlerChain() { 37 return handlerChain; 39 } 40 41 49 public List <Handler> getHandlerChain(boolean includeSystemHandlers) { 50 if (!includeSystemHandlers) { 51 return getHandlerChain(); 52 } 53 List <Handler> allHandlers = new ArrayList <Handler>(); 54 if (null != preLogicalSystemHandlers) { 55 allHandlers.addAll(preLogicalSystemHandlers); 56 } 57 List <Handler> userHandlers = handlerChain; 59 if (null == userHandlers) { 60 userHandlers = new ArrayList <Handler>(); 61 } 62 Iterator <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 99 public void setHandlerChain(List <Handler> chain) { 100 assert chain != null; 101 handlerChain = chain; 102 } 103 104 105 106 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 129 public List <Handler> getPreLogicalSystemHandlers() { 130 if (null == preLogicalSystemHandlers) { 131 preLogicalSystemHandlers = new ArrayList <Handler>(); 132 } 133 return preLogicalSystemHandlers; 134 } 135 136 142 public List <Handler> getPostLogicalSystemHandlers() { 143 if (null == postLogicalSystemHandlers) { 144 postLogicalSystemHandlers = new ArrayList <Handler>(); 145 } 146 return postLogicalSystemHandlers; 147 } 148 149 154 public List <Handler> getPreProtocolSystemHandlers() { 155 if (null == preProtocolSystemHandlers) { 156 preProtocolSystemHandlers = new ArrayList <Handler>(); 157 } 158 return preProtocolSystemHandlers; 159 } 160 161 166 public List <Handler> getPostProtocolSystemHandlers() { 167 if (null == postProtocolSystemHandlers) { 168 postProtocolSystemHandlers = new ArrayList <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 ; 220 221 public abstract void read(InputStreamMessageContext inContext, MessageContext msgContext) 222 throws IOException ; 223 224 public abstract boolean hasFault(MessageContext msgContext); 225 226 public abstract void updateMessageContext(MessageContext msgContext); 227 228 } 229
| Popular Tags
|