Source Code Cross Referenced for OutParamHandler.java in  » Testing » sqlunit » net » sourceforge » sqlunit » handlers » 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 » Testing » sqlunit » net.sourceforge.sqlunit.handlers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: OutParamHandler.java,v 1.6 2006/06/25 23:02:50 spal Exp $
003:         * $Source: /cvsroot/sqlunit/sqlunit/src/net/sourceforge/sqlunit/handlers/OutParamHandler.java,v $
004:         * SQLUnit - a test harness for unit testing database stored procedures.
005:         * Copyright (C) 2003  The SQLUnit Team
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) 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
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:        package net.sourceforge.sqlunit.handlers;
022:
023:        import net.sourceforge.sqlunit.HandlerFactory;
024:        import net.sourceforge.sqlunit.IErrorCodes;
025:        import net.sourceforge.sqlunit.IHandler;
026:        import net.sourceforge.sqlunit.SQLUnitException;
027:        import net.sourceforge.sqlunit.beans.OutParam;
028:        import net.sourceforge.sqlunit.beans.ResultSetBean;
029:        import net.sourceforge.sqlunit.beans.StructBean;
030:        import net.sourceforge.sqlunit.utils.XMLUtils;
031:
032:        import org.apache.log4j.Logger;
033:        import org.jdom.Element;
034:
035:        /**
036:         * The OutParamHandler takes the JDOM Element representing the outparam tag 
037:         * and converts it to a OutParam object.
038:         * @author Sujit Pal (spal@users.sourceforge.net)
039:         * @version $Revision: 1.6 $
040:         * @sqlunit.parent name="result" ref="result"
041:         * @sqlunit.element name="outparam"
042:         *  description="The outparam tag is used to represent OUT parameters 
043:         *  returned as a result of a Stored procedure call. The value is 
044:         *  stored in the body text as a String or as a embedded resultset
045:         *  element in case of CURSOR type OUT parameters."
046:         *  syntax="(BODY)|(resultset)|(struct)"
047:         * @sqlunit.attrib name="id"
048:         *  description="The param-id of the outparam parameter."
049:         *  required="Yes"
050:         * @sqlunit.attrib name="name"
051:         *  description="The name of the outparam parameter. This is mainly for 
052:         *  readability to help stored procedure authors/testers to spot errors 
053:         *  quickly."
054:         *  required="No"
055:         * @sqlunit.attrib name="type"
056:         *  description="Specifies the type name of the parameter."
057:         *  required="Yes"
058:         * @sqlunit.child name="resultset"
059:         *  description="This is needed only when the type of the OUT parameter
060:         *  is a CURSOR, and specifies the value of the CURSOR outparam."
061:         *  required="Not if the type is not CURSOR"
062:         *  ref="resultset"
063:         * @sqlunit.example name="A outparam with a INTEGER value"
064:         *  description="
065:         *  <outparam id=\"1\" type=\"INTEGER\">24</outparam>
066:         *  "
067:         * @sqlunit.example name="A outparam tag with an embedded CURSOR"
068:         *  description="
069:         *  <outparam id=\"1\" type=\"oracle.CURSOR\">{\n}
070:         *  {\t}<resultset id=\"1\">{\n}
071:         *  {\t}{\t}<row id=\"1\">{\n}
072:         *  {\t}{\t}{\t}<col id=\"1\" type=\"INTEGER\">7</col>{\n}
073:         *  {\t}{\t}{\t}<col id=\"2\" type=\"VARCHAR\">James Bond</col>{\n}
074:         *  {\t}{\t}{\t}<col id=\"3\" type=\"VARCHAR\">Martini</col>{\n}
075:         *  {\t}{\t}</row>{\n}
076:         *  {\t}</resultset>{\n}
077:         *  </outparam>
078:         *  "
079:         */
080:        public class OutParamHandler implements  IHandler {
081:
082:            private static final Logger LOG = Logger
083:                    .getLogger(OutParamHandler.class);
084:
085:            /**
086:             * Processes the JDOM Element representing the outparam tag returns the
087:             * OutParam object.
088:             * @param elOutParam the JDOM Element representing the outparam tag.
089:             * @return a OutParam object. Client needs to cast to a OutParam.
090:             * @exception Exception if something went wrong processing.
091:             */
092:            public final Object process(final Element elOutParam)
093:                    throws Exception {
094:                LOG.debug(">> process(elOutParam)");
095:                if (elOutParam == null) {
096:                    throw new SQLUnitException(IErrorCodes.ELEMENT_IS_NULL,
097:                            new String[] { "param" });
098:                }
099:                OutParam op = new OutParam();
100:                op.setId(XMLUtils.getAttributeValue(elOutParam, "id"));
101:                op.setName(XMLUtils.getAttributeValue(elOutParam, "name"));
102:                op.setType(XMLUtils.getAttributeValue(elOutParam, "type"));
103:                Element elResultSet = elOutParam.getChild("resultset");
104:                Element elStruct = elOutParam.getChild("struct");
105:                if (elResultSet != null) {
106:                    // contains a resultset bean
107:                    if (!op.getType().endsWith("CURSOR")) {
108:                        throw new SQLUnitException(IErrorCodes.IS_A_CURSOR,
109:                                new String[] { op.getId(), op.getType() });
110:                    }
111:                    IHandler resultSetHandler = HandlerFactory
112:                            .getInstance(elResultSet.getName());
113:                    ResultSetBean rsb = (ResultSetBean) resultSetHandler
114:                            .process(elResultSet);
115:                    op.setValue(rsb);
116:                } else if (elStruct != null) {
117:                    if (!op.getType().endsWith("STRUCT")) {
118:                        throw new SQLUnitException(IErrorCodes.IS_A_STRUCT,
119:                                new String[] { op.getId(), op.getType() });
120:                    }
121:                    IHandler structHandler = HandlerFactory
122:                            .getInstance(elStruct.getName());
123:                    StructBean sb = (StructBean) structHandler
124:                            .process(elStruct);
125:                    op.setValue(sb);
126:                } else {
127:                    // contains a String
128:                    op.setValue(XMLUtils.getText(elOutParam));
129:                }
130:                return op;
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.