1 57 58 package org.apache.wsif.providers.jms; 59 60 import java.io.Serializable ; 61 import java.util.HashMap ; 62 import java.util.Iterator ; 63 import java.util.Map ; 64 65 import javax.wsdl.BindingOperation; 66 import javax.wsdl.Definition; 67 import javax.wsdl.Port; 68 import javax.wsdl.extensions.ExtensibilityElement; 69 70 import org.apache.wsif.WSIFException; 71 import org.apache.wsif.WSIFOperation; 72 import org.apache.wsif.base.WSIFDefaultPort; 73 import org.apache.wsif.format.WSIFFormatter; 74 import org.apache.wsif.logging.Trc; 75 import org.apache.wsif.providers.WSIFDynamicTypeMap; 76 import org.apache.wsif.util.WSIFProperties; 77 import org.apache.wsif.util.WSIFUtils; 78 import org.apache.wsif.util.jms.WSIFJMSDestination; 79 import org.apache.wsif.util.jms.WSIFJMSFinder; 80 import org.apache.wsif.wsdl.extensions.jms.JMSAddress; 81 82 89 public class WSIFPort_Jms extends WSIFDefaultPort implements Serializable { 90 91 private static final long serialVersionUID = 1L; 92 93 private Definition fieldDefinition = null; 94 private Port fieldPortModel = null; 95 private JMSAddress fieldObjectReference = null; 97 protected Map operationInstances = new HashMap (); 98 transient private WSIFJMSDestination jmsDest; 99 100 103 public WSIFPort_Jms( 104 Definition def, 105 Port port, 106 WSIFDynamicTypeMap typeMap) throws WSIFException { 107 Trc.entry(this, def, port, typeMap); 108 109 fieldDefinition = def; 110 fieldPortModel = port; 111 112 if (Trc.ON) 113 Trc.exit(deep()); 114 } 115 116 119 public WSIFOperation createOperation(String operationName) 120 throws WSIFException { 121 Trc.entry(this, operationName); 122 WSIFOperation wo = createOperation(operationName, null, null); 123 Trc.exit(wo); 124 return wo; 125 } 126 127 130 public WSIFOperation createOperation( 131 String operationName, 132 String inputName, 133 String outputName) 134 throws WSIFException { 135 Trc.entry(this, operationName, inputName, outputName); 136 137 WSIFOperation_Jms op = 138 getDynamicWSIFOperation(operationName, inputName, outputName); 139 if (op == null) { 140 throw new WSIFException( 141 "Could not create operation: " 142 + operationName 143 + ":" 144 + inputName 145 + ":" 146 + outputName); 147 } 148 WSIFOperation wo = op.copy(); 149 Trc.exit(wo); 150 return wo; 151 } 152 153 156 public WSIFOperation_Jms getDynamicWSIFOperation( 157 String name, 158 String inputName, 159 String outputName) 160 throws WSIFException { 161 Trc.entry(this, name, inputName, outputName); 162 163 WSIFOperation_Jms tempOp = 164 (WSIFOperation_Jms) operationInstances.get(getKey(name, inputName, outputName)); 165 166 WSIFOperation_Jms operation = null; 167 if (tempOp != null) { 168 operation = tempOp.copy(); 169 } 170 171 if (operation == null) { 172 BindingOperation bindingOperationModel = 173 WSIFUtils.getBindingOperation( 174 fieldPortModel.getBinding(), name, inputName, outputName ); 175 176 if (bindingOperationModel != null) { 177 operation = 178 new WSIFOperation_Jms( 179 fieldPortModel, 180 bindingOperationModel, 181 this); 182 setDynamicWSIFOperation(name, inputName, outputName, operation); 183 } 184 } 185 186 Trc.exit(operation); 187 return operation; 188 } 189 190 public void setDynamicWSIFOperation( 192 String name, 193 String inputName, 194 String outputName, 195 WSIFOperation_Jms value) { 196 Trc.entry(this, name, inputName, outputName); 197 198 operationInstances.put(getKey(name, inputName, outputName), value); 199 Trc.exit(); 200 } 201 202 207 public boolean supportsSync() { 208 Trc.entry(this); 209 Trc.exit(true); 210 return true; 211 } 212 213 public boolean supportsAsync() { 214 Trc.entry(this); 215 Trc.exit(true); 216 return true; 217 } 218 219 222 public Definition getDefinition() { 223 Trc.entry(this); 224 Trc.exit(fieldDefinition); 225 return fieldDefinition; 226 } 227 228 public void setDefinition(Definition value) { 229 Trc.entry(this, value); 230 fieldDefinition = value; 231 Trc.exit(); 232 } 233 234 public Port getPortModel() { 235 Trc.entry(this); 236 Trc.exit(fieldPortModel); 237 return fieldPortModel; 238 } 239 240 public void setPortModel(Port value) { 241 Trc.entry(this, value); 242 fieldPortModel = value; 243 Trc.exit(); 244 } 245 246 public JMSAddress getObjectReference() throws WSIFException { 247 Trc.entry(this); 248 if (fieldObjectReference == null) { 249 250 try { 251 ExtensibilityElement portExtension = 252 (ExtensibilityElement) fieldPortModel.getExtensibilityElements().get(0); 253 254 if (portExtension == null) { 255 throw new WSIFException("Jms missing port extension"); 256 } 257 258 fieldObjectReference = (JMSAddress) portExtension; 259 260 } catch (Exception ex) { 261 Trc.exception(ex); 262 throw new WSIFException( 263 "Could not create object of class '???todo??? " + "'", 264 ex); 265 } 266 } 267 Trc.exit(fieldObjectReference); 268 return fieldObjectReference; 269 } 270 271 public void setObjectReference(JMSAddress newObjectReference) { 272 Trc.entry(this, newObjectReference); 273 fieldObjectReference = newObjectReference; 274 Trc.exit(); 275 } 276 277 public WSIFFormatter getFormatter() { 278 Trc.entry(this); 279 WSIFFormatter wf = new JMSFormatter(fieldDefinition, fieldPortModel); 280 Trc.exit(wf); 281 return wf; 282 } 283 284 288 public WSIFJMSDestination getJmsDestination() throws WSIFException { 289 if (jmsDest==null) { 290 jmsDest = 291 new WSIFJMSDestination( 292 WSIFJMSFinder.newFinder( 293 getObjectReference(), 294 fieldPortModel.getName()), 295 getObjectReference().getJmsProvDestName(), 296 WSIFProperties.getSyncTimeout()); 297 } 298 return jmsDest; 299 } 300 301 304 public void close() throws WSIFException { 305 Trc.entry(this); 306 if (jmsDest != null) { 307 jmsDest.close(); 308 } 309 Trc.exit(); 310 } 311 312 315 public String deep() { 316 String buff = ""; 317 try { 318 buff = new String (super.toString() + ":\n"); 319 320 buff += "definition:" + Trc.brief(fieldDefinition); 321 buff += " portModel:" + Trc.brief(fieldPortModel); 322 buff += " objectReference:" + fieldObjectReference; 323 324 buff += " operationInstances: "; 325 if (operationInstances == null) 326 buff += "null"; 327 else { 328 buff += "size:" + operationInstances.size(); 329 Iterator it = operationInstances.keySet().iterator(); 330 int i = 0; 331 while (it.hasNext()) { 332 String key = (String ) it.next(); 333 WSIFOperation_Jms woj = (WSIFOperation_Jms) operationInstances.get(key); 334 buff += "\noperationInstances[" + i + "]:" + key + " " + woj + " "; 335 i++; 336 } 337 } 338 } catch (Exception e) { 339 Trc.exceptionInTrace(e); 340 } 341 return buff; 342 } 343 344 } | Popular Tags |