001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2007 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: Wsdl2Schema.java 6621 2007-04-11 01:08:00Z zjin $
023: */
024:
025: package com.bostechcorp.cbesb.common.wsdl;
026:
027: import java.io.File;
028: import java.util.Iterator;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032:
033: public class Wsdl2Schema {
034:
035: protected static transient Log logger = LogFactory
036: .getLog(Wsdl2Schema.class);
037:
038: /**
039: * @param args
040: */
041: public static void main(String[] args) {
042: File wsdlFile;
043: File destDir;
044: if (args.length != 2) {
045: System.err.println("Usage: Wsdl2Schema wsdlFile destDir");
046: System.exit(-1);
047: }
048: wsdlFile = new File(args[0]);
049: destDir = new File(args[1]);
050: if (!wsdlFile.exists()) {
051: System.err.println("WSDL file does not exist: "
052: + wsdlFile.getAbsolutePath());
053: System.exit(-1);
054: }
055: if (!wsdlFile.isFile()) {
056: System.err.println("Specified WSDL is not a file: "
057: + wsdlFile.getAbsolutePath());
058: System.exit(-1);
059: }
060: if (!destDir.exists()) {
061: System.err.println("Destination does not exist: "
062: + destDir.getAbsolutePath());
063: System.exit(-1);
064: }
065: if (!destDir.isDirectory()) {
066: System.err.println("Destination is not a directory: "
067: + destDir.getAbsolutePath());
068: System.exit(-1);
069: }
070:
071: try {
072: WsdlInfo wsdl = WsdlInfo.load(wsdlFile);
073:
074: System.out.println("Default Location URI = "
075: + wsdl.getDefaultLocationURI());
076: //System.out.println(wsdl.toString());
077:
078: wsdl.saveTypesAsSchemas(destDir);
079:
080: for (Iterator serviceIter = wsdl.getServices().iterator(); serviceIter
081: .hasNext();) {
082: ServiceInfo service = (ServiceInfo) serviceIter.next();
083: for (Iterator portIterator = service.getPorts()
084: .iterator(); portIterator.hasNext();) {
085: PortInfo port = (PortInfo) portIterator.next();
086: for (Iterator operationIter = port.getOperations()
087: .iterator(); operationIter.hasNext();) {
088: OperationInfo operation = (OperationInfo) operationIter
089: .next();
090: File schemaFile = new File(destDir, service
091: .getName()
092: + "_"
093: + port.getName()
094: + "_"
095: + operation.getName() + ".xsd");
096: operation.SaveAsSchema(schemaFile);
097: }
098: }
099:
100: }
101:
102: } catch (Exception e) {
103: logger.error("Exception in main(): " + e.getMessage());
104: if (logger.isDebugEnabled()) {
105: logger.debug("Exception in main():", e);
106: }
107: System.exit(-1);
108: }
109:
110: }
111:
112: }
|