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


001:        /*
002:         * $Id: OutParam.java,v 1.9 2006/06/25 23:02:50 spal Exp $
003:         * $Source: /cvsroot/sqlunit/sqlunit/src/net/sourceforge/sqlunit/beans/OutParam.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.beans;
022:
023:        import net.sourceforge.sqlunit.SQLUnitException;
024:        import net.sourceforge.sqlunit.TypeMapper;
025:        import net.sourceforge.sqlunit.types.BigDecimalType;
026:        import net.sourceforge.sqlunit.utils.TypeUtils;
027:
028:        import org.apache.log4j.Logger;
029:        import org.jdom.Element;
030:
031:        /**
032:         * The OutParam models a SQLUnit outparam element.
033:         * @author Sujit Pal (spal@users.sourceforge.net)
034:         * @version $Revision: 1.9 $
035:         */
036:        public class OutParam {
037:
038:            private static final Logger LOG = Logger.getLogger(OutParam.class);
039:
040:            private String id;
041:            private String name;
042:            private String type;
043:            private Object value;
044:
045:            /**
046:             * Default constructor.
047:             */
048:            public OutParam() {
049:                // default constructor
050:            }
051:
052:            /**
053:             * Returns the outparam id.
054:             * @return the param id.
055:             */
056:            public final String getId() {
057:                return id;
058:            }
059:
060:            /**
061:             * Sets the outparam id.
062:             * @param id the param id.
063:             */
064:            public final void setId(final String id) {
065:                this .id = id;
066:            }
067:
068:            /**
069:             * Returns the outparam name.
070:             * @return the outparam name.
071:             */
072:            public final String getName() {
073:                return name;
074:            }
075:
076:            /**
077:             * Sets the outparam name.
078:             * @param name the outparam name.
079:             */
080:            public final void setName(final String name) {
081:                this .name = name;
082:            }
083:
084:            /**
085:             * Returns the outparam type.
086:             * @return the outparam type.
087:             */
088:            public final String getType() {
089:                return type;
090:            }
091:
092:            /**
093:             * Convenience method to return the SQL (numeric) type from the
094:             * supplied (String XML) type.
095:             * @return the SQL Type for this parameter.
096:             * @exception SQLUnitException if one is thrown.
097:             */
098:            public final int getSQLType() throws SQLUnitException {
099:                return TypeUtils.getSqlTypeFromXmlType(type);
100:            }
101:
102:            /**
103:             * Sets the outparam type.
104:             * @param type the outparam type.
105:             */
106:            public final void setType(final String type) {
107:                this .type = type;
108:            }
109:
110:            /**
111:             * Returns the outparam value as a String.
112:             * @return the outparam value.
113:             */
114:            public final String getValue() {
115:                return value.toString();
116:            }
117:
118:            /**
119:             * Sets the param value from a String.
120:             * @param value the param value.
121:             */
122:            public final void setValue(final String value) {
123:                this .value = value;
124:            }
125:
126:            /**
127:             * Sets the outparam value from a ResultSetBean.
128:             * @param value a ResultSetBean object.
129:             */
130:            public final void setValue(final ResultSetBean value) {
131:                this .value = value;
132:            }
133:
134:            /**
135:             * Sets the outparam value from a StructBean.
136:             * @param value a ResultSetBean object.
137:             */
138:            public final void setValue(final StructBean value) {
139:                this .value = value;
140:            }
141:
142:            /**
143:             * Returns true if the outparams are equal.
144:             * @param obj the Object to compare against.
145:             * @return true if the two Objects are equal, false otherwise.
146:             */
147:            public final boolean equals(final Object obj) {
148:                if (!(obj instanceof  OutParam)) {
149:                    return false;
150:                }
151:                OutParam that = (OutParam) obj;
152:                try {
153:                    boolean isTypeEqual = this .getType().equals(that.getType());
154:                    if (isTypeEqual) {
155:                        String className = TypeMapper.findClassById(TypeUtils
156:                                .getSqlTypeFromXmlType(this .getType()));
157:                        // special treatment for BigDecimal, we need to normalize
158:                        // the scales
159:                        if (BigDecimalType.class.getName().equals(className)) {
160:                            return isTypeEqual
161:                                    && TypeUtils.isValueOfBigDecimalEqual(this 
162:                                            .getValue(), that.getValue());
163:                        } else {
164:                            return isTypeEqual
165:                                    && this .getValue().equals(that.getValue());
166:                        }
167:                    } else {
168:                        return false;
169:                    }
170:                } catch (SQLUnitException e) {
171:                    return false;
172:                }
173:            }
174:
175:            /**
176:             * Returns a hashcode for the OutParam object. This is the sum of the
177:             * hashcode for the type and the hashcode for the value.
178:             * @return the hash code for the OutParam object.
179:             */
180:            public final int hashCode() {
181:                return this .getValue().hashCode() + this .getType().hashCode();
182:            }
183:
184:            /**
185:             * Returns the string representation of this object.
186:             * @return the String representation of this object.
187:             */
188:            public final String toString() {
189:                StringBuffer buf = new StringBuffer();
190:                buf.append(getValue()).append("(").append(getType())
191:                        .append(")");
192:                return buf.toString();
193:            }
194:
195:            /**
196:             * Returns a JDOM Element representing this bean.
197:             * @return a JDOM Element representing this bean.
198:             */
199:            public final Element toElement() {
200:                Element elOutParam = new Element("outparam");
201:                elOutParam.setAttribute("id", getId());
202:                if (getName() != null) {
203:                    elOutParam.setAttribute("name", getName());
204:                }
205:                elOutParam.setAttribute("type", getType());
206:                if (value instanceof  ResultSetBean) {
207:                    ResultSetBean rsb = (ResultSetBean) value;
208:                    Element elResultSet = rsb.toElement();
209:                    elOutParam.addContent(elResultSet);
210:                } else if (value instanceof  StructBean) {
211:                    StructBean sb = (StructBean) value;
212:                    Element elStruct = sb.toElement();
213:                    elOutParam.addContent(elStruct);
214:                } else {
215:                    elOutParam.setText(value.toString());
216:                }
217:                return elOutParam;
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.