KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > webservice > metadata > jaxrpcmapping > JavaWsdlMappingFactory


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.webservice.metadata.jaxrpcmapping;
8
9 // $Id: JavaWsdlMappingFactory.java,v 1.9.2.5 2005/06/19 10:07:09 bill Exp $
10

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 JavaDoc;
18
19 import javax.xml.namespace.QName JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.net.URL JavaDoc;
23
24 /**
25  * A JBossXB factory for {@link org.jboss.webservice.metadata.jaxrpcmapping.JavaWsdlMapping}
26  *
27  * @author Thomas.Diesler@jboss.org
28  * @since 14-May-2004
29  */

30 public class JavaWsdlMappingFactory implements ObjectModelFactory
31 {
32    // provide logging
33
private static final Logger log = Logger.getLogger(JavaWsdlMappingFactory.class);
34
35    // Hide constructor
36
private JavaWsdlMappingFactory()
37    {
38    }
39
40    /**
41     * Create a new instance of a jaxrpc-mapping factory
42     */

43    public static JavaWsdlMappingFactory newInstance()
44    {
45       return new JavaWsdlMappingFactory();
46    }
47
48    /**
49     * Factory method for JavaWsdlMapping
50     */

51    public JavaWsdlMapping parse(URL JavaDoc jaxrpcMappingFile) throws IOException JavaDoc
52    {
53       if(jaxrpcMappingFile == null)
54       {
55          throw new IllegalArgumentException JavaDoc("URL cannot be null");
56       }
57
58       // setup the XML binding Unmarshaller
59
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
60       InputStream JavaDoc 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 JavaDoc ioex = new IOException JavaDoc("Cannot parse: " + jaxrpcMappingFile);
69          Throwable JavaDoc 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    /**
81     * This method is called on the factory by the object model builder when the parsing starts.
82     */

83    public Object JavaDoc newRoot(Object JavaDoc root,
84                          UnmarshallingContext navigator,
85                          String JavaDoc namespaceURI,
86                          String JavaDoc localName,
87                          Attributes JavaDoc attrs)
88    {
89       return new JavaWsdlMapping();
90    }
91
92    public Object JavaDoc completeRoot(Object JavaDoc root, UnmarshallingContext ctx, String JavaDoc uri, String JavaDoc name)
93    {
94       return root;
95    }
96
97    /**
98     * Called when parsing of a new element started.
99     */

100    public Object JavaDoc newChild(JavaWsdlMapping javaWsdlMapping,
101                           UnmarshallingContext navigator,
102                           String JavaDoc namespaceURI,
103                           String JavaDoc localName,
104                           Attributes JavaDoc 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    /**
131     * Called when parsing character is complete.
132     */

133    public void addChild(JavaWsdlMapping javaWsdlMapping, PackageMapping packageMapping, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
134    {
135       log.trace("addChild: [obj=" + javaWsdlMapping + ",child=" + packageMapping + "]");
136       javaWsdlMapping.addPackageMapping(packageMapping);
137    }
138
139    /**
140     * Called when parsing character is complete.
141     */

142    public void addChild(JavaWsdlMapping javaWsdlMapping, JavaXmlTypeMapping typeMapping, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
143    {
144       log.trace("addChild: [obj=" + javaWsdlMapping + ",child=" + typeMapping + "]");
145       javaWsdlMapping.addJavaXmlTypeMappings(typeMapping);
146    }
147
148    /**
149     * Called when parsing character is complete.
150     */

151    public void addChild(JavaWsdlMapping javaWsdlMapping,
152                         ExceptionMapping exceptionMapping,
153                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
154    {
155       log.trace("addChild: [obj=" + javaWsdlMapping + ",child=" + exceptionMapping + "]");
156       javaWsdlMapping.addExceptionMappings(exceptionMapping);
157    }
158
159    /**
160     * Called when parsing character is complete.
161     */

162    public void addChild(JavaWsdlMapping javaWsdlMapping,
163                         ServiceInterfaceMapping siMapping,
164                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
165    {
166       log.trace("addChild: [obj=" + javaWsdlMapping + ",child=" + siMapping + "]");
167       javaWsdlMapping.addServiceInterfaceMappings(siMapping);
168    }
169
170    /**
171     * Called when parsing character is complete.
172     */

173    public void addChild(JavaWsdlMapping javaWsdlMapping,
174                         ServiceEndpointInterfaceMapping seiMapping,
175                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
176    {
177       log.trace("addChild: [obj=" + javaWsdlMapping + ",child=" + seiMapping + "]");
178       javaWsdlMapping.addServiceEndpointInterfaceMappings(seiMapping);
179    }
180
181    /**
182     * Called when a new simple child element with text value was read from the XML content.
183     */

184    public void setValue(PackageMapping packageMapping,
185                         UnmarshallingContext navigator,
186                         String JavaDoc namespaceURI,
187                         String JavaDoc localName,
188                         String JavaDoc 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    /**
202     * Called when parsing of a new element started.
203     */

204    public Object JavaDoc newChild(JavaXmlTypeMapping typeMapping,
205                           UnmarshallingContext navigator,
206                           String JavaDoc namespaceURI,
207                           String JavaDoc localName,
208                           Attributes JavaDoc 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    /**
219     * Called when parsing character is complete.
220     */

221    public void addChild(JavaXmlTypeMapping typeMapping, VariableMapping variableMapping, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
222    {
223       log.trace("addChild: [obj=" + typeMapping + ",child=" + variableMapping + "]");
224       typeMapping.addVariableMapping(variableMapping);
225    }
226
227    /**
228     * Called when a new simple child element with text value was read from the XML content.
229     */

230    public void setValue(JavaXmlTypeMapping typeMapping,
231                         UnmarshallingContext navigator,
232                         String JavaDoc namespaceURI,
233                         String JavaDoc localName,
234                         String JavaDoc 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 JavaDoc("Invalid anonymous qname: " + value);
250
251          String JavaDoc nsURI = value.substring(0, index);
252          String JavaDoc localPart = value.substring(index + 1);
253          typeMapping.setAnonymousTypeQName(new QName JavaDoc(nsURI, localPart));
254       }
255       else if("qname-scope".equals(localName))
256       {
257          typeMapping.setQnameScope(value);
258       }
259    }
260
261    /**
262     * Called when a new simple child element with text value was read from the XML content.
263     */

264    public void setValue(ExceptionMapping exceptionMapping,
265                         UnmarshallingContext navigator,
266                         String JavaDoc namespaceURI,
267                         String JavaDoc localName,
268                         String JavaDoc 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    /**
286     * Called when parsing of a new element started.
287     */

288    public Object JavaDoc newChild(ServiceInterfaceMapping siMapping,
289                           UnmarshallingContext navigator,
290                           String JavaDoc namespaceURI,
291                           String JavaDoc localName,
292                           Attributes JavaDoc 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    /**
303     * Called when parsing character is complete.
304     */

305    public void addChild(ServiceInterfaceMapping siMapping, PortMapping portMapping, UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
306    {
307       log.trace("addChild: [obj=" + siMapping + ",child=" + portMapping + "]");
308       siMapping.addPortMapping(portMapping);
309    }
310
311    /**
312     * Called when a new simple child element with text value was read from the XML content.
313     */

314    public void setValue(ServiceInterfaceMapping siMapping,
315                         UnmarshallingContext navigator,
316                         String JavaDoc namespaceURI,
317                         String JavaDoc localName,
318                         String JavaDoc 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    /**
332     * Called when parsing of a new element started.
333     */

334    public Object JavaDoc newChild(ServiceEndpointInterfaceMapping seiMapping,
335                           UnmarshallingContext navigator,
336                           String JavaDoc namespaceURI,
337                           String JavaDoc localName,
338                           Attributes JavaDoc 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    /**
349     * Called when parsing character is complete.
350     */

351    public void addChild(ServiceEndpointInterfaceMapping seiMapping,
352                         ServiceEndpointMethodMapping seiMethodMapping,
353                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
354    {
355       log.trace("addChild: [obj=" + seiMapping + ",child=" + seiMapping + "]");
356       seiMapping.addServiceEndpointMethodMapping(seiMethodMapping);
357    }
358
359    /**
360     * Called when a new simple child element with text value was read from the XML content.
361     */

362    public void setValue(ServiceEndpointInterfaceMapping seiMapping,
363                         UnmarshallingContext navigator,
364                         String JavaDoc namespaceURI,
365                         String JavaDoc localName,
366                         String JavaDoc 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    /**
384     * Called when a new simple child element with text value was read from the XML content.
385     */

386    public void setValue(VariableMapping variableMapping,
387                         UnmarshallingContext navigator,
388                         String JavaDoc namespaceURI,
389                         String JavaDoc localName,
390                         String JavaDoc 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    /**
416     * Called when a new simple child element with text value was read from the XML content.
417     */

418    public void setValue(PortMapping portMapping,
419                         UnmarshallingContext navigator,
420                         String JavaDoc namespaceURI,
421                         String JavaDoc localName,
422                         String JavaDoc 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    /**
436     * Called when parsing of a new element started.
437     */

438    public Object JavaDoc newChild(ServiceEndpointMethodMapping methodMapping,
439                           UnmarshallingContext navigator,
440                           String JavaDoc namespaceURI,
441                           String JavaDoc localName,
442                           Attributes JavaDoc 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    /**
457     * Called when parsing character is complete.
458     */

459    public void addChild(ServiceEndpointMethodMapping methodMapping,
460                         MethodParamPartsMapping partsMapping,
461                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
462    {
463       log.trace("addChild: [obj=" + methodMapping + ",child=" + partsMapping + "]");
464       methodMapping.addMethodParamPartsMapping(partsMapping);
465    }
466
467    /**
468     * Called when parsing character is complete.
469     */

470    public void addChild(ServiceEndpointMethodMapping methodMapping,
471                         WsdlReturnValueMapping returnValueMapping,
472                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
473    {
474       log.trace("addChild: [obj=" + methodMapping + ",child=" + returnValueMapping + "]");
475       methodMapping.setWsdlReturnValueMapping(returnValueMapping);
476    }
477
478    /**
479     * Called when a new simple child element with text value was read from the XML content.
480     */

481    public void setValue(ServiceEndpointMethodMapping methodMapping,
482                         UnmarshallingContext navigator,
483                         String JavaDoc namespaceURI,
484                         String JavaDoc localName,
485                         String JavaDoc 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    /**
503     * Called when parsing of a new element started.
504     */

505    public Object JavaDoc newChild(MethodParamPartsMapping partsMapping,
506                           UnmarshallingContext navigator,
507                           String JavaDoc namespaceURI,
508                           String JavaDoc localName,
509                           Attributes JavaDoc 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    /**
520     * Called when parsing character is complete.
521     */

522    public void addChild(MethodParamPartsMapping partsMapping,
523                         WsdlMessageMapping msgMapping,
524                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
525    {
526       log.trace("addChild: [obj=" + partsMapping + ",child=" + msgMapping + "]");
527       partsMapping.setWsdlMessageMapping(msgMapping);
528    }
529
530    /**
531     * Called when a new simple child element with text value was read from the XML content.
532     */

533    public void setValue(MethodParamPartsMapping partsMapping,
534                         UnmarshallingContext navigator,
535                         String JavaDoc namespaceURI,
536                         String JavaDoc localName,
537                         String JavaDoc value)
538    {
539       log.trace("setValue: [obj=" + partsMapping + ",value=" + value + "]");
540       if("param-position".equals(localName))
541       {
542          partsMapping.setParamPosition(new Integer JavaDoc(value).intValue());
543       }
544       else if("param-type".equals(localName))
545       {
546          partsMapping.setParamType(value);
547       }
548    }
549
550    /**
551     * Called when a new simple child element with text value was read from the XML content.
552     */

553    public void setValue(WsdlReturnValueMapping retValueMapping,
554                         UnmarshallingContext navigator,
555                         String JavaDoc namespaceURI,
556                         String JavaDoc localName,
557                         String JavaDoc 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    /**
575     * Called when a new simple child element with text value was read from the XML content.
576     */

577    public void setValue(WsdlMessageMapping msgMapping,
578                         UnmarshallingContext navigator,
579                         String JavaDoc namespaceURI,
580                         String JavaDoc localName,
581                         String JavaDoc 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