KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > wsdl > builder > wsdl4j > WSDL1ToWOMBuilder


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis2.wsdl.builder.wsdl4j;
17
18 import org.apache.axis2.wsdl.WSDLVersionWrapper;
19 import org.apache.axis2.wsdl.builder.WOMBuilder;
20 import org.apache.axis2.wsdl.builder.WSDLComponentFactory;
21 import org.apache.wsdl.WSDLDescription;
22 import org.apache.wsdl.impl.WSDLDescriptionImpl;
23 import org.apache.wsdl.util.Utils;
24 import org.w3c.dom.Document JavaDoc;
25 import org.xml.sax.SAXException JavaDoc;
26
27 import javax.wsdl.Definition;
28 import javax.wsdl.WSDLException;
29 import javax.wsdl.factory.WSDLFactory;
30 import javax.wsdl.xml.WSDLReader;
31 import javax.xml.parsers.ParserConfigurationException JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.InputStream JavaDoc;
34
35 /**
36  * @author chathura@opensource.lk
37  */

38 public class WSDL1ToWOMBuilder implements WOMBuilder {
39
40     public WSDLVersionWrapper build(InputStream JavaDoc in) throws WSDLException {
41
42         WSDLDescription wsdlDescription = new WSDLDescriptionImpl();
43
44         Definition wsdl1Definition = this.readInTheWSDLFile(in);
45         WSDLPump pump = new WSDLPump(wsdlDescription, wsdl1Definition);
46         pump.pump();
47
48         return new WSDLVersionWrapper(wsdlDescription, wsdl1Definition);
49     }
50     
51     public WSDLVersionWrapper build (InputStream JavaDoc in, WSDLComponentFactory wsdlComponentFactory) throws WSDLException{
52         WSDLDescription wsdlDescription = wsdlComponentFactory.createDescription();
53
54         Definition wsdl1Definition = this.readInTheWSDLFile(in);
55         WSDLPump pump = new WSDLPump(wsdlDescription, wsdl1Definition, wsdlComponentFactory);
56         pump.pump();
57
58         return new WSDLVersionWrapper(wsdlDescription, wsdl1Definition);
59         
60     }
61
62     private Definition readInTheWSDLFile(InputStream JavaDoc in) throws WSDLException {
63
64         WSDLReader reader =
65                 WSDLFactory.newInstance().newWSDLReader();
66         Document JavaDoc doc;
67         try {
68             doc = Utils.newDocument(in);
69         } catch (ParserConfigurationException JavaDoc e) {
70             throw new WSDLException(WSDLException.PARSER_ERROR, "Parser Configuration Error", e);
71         } catch (SAXException JavaDoc e) {
72             throw new WSDLException(WSDLException.PARSER_ERROR, "Parser SAX Error", e);
73
74         } catch (IOException JavaDoc e) {
75             throw new WSDLException(WSDLException.INVALID_WSDL, "IO Error", e);
76         }
77
78         return reader.readWSDL(null, doc);
79     }
80
81
82 }
83
Popular Tags