1 57 58 package org.apache.wsif.providers.java; 59 60 import java.io.Serializable ; 61 import java.util.HashMap ; 62 import java.util.Iterator ; 63 import java.util.Map ; 64 import java.util.Vector ; 65 66 import javax.wsdl.BindingOperation; 67 import javax.wsdl.Definition; 68 import javax.wsdl.Port; 69 import javax.wsdl.extensions.ExtensibilityElement; 70 import javax.xml.namespace.QName ; 71 72 import org.apache.wsif.WSIFException; 73 import org.apache.wsif.WSIFOperation; 74 import org.apache.wsif.base.WSIFDefaultPort; 75 import org.apache.wsif.logging.Trc; 76 import org.apache.wsif.providers.WSIFDynamicTypeMap; 77 import org.apache.wsif.util.WSIFUtils; 78 import org.apache.wsif.wsdl.extensions.format.TypeMap; 79 import org.apache.wsif.wsdl.extensions.format.TypeMapping; 80 import org.apache.wsif.wsdl.extensions.java.JavaAddress; 81 82 90 public class WSIFPort_Java extends WSIFDefaultPort implements Serializable { 91 92 private static final long serialVersionUID = 1L; 93 94 private javax.wsdl.Definition fieldDefinition = null; 95 private javax.wsdl.Port fieldPortModel = null; 96 private java.lang.Object fieldObjectReference = null; private Map fieldTypeMaps = new HashMap (); 98 99 protected Map operationInstances = new HashMap (); 100 101 public WSIFPort_Java(Definition def, Port port, WSIFDynamicTypeMap typeMap) 102 throws WSIFException { 103 Trc.entry(this, def, port, typeMap); 104 fieldDefinition = def; 105 fieldPortModel = port; 106 buildTypeMap(); 107 if (Trc.ON) 108 Trc.exit(deep()); 109 } 110 111 public Definition getDefinition() { 112 Trc.entry(this); 113 Trc.exit(fieldDefinition); 114 return fieldDefinition; 115 } 116 117 public WSIFOperation createOperation(String operationName) 118 throws WSIFException { 119 Trc.entry(this); 120 WSIFOperation wo = createOperation(operationName, null, null); 121 Trc.exit(wo); 122 return wo; 123 } 124 125 public WSIFOperation createOperation( 126 String operationName, 127 String inputName, 128 String outputName) 129 throws WSIFException { 130 Trc.entry(this, operationName, inputName, outputName); 131 132 WSIFOperation_Java op = 133 getDynamicWSIFOperation(operationName, inputName, outputName); 134 if (op == null) { 135 throw new WSIFException( 136 "Could not create operation: " 137 + operationName 138 + ":" 139 + inputName 140 + ":" 141 + outputName); 142 } 143 WSIFOperation wo = op.copy(); 144 Trc.exit(wo); 145 return wo; 146 } 147 148 protected WSIFOperation_Java getDynamicWSIFOperation( 149 String name, 150 String inputName, 151 String outputName) 152 throws WSIFException { 153 Trc.entry(this, name, inputName, outputName); 154 155 WSIFOperation_Java operation = 156 (WSIFOperation_Java) operationInstances.get( 157 getKey(name, inputName, outputName)); 158 159 if (operation == null) { 160 BindingOperation bindingOperationModel = 161 WSIFUtils.getBindingOperation( 162 fieldPortModel.getBinding(), name, inputName, outputName ); 163 164 if (bindingOperationModel != null) { 165 operation = 166 new WSIFOperation_Java( 167 fieldPortModel, 168 bindingOperationModel, 169 this, 170 fieldTypeMaps); 171 setDynamicWSIFOperation(name, inputName, outputName, operation); 172 } 173 } 174 Trc.exit(operation); 175 return operation; 176 } 177 178 public java.lang.Object getObjectReference() throws WSIFException { 179 Trc.entry(this); 180 if (fieldObjectReference == null) { 181 JavaAddress address = null; 182 183 try { 184 ExtensibilityElement portExtension = 185 (ExtensibilityElement) fieldPortModel.getExtensibilityElements().get(0); 186 187 if (portExtension == null) { 188 throw new WSIFException("missing port extension"); 189 } 190 191 address = (JavaAddress) portExtension; 192 193 fieldObjectReference = 194 Class 195 .forName( 196 address.getClassName(), 197 true, 198 Thread.currentThread().getContextClassLoader()) 199 .newInstance(); 200 } catch (Exception ex) { 201 Trc.exception(ex); 202 throw new WSIFException( 203 "Could not create object of class '" + address.getClassName() + "'", 204 ex); 205 } 206 } 207 Trc.exit(fieldObjectReference); 208 return fieldObjectReference; 209 } 210 211 public Port getPortModel() { 212 Trc.entry(this); 213 Trc.exit(fieldPortModel); 214 return fieldPortModel; 215 } 216 217 public void setDefinition(Definition value) { 218 Trc.entry(this, value); 219 fieldDefinition = value; 220 Trc.exit(); 221 } 222 223 public void setDynamicWSIFOperation( 225 String name, 226 String inputName, 227 String outputName, 228 WSIFOperation_Java value) { 229 Trc.entry(this, name, inputName, outputName, value); 230 operationInstances.put(getKey(name, inputName, outputName), value); 231 Trc.exit(); 232 } 233 234 public void setObjectReference(java.lang.Object newObjectReference) { 235 Trc.entry(this, newObjectReference); 236 fieldObjectReference = newObjectReference; 237 Trc.exit(); 238 } 239 240 public void setPortModel(Port value) { 241 Trc.entry(this, value); 242 fieldPortModel = value; 243 Trc.exit(); 244 } 245 246 private void buildTypeMap() throws WSIFException { 247 Trc.entry(this); 248 TypeMapping typeMapping = null; 249 250 Iterator bindingIterator = 252 this.fieldPortModel.getBinding().getExtensibilityElements().iterator(); 253 254 while (bindingIterator.hasNext()) { 257 Object next = bindingIterator.next(); 258 if (next instanceof TypeMapping) { 259 typeMapping = (TypeMapping) next; 260 if ("Java".equals(typeMapping.getEncoding()) && 261 "Java".equals(typeMapping.getStyle())) 262 break; 263 typeMapping = null; 264 } 265 } 266 267 if (typeMapping == null) { 268 QName bindingName = fieldPortModel.getBinding().getQName(); 269 throw new WSIFException( 270 "Binding " 271 + (bindingName == null ? "<null>" : bindingName.toString()) 272 + " does not contain a typeMap with encoding=Java and style=Java"); 273 } 274 275 bindingIterator = typeMapping.getMaps().iterator(); 277 while (bindingIterator.hasNext()) { 278 TypeMap typeMap = (TypeMap) bindingIterator.next(); 279 QName typeName = typeMap.getTypeName(); 281 if (typeName == null) typeName = typeMap.getElementName(); 282 String type = typeMap.getFormatType(); 283 if (typeName != null && type != null) { 284 if (fieldTypeMaps.containsKey(typeName)) { 285 Vector v = null; 286 Object obj = fieldTypeMaps.get(typeName); 287 if (obj instanceof Vector ) { 288 v = (Vector ) obj; 289 } else { 290 v = new Vector (); 291 v.addElement(obj); 292 } 293 v.addElement(type); 294 this.fieldTypeMaps.put(typeName, v); 295 } else { 296 this.fieldTypeMaps.put(typeName, type); 297 } 298 } else { 299 throw new WSIFException("Error in binding TypeMap. Key or Value is null"); 300 } 301 } 302 Trc.exit(); 303 } 304 305 public String deep() { 306 String buff = ""; 307 try { 308 buff = new String (super.toString() + ":\n"); 309 310 buff += "definition:" + fieldDefinition == null 311 ? "null" 312 : fieldDefinition.getQName() == null 313 ? "unknown" 314 : fieldDefinition.getQName().toString(); 315 buff += " portModel:" + fieldPortModel == null 316 ? "null" 317 : fieldPortModel.getName() == null 318 ? "unknown" 319 : fieldPortModel.getName().toString(); 320 buff += " objectReference:" + fieldObjectReference; 321 322 buff += " operationInstances:"; 323 if (operationInstances == null) 324 buff += "null"; 325 else { 326 buff += " size:" + operationInstances.size(); 327 Iterator it = operationInstances.keySet().iterator(); 328 int i = 0; 329 while (it.hasNext()) { 330 String key = (String ) it.next(); 331 WSIFOperation_Java woj = (WSIFOperation_Java) operationInstances.get(key); 332 buff += "\noperationInstances[" + i + "]:" + key + " " + woj + " "; 333 i++; 334 } 335 } 336 } catch (Exception e) { 337 Trc.exceptionInTrace(e); 338 } 339 340 return buff; 341 } 342 } | Popular Tags |