KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > wsdl > builder > WOMBuilderFactory


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;
17
18 import org.apache.axis2.wsdl.builder.wsdl4j.WSDL1ToWOMBuilder;
19 import org.apache.wsdl.WSDLConstants;
20 import org.apache.wsdl.util.Utils;
21 import org.w3c.dom.Document JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23
24 import javax.wsdl.WSDLException;
25 import javax.xml.parsers.ParserConfigurationException JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.InputStream JavaDoc;
28
29 /**
30  * @author chathura@opensource.lk
31  */

32 public class WOMBuilderFactory {
33
34     public static final int WSDL11 = 1;
35     public static final int wsdl20 = 2;
36
37
38     public static WOMBuilder getBuilder(int wsdlDocumentType) throws WSDLException {
39
40         if (wsdlDocumentType == WSDL11) {
41             return new WSDL1ToWOMBuilder();
42         }
43         if (wsdlDocumentType == wsdl20) {
44             return new WSDL2ToWOMBuilder();
45         }
46         throw new WSDLException(WSDLException.INVALID_WSDL, "The document type specified is not valid");
47     }
48
49
50     public static WOMBuilder getBuilder(InputStream JavaDoc in) throws WSDLException {
51         // Load the wsdl as a DOM
52
Document JavaDoc doc;
53         try {
54             doc = Utils.newDocument(in);
55         } catch (ParserConfigurationException JavaDoc e) {
56             throw new WSDLException(WSDLException.PARSER_ERROR, "Parser Configuration Exception", e);
57         } catch (IOException JavaDoc e1) {
58             throw new WSDLException(WSDLException.PARSER_ERROR, "WSDL Document read error", e1);
59         } catch (SAXException JavaDoc e2) {
60             throw new WSDLException(WSDLException.PARSER_ERROR, "Parser Exception", e2);
61         }
62         
63         
64         //Check the target namespace of the WSDL and determine the WSDL version.
65
int version = getWSDLVersion(doc);
66
67         if (version == WSDL11) {
68             return (WOMBuilder) new WSDL1ToWOMBuilder();
69         } else if (version == wsdl20) {
70             return (WOMBuilder) new WSDL2ToWOMBuilder();
71         }
72
73         throw new WSDLException(WSDLException.OTHER_ERROR, "Unable to Figure out the WSDL vesion of the Document");
74     }
75
76     /**
77      * Will return an int that will represent the wsdl version and the int will correspond to the static
78      * variables defined in this class.
79      *
80      * @param doc
81      * @return
82      * @throws WSDLException If the version cannot be determined
83      */

84     private static int getWSDLVersion(Document JavaDoc doc) throws WSDLException {
85         //TODO check weather the namespaces are correct and the / problem too
86
if (WSDLConstants.WSDL2_0_NAMESPACE.equals(doc.getDocumentElement().getNamespaceURI())) {
87             return wsdl20;
88         } else if (WSDLConstants.WSDL1_1_NAMESPACE.equals(doc.getDocumentElement().getNamespaceURI())) {
89             return WSDL11;
90         }
91
92         throw new WSDLException(WSDLException.OTHER_ERROR, "Unable to Figure out the WSDL vesion of the Document");
93     }
94 }
95
Popular Tags