Source Code Cross Referenced for DecimalLocaleConverter.java in  » Library » Apache-commons-beanutils-1.8.0-BETA-src » org » apache » commons » beanutils » locale » converters » 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 » Library » Apache commons beanutils 1.8.0 BETA src » org.apache.commons.beanutils.locale.converters 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.beanutils.locale.converters;
019:
020:        import org.apache.commons.beanutils.locale.BaseLocaleConverter;
021:        import org.apache.commons.logging.Log;
022:        import org.apache.commons.logging.LogFactory;
023:
024:        import java.text.DecimalFormat;
025:        import java.text.ParseException;
026:        import java.util.Locale;
027:
028:        /**
029:         * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter} 
030:         * implementation that converts an incoming
031:         * locale-sensitive String into a <code>java.lang.Number</code> object,
032:         * optionally using a default value or throwing a 
033:         * {@link org.apache.commons.beanutils.ConversionException}
034:         * if a conversion error occurs.</p>
035:         *
036:         * @author Yauheny Mikulski
037:         * @author Yoav Shapira
038:         * @since 1.7
039:         */
040:
041:        public class DecimalLocaleConverter extends BaseLocaleConverter {
042:
043:            // ----------------------------------------------------- Instance Variables
044:
045:            /** All logging goes through this logger */
046:            private Log log = LogFactory.getLog(DecimalLocaleConverter.class);
047:
048:            // ----------------------------------------------------------- Constructors
049:
050:            /**
051:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
052:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
053:             * if a conversion error occurs. The locale is the default locale for
054:             * this instance of the Java Virtual Machine and an unlocalized pattern is used
055:             * for the convertion.
056:             *
057:             */
058:            public DecimalLocaleConverter() {
059:
060:                this (false);
061:            }
062:
063:            /**
064:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
065:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
066:             * if a conversion error occurs. The locale is the default locale for
067:             * this instance of the Java Virtual Machine.
068:             *
069:             * @param locPattern    Indicate whether the pattern is localized or not
070:             */
071:            public DecimalLocaleConverter(boolean locPattern) {
072:
073:                this (Locale.getDefault(), locPattern);
074:            }
075:
076:            /**
077:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
078:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
079:             * if a conversion error occurs. An unlocalized pattern is used for the convertion.
080:             *
081:             * @param locale        The locale
082:             */
083:            public DecimalLocaleConverter(Locale locale) {
084:
085:                this (locale, false);
086:            }
087:
088:            /**
089:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
090:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
091:             * if a conversion error occurs.
092:             *
093:             * @param locale        The locale
094:             * @param locPattern    Indicate whether the pattern is localized or not
095:             */
096:            public DecimalLocaleConverter(Locale locale, boolean locPattern) {
097:
098:                this (locale, (String) null, locPattern);
099:            }
100:
101:            /**
102:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
103:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
104:             * if a conversion error occurs. An unlocalized pattern is used for the convertion.
105:             *
106:             * @param locale        The locale
107:             * @param pattern       The convertion pattern
108:             */
109:            public DecimalLocaleConverter(Locale locale, String pattern) {
110:
111:                this (locale, pattern, false);
112:            }
113:
114:            /**
115:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
116:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
117:             * if a conversion error occurs.
118:             *
119:             * @param locale        The locale
120:             * @param pattern       The convertion pattern
121:             * @param locPattern    Indicate whether the pattern is localized or not
122:             */
123:            public DecimalLocaleConverter(Locale locale, String pattern,
124:                    boolean locPattern) {
125:
126:                super (locale, pattern, locPattern);
127:            }
128:
129:            /**
130:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
131:             * that will return the specified default value
132:             * if a conversion error occurs. The locale is the default locale for
133:             * this instance of the Java Virtual Machine and an unlocalized pattern is used
134:             * for the convertion.
135:             *
136:             * @param defaultValue  The default value to be returned
137:             */
138:            public DecimalLocaleConverter(Object defaultValue) {
139:
140:                this (defaultValue, false);
141:            }
142:
143:            /**
144:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
145:             * that will return the specified default value
146:             * if a conversion error occurs. The locale is the default locale for
147:             * this instance of the Java Virtual Machine.
148:             *
149:             * @param defaultValue  The default value to be returned
150:             * @param locPattern    Indicate whether the pattern is localized or not
151:             */
152:            public DecimalLocaleConverter(Object defaultValue,
153:                    boolean locPattern) {
154:
155:                this (defaultValue, Locale.getDefault(), locPattern);
156:            }
157:
158:            /**
159:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
160:             * that will return the specified default value
161:             * if a conversion error occurs. An unlocalized pattern is used for the convertion.
162:             *
163:             * @param defaultValue  The default value to be returned
164:             * @param locale        The locale
165:             */
166:            public DecimalLocaleConverter(Object defaultValue, Locale locale) {
167:
168:                this (defaultValue, locale, false);
169:            }
170:
171:            /**
172:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
173:             * that will return the specified default value
174:             * if a conversion error occurs.
175:             *
176:             * @param defaultValue  The default value to be returned
177:             * @param locale        The locale
178:             * @param locPattern    Indicate whether the pattern is localized or not
179:             */
180:            public DecimalLocaleConverter(Object defaultValue, Locale locale,
181:                    boolean locPattern) {
182:
183:                this (defaultValue, locale, null, locPattern);
184:            }
185:
186:            /**
187:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
188:             * that will return the specified default value
189:             * if a conversion error occurs. An unlocalized pattern is used for the convertion.
190:             *
191:             * @param defaultValue  The default value to be returned
192:             * @param locale        The locale
193:             * @param pattern       The convertion pattern
194:             */
195:            public DecimalLocaleConverter(Object defaultValue, Locale locale,
196:                    String pattern) {
197:
198:                this (defaultValue, locale, pattern, false);
199:            }
200:
201:            /**
202:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
203:             * that will return the specified default value
204:             * if a conversion error occurs.
205:             *
206:             * @param defaultValue  The default value to be returned
207:             * @param locale        The locale
208:             * @param pattern       The convertion pattern
209:             * @param locPattern    Indicate whether the pattern is localized or not
210:             */
211:            public DecimalLocaleConverter(Object defaultValue, Locale locale,
212:                    String pattern, boolean locPattern) {
213:
214:                super (defaultValue, locale, pattern, locPattern);
215:
216:            }
217:
218:            // --------------------------------------------------------- Methods
219:
220:            /**
221:             * Convert the specified locale-sensitive input object into an output 
222:             * object of the specified type.
223:             *
224:             * @param value The input object to be converted
225:             * @param pattern The pattern is used for the convertion
226:             * @return The converted value
227:             *
228:             * @exception org.apache.commons.beanutils.ConversionException if conversion
229:             * cannot be performed successfully
230:             * @throws ParseException if an error occurs parsing a String to a Number
231:             */
232:            protected Object parse(Object value, String pattern)
233:                    throws ParseException {
234:
235:                if (value instanceof  Number) {
236:                    return value;
237:                }
238:
239:                // Note that despite the ambiguous "getInstance" name, and despite the
240:                // fact that objects returned from this method have the same toString
241:                // representation, each call to getInstance actually returns a new
242:                // object.
243:                DecimalFormat formatter = (DecimalFormat) DecimalFormat
244:                        .getInstance(locale);
245:
246:                // if some constructors default pattern to null, it makes only sense 
247:                // to handle null pattern gracefully
248:                if (pattern != null) {
249:                    if (locPattern) {
250:                        formatter.applyLocalizedPattern(pattern);
251:                    } else {
252:                        formatter.applyPattern(pattern);
253:                    }
254:                } else {
255:                    log.info("No pattern provided, using default.");
256:                }
257:
258:                return formatter.parse((String) value);
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.