1 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 ; 22 import org.xml.sax.SAXException ; 23 24 import javax.wsdl.WSDLException; 25 import javax.xml.parsers.ParserConfigurationException ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 29 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 in) throws WSDLException { 51 Document doc; 53 try { 54 doc = Utils.newDocument(in); 55 } catch (ParserConfigurationException e) { 56 throw new WSDLException(WSDLException.PARSER_ERROR, "Parser Configuration Exception", e); 57 } catch (IOException e1) { 58 throw new WSDLException(WSDLException.PARSER_ERROR, "WSDL Document read error", e1); 59 } catch (SAXException e2) { 60 throw new WSDLException(WSDLException.PARSER_ERROR, "Parser Exception", e2); 61 } 62 63 64 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 84 private static int getWSDLVersion(Document doc) throws WSDLException { 85 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 |