1 57 58 59 package org.apache.wsif.providers.jca; 60 61 import org.apache.wsif.*; 62 import org.apache.wsif.format.*; 63 import org.apache.wsif.providers.jca.WSIFUtils_JCA; 64 import org.apache.wsif.logging.*; 65 import java.net.MalformedURLException ; 66 import java.net.URL ; 67 import java.util.*; 68 import javax.wsdl.*; 69 import javax.wsdl.extensions.ExtensibilityElement; 70 71 79 80 public class WSIFMessage_JCAStreamable extends org.apache.wsif.providers.jca.WSIFMessage_JCA implements javax.resource.cci.Streamable { 81 82 private static final long serialVersionUID = 1L; 83 private Message fieldMessageModel = null; 84 private java.util.HashMap fieldPartNameFormatHandlerMapping = new java.util.HashMap (); 85 86 89 public WSIFMessage_JCAStreamable(Definition aDefinition, Binding aBinding, String aOperationName, String aInputName, String aOutputName, int aMessageType) { 90 super(aDefinition, aBinding, aOperationName, aInputName, aOutputName, aMessageType); 91 Operation operation = aBinding.getPortType().getOperation(aOperationName, aInputName, aOutputName); 92 switch(aMessageType){ 93 case WSIFMessage_JCA.INPUT_MESSAGE: 94 if(operation.getInput() != null) { 95 this.fieldMessageModel = operation.getInput().getMessage(); 96 setMessageDefinition(this.fieldMessageModel); 97 } 98 break; 99 case WSIFMessage_JCA.OUTPUT_MESSAGE: 100 if(operation.getOutput() != null) { 101 this.fieldMessageModel = operation.getOutput().getMessage(); 102 setMessageDefinition(this.fieldMessageModel); 103 } 104 break; 105 case WSIFMessage_JCA.FAULT_MESSAGE: 106 break; 107 default: 108 this.fieldMessageModel = operation.getInput().getMessage(); 110 setMessageDefinition(this.fieldMessageModel); 111 break; 112 } 113 } 114 115 116 125 public void read(java.io.InputStream inputStream) throws java.io.IOException { 126 127 try { 128 Trc.entry(this); 129 if(fieldMessageModel == null) 130 return; 131 HashMap partsToNotProcess = new HashMap(); 132 BindingOperation bindingOperation = fieldBinding.getBindingOperation(fieldOperationName, fieldInputName, fieldOutputName); 133 BindingOutput bindingOutput = bindingOperation.getBindingOutput(); 134 if (bindingOutput != null) { 135 List list = bindingOutput.getExtensibilityElements(); 136 Iterator inputIterator = list.iterator(); 137 while (inputIterator.hasNext()) { 138 ExtensibilityElement ele = (ExtensibilityElement)inputIterator.next(); 139 if (ele instanceof WSIFBindingOperation_JCAProperty) { 140 WSIFBindingOperation_JCAProperty prop = (WSIFBindingOperation_JCAProperty)ele; 141 String partName = prop.getPartName(); 142 partsToNotProcess.put(partName,partName); 143 } 144 } 145 } 146 Iterator iterator = this.fieldMessageModel.getOrderedParts(null).iterator(); 147 while (iterator.hasNext()) { 148 Part part = (Part) iterator.next(); 149 String partName = part.getName(); 150 151 if (partsToNotProcess.get(partName) != null) continue; 152 153 WSIFFormatHandler_JCA formatHandler = null; 154 if (this.fieldPartNameFormatHandlerMapping.containsKey(partName)) 155 formatHandler = 156 (WSIFFormatHandler_JCA) this.fieldPartNameFormatHandlerMapping.get(partName); 157 else { 158 formatHandler = (WSIFFormatHandler_JCA) WSIFUtils_JCA.getFormatHandler(part, this.fieldDefinition, this.fieldBinding); 159 this.fieldPartNameFormatHandlerMapping.put(partName, formatHandler); 160 } 161 formatHandler.read(inputStream); 162 } 163 Trc.exit(); 164 } 165 catch (Exception exn1) { 166 Trc.exception(exn1); 167 throw new java.io.IOException (WSIFResource_JCA.get("WSIF1004E", exn1.getLocalizedMessage())); 168 } 169 } 170 171 172 180 public void write(java.io.OutputStream outputStream) throws java.io.IOException { 181 182 try { 183 Trc.entry(this); 184 185 HashMap partsToNotProcess = new HashMap(); 186 BindingOperation bindingOperation = fieldBinding.getBindingOperation(fieldOperationName, fieldInputName, fieldOutputName); 187 BindingInput bindingInput = bindingOperation.getBindingInput(); 188 if (bindingInput != null) { 189 List list = bindingInput.getExtensibilityElements(); 190 Iterator inputIterator = list.iterator(); 191 while (inputIterator.hasNext()) { 192 ExtensibilityElement ele = (ExtensibilityElement) inputIterator.next(); 193 if (ele instanceof WSIFBindingOperation_JCAProperty) { 194 WSIFBindingOperation_JCAProperty prop = (WSIFBindingOperation_JCAProperty) ele; 195 String partName = prop.getPartName(); 196 partsToNotProcess.put(partName, partName); 197 } 198 } 199 } 200 201 Iterator iterator = this.getPartNames(); 202 while (iterator.hasNext()) { 203 String partName = (String ) iterator.next(); 204 if (partsToNotProcess.get(partName) != null) 205 continue; 206 Object oPart = this.parts.get(partName); 207 WSIFFormatHandler_JCA formatHandler = null; 208 if (oPart instanceof WSIFFormatPart) { 209 WSIFFormatPart jcaPart = (WSIFFormatPart) oPart; 210 if (jcaPart._getFormatHandler() != null) { 211 formatHandler = (WSIFFormatHandler_JCA) jcaPart._getFormatHandler(); 212 this.fieldPartNameFormatHandlerMapping.put(partName, formatHandler); 213 } 214 } 215 if (formatHandler == null) { 216 if (this.fieldPartNameFormatHandlerMapping.containsKey(partName)) 217 formatHandler = (WSIFFormatHandler_JCA) this.fieldPartNameFormatHandlerMapping.get(partName); 218 else { 219 if (fieldMessageModel == null) 220 return; 221 Part part = (Part) this.fieldMessageModel.getPart(partName); 222 formatHandler = (WSIFFormatHandler_JCA) WSIFUtils_JCA.getFormatHandler(part, this.fieldDefinition, this.fieldBinding); 223 this.fieldPartNameFormatHandlerMapping.put(partName, formatHandler); 224 } 225 formatHandler.setObjectPart(oPart); 226 } 227 formatHandler.write(outputStream); 228 } 229 Trc.exit(); 230 } 231 catch (Exception exn1) { 232 Trc.exception(exn1); 233 throw new java.io.IOException (WSIFResource_JCA.get("WSIF1005E", exn1.getLocalizedMessage())); 234 235 } 236 237 } 238 239 247 public Object getObjectPart(String partName) { 248 249 Trc.entry(this, partName); 250 251 if(this.parts != null){ 252 Object existingPart = this.parts.get(partName); 253 if (existingPart != null) 254 return existingPart; 255 } 256 try { 257 WSIFFormatHandler_JCA formatHandler = 258 (WSIFFormatHandler_JCA) this.fieldPartNameFormatHandlerMapping.get(partName); 259 if (formatHandler != null) { 260 if(this.fieldInteractionSpec != null) 261 formatHandler.setInteractionSpec(this.fieldInteractionSpec); 262 Object retPart = formatHandler.getObjectPart(); 263 this.setObjectPart(partName, retPart); 264 Trc.exit(retPart); 265 return retPart; 266 } 267 else { 268 if(fieldMessageModel == null) 269 return null; 270 Part part = (Part) this.fieldMessageModel.getPart(partName); 271 if (part == null) return null; 272 formatHandler = (WSIFFormatHandler_JCA)WSIFUtils_JCA.getFormatHandler(part, this.fieldDefinition, this.fieldBinding); 273 if(this.fieldInteractionSpec != null) 274 formatHandler.setInteractionSpec(this.fieldInteractionSpec); 275 Object retPart = formatHandler.getObjectPart(); 276 this.setObjectPart(partName, retPart); 277 Trc.exit(retPart); 278 return retPart; 279 } 280 281 } 282 catch (Exception exn) { 283 Trc.exception(exn); 284 throw new RuntimeException (WSIFResource_JCA.get("WSIF1007E", exn.getLocalizedMessage())); 285 } 286 } 287 288 296 public Object getObjectPart(String partName, Class sourceClass) { 297 298 Trc.entry(this, partName, sourceClass); 299 300 try { 301 if (this.parts != null) { 302 Object existingPart = this.parts.get(partName); 303 if (existingPart != null) { 304 if (sourceClass.isAssignableFrom(existingPart.getClass())){ 305 Trc.exit(existingPart); 306 return existingPart; 307 } 308 } 309 } 310 } 311 catch (Exception exn) { 312 Trc.exception(exn); 313 } 314 315 try { 316 WSIFFormatHandler_JCA formatHandler = (WSIFFormatHandler_JCA) this.fieldPartNameFormatHandlerMapping.get(partName); 317 if (formatHandler != null) { 318 if(this.fieldInteractionSpec != null) 319 formatHandler.setInteractionSpec(this.fieldInteractionSpec); 320 Object retSource = formatHandler.getObjectPart(sourceClass); 321 this.setObjectPart(partName, retSource); 322 Trc.exit(retSource); 323 return retSource; 324 } 325 else { 326 if(fieldMessageModel == null) 327 return null; 328 Part part = (Part) this.fieldMessageModel.getPart(partName); 329 if (part == null) return null; 330 formatHandler = (WSIFFormatHandler_JCA)WSIFUtils_JCA.getFormatHandler(part, this.fieldDefinition, this.fieldBinding); 331 if(this.fieldInteractionSpec != null) 332 formatHandler.setInteractionSpec(this.fieldInteractionSpec); 333 Object retSource = formatHandler.getObjectPart(sourceClass); 334 this.setObjectPart(partName, retSource); 335 Trc.exit(retSource); 336 return retSource; 337 } 338 } 339 catch (Exception exn) { 340 Trc.exception(exn); 341 throw new RuntimeException (WSIFResource_JCA.get("WSIF1007E", exn.getLocalizedMessage())); 342 } 343 } 344 345 348 public Iterator getPartNames() { 349 350 try{ 351 if(this.fieldMessageModel == null) 352 return null; 353 return this.fieldMessageModel.getParts().keySet().iterator(); 354 } 355 catch(Throwable exn){ 356 return null; 357 } 358 } 359 360 363 public Iterator getParts() { 364 365 try{ 366 Iterator partNames = this.getPartNames(); 367 while(partNames.hasNext()){ 368 String nextName = (String )partNames.next(); 369 this.getObjectPart(nextName); 370 } 371 return(this.parts.values().iterator()); 372 } 373 catch(Throwable exn){ 374 return null; 375 } 376 } 377 378 379 } | Popular Tags |