1 7 package org.jboss.webservice.metadata.jaxrpcmapping; 8 9 11 import org.jboss.logging.Logger; 12 import org.jboss.xb.binding.UnmarshallingContext; 13 import org.jboss.xb.binding.ObjectModelFactory; 14 import org.jboss.xb.binding.Unmarshaller; 15 import org.jboss.xb.binding.UnmarshallerFactory; 16 import org.jboss.xb.binding.JBossXBException; 17 import org.xml.sax.Attributes ; 18 19 import javax.xml.namespace.QName ; 20 import java.io.InputStream ; 21 import java.io.IOException ; 22 import java.net.URL ; 23 24 30 public class JavaWsdlMappingFactory implements ObjectModelFactory 31 { 32 private static final Logger log = Logger.getLogger(JavaWsdlMappingFactory.class); 34 35 private JavaWsdlMappingFactory() 37 { 38 } 39 40 43 public static JavaWsdlMappingFactory newInstance() 44 { 45 return new JavaWsdlMappingFactory(); 46 } 47 48 51 public JavaWsdlMapping parse(URL jaxrpcMappingFile) throws IOException 52 { 53 if(jaxrpcMappingFile == null) 54 { 55 throw new IllegalArgumentException ("URL cannot be null"); 56 } 57 58 Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller(); 60 InputStream is = jaxrpcMappingFile.openStream(); 61 try 62 { 63 JavaWsdlMapping javaWsdlMapping = (JavaWsdlMapping)unmarshaller.unmarshal(is, this, null); 64 return javaWsdlMapping; 65 } 66 catch (JBossXBException e) 67 { 68 IOException ioex = new IOException ("Cannot parse: " + jaxrpcMappingFile); 69 Throwable cause = e.getCause(); 70 if (cause != null) 71 ioex.initCause(cause); 72 throw ioex; 73 } 74 finally 75 { 76 is.close(); 77 } 78 } 79 80 83 public Object newRoot(Object root, 84 UnmarshallingContext navigator, 85 String namespaceURI, 86 String localName, 87 Attributes attrs) 88 { 89 return new JavaWsdlMapping(); 90 } 91 92 public Object completeRoot(Object root, UnmarshallingContext ctx, String uri, String name) 93 { 94 return root; 95 } 96 97 100 public Object newChild(JavaWsdlMapping javaWsdlMapping, 101 UnmarshallingContext navigator, 102 String namespaceURI, 103 String localName, 104 Attributes attrs) 105 { 106 log.trace("newChild: " + localName); 107 if("package-mapping".equals(localName)) 108 { 109 return new PackageMapping(javaWsdlMapping); 110 } 111 if("java-xml-type-mapping".equals(localName)) 112 { 113 return new JavaXmlTypeMapping(javaWsdlMapping); 114 } 115 if("exception-mapping".equals(localName)) 116 { 117 return new ExceptionMapping(javaWsdlMapping); 118 } 119 if("service-interface-mapping".equals(localName)) 120 { 121 return new ServiceInterfaceMapping(javaWsdlMapping); 122 } 123 if("service-endpoint-interface-mapping".equals(localName)) 124 { 125 return new ServiceEndpointInterfaceMapping(javaWsdlMapping); 126 } 127 return null; 128 } 129 130 133 public void addChild(JavaWsdlMapping javaWsdlMapping, PackageMapping packageMapping, UnmarshallingContext navigator, String namespaceURI, String localName) 134 { 135 log.trace("addChild: [obj=" + javaWsdlMapping + ",child=" + packageMapping + "]"); 136 javaWsdlMapping.addPackageMapping(packageMapping); 137 } 138 139 142 public void addChild(JavaWsdlMapping javaWsdlMapping, JavaXmlTypeMapping typeMapping, UnmarshallingContext navigator, String namespaceURI, String localName) 143 { 144 log.trace("addChild: [obj=" + javaWsdlMapping + ",child=" + typeMapping + "]"); 145 javaWsdlMapping.addJavaXmlTypeMappings(typeMapping); 146 } 147 148 151 public void addChild(JavaWsdlMapping javaWsdlMapping, 152 ExceptionMapping exceptionMapping, 153 UnmarshallingContext navigator, String namespaceURI, String localName) 154 { 155 log.trace("addChild: [obj=" + javaWsdlMapping + ",child=" + exceptionMapping + "]"); 156 javaWsdlMapping.addExceptionMappings(exceptionMapping); 157 } 158 159 162 public void addChild(JavaWsdlMapping javaWsdlMapping, 163 ServiceInterfaceMapping siMapping, 164 UnmarshallingContext navigator, String namespaceURI, String localName) 165 { 166 log.trace("addChild: [obj=" + javaWsdlMapping + ",child=" + siMapping + "]"); 167 javaWsdlMapping.addServiceInterfaceMappings(siMapping); 168 } 169 170 173 public void addChild(JavaWsdlMapping javaWsdlMapping, 174 ServiceEndpointInterfaceMapping seiMapping, 175 UnmarshallingContext navigator, String namespaceURI, String localName) 176 { 177 log.trace("addChild: [obj=" + javaWsdlMapping + ",child=" + seiMapping + "]"); 178 javaWsdlMapping.addServiceEndpointInterfaceMappings(seiMapping); 179 } 180 181 184 public void setValue(PackageMapping packageMapping, 185 UnmarshallingContext navigator, 186 String namespaceURI, 187 String localName, 188 String value) 189 { 190 log.trace("setValue: [obj=" + packageMapping + ",value=" + value + "]"); 191 if("package-type".equals(localName)) 192 { 193 packageMapping.setPackageType(value); 194 } 195 else if("namespaceURI".equals(localName)) 196 { 197 packageMapping.setNamespaceURI(value); 198 } 199 } 200 201 204 public Object newChild(JavaXmlTypeMapping typeMapping, 205 UnmarshallingContext navigator, 206 String namespaceURI, 207 String localName, 208 Attributes attrs) 209 { 210 log.trace("newChild: " + localName); 211 if("variable-mapping".equals(localName)) 212 { 213 return new VariableMapping(typeMapping); 214 } 215 return null; 216 } 217 218 221 public void addChild(JavaXmlTypeMapping typeMapping, VariableMapping variableMapping, UnmarshallingContext navigator, String namespaceURI, String localName) 222 { 223 log.trace("addChild: [obj=" + typeMapping + ",child=" + variableMapping + "]"); 224 typeMapping.addVariableMapping(variableMapping); 225 } 226 227 230 public void setValue(JavaXmlTypeMapping typeMapping, 231 UnmarshallingContext navigator, 232 String namespaceURI, 233 String localName, 234 String value) 235 { 236 log.trace("setValue: [obj=" + typeMapping + ",value=" + value + "]"); 237 if("java-type".equals(localName)) 238 { 239 typeMapping.setJavaType(value); 240 } 241 else if("root-type-qname".equals(localName)) 242 { 243 typeMapping.setRootTypeQName(navigator.resolveQName(value)); 244 } 245 else if("anonymous-type-qname".equals(localName)) 246 { 247 int index = value.lastIndexOf(':'); 248 if(index < 0) 249 throw new IllegalArgumentException ("Invalid anonymous qname: " + value); 250 251 String nsURI = value.substring(0, index); 252 String localPart = value.substring(index + 1); 253 typeMapping.setAnonymousTypeQName(new QName (nsURI, localPart)); 254 } 255 else if("qname-scope".equals(localName)) 256 { 257 typeMapping.setQnameScope(value); 258 } 259 } 260 261 264 public void setValue(ExceptionMapping exceptionMapping, 265 UnmarshallingContext navigator, 266 String namespaceURI, 267 String localName, 268 String value) 269 { 270 log.trace("setValue: [obj=" + exceptionMapping + ",value=" + value + "]"); 271 if("exception-type".equals(localName)) 272 { 273 exceptionMapping.setExceptionType(value); 274 } 275 else if("wsdl-message".equals(localName)) 276 { 277 exceptionMapping.setWsdlMessage(navigator.resolveQName(value)); 278 } 279 else if("constructor-parameter-order".equals(localName)) 280 { 281 exceptionMapping.addConstructorParameter(value); 282 } 283 } 284 285 288 public Object newChild(ServiceInterfaceMapping siMapping, 289 UnmarshallingContext navigator, 290 String namespaceURI, 291 String localName, 292 Attributes attrs) 293 { 294 log.trace("newChild: " + localName); 295 if("port-mapping".equals(localName)) 296 { 297 return new PortMapping(siMapping); 298 } 299 return null; 300 } 301 302 305 public void addChild(ServiceInterfaceMapping siMapping, PortMapping portMapping, UnmarshallingContext navigator, String namespaceURI, String localName) 306 { 307 log.trace("addChild: [obj=" + siMapping + ",child=" + portMapping + "]"); 308 siMapping.addPortMapping(portMapping); 309 } 310 311 314 public void setValue(ServiceInterfaceMapping siMapping, 315 UnmarshallingContext navigator, 316 String namespaceURI, 317 String localName, 318 String value) 319 { 320 log.trace("setValue: [obj=" + siMapping + ",value=" + value + "]"); 321 if("service-interface".equals(localName)) 322 { 323 siMapping.setServiceInterface(value); 324 } 325 else if("wsdl-service-name".equals(localName)) 326 { 327 siMapping.setWsdlServiceName(navigator.resolveQName(value)); 328 } 329 } 330 331 334 public Object newChild(ServiceEndpointInterfaceMapping seiMapping, 335 UnmarshallingContext navigator, 336 String namespaceURI, 337 String localName, 338 Attributes attrs) 339 { 340 log.trace("newChild: " + localName); 341 if("service-endpoint-method-mapping".equals(localName)) 342 { 343 return new ServiceEndpointMethodMapping(seiMapping); 344 } 345 return null; 346 } 347 348 351 public void addChild(ServiceEndpointInterfaceMapping seiMapping, 352 ServiceEndpointMethodMapping seiMethodMapping, 353 UnmarshallingContext navigator, String namespaceURI, String localName) 354 { 355 log.trace("addChild: [obj=" + seiMapping + ",child=" + seiMapping + "]"); 356 seiMapping.addServiceEndpointMethodMapping(seiMethodMapping); 357 } 358 359 362 public void setValue(ServiceEndpointInterfaceMapping seiMapping, 363 UnmarshallingContext navigator, 364 String namespaceURI, 365 String localName, 366 String value) 367 { 368 log.trace("setValue: [obj=" + seiMapping + ",value=" + value + "]"); 369 if("service-endpoint-interface".equals(localName)) 370 { 371 seiMapping.setServiceEndpointInterface(value); 372 } 373 else if("wsdl-port-type".equals(localName)) 374 { 375 seiMapping.setWsdlPortType(navigator.resolveQName(value)); 376 } 377 else if("wsdl-binding".equals(localName)) 378 { 379 seiMapping.setWsdlBinding(navigator.resolveQName(value)); 380 } 381 } 382 383 386 public void setValue(VariableMapping variableMapping, 387 UnmarshallingContext navigator, 388 String namespaceURI, 389 String localName, 390 String value) 391 { 392 log.trace("setValue: [obj=" + variableMapping + ",value=" + value + "]"); 393 if("java-variable-name".equals(localName)) 394 { 395 variableMapping.setJavaVariableName(value); 396 } 397 else if("data-member".equals(localName)) 398 { 399 variableMapping.setDataMember(true); 400 } 401 else if("xml-attribute-name".equals(localName)) 402 { 403 variableMapping.setXmlAttributeName(value); 404 } 405 else if("xml-element-name".equals(localName)) 406 { 407 variableMapping.setXmlElementName(value); 408 } 409 else if("xml-wildcard".equals(localName)) 410 { 411 variableMapping.setXmlWildcard(value); 412 } 413 } 414 415 418 public void setValue(PortMapping portMapping, 419 UnmarshallingContext navigator, 420 String namespaceURI, 421 String localName, 422 String value) 423 { 424 log.trace("setValue: [obj=" + portMapping + ",value=" + value + "]"); 425 if("port-name".equals(localName)) 426 { 427 portMapping.setPortName(value); 428 } 429 else if("java-port-name".equals(localName)) 430 { 431 portMapping.setJavaPortName(value); 432 } 433 } 434 435 438 public Object newChild(ServiceEndpointMethodMapping methodMapping, 439 UnmarshallingContext navigator, 440 String namespaceURI, 441 String localName, 442 Attributes attrs) 443 { 444 log.trace("newChild: " + localName); 445 if("method-param-parts-mapping".equals(localName)) 446 { 447 return new MethodParamPartsMapping(methodMapping); 448 } 449 if("wsdl-return-value-mapping".equals(localName)) 450 { 451 return new WsdlReturnValueMapping(methodMapping); 452 } 453 return null; 454 } 455 456 459 public void addChild(ServiceEndpointMethodMapping methodMapping, 460 MethodParamPartsMapping partsMapping, 461 UnmarshallingContext navigator, String namespaceURI, String localName) 462 { 463 log.trace("addChild: [obj=" + methodMapping + ",child=" + partsMapping + "]"); 464 methodMapping.addMethodParamPartsMapping(partsMapping); 465 } 466 467 470 public void addChild(ServiceEndpointMethodMapping methodMapping, 471 WsdlReturnValueMapping returnValueMapping, 472 UnmarshallingContext navigator, String namespaceURI, String localName) 473 { 474 log.trace("addChild: [obj=" + methodMapping + ",child=" + returnValueMapping + "]"); 475 methodMapping.setWsdlReturnValueMapping(returnValueMapping); 476 } 477 478 481 public void setValue(ServiceEndpointMethodMapping methodMapping, 482 UnmarshallingContext navigator, 483 String namespaceURI, 484 String localName, 485 String value) 486 { 487 log.trace("setValue: [obj=" + methodMapping + ",value=" + value + "]"); 488 if("java-method-name".equals(localName)) 489 { 490 methodMapping.setJavaMethodName(value); 491 } 492 else if("wsdl-operation".equals(localName)) 493 { 494 methodMapping.setWsdlOperation(value); 495 } 496 else if("wrapped-element".equals(localName)) 497 { 498 methodMapping.setWrappedElement(true); 499 } 500 } 501 502 505 public Object newChild(MethodParamPartsMapping partsMapping, 506 UnmarshallingContext navigator, 507 String namespaceURI, 508 String localName, 509 Attributes attrs) 510 { 511 log.trace("newChild: " + localName); 512 if("wsdl-message-mapping".equals(localName)) 513 { 514 return new WsdlMessageMapping(partsMapping); 515 } 516 return null; 517 } 518 519 522 public void addChild(MethodParamPartsMapping partsMapping, 523 WsdlMessageMapping msgMapping, 524 UnmarshallingContext navigator, String namespaceURI, String localName) 525 { 526 log.trace("addChild: [obj=" + partsMapping + ",child=" + msgMapping + "]"); 527 partsMapping.setWsdlMessageMapping(msgMapping); 528 } 529 530 533 public void setValue(MethodParamPartsMapping partsMapping, 534 UnmarshallingContext navigator, 535 String namespaceURI, 536 String localName, 537 String value) 538 { 539 log.trace("setValue: [obj=" + partsMapping + ",value=" + value + "]"); 540 if("param-position".equals(localName)) 541 { 542 partsMapping.setParamPosition(new Integer (value).intValue()); 543 } 544 else if("param-type".equals(localName)) 545 { 546 partsMapping.setParamType(value); 547 } 548 } 549 550 553 public void setValue(WsdlReturnValueMapping retValueMapping, 554 UnmarshallingContext navigator, 555 String namespaceURI, 556 String localName, 557 String value) 558 { 559 log.trace("setValue: [obj=" + retValueMapping + ",value=" + value + "]"); 560 if("method-return-value".equals(localName)) 561 { 562 retValueMapping.setMethodReturnValue(value); 563 } 564 else if("wsdl-message".equals(localName)) 565 { 566 retValueMapping.setWsdlMessage(navigator.resolveQName(value)); 567 } 568 else if("wsdl-message-part-name".equals(localName)) 569 { 570 retValueMapping.setWsdlMessagePartName(value); 571 } 572 } 573 574 577 public void setValue(WsdlMessageMapping msgMapping, 578 UnmarshallingContext navigator, 579 String namespaceURI, 580 String localName, 581 String value) 582 { 583 log.trace("setValue: [obj=" + msgMapping + ",value=" + value + "]"); 584 if("wsdl-message".equals(localName)) 585 { 586 msgMapping.setWsdlMessage(navigator.resolveQName(value)); 587 } 588 else if("wsdl-message-part-name".equals(localName)) 589 { 590 msgMapping.setWsdlMessagePartName(value); 591 } 592 else if("parameter-mode".equals(localName)) 593 { 594 msgMapping.setParameterMode(value); 595 } 596 else if("soap-header".equals(localName)) 597 { 598 msgMapping.setSoapHeader(true); 599 } 600 } 601 } 602 | Popular Tags |