Source Code Cross Referenced for WSDLGenerator.java in  » IDE-Netbeans » sql.project » org » netbeans » modules » sql » project » wsdl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » sql.project » org.netbeans.modules.sql.project.wsdl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * The contents of this file are subject to the terms of the Common Development
0003:         * and Distribution License (the License). You may not use this file except in
0004:         * compliance with the License.
0005:         * 
0006:         * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
0007:         * or http://www.netbeans.org/cddl.txt.
0008:         * 
0009:         * When distributing Covered Code, include this CDDL Header Notice in each file
0010:         * and include the License file at http://www.netbeans.org/cddl.txt.
0011:         * If applicable, add the following below the CDDL Header, with the fields
0012:         * enclosed by brackets [] replaced by your own identifying information:
0013:         * "Portions Copyrighted [year] [name of copyright owner]"
0014:         * 
0015:         * The Original Software is NetBeans. The Initial Developer of the Original
0016:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0017:         * Microsystems, Inc. All Rights Reserved.
0018:         */
0019:
0020:        /*
0021:         *                 Sun Public License Notice
0022:         *
0023:         * The contents of this file are subject to the Sun Public License
0024:         * Version 1.0 (the "License"). You may not use this file except in
0025:         * compliance with the License. A copy of the License is available at
0026:         * http://www.sun.com/
0027:         *
0028:         * The Original Code is NetBeans. The Initial Developer of the Original
0029:         * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
0030:         * Microsystems, Inc. All Rights Reserved.
0031:         */
0032:
0033:        package org.netbeans.modules.sql.project.wsdl;
0034:
0035:        import org.netbeans.modules.sql.project.dbmodel.DBMetaData;
0036:        import org.netbeans.modules.sql.project.dbmodel.PrepStmt;
0037:        import org.netbeans.modules.sql.project.dbmodel.ResultSetColumn;
0038:        import org.netbeans.modules.sql.project.dbmodel.ResultSetColumns;
0039:        import org.netbeans.modules.sql.project.dbmodel.Parameter;
0040:        import org.netbeans.modules.sql.project.dbmodel.Procedure;
0041:
0042:        import org.netbeans.api.db.explorer.DatabaseConnection;
0043:
0044:        import java.util.logging.Logger;
0045:        import java.util.logging.Level;
0046:        import java.util.List;
0047:        import java.util.Iterator;
0048:        import java.util.HashMap;
0049:        import java.util.Map;
0050:        import java.util.StringTokenizer;
0051:
0052:        import java.net.URL;
0053:        import java.net.URI;
0054:        import java.io.FileInputStream;
0055:        import java.io.FileNotFoundException;
0056:        import java.io.FileOutputStream;
0057:        import java.io.InputStream;
0058:        import java.io.OutputStream;
0059:        import java.io.Writer;
0060:        import java.io.FileWriter;
0061:        import java.io.IOException;
0062:        import java.io.PrintWriter;
0063:        import java.io.File;
0064:        import java.io.BufferedReader;
0065:        import java.io.FileReader;
0066:        import java.sql.Connection;
0067:
0068:        import javax.swing.JOptionPane;
0069:        import javax.swing.JFrame;
0070:        import javax.wsdl.extensions.soap.SOAPAddress;
0071:        import javax.wsdl.extensions.soap.SOAPBinding;
0072:
0073:        import javax.wsdl.factory.WSDLFactory;
0074:        import javax.wsdl.xml.WSDLWriter;
0075:        import javax.wsdl.xml.WSDLReader;
0076:        import javax.wsdl.Definition;
0077:        import javax.wsdl.WSDLException;
0078:        import javax.wsdl.Types;
0079:        import javax.wsdl.PortType;
0080:        import javax.wsdl.Service;
0081:        import javax.wsdl.Port;
0082:        import javax.wsdl.Message;
0083:        import javax.wsdl.Part;
0084:        import javax.wsdl.Operation;
0085:        import javax.wsdl.Input;
0086:        import javax.wsdl.Output;
0087:        import javax.wsdl.Binding;
0088:        import javax.wsdl.BindingOperation;
0089:        import javax.wsdl.BindingInput;
0090:        import javax.wsdl.BindingOutput;
0091:        import javax.wsdl.extensions.schema.Schema;
0092:        import javax.wsdl.extensions.UnknownExtensibilityElement;
0093:        import javax.xml.namespace.QName;
0094:        import javax.xml.parsers.DocumentBuilderFactory;
0095:        import javax.xml.parsers.ParserConfigurationException;
0096:        import javax.xml.transform.TransformerFactory;
0097:        import javax.xml.transform.Transformer;
0098:        import javax.xml.transform.OutputKeys;
0099:        import javax.xml.transform.dom.DOMSource;
0100:        import javax.xml.transform.stream.StreamResult;
0101:
0102:        import org.w3c.dom.Element;
0103:        import org.w3c.dom.NodeList;
0104:        import org.w3c.dom.Node;
0105:        import org.w3c.dom.Document;
0106:        import org.xml.sax.SAXException;
0107:        import org.openide.util.NbBundle;
0108:
0109:        public class WSDLGenerator {
0110:
0111:            public static HashMap builtInTypes = new HashMap();
0112:            private static Logger logger = Logger.getLogger(WSDLGenerator.class
0113:                    .getName());
0114:            private static WSDLFactory factory;
0115:            private static DocumentBuilderFactory docBuilderfactory;
0116:
0117:            private Definition def;
0118:            private DBMetaData dbmeta;
0119:            private String sqlFileName;
0120:            private List sqlFileList = null;
0121:            private String schema;
0122:            private String wsdlFileLocation;
0123:            private String engineFileName;
0124:            private Document doc;
0125:            private String STATEMENT_TYPE = null;
0126:            private String wsdlFileName = null;
0127:            private boolean wsdlFileExsits = false;
0128:            private Connection conn;
0129:            private DatabaseConnection dbConn;
0130:            private JFrame frame;
0131:            private static final String SELECT_STATEMENT = "SELECT";
0132:            private static final String INSERT_STATEMENT = "INSERT";
0133:            private static final String UPDATE_STATEMENT = "UPDATE";
0134:            private static final String DELETE_STATEMENT = "DELETE";
0135:            private static final String DDL_STATEMENT_CREATE = "CREATE";
0136:            private static final String DDL_STATEMENT_ALTER = "ALTER";
0137:            private static final String DDL_STATEMENT_DROP = "DROP";
0138:            private static final String TRUNCATE_STATEMENT = "TRUNCATE";
0139:            private static final String PROC_STATEMENT = "EXEC";
0140:
0141:            static {
0142:                builtInTypes.put("byte[]", "xsd:base64Binary");
0143:                builtInTypes.put("boolean", "xsd:boolean");
0144:                builtInTypes.put("byte", "xsd:byte");
0145:                builtInTypes.put("java.util.Calendar", "xsd:dateTime");
0146:                builtInTypes.put("java.math.BigDecimal", "xsd:decimal");
0147:                builtInTypes.put("double", "xsd:double");
0148:                builtInTypes.put("float", "xsd:float");
0149:                builtInTypes.put("byte[]", "xsd:hexBinary");
0150:                builtInTypes.put("int", "xsd:int");
0151:                builtInTypes.put("java.math.BigInteger", "xsd:integer");
0152:                builtInTypes.put("long", "xsd:long");
0153:                builtInTypes.put("javax.xml.namespace.QName", "xsd:QName");
0154:                builtInTypes.put("short", "xsd:short");
0155:                builtInTypes.put("java.lang.String", "xsd:string");
0156:                builtInTypes.put("java.sql.Time", "xsd:string");
0157:                builtInTypes.put("java.sql.Timestamp", "xsd:string");
0158:                builtInTypes.put("java.sql.Date", "xsd:string");
0159:
0160:                // temporary for demo
0161:                builtInTypes.put("java.sql.Blob", "xsd:string");
0162:                builtInTypes.put("java.sql.Clob", "xsd:string");
0163:                //added by abey for Procedure with parameter of type RefCursor
0164:                builtInTypes.put("java.sql.ResultSet", "xsd:ResultSet");
0165:
0166:            }
0167:
0168:            static {
0169:                initFactory();
0170:            }
0171:
0172:            /**
0173:             * Constructor
0174:             * @param dbmeta
0175:             * @param sqlFile
0176:             * @param wsdlFileLocation
0177:             */
0178:            public WSDLGenerator(DBMetaData dbmeta, String sqlFile,
0179:                    String wsdlFileLocation, String engineFileName) {
0180:                this .dbmeta = dbmeta;
0181:                this .sqlFileName = sqlFile;
0182:                this .wsdlFileLocation = wsdlFileLocation;
0183:                this .engineFileName = engineFileName.substring(0,
0184:                        engineFileName.indexOf(".xml"));
0185:            }
0186:
0187:            public WSDLGenerator(Connection conn, List sqlFiles,
0188:                    String wsdlFileName, String wsdlFileLocation,
0189:                    String engineFileName) {
0190:                this .conn = conn;
0191:                this .sqlFileList = sqlFiles;
0192:                this .wsdlFileLocation = wsdlFileLocation;
0193:                this .wsdlFileName = wsdlFileName;
0194:                this .engineFileName = engineFileName.substring(0,
0195:                        engineFileName.indexOf(".xml"));
0196:            }
0197:
0198:            /**
0199:             * initialize the WSDLFactory
0200:             */
0201:            private static void initFactory() {
0202:                if (factory == null) {
0203:                    try {
0204:                        factory = WSDLFactory.newInstance();
0205:                        docBuilderfactory = DocumentBuilderFactory
0206:                                .newInstance();
0207:                    } catch (WSDLException wsdle) {
0208:                        logger.log(Level.WARNING, wsdle.getMessage(), wsdle);
0209:                    }
0210:                }
0211:            }
0212:
0213:            /**
0214:             * reads an sqlpro wsdl template file and genarates the javax.wsdl.Definition
0215:             *
0216:             * @return Definition
0217:             * @throws WSDLException
0218:             */
0219:            private Definition getWsdlTemplate() throws WSDLException,
0220:                    ParserConfigurationException, SAXException, IOException {
0221:                Definition def = null;
0222:                try {
0223:                    URL u = WSDLGenerator.class
0224:                            .getResource("sqlpro.wsdl.template");
0225:                    if (u != null) {
0226:                        String wsdlURI = u.getFile().indexOf(".jar") > 0 ? "jar:"
0227:                                + u.getFile()
0228:                                : u.getFile();
0229:                        def = readWSDLFile(wsdlURI);
0230:
0231:                    } else {
0232:                        logger.log(Level.WARNING,
0233:                                "Unable to locate the wsdl template");
0234:                    }
0235:                } catch (WSDLException e) {
0236:                    logger.log(Level.SEVERE, e.getMessage(), e);
0237:                    throw e;
0238:                } catch (ParserConfigurationException e) {
0239:                    logger.log(Level.SEVERE, e.getMessage(), e);
0240:                    throw e;
0241:                } catch (SAXException e) {
0242:                    logger.log(Level.SEVERE, e.getMessage(), e);
0243:                    throw e;
0244:                } catch (IOException e) {
0245:                    logger.log(Level.SEVERE, e.getMessage(), e);
0246:                    throw e;
0247:                }
0248:                return def;
0249:            }
0250:
0251:            private Definition readWSDLFile(String wsdlURI)
0252:                    throws SAXException, IOException,
0253:                    ParserConfigurationException, WSDLException {
0254:                WSDLReader reader = factory.newWSDLReader();
0255:                Definition def;
0256:                docBuilderfactory.setNamespaceAware(true);
0257:                docBuilderfactory.setValidating(false);
0258:                doc = docBuilderfactory.newDocumentBuilder().parse(wsdlURI);
0259:                def = reader.readWSDL(wsdlURI, doc);
0260:                return def;
0261:            }
0262:
0263:            public Definition generateWSDL() throws Exception {
0264:                try {
0265:                    //wsdlFileName = wsdlFileLocation + "/" + sqlFileName + ".wsdl";
0266:                    File f1 = new File(wsdlFileLocation + File.separator
0267:                            + wsdlFileName + ".wsdl");
0268:                    File f2 = new File(wsdlFileLocation + File.separator
0269:                            + wsdlFileName + ".wsdl_old");
0270:                    if (f1.exists()) {
0271:                        try {
0272:                            InputStream in = new FileInputStream(f1);
0273:                            OutputStream out = new FileOutputStream(f2);
0274:                            byte[] buf = new byte[1024];
0275:                            int len;
0276:                            while ((len = in.read(buf)) > 0) {
0277:                                out.write(buf, 0, len);
0278:                            }
0279:                            in.close();
0280:                            out.close();
0281:                            System.out.println("File copied.");
0282:                        } catch (FileNotFoundException ex) {
0283:                            logger.log(Level.WARNING, ex.getMessage(), ex);
0284:                        } catch (IOException e) {
0285:                            logger.log(Level.WARNING, e.getMessage(), e);
0286:                        }
0287:                    }
0288:                    this .def = getWsdlTemplate();
0289:                    modifyWSDL();
0290:                    writeWsdl();
0291:                } catch (Exception e) {
0292:                    logger.log(Level.SEVERE, e.getMessage(), e);
0293:                    throw e;
0294:                }
0295:                return def;
0296:            }
0297:
0298:            private Definition loadExistingWSDLFile(String wsdlFileName) {
0299:                try {
0300:                    URI f = new File(wsdlFileLocation + File.separator
0301:                            + wsdlFileName + ".wsdl").toURI();
0302:                    Definition def = readWSDLFile(f.getPath());
0303:                    return def;
0304:                } catch (Exception mfe) {
0305:                    logger.log(Level.SEVERE,
0306:                            "Unable to load existing wsdl file " + wsdlFileName
0307:                                    + " Reason: " + mfe.getLocalizedMessage());
0308:                }
0309:                return null;
0310:            }
0311:
0312:            /**
0313:             * modify the wsdl template
0314:             */
0315:            private void modifyWSDL() throws Exception {
0316:                try {
0317:                    modifyName();
0318:
0319:                    if (sqlFileList != null) {
0320:                        for (int i = 0; i < sqlFileList.size(); i++) {
0321:                            File f = (File) sqlFileList.get(i);
0322:                            sqlFileName = f.getName().trim().substring(0,
0323:                                    f.getName().indexOf(".sql"));
0324:                            modifyMessageTypes(f);
0325:                            createMessages();
0326:                            PortType pt = createPortType();
0327:                            Binding binding = createBinding(pt);
0328:                            modifyServices(binding);
0329:                        }
0330:                        modifyPartnerLink();
0331:                    }
0332:                } catch (Exception e) {
0333:                    logger.log(Level.SEVERE, e.getLocalizedMessage());
0334:                    throw e;
0335:                }
0336:            }
0337:
0338:            private void modifyName() {
0339:                QName q = def.getQName();
0340:                q = new QName(q.getNamespaceURI(), wsdlFileName);
0341:                def.setQName(q);
0342:            }
0343:
0344:            private void modifyMessageTypes(File sqlFile) throws Exception {
0345:                try {
0346:                    Element currRequest = null;
0347:                    Element currResponse = null;
0348:
0349:                    //Read sql file.
0350:                    BufferedReader reader = new BufferedReader(new FileReader(
0351:                            sqlFile));
0352:                    String line = null;
0353:                    StringBuffer sqlText = new StringBuffer();
0354:                    while ((line = reader.readLine()) != null) {
0355:                        if (sqlText.length() != 0) {
0356:                            sqlText.append("\n");
0357:                        }
0358:                        sqlText.append(line);
0359:                    }
0360:                    dbmeta = new DBMetaData(conn, sqlText.toString());
0361:                    logger.log(Level.INFO, "SQL Statement is:["
0362:                            + dbmeta.getSQLText() + "]");
0363:                    parseSQLStatement(sqlText.toString());
0364:                    Types types = def.getTypes();
0365:
0366:                    if (null != types) {
0367:                        List schemaList = types.getExtensibilityElements();
0368:                        for (Iterator iterator1 = schemaList.iterator(); iterator1
0369:                                .hasNext();) {
0370:                            Object o = iterator1.next();
0371:                            if (o instanceof  Schema) {
0372:                                Schema schemaType = (Schema) o;
0373:                                Element e = schemaType.getElement();
0374:                                currRequest = getElementByName(e, sqlFileName
0375:                                        + "Request");
0376:                                if (currRequest == null) {
0377:                                    currRequest = createElementWithComplexType(sqlFileName
0378:                                            + "Request");
0379:                                }
0380:                                if (STATEMENT_TYPE != null) {
0381:                                    if (STATEMENT_TYPE
0382:                                            .equalsIgnoreCase(SELECT_STATEMENT)) {
0383:                                        currResponse = getElementByName(e,
0384:                                                sqlFileName + "Response");
0385:                                        if (currResponse == null) {
0386:                                            currResponse = createElementWithComplexType(sqlFileName
0387:                                                    + "Response");
0388:                                        }
0389:                                        generateSelectSchemaElements(
0390:                                                currRequest, currResponse);
0391:                                    } else if (STATEMENT_TYPE
0392:                                            .equalsIgnoreCase(INSERT_STATEMENT)) {
0393:                                        currResponse = getElementByName(e,
0394:                                                sqlFileName + "Response");
0395:                                        removeSchemaElements(currRequest,
0396:                                                currResponse);
0397:                                        if (currResponse == null) {
0398:                                            currResponse = createElement(
0399:                                                    "numRowsEffected",
0400:                                                    "xsd:int");
0401:                                        }
0402:                                        currResponse = getElementByName(e,
0403:                                                "numRowsEffected");
0404:                                        if (currResponse == null) {
0405:                                            currResponse = createElement(
0406:                                                    "numRowsEffected",
0407:                                                    "xsd:int");
0408:                                        }
0409:                                        generateInsertSchemaElements(
0410:                                                currRequest, currResponse);
0411:                                    } else if (STATEMENT_TYPE
0412:                                            .equalsIgnoreCase(UPDATE_STATEMENT)) {
0413:                                        currResponse = getElementByName(e,
0414:                                                sqlFileName + "Response");
0415:                                        removeSchemaElements(currRequest,
0416:                                                currResponse);
0417:                                        if (currResponse == null) {
0418:                                            currResponse = createElement(
0419:                                                    "numRowsEffected",
0420:                                                    "xsd:int");
0421:                                        }
0422:                                        currResponse = getElementByName(e,
0423:                                                "numRowsEffected");
0424:                                        if (currResponse == null) {
0425:                                            currResponse = createElement(
0426:                                                    "numRowsEffected",
0427:                                                    "xsd:int");
0428:                                        }
0429:                                        generateInsertSchemaElements(
0430:                                                currRequest, currResponse);
0431:                                    } else if (STATEMENT_TYPE
0432:                                            .equalsIgnoreCase(DELETE_STATEMENT)) {
0433:                                        currResponse = getElementByName(e,
0434:                                                sqlFileName + "Response");
0435:                                        removeSchemaElements(currRequest,
0436:                                                currResponse);
0437:                                        if (currResponse == null) {
0438:                                            currResponse = createElement(
0439:                                                    "numRowsEffected",
0440:                                                    "xsd:int");
0441:                                        }
0442:                                        currResponse = getElementByName(e,
0443:                                                "numRowsEffected");
0444:                                        if (currResponse == null) {
0445:                                            currResponse = createElement(
0446:                                                    "numRowsEffected",
0447:                                                    "xsd:int");
0448:                                        }
0449:                                        generateInsertSchemaElements(
0450:                                                currRequest, currResponse);
0451:                                    } else if (STATEMENT_TYPE
0452:                                            .equalsIgnoreCase(DDL_STATEMENT_CREATE)) {
0453:                                        currResponse = getElementByName(e,
0454:                                                sqlFileName + "Response");
0455:                                        removeSchemaElements(currRequest,
0456:                                                currResponse);
0457:                                        if (currResponse == null) {
0458:                                            currResponse = createElement(
0459:                                                    "numRowsEffected",
0460:                                                    "xsd:int");
0461:                                        }
0462:                                        currResponse = getElementByName(e,
0463:                                                "numRowsEffected");
0464:                                        if (currResponse == null) {
0465:                                            currResponse = createElement(
0466:                                                    "numRowsEffected",
0467:                                                    "xsd:int");
0468:                                        }
0469:                                        generateCreateSchemaElements(
0470:                                                currRequest, currResponse);
0471:                                    } else if (STATEMENT_TYPE
0472:                                            .equalsIgnoreCase(DDL_STATEMENT_ALTER)) {
0473:                                        currResponse = getElementByName(e,
0474:                                                sqlFileName + "Response");
0475:                                        removeSchemaElements(currRequest,
0476:                                                currResponse);
0477:                                        if (currResponse == null) {
0478:                                            currResponse = createElement(
0479:                                                    "numRowsEffected",
0480:                                                    "xsd:int");
0481:                                        }
0482:                                        currResponse = getElementByName(e,
0483:                                                "numRowsEffected");
0484:                                        if (currResponse == null) {
0485:                                            currResponse = createElement(
0486:                                                    "numRowsEffected",
0487:                                                    "xsd:int");
0488:                                        }
0489:                                        generateAlterSchemaElements(
0490:                                                currRequest, currResponse);
0491:                                    } else if (STATEMENT_TYPE
0492:                                            .equalsIgnoreCase(DDL_STATEMENT_DROP)) {
0493:                                        currResponse = getElementByName(e,
0494:                                                sqlFileName + "Response");
0495:                                        removeSchemaElements(currRequest,
0496:                                                currResponse);
0497:                                        if (currResponse == null) {
0498:                                            currResponse = createElement(
0499:                                                    "numRowsEffected",
0500:                                                    "xsd:int");
0501:                                        }
0502:                                        currResponse = getElementByName(e,
0503:                                                "numRowsEffected");
0504:                                        if (currResponse == null) {
0505:                                            currResponse = createElement(
0506:                                                    "numRowsEffected",
0507:                                                    "xsd:int");
0508:                                        }
0509:                                        generateDropSchemaElements(currRequest,
0510:                                                currResponse);
0511:                                    } else if (STATEMENT_TYPE
0512:                                            .equalsIgnoreCase(TRUNCATE_STATEMENT)) {
0513:                                        currResponse = getElementByName(e,
0514:                                                sqlFileName + "Response");
0515:                                        removeSchemaElements(currRequest,
0516:                                                currResponse);
0517:                                        if (currResponse == null) {
0518:                                            currResponse = createElement(
0519:                                                    "numRowsEffected",
0520:                                                    "xsd:int");
0521:                                        }
0522:                                        currResponse = getElementByName(e,
0523:                                                "numRowsEffected");
0524:                                        if (currResponse == null) {
0525:                                            currResponse = createElement(
0526:                                                    "numRowsEffected",
0527:                                                    "xsd:int");
0528:                                        }
0529:                                        generateTruncateSchemaElements(
0530:                                                currRequest, currResponse);
0531:                                    } else if (STATEMENT_TYPE
0532:                                            .equalsIgnoreCase(PROC_STATEMENT)) {
0533:                                        currResponse = getElementByName(e,
0534:                                                sqlFileName + "Response");
0535:                                        if (currResponse == null) {
0536:                                            currResponse = createElementWithComplexType(sqlFileName
0537:                                                    + "Response");
0538:                                        }
0539:                                        generateProcSchemaElements(currRequest,
0540:                                                currResponse);
0541:                                    }
0542:                                    e.appendChild(currRequest);
0543:                                    e.appendChild(currResponse);
0544:                                } else {
0545:                                    throw new Exception(
0546:                                            "Unsupported SQL Statement entered: "
0547:                                                    + sqlText);
0548:                                }
0549:
0550:                            } else if (o instanceof  UnknownExtensibilityElement) {
0551:                                //
0552:                            }
0553:                        }
0554:                    }
0555:
0556:                } catch (Exception e) {
0557:                    logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
0558:                    JOptionPane.showMessageDialog(frame, NbBundle.getMessage(
0559:                            WSDLGenerator.class, "LBL_MSG"), "Warning",
0560:                            JOptionPane.WARNING_MESSAGE);
0561:                    throw e;
0562:                }
0563:
0564:            }
0565:
0566:            private void createMessages() {
0567:                QName responseQName = null;
0568:                QName partQName = null;
0569:                Message m = def.createMessage();
0570:                QName qname = new QName(def.getTargetNamespace(), sqlFileName
0571:                        + "Request");
0572:                Part p = def.createPart();
0573:                p.setName(sqlFileName + "RequestPart");
0574:                p.setElementName(qname);
0575:                m.addPart(p);
0576:                m.setQName(qname);
0577:                m.setUndefined(false);
0578:                def.addMessage(m);
0579:                Message mResponse = def.createMessage();
0580:                Part p2 = def.createPart();
0581:
0582:                if (STATEMENT_TYPE.equalsIgnoreCase(SELECT_STATEMENT)
0583:                        || STATEMENT_TYPE.equalsIgnoreCase(PROC_STATEMENT)) {
0584:                    partQName = new QName(def.getTargetNamespace(), sqlFileName
0585:                            + "Response");
0586:                } else if (STATEMENT_TYPE.equalsIgnoreCase(INSERT_STATEMENT)
0587:                        || STATEMENT_TYPE.equalsIgnoreCase(UPDATE_STATEMENT)
0588:                        || STATEMENT_TYPE.equalsIgnoreCase(DELETE_STATEMENT)
0589:                        || STATEMENT_TYPE
0590:                                .equalsIgnoreCase(DDL_STATEMENT_CREATE)
0591:                        || STATEMENT_TYPE.equalsIgnoreCase(DDL_STATEMENT_ALTER)
0592:                        || STATEMENT_TYPE.equalsIgnoreCase(DDL_STATEMENT_DROP)
0593:                        || STATEMENT_TYPE.equalsIgnoreCase(TRUNCATE_STATEMENT)) {
0594:                    partQName = new QName(def.getTargetNamespace(),
0595:                            "numRowsEffected");
0596:                }
0597:                p2.setName(sqlFileName + "ResponsePart");
0598:                p2.setElementName(partQName);
0599:                mResponse.addPart(p2);
0600:                responseQName = new QName(def.getTargetNamespace(), sqlFileName
0601:                        + "Response");
0602:                mResponse.setQName(responseQName);
0603:                mResponse.setUndefined(false);
0604:                def.addMessage(mResponse);
0605:
0606:            }
0607:
0608:            /**
0609:             * this sets the portType name according to the given engine file
0610:             */
0611:            private PortType createPortType() {
0612:                QName qn = new QName(def.getTargetNamespace(), wsdlFileName
0613:                        + "_sqlsePortType");
0614:                PortType pt = def.getPortType(qn);
0615:
0616:                if (pt == null) {
0617:                    pt = def.createPortType();
0618:                    pt.setQName(qn);
0619:                    pt.setUndefined(false);
0620:                    def.addPortType(pt);
0621:                }
0622:                createPortTypeOperations(pt);
0623:                return pt;
0624:            }
0625:
0626:            private void createPortTypeOperations(PortType pt) {
0627:                Operation op = pt.getOperation(sqlFileName, sqlFileName
0628:                        + "Request", sqlFileName + "Response");
0629:                if (op == null) {
0630:                    op = def.createOperation();
0631:                    op.setName(sqlFileName);
0632:                    Input input = def.createInput();
0633:                    Output output = def.createOutput();
0634:                    input.setMessage(getMessageByName(sqlFileName + "Request"));
0635:                    input.setName(sqlFileName + "Request");
0636:                    output
0637:                            .setMessage(getMessageByName(sqlFileName
0638:                                    + "Response"));
0639:                    output.setName(sqlFileName + "Response");
0640:                    op.setInput(input);
0641:                    op.setOutput(output);
0642:                    op.setUndefined(false);
0643:                    pt.addOperation(op);
0644:                }
0645:            }
0646:
0647:            private Binding createBinding(PortType pt) {
0648:                QName qname = new QName(def.getTargetNamespace(), wsdlFileName
0649:                        + "Binding");
0650:                Binding binding = def.getBinding(qname);
0651:                if (binding == null) {
0652:                    binding = def.createBinding();
0653:                    binding.setQName(qname);
0654:                    binding.setUndefined(false);
0655:                    binding.setPortType(pt);
0656:                    def.addBinding(binding);
0657:                } else {
0658:                    PortType pt2 = binding.getPortType();
0659:                    if (pt2.equals(pt)) {
0660:                        BindingOperation bindingOp = binding
0661:                                .getBindingOperation(sqlFileName, sqlFileName
0662:                                        + "Request", sqlFileName + "Response");
0663:                        if (bindingOp != null) {
0664:                            return binding;
0665:                        }
0666:                    } else {
0667:                        binding.setPortType(pt2);
0668:                        pt = pt2;
0669:                    }
0670:                }
0671:
0672:                BindingOperation bo = def.createBindingOperation();
0673:                bo.setName(sqlFileName);
0674:                if (pt != null) {
0675:                    Operation op = pt.getOperation(sqlFileName, sqlFileName
0676:                            + "Request", sqlFileName + "Response");
0677:                    if (op != null) {
0678:                        bo.setOperation(op);
0679:                        BindingInput binput = def.createBindingInput();
0680:                        binput.setName(sqlFileName + "Request");
0681:                        bo.setBindingInput(binput);
0682:                        BindingOutput boutput = def.createBindingOutput();
0683:                        boutput.setName(sqlFileName + "Response");
0684:                        bo.setBindingOutput(boutput);
0685:                        binding.addBindingOperation(bo);
0686:                    }
0687:                }
0688:                return binding;
0689:            }
0690:
0691:            private Message getMessageByName(String messageName) {
0692:                QName qname = new QName("http://com.sun.jbi/sqlse/sqlseengine",
0693:                        messageName);
0694:                return def.getMessage(qname);
0695:            }
0696:
0697:            private void modifyMessageElementName(Message message,
0698:                    String partName, String newElementName) {
0699:                Part part = message.getPart(partName);
0700:                if (part != null) {
0701:                    QName qname = new QName(
0702:                            "http://com.sun.jbi/sqlse/sqlseengine",
0703:                            newElementName);
0704:                    part.setElementName(qname);
0705:                }
0706:            }
0707:
0708:            private void modifyServices(Binding binding) {
0709:                Port p = null;
0710:                QName qname = new QName(def.getTargetNamespace(), wsdlFileName
0711:                        + "_sqlseService");
0712:                Service service = def.getService(qname);
0713:                if (service == null) {
0714:                    service = def.createService();
0715:                    service.setQName(qname);
0716:                    p = def.createPort();
0717:                    p.setBinding(binding);
0718:                    p.setName(wsdlFileName + "_sqlsePort");
0719:                    service.addPort(p);
0720:                    def.addService(service);
0721:                }
0722:            }
0723:
0724:            private void modifyPartnerLink() {
0725:                if (!wsdlFileExsits) {
0726:                    List l = def.getExtensibilityElements();
0727:                    UnknownExtensibilityElement plinkType = (UnknownExtensibilityElement) l
0728:                            .get(0);
0729:                    //set plinkType name
0730:                    plinkType.getElement();
0731:                    String plinkName = plinkType.getElement().getAttribute(
0732:                            "name");
0733:                    plinkType.getElement().setAttribute("name",
0734:                            wsdlFileName + "_" + plinkName);
0735:
0736:                    //set plink:role name and portType
0737:                    NodeList nl = plinkType.getElement().getChildNodes();
0738:                    Element plinkRole = (Element) nl.item(1);
0739:                    plinkRole.setAttribute("name", wsdlFileName + "_"
0740:                            + plinkRole.getAttribute("name"));
0741:
0742:                    String temp = plinkRole.getAttribute("portType").substring(
0743:                            "tns:".length());
0744:                    plinkRole.setAttribute("portType", "tns:" + wsdlFileName
0745:                            + "_" + temp);
0746:                }
0747:
0748:            }
0749:
0750:            private void generateDeleteSchemaElements(Element requestElement,
0751:                    Element responseElement) throws Exception {
0752:                try {
0753:                    PrepStmt prep = dbmeta.getPrepStmtMetaData();
0754:                    if (requestElement != null) {
0755:                        Element sequenceElement = getElementByName(
0756:                                requestElement, "xsd:sequence");
0757:                        if (sequenceElement != null) {
0758:                            if (prep.getNumParameters() > 0) {
0759:                                addPreparedStmtParametersToElement(prep,
0760:                                        sequenceElement);
0761:                            } else {
0762:                                //remove elements under the current requestItem.             
0763:                                NodeList list = sequenceElement.getChildNodes();
0764:                                if (list != null) {
0765:                                    for (int j = list.getLength() - 1; j >= 0; j--) {
0766:                                        sequenceElement.removeChild(list
0767:                                                .item(j));
0768:                                    }
0769:                                }
0770:
0771:                            }
0772:                            //sequenceElement.removeChild(colElem1);
0773:                        }
0774:                    }
0775:                    if (responseElement != null) {
0776:                        Element colElem2 = getElementByName(responseElement,
0777:                                "xsd:sequence");
0778:                        if (colElem2 != null) {
0779:                            addResultSetColumnsToElement(prep, colElem2);
0780:                            //colElem2.getParentNode().removeChild(colElem2);
0781:                        }
0782:                    }
0783:                } catch (Exception e) {
0784:                    logger.log(Level.SEVERE, e.getLocalizedMessage());
0785:                    throw e;
0786:                }
0787:            }
0788:
0789:            private void generateCreateSchemaElements(Element requestElement,
0790:                    Element responseElement) throws Exception {
0791:                try {
0792:                    PrepStmt prep = dbmeta.getPrepStmtMetaData();
0793:                    if (dbmeta.getErrPrepStmtMetaData()) {
0794:                        JOptionPane
0795:                                .showMessageDialog(
0796:                                        frame,
0797:                                        "Problem in generating the message types for WSDL.Update the generated WSDL if needed.Please see the log for more details.",
0798:                                        "Warning", JOptionPane.WARNING_MESSAGE);
0799:                    }
0800:                    if (requestElement != null) {
0801:                        Element sequenceElement = getElementByName(
0802:                                requestElement, "xsd:sequence");
0803:                        if (sequenceElement != null) {
0804:                            if (prep.getNumParameters() > 0) {
0805:                                addPreparedStmtParametersToElement(prep,
0806:                                        sequenceElement);
0807:                            } else {
0808:                                //remove elements under the current requestItem.             
0809:                                NodeList list = sequenceElement.getChildNodes();
0810:                                if (list != null) {
0811:                                    for (int j = list.getLength() - 1; j >= 0; j--) {
0812:                                        sequenceElement.removeChild(list
0813:                                                .item(j));
0814:                                    }
0815:                                }
0816:
0817:                            }
0818:                            //sequenceElement.removeChild(colElem1);
0819:                        }
0820:                    }
0821:                    if (responseElement != null) {
0822:                        Element colElem2 = getElementByName(responseElement,
0823:                                "xsd:sequence");
0824:                        if (colElem2 != null) {
0825:                            addResultSetColumnsToElement(prep, colElem2);
0826:                            //colElem2.getParentNode().removeChild(colElem2);
0827:                        }
0828:                    }
0829:                } catch (Exception e) {
0830:                    logger.log(Level.SEVERE, e.getLocalizedMessage());
0831:                    JOptionPane
0832:                            .showMessageDialog(
0833:                                    frame,
0834:                                    "Problem in generating the message types for WSDL.Update the generated WSDL if needed.Please see the log for more details.",
0835:                                    "Warning", JOptionPane.WARNING_MESSAGE);
0836:                }
0837:            }
0838:
0839:            private void generateAlterSchemaElements(Element requestElement,
0840:                    Element responseElement) throws Exception {
0841:                try {
0842:                    PrepStmt prep = dbmeta.getPrepStmtMetaData();
0843:                    if (dbmeta.getErrPrepStmtMetaData()) {
0844:                        JOptionPane
0845:                                .showMessageDialog(
0846:                                        frame,
0847:                                        "Problem in generating the message types for WSDL.Update the generated WSDL if needed.Please see the log for more details.",
0848:                                        "Warning", JOptionPane.WARNING_MESSAGE);
0849:                    }
0850:                    if (requestElement != null) {
0851:                        Element sequenceElement = getElementByName(
0852:                                requestElement, "xsd:sequence");
0853:                        if (sequenceElement != null) {
0854:                            if (prep.getNumParameters() > 0) {
0855:                                addPreparedStmtParametersToElement(prep,
0856:                                        sequenceElement);
0857:                            } else {
0858:                                //remove elements under the current requestItem.             
0859:                                NodeList list = sequenceElement.getChildNodes();
0860:                                if (list != null) {
0861:                                    for (int j = list.getLength() - 1; j >= 0; j--) {
0862:                                        sequenceElement.removeChild(list
0863:                                                .item(j));
0864:                                    }
0865:                                }
0866:
0867:                            }
0868:                            //sequenceElement.removeChild(colElem1);
0869:                        }
0870:                    }
0871:                    if (responseElement != null) {
0872:                        Element colElem2 = getElementByName(responseElement,
0873:                                "xsd:sequence");
0874:                        if (colElem2 != null) {
0875:                            addResultSetColumnsToElement(prep, colElem2);
0876:                            //colElem2.getParentNode().removeChild(colElem2);
0877:                        }
0878:                    }
0879:                } catch (Exception e) {
0880:                    logger.log(Level.SEVERE, e.getLocalizedMessage());
0881:                    throw e;
0882:                }
0883:            }
0884:
0885:            private void generateDropSchemaElements(Element requestElement,
0886:                    Element responseElement) throws Exception {
0887:                try {
0888:                    PrepStmt prep = dbmeta.getPrepStmtMetaData();
0889:                    if (dbmeta.getErrPrepStmtMetaData()) {
0890:                        JOptionPane
0891:                                .showMessageDialog(
0892:                                        frame,
0893:                                        "Problem in generating the message types for WSDL.Update the generated WSDL if needed.Please see the log for more details.",
0894:                                        "Warning", JOptionPane.WARNING_MESSAGE);
0895:                    }
0896:                    if (requestElement != null) {
0897:                        Element sequenceElement = getElementByName(
0898:                                requestElement, "xsd:sequence");
0899:                        if (sequenceElement != null) {
0900:                            if (prep.getNumParameters() > 0) {
0901:                                addPreparedStmtParametersToElement(prep,
0902:                                        sequenceElement);
0903:                            } else {
0904:                                //remove elements under the current requestItem.             
0905:                                NodeList list = sequenceElement.getChildNodes();
0906:                                if (list != null) {
0907:                                    for (int j = list.getLength() - 1; j >= 0; j--) {
0908:                                        sequenceElement.removeChild(list
0909:                                                .item(j));
0910:                                    }
0911:                                }
0912:
0913:                            }
0914:                            //sequenceElement.removeChild(colElem1);
0915:                        }
0916:                    }
0917:                    if (responseElement != null) {
0918:                        Element colElem2 = getElementByName(responseElement,
0919:                                "xsd:sequence");
0920:                        if (colElem2 != null) {
0921:                            addResultSetColumnsToElement(prep, colElem2);
0922:                            //colElem2.getParentNode().removeChild(colElem2);
0923:                        }
0924:                    }
0925:                } catch (Exception e) {
0926:                    logger.log(Level.SEVERE, e.getLocalizedMessage());
0927:                    throw e;
0928:                }
0929:            }
0930:
0931:            private void generateTruncateSchemaElements(Element requestElement,
0932:                    Element responseElement) throws Exception {
0933:                try {
0934:                    PrepStmt prep = dbmeta.getPrepStmtMetaData();
0935:                    if (dbmeta.getErrPrepStmtMetaData()) {
0936:                        JOptionPane
0937:                                .showMessageDialog(
0938:                                        frame,
0939:                                        "Problem in generating the message types for WSDL.Update the generated WSDL if needed.Please see the log for more details.",
0940:                                        "Warning", JOptionPane.WARNING_MESSAGE);
0941:                    }
0942:                    if (requestElement != null) {
0943:                        Element sequenceElement = getElementByName(
0944:                                requestElement, "xsd:sequence");
0945:                        if (sequenceElement != null) {
0946:                            if (prep.getNumParameters() > 0) {
0947:                                addPreparedStmtParametersToElement(prep,
0948:                                        sequenceElement);
0949:                            } else {
0950:                                //remove elements under the current requestItem.             
0951:                                NodeList list = sequenceElement.getChildNodes();
0952:                                if (list != null) {
0953:                                    for (int j = list.getLength() - 1; j >= 0; j--) {
0954:                                        sequenceElement.removeChild(list
0955:                                                .item(j));
0956:                                    }
0957:                                }
0958:
0959:                            }
0960:                            //sequenceElement.removeChild(colElem1);
0961:                        }
0962:                    }
0963:                    if (responseElement != null) {
0964:                        Element colElem2 = getElementByName(responseElement,
0965:                                "xsd:sequence");
0966:                        if (colElem2 != null) {
0967:                            addResultSetColumnsToElement(prep, colElem2);
0968:                            //colElem2.getParentNode().removeChild(colElem2);
0969:                        }
0970:                    }
0971:                } catch (Exception e) {
0972:                    logger.log(Level.SEVERE, e.getLocalizedMessage());
0973:                    throw e;
0974:                }
0975:            }
0976:
0977:            private void generateInsertSchemaElements(Element requestElement,
0978:                    Element responseElement) throws Exception {
0979:                try {
0980:                    PrepStmt prep = dbmeta.getPrepStmtMetaData();
0981:                    if (dbmeta.getErrPrepStmtMetaData()) {
0982:                        JOptionPane
0983:                                .showMessageDialog(
0984:                                        frame,
0985:                                        "Problem in generating the message types for WSDL.Update the generated WSDL if needed.Please see the log for more details.",
0986:                                        "Warning", JOptionPane.WARNING_MESSAGE);
0987:                    }
0988:                    if (requestElement != null) {
0989:                        Element sequenceElement = getElementByName(
0990:                                requestElement, "xsd:sequence");
0991:                        if (sequenceElement != null) {
0992:                            if (prep.getNumParameters() > 0) {
0993:                                addPreparedStmtParametersToElement(prep,
0994:                                        sequenceElement);
0995:                            } else {
0996:                                //remove elements under the current requestItem.             
0997:                                NodeList list = sequenceElement.getChildNodes();
0998:                                if (list != null) {
0999:                                    for (int j = list.getLength() - 1; j >= 0; j--) {
1000:                                        sequenceElement.removeChild(list
1001:                                                .item(j));
1002:                                    }
1003:                                }
1004:
1005:                            }
1006:                            //sequenceElement.removeChild(colElem1);
1007:                        }
1008:                    }
1009:                    if (responseElement != null) {
1010:                        Element colElem2 = getElementByName(responseElement,
1011:                                "xsd:sequence");
1012:                        if (colElem2 != null) {
1013:                            addResultSetColumnsToElement(prep, colElem2);
1014:                            //colElem2.getParentNode().removeChild(colElem2);
1015:                        }
1016:                    }
1017:                } catch (Exception e) {
1018:                    logger.log(Level.SEVERE, e.getLocalizedMessage());
1019:                    throw e;
1020:                }
1021:            }
1022:
1023:            /**
1024:             * Adds a whereClause to the request element and resultset to the result element.
1025:             * @param requestElement
1026:             * @param responseElement
1027:             * @throws Exception 
1028:             */
1029:            private void generateSelectSchemaElements(Element requestElement,
1030:                    Element responseElement) throws Exception {
1031:                try {
1032:                    PrepStmt prep = dbmeta.getPrepStmtMetaData();
1033:                    if (dbmeta.getErrPrepStmtMetaData()) {
1034:                        JOptionPane
1035:                                .showMessageDialog(
1036:                                        frame,
1037:                                        "Problem in generating the message types for WSDL.Update the generated WSDL if needed.Please see the log for more details.",
1038:                                        "Warning", JOptionPane.WARNING_MESSAGE);
1039:                    }
1040:
1041:                    if (requestElement != null) {
1042:                        Element sequenceElement = getElementByName(
1043:                                requestElement, "xsd:sequence");
1044:                        if (sequenceElement != null) {
1045:                            if (prep.getNumParameters() > 0) {
1046:                                addPreparedStmtParametersToElement(prep,
1047:                                        sequenceElement);
1048:                            } else {
1049:                                //remove elements under the current requestItem.             
1050:                                NodeList list = sequenceElement.getChildNodes();
1051:                                if (list != null) {
1052:                                    for (int j = list.getLength() - 1; j >= 0; j--) {
1053:                                        sequenceElement.removeChild(list
1054:                                                .item(j));
1055:                                    }
1056:                                }
1057:
1058:                            }
1059:                            //sequenceElement.removeChild(colElem1);
1060:                        }
1061:                    }
1062:                    if (responseElement != null) {
1063:                        Element colElem2 = getElementByName(responseElement,
1064:                                "xsd:sequence");
1065:                        if (colElem2 != null) {
1066:                            addResultSetColumnsToElement(prep, colElem2);
1067:                            //colElem2.getParentNode().removeChild(colElem2);
1068:                        }
1069:                    }
1070:                } catch (Exception e) {
1071:                    logger.log(Level.SEVERE, e.getLocalizedMessage());
1072:                    throw e;
1073:                }
1074:            }
1075:
1076:            /**
1077:             * Adds Input parameters to the request element and resultset to the result element.
1078:             * @param requestElement
1079:             * @param responseElement
1080:             * @throws Exception 
1081:             */
1082:            private void generateProcSchemaElements(Element requestElement,
1083:                    Element responseElement) throws Exception {
1084:                try {
1085:                    String catalog = conn.getCatalog();
1086:                    schema = dbConn.getSchema();
1087:                    String procName = getProcName();
1088:                    if (catalog == null) {
1089:                        catalog = "";
1090:                    }
1091:                    Procedure proc = dbmeta.getProcedureMetaData(catalog,
1092:                            schema, procName, "Procedure");
1093:                    if (dbmeta.getErrProcMetaData()) {
1094:                        JOptionPane
1095:                                .showMessageDialog(
1096:                                        frame,
1097:                                        "Problem in generating the message types for WSDL.Update the generated WSDL if needed.Please see the log for more details.",
1098:                                        "Warning", JOptionPane.WARNING_MESSAGE);
1099:                    }
1100:                    if (proc.getHasReturn()) {
1101:                        //dbmeta.getProcResultSetColumns(catalog, schema, procName, "Procedure", proc);
1102:                    }
1103:                    if (requestElement != null) {
1104:                        Element sequenceElement = getElementByName(
1105:                                requestElement, "xsd:sequence");
1106:                        if (sequenceElement != null) {
1107:                            if (proc.getNumParameters() > 0) {
1108:                                addProcedureParametersToElement(proc,
1109:                                        sequenceElement);
1110:                            } else {
1111:                                //remove elements under the current requestItem.             
1112:                                NodeList list = sequenceElement.getChildNodes();
1113:                                if (list != null) {
1114:                                    for (int j = list.getLength() - 1; j >= 0; j--) {
1115:                                        sequenceElement.removeChild(list
1116:                                                .item(j));
1117:                                    }
1118:                                }
1119:
1120:                            }
1121:                            //sequenceElement.removeChild(colElem1);
1122:                        }
1123:                    }
1124:                    if (responseElement != null) {
1125:                        Element colElem2 = getElementByName(responseElement,
1126:                                "xsd:sequence");
1127:                        if (colElem2 != null) {
1128:                            addProcedureResultSetColumnsToElement(proc,
1129:                                    colElem2);
1130:                            //colElem2.getParentNode().removeChild(colElem2);
1131:                        }
1132:                    }
1133:                } catch (Exception e) {
1134:                    logger.log(Level.SEVERE, e.getLocalizedMessage());
1135:                    throw e;
1136:                }
1137:            }
1138:
1139:            /**
1140:             * Given a xml Element and a Prepstmnt object, adds the resultset columns
1141:             * and their types as sub elements.
1142:             * @param prep
1143:             * @param sequenceElement
1144:             */
1145:            private void addResultSetColumnsToElement(PrepStmt prep,
1146:                    Element sequenceElement) throws WSDLException {
1147:                String colType = null;
1148:                if (sequenceElement != null) {
1149:                    NodeList list = sequenceElement.getChildNodes();
1150:                    if (list != null) {
1151:                        for (int j = list.getLength() - 1; j >= 0; j--) {
1152:                            sequenceElement.removeChild(list.item(j));
1153:                        }
1154:                    }
1155:                }
1156:                if (prep != null) {
1157:                    ResultSetColumn[] rs = prep.getResultSetColumns();
1158:                    if (rs != null && rs.length > 0) {
1159:                        for (int i = 0; i < rs.length; i++) {
1160:                            try {
1161:                                colType = rs[i].getJavaType();
1162:                                Element elem = null;
1163:                                if (isBuiltInType(colType)) {
1164:                                    elem = createElement(rs[i].getName(),
1165:                                            (String) WSDLGenerator.builtInTypes
1166:                                                    .get(colType));
1167:                                } else {
1168:                                    throw new WSDLException(
1169:                                            WSDLException.INVALID_WSDL,
1170:                                            "Invalid datatype encountered");
1171:                                }
1172:                                sequenceElement.appendChild(elem);
1173:                            } catch (WSDLException e) {
1174:                                logger.log(Level.SEVERE, e
1175:                                        .getLocalizedMessage());
1176:                                throw new WSDLException(
1177:                                        WSDLException.INVALID_WSDL,
1178:                                        "Check if the sql entered is valid");
1179:                            }
1180:                        }
1181:                    }
1182:                }
1183:            }
1184:
1185:            /**
1186:             * Given a xml Element and a Procedure object, adds the resultset columns
1187:             * and their types as sub elements.
1188:             * @param proc
1189:             * @param sequenceElement
1190:             */
1191:            private void addProcedureResultSetColumnsToElement(Procedure proc,
1192:                    Element sequenceElement) throws WSDLException {
1193:                String colType = null;
1194:                if (sequenceElement != null) {
1195:                    NodeList list = sequenceElement.getChildNodes();
1196:                    if (list != null) {
1197:                        for (int j = list.getLength() - 1; j >= 0; j--) {
1198:                            sequenceElement.removeChild(list.item(j));
1199:                        }
1200:                    }
1201:                }
1202:                if (proc != null) {
1203:                    ResultSetColumns[] rss = proc.getResultSetColumnsArray();
1204:                    for (int j = 0; j < rss.length; j++) {
1205:                        ResultSetColumn rs = rss[j].get(j);
1206:                        if (rs != null) {
1207:                            try {
1208:                                colType = rs.getJavaType();
1209:                                Element elem = null;
1210:                                if (isBuiltInType(colType)) {
1211:                                    elem = createElement(rs.getName(),
1212:                                            (String) WSDLGenerator.builtInTypes
1213:                                                    .get(colType));
1214:                                } else {
1215:                                    throw new WSDLException(
1216:                                            WSDLException.INVALID_WSDL,
1217:                                            "Invalid datatype encountered");
1218:                                }
1219:                                sequenceElement.appendChild(elem);
1220:                            } catch (WSDLException e) {
1221:                                logger.log(Level.SEVERE, e
1222:                                        .getLocalizedMessage());
1223:                                throw new WSDLException(
1224:                                        WSDLException.INVALID_WSDL,
1225:                                        "Check if the sql entered is valid");
1226:                            }
1227:                        }
1228:                    }
1229:
1230:                }
1231:            }
1232:
1233:            /**
1234:             * Adds prepared statement parameters to the element.
1235:             * @param prep
1236:             * @param sequenceElement
1237:             */
1238:            private void addPreparedStmtParametersToElement(PrepStmt prep,
1239:                    Element sequenceElement) {
1240:                if (prep.getNumParameters() > 0) {
1241:                    if (sequenceElement != null) {
1242:                        NodeList list = sequenceElement.getChildNodes();
1243:                        if (list != null) {
1244:                            for (int j = list.getLength() - 1; j >= 0; j--) {
1245:                                sequenceElement.removeChild(list.item(j));
1246:                            }
1247:                        }
1248:                        Parameter[] params = prep.getParameters();
1249:                        for (int i = 0; i < prep.getNumParameters(); i++) {
1250:                            Element elem2 = createElement(params[i].getName(),
1251:                                    (String) WSDLGenerator.builtInTypes
1252:                                            .get(params[i].getJavaType()));
1253:                            sequenceElement.appendChild(elem2);
1254:                        }
1255:
1256:                    }
1257:                }
1258:            }
1259:
1260:            /**
1261:             * Adds Procedure parameters to the element.
1262:             * @param prep
1263:             * @param sequenceElement
1264:             */
1265:            private void addProcedureParametersToElement(Procedure prep,
1266:                    Element sequenceElement) {
1267:                if (prep.getNumParameters() > 0) {
1268:                    if (sequenceElement != null) {
1269:                        NodeList list = sequenceElement.getChildNodes();
1270:                        if (list != null) {
1271:                            for (int j = list.getLength() - 1; j >= 0; j--) {
1272:                                sequenceElement.removeChild(list.item(j));
1273:                            }
1274:                        }
1275:                        Parameter[] params = prep.getParameters();
1276:                        for (int i = 0; i < prep.getNumParameters(); i++) {
1277:                            Element elem2 = createElement(params[i].getName(),
1278:                                    (String) WSDLGenerator.builtInTypes
1279:                                            .get(params[i].getJavaType()));
1280:                            sequenceElement.appendChild(elem2);
1281:                        }
1282:
1283:                    }
1284:                }
1285:            }
1286:
1287:            /**
1288:             * Helper method to return the Element with the name elementName from a 
1289:             * top level element e. The method recursively looks thru sub elements and 
1290:             * returns it once it is found. or a null.
1291:             * @param e
1292:             * @param elementName
1293:             * @return
1294:             */
1295:            private Element getElementByName(Element e, String elementName) {
1296:                if (e.getAttribute("name").equalsIgnoreCase(elementName)) {
1297:                    return e;
1298:                }
1299:                NodeList list = e.getChildNodes();
1300:                Element el = null;
1301:                Element e2 = null;
1302:                for (int i = 0; i < list.getLength(); i++) {
1303:                    if (e2 == null) {
1304:                        Node n = list.item(i);
1305:                        if (n.getNodeType() == Node.ELEMENT_NODE) {
1306:                            el = (Element) n;
1307:                            if ((el.getAttribute("name")
1308:                                    .equalsIgnoreCase(elementName))
1309:                                    || el.getTagName().equalsIgnoreCase(
1310:                                            elementName)
1311:                                    || ((el.getLocalName() != null) && el
1312:                                            .getLocalName().equalsIgnoreCase(
1313:                                                    elementName))) {
1314:                                e2 = el;
1315:                                break;
1316:                            } else {
1317:                                e2 = getElementByName(el, elementName);
1318:                                if ((e2 != null)
1319:                                        && (e2.getAttribute("name")
1320:                                                .equalsIgnoreCase(elementName))) {
1321:                                    return e2;
1322:                                }
1323:                            }
1324:                        }
1325:                    } else {
1326:                        break;
1327:                    }
1328:                }
1329:                return e2;
1330:            }
1331:
1332:            /**
1333:             * Helper method which sets the sql statement type from the sql text.
1334:             * @param sqlText
1335:             */
1336:            private void parseSQLStatement(String sqlText) {
1337:                sqlText = sqlText.trim();
1338:                String modSQLText = sqlText.toUpperCase();
1339:                if (modSQLText.startsWith(SELECT_STATEMENT)) {
1340:                    STATEMENT_TYPE = SELECT_STATEMENT;
1341:                } else if (modSQLText.startsWith(INSERT_STATEMENT)) {
1342:                    STATEMENT_TYPE = INSERT_STATEMENT;
1343:                } else if (modSQLText.startsWith(UPDATE_STATEMENT)) {
1344:                    STATEMENT_TYPE = UPDATE_STATEMENT;
1345:                } else if (modSQLText.startsWith(DELETE_STATEMENT)) {
1346:                    STATEMENT_TYPE = DELETE_STATEMENT;
1347:                } else if (modSQLText.startsWith(TRUNCATE_STATEMENT)) {
1348:                    STATEMENT_TYPE = TRUNCATE_STATEMENT;
1349:                } else if (modSQLText.startsWith(DDL_STATEMENT_CREATE)) {
1350:                    STATEMENT_TYPE = DDL_STATEMENT_CREATE;
1351:                } else if (modSQLText.startsWith(DDL_STATEMENT_ALTER)) {
1352:                    STATEMENT_TYPE = DDL_STATEMENT_ALTER;
1353:                } else if (modSQLText.startsWith(DDL_STATEMENT_DROP)) {
1354:                    STATEMENT_TYPE = DDL_STATEMENT_DROP;
1355:                } else {
1356:                    STATEMENT_TYPE = PROC_STATEMENT;
1357:                }
1358:
1359:            }
1360:
1361:            /**
1362:             * persist the wsdl file to disk
1363:             *
1364:             * @throws WSDLException
1365:             */
1366:            private void writeWsdl() throws WSDLException {
1367:                try {
1368:                    WSDLWriter writer = factory.newWSDLWriter();
1369:                    Writer sink = new FileWriter(wsdlFileLocation
1370:                            + File.separator + wsdlFileName + ".wsdl");
1371:                    writer.writeWSDL(def, sink);
1372:                    logger.log(Level.INFO, "Successfully generated wsdl file:"
1373:                            + wsdlFileName + ".wsdl");
1374:                } catch (Exception e) {
1375:                    throw new WSDLException(WSDLException.OTHER_ERROR, e
1376:                            .getMessage());
1377:                }
1378:
1379:            }
1380:
1381:            private void indentWSDLFile(Writer writer) {
1382:                try {
1383:                    // Use a Transformer for output
1384:                    TransformerFactory tFactory = TransformerFactory
1385:                            .newInstance();
1386:                    Transformer transformer = tFactory.newTransformer();
1387:                    DOMSource source = new DOMSource(doc);
1388:                    PrintWriter pw = new PrintWriter(writer); //USE PRINTWRITER
1389:                    StreamResult result = new StreamResult(pw);
1390:                    transformer.setOutputProperty(OutputKeys.METHOD, "xml"); // NOI18N
1391:                    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // NOI18N
1392:                    transformer.setOutputProperty(OutputKeys.MEDIA_TYPE,
1393:                            "text/xml"); // NOI18N
1394:                    //transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");  // NOI18N
1395:                    // indent the output to make it more legible... 
1396:                    try {
1397:                        transformer.setOutputProperty(
1398:                                "{http://xml.apache.org/xslt}indent-amount",
1399:                                "4"); // NOI18N
1400:                        transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // NOI18N
1401:                    } catch (Exception e) {
1402:                        ; // the JAXP implementation doesn't support indentation, no big deal
1403:                    }
1404:                    transformer.transform(source, result);
1405:                } catch (Exception e) {
1406:                    logger.log(Level.WARNING, "Unable to indent wsdl file "
1407:                            + e.getLocalizedMessage());
1408:                }
1409:
1410:            }
1411:
1412:            /**
1413:             * Check if the column type is a xsd built in type.
1414:             * @param type
1415:             * @return
1416:             */
1417:            public static boolean isBuiltInType(String type) {
1418:                return (builtInTypes.get(type) != null);
1419:            }
1420:
1421:            private Element createElementWithComplexType(String name) {
1422:                Element elem = doc.createElement("xsd:element");
1423:                elem.setAttribute("name", name);
1424:                Element complexType = doc.createElement("xsd:complexType");
1425:                Element sequence = doc.createElement("xsd:sequence");
1426:                complexType.appendChild(sequence);
1427:                elem.appendChild(complexType);
1428:                return elem;
1429:            }
1430:
1431:            private Element createElement(String name, String type) {
1432:                Element elem = doc.createElementNS(
1433:                        "http://www.w3.org/2001/XMLSchema", "xsd:element");
1434:                elem.setAttribute("name", name);
1435:                elem.setAttribute("type", type);
1436:                return elem;
1437:            }
1438:
1439:            private void removeSchemaElements(Element requestElement,
1440:                    Element responseElement) {
1441:                try {
1442:                    if (requestElement != null) {
1443:                        Element sequenceElement = getElementByName(
1444:                                requestElement, "xsd:sequence");
1445:                        if (sequenceElement != null) {
1446:
1447:                            //remove elements under the current requestItem.             
1448:                            NodeList list = sequenceElement.getChildNodes();
1449:                            if (list != null) {
1450:                                for (int j = list.getLength() - 1; j >= 0; j--) {
1451:                                    sequenceElement.removeChild(list.item(j));
1452:                                }
1453:                            }
1454:                            //sequenceElement.removeChild(colElem1);
1455:                        }
1456:                    }
1457:                    if (responseElement != null) {
1458:                        if (responseElement != null) {
1459:                            NodeList list = responseElement.getChildNodes();
1460:                            if (list != null) {
1461:                                for (int j = list.getLength() - 1; j >= 0; j--) {
1462:                                    responseElement.removeChild(list.item(j));
1463:                                }
1464:                            }
1465:                        }
1466:                    }
1467:                } catch (Exception e) {
1468:                    logger.log(Level.SEVERE, e.getLocalizedMessage());
1469:                }
1470:            }
1471:
1472:            public void setDBConnection(DatabaseConnection con) {
1473:                this .dbConn = con;
1474:                this .schema = schema;
1475:            }
1476:
1477:            private String getProcName() {
1478:                String proc_name = "";
1479:                String schema = "";
1480:                final StringTokenizer tok = new StringTokenizer(dbmeta
1481:                        .getSQLText(), " ");
1482:
1483:                while (tok.hasMoreElements()) {
1484:                    String column = (String) tok.nextElement();
1485:                    int cnt = 0;
1486:                    column = column.toLowerCase();
1487:                    if (column.endsWith("call")) {
1488:                        cnt++;
1489:                        proc_name = (String) tok.nextElement();
1490:                        if (proc_name.contains(".")) {
1491:                            final StringTokenizer tok1 = new StringTokenizer(
1492:                                    proc_name, ".");
1493:                            schema = tok1.nextToken();
1494:                            proc_name = tok1.nextToken();
1495:                        }
1496:                        if (proc_name.contains("(")) {
1497:                            int i = proc_name.indexOf("(");
1498:                            proc_name = proc_name.substring(0, i);
1499:                        }
1500:                        if (proc_name.contains("}")) {
1501:                            int i = proc_name.indexOf("}");
1502:                            proc_name = proc_name.substring(0, i);
1503:                        }
1504:                    }
1505:                    if (cnt > 0)
1506:                        break;
1507:                }
1508:                return proc_name;
1509:            }
1510:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.