Source Code Cross Referenced for NumberPropertyEditor.java in  » Testing » DDSteps » org » ddsteps » 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 » DDSteps » org.ddsteps.beans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* NumberPropertyEditor.java
002:         * 
003:         * DDSteps - Data Driven JUnit Test Steps
004:         * Copyright (C) 2005 Jayway AB
005:         * www.ddsteps.org
006:         * 
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License version 2.1 as published by the Free Software Foundation.
010:         * 
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         * 
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, visit 
018:         * http://www.opensource.org/licenses/lgpl-license.php
019:         */
020:
021:        package org.ddsteps.beans;
022:
023:        import java.text.NumberFormat;
024:
025:        import org.springframework.beans.propertyeditors.CustomNumberEditor;
026:
027:        /**
028:         * @author adam
029:         * @version $Id: NumberPropertyEditor.java,v 1.1 2005/12/03 12:51:41 adamskogman Exp $
030:         */
031:        public class NumberPropertyEditor extends CustomNumberEditor {
032:
033:            /**
034:             * The target class. Don't you just hate it when fields are private, not
035:             * protected, and there is no getter. Not even a protected getter... So we
036:             * duplicate it here.
037:             */
038:            protected final Class targetClass;
039:
040:            /**
041:             * @param numberClass
042:             *            The TARGET class.
043:             * @param allowEmpty
044:             * @throws IllegalArgumentException
045:             */
046:            public NumberPropertyEditor(Class numberClass, boolean allowEmpty)
047:                    throws IllegalArgumentException {
048:                super (numberClass, allowEmpty);
049:                this .targetClass = numberClass;
050:
051:            }
052:
053:            /**
054:             * @param numberClass
055:             *            The TARGET class.
056:             * @param numberFormat
057:             * @param allowEmpty
058:             * @throws IllegalArgumentException
059:             */
060:            public NumberPropertyEditor(Class numberClass,
061:                    NumberFormat numberFormat, boolean allowEmpty)
062:                    throws IllegalArgumentException {
063:                super (numberClass, numberFormat, allowEmpty);
064:                this .targetClass = numberClass;
065:            }
066:
067:            /**
068:             * Adds Number to Number conversions.
069:             * 
070:             * Spring says to do this (read the comments in BeanWrapperImpl), if you
071:             * want to do Object to Object conversions, and not go through a String.
072:             * 
073:             * In this case, we handle all kinds of Numbers (that is native and wrappers
074:             * for byte, short, ..., long, float and double.
075:             * 
076:             * @see java.beans.PropertyEditor#setValue(java.lang.Object)
077:             */
078:            public void setValue(Object value) {
079:
080:                if (value instanceof  Number) {
081:                    Number number = (Number) value;
082:
083:                    // This smells. Long if-else alsways smells. Someday, this will go
084:                    // away. Or else we'll have to make it do so... :-)
085:
086:                    // OK, it's a number, so let's use the conversion methods
087:                    // in the java.lang.Number base class.
088:
089:                    // We don't need to check for the native types (int, long...)
090:                    // since the target class is always a Wrapper type.
091:                    if (targetClass == Integer.class) {
092:                        value = new Integer(number.intValue());
093:                    } else if (targetClass == Long.class) {
094:                        value = new Long(number.longValue());
095:                    } else if (targetClass == Float.class) {
096:                        value = new Float(number.floatValue());
097:                    } else if (targetClass == Double.class) {
098:                        value = new Double(number.doubleValue());
099:                    } else if (targetClass == Short.class) {
100:                        value = new Short(number.shortValue());
101:                    } else if (targetClass == Byte.class) {
102:                        value = new Byte(number.byteValue());
103:                    }
104:                }
105:
106:                super.setValue(value);
107:            }
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.