Source Code Cross Referenced for ShortLocaleConverter.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 java.util.Locale;
021:        import java.text.ParseException;
022:        import org.apache.commons.beanutils.ConversionException;
023:
024:        /**
025:         * <p>Standard {@link org.apache.commons.beanutils.locale.LocaleConverter} 
026:         * implementation that converts an incoming
027:         * locale-sensitive String into a <code>java.lang.Short</code> object,
028:         * optionally using a default value or throwing a 
029:         * {@link org.apache.commons.beanutils.ConversionException}
030:         * if a conversion error occurs.</p>
031:         *
032:         * @author Yauheny Mikulski
033:         */
034:
035:        public class ShortLocaleConverter extends DecimalLocaleConverter {
036:
037:            // ----------------------------------------------------------- Constructors
038:
039:            /**
040:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
041:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
042:             * if a conversion error occurs. The locale is the default locale for
043:             * this instance of the Java Virtual Machine and an unlocalized pattern is used
044:             * for the convertion.
045:             *
046:             */
047:            public ShortLocaleConverter() {
048:
049:                this (false);
050:            }
051:
052:            /**
053:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
054:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
055:             * if a conversion error occurs. The locale is the default locale for
056:             * this instance of the Java Virtual Machine.
057:             *
058:             * @param locPattern    Indicate whether the pattern is localized or not
059:             */
060:            public ShortLocaleConverter(boolean locPattern) {
061:
062:                this (Locale.getDefault(), locPattern);
063:            }
064:
065:            /**
066:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
067:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
068:             * if a conversion error occurs. An unlocalized pattern is used for the convertion.
069:             *
070:             * @param locale        The locale
071:             */
072:            public ShortLocaleConverter(Locale locale) {
073:
074:                this (locale, false);
075:            }
076:
077:            /**
078:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
079:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
080:             * if a conversion error occurs.
081:             *
082:             * @param locale        The locale
083:             * @param locPattern    Indicate whether the pattern is localized or not
084:             */
085:            public ShortLocaleConverter(Locale locale, boolean locPattern) {
086:
087:                this (locale, (String) null, locPattern);
088:            }
089:
090:            /**
091:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
092:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
093:             * if a conversion error occurs. An unlocalized pattern is used for the convertion.
094:             *
095:             * @param locale        The locale
096:             * @param pattern       The convertion pattern
097:             */
098:            public ShortLocaleConverter(Locale locale, String pattern) {
099:
100:                this (locale, pattern, false);
101:            }
102:
103:            /**
104:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
105:             * that will throw a {@link org.apache.commons.beanutils.ConversionException}
106:             * if a conversion error occurs.
107:             *
108:             * @param locale        The locale
109:             * @param pattern       The convertion pattern
110:             * @param locPattern    Indicate whether the pattern is localized or not
111:             */
112:            public ShortLocaleConverter(Locale locale, String pattern,
113:                    boolean locPattern) {
114:
115:                super (locale, pattern, locPattern);
116:            }
117:
118:            /**
119:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
120:             * that will return the specified default value
121:             * if a conversion error occurs. The locale is the default locale for
122:             * this instance of the Java Virtual Machine and an unlocalized pattern is used
123:             * for the convertion.
124:             *
125:             * @param defaultValue  The default value to be returned
126:             */
127:            public ShortLocaleConverter(Object defaultValue) {
128:
129:                this (defaultValue, false);
130:            }
131:
132:            /**
133:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
134:             * that will return the specified default value
135:             * if a conversion error occurs. The locale is the default locale for
136:             * this instance of the Java Virtual Machine.
137:             *
138:             * @param defaultValue  The default value to be returned
139:             * @param locPattern    Indicate whether the pattern is localized or not
140:             */
141:            public ShortLocaleConverter(Object defaultValue, boolean locPattern) {
142:
143:                this (defaultValue, Locale.getDefault(), locPattern);
144:            }
145:
146:            /**
147:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
148:             * that will return the specified default value
149:             * if a conversion error occurs. An unlocalized pattern is used for the convertion.
150:             *
151:             * @param defaultValue  The default value to be returned
152:             * @param locale        The locale
153:             */
154:            public ShortLocaleConverter(Object defaultValue, Locale locale) {
155:
156:                this (defaultValue, locale, false);
157:            }
158:
159:            /**
160:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
161:             * that will return the specified default value
162:             * if a conversion error occurs.
163:             *
164:             * @param defaultValue  The default value to be returned
165:             * @param locale        The locale
166:             * @param locPattern    Indicate whether the pattern is localized or not
167:             */
168:            public ShortLocaleConverter(Object defaultValue, Locale locale,
169:                    boolean locPattern) {
170:
171:                this (defaultValue, locale, null, locPattern);
172:            }
173:
174:            /**
175:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
176:             * that will return the specified default value
177:             * if a conversion error occurs. An unlocalized pattern is used for the convertion.
178:             *
179:             * @param defaultValue  The default value to be returned
180:             * @param locale        The locale
181:             * @param pattern       The convertion pattern
182:             */
183:            public ShortLocaleConverter(Object defaultValue, Locale locale,
184:                    String pattern) {
185:
186:                this (defaultValue, locale, pattern, false);
187:            }
188:
189:            /**
190:             * Create a {@link org.apache.commons.beanutils.locale.LocaleConverter} 
191:             * that will return the specified default value
192:             * if a conversion error occurs.
193:             *
194:             * @param defaultValue  The default value to be returned
195:             * @param locale        The locale
196:             * @param pattern       The convertion pattern
197:             * @param locPattern    Indicate whether the pattern is localized or not
198:             */
199:            public ShortLocaleConverter(Object defaultValue, Locale locale,
200:                    String pattern, boolean locPattern) {
201:
202:                super (defaultValue, locale, pattern, locPattern);
203:            }
204:
205:            /**
206:             * Convert the specified locale-sensitive input object into an output object of the
207:             * specified type. This method will return values of type Short.
208:             *
209:             * @param value The input object to be converted
210:             * @param pattern The pattern is used for the convertion
211:             * @return The converted value
212:             *
213:             * @exception org.apache.commons.beanutils.ConversionException if conversion cannot be performed
214:             *  successfully
215:             * @throws ParseException if an error occurs parsing a String to a Number
216:             */
217:            protected Object parse(Object value, String pattern)
218:                    throws ParseException {
219:
220:                Object result = super .parse(value, pattern);
221:
222:                if (result == null || result instanceof  Short) {
223:                    return result;
224:                }
225:
226:                Number parsed = (Number) result;
227:                if (parsed.longValue() != parsed.shortValue()) {
228:                    throw new ConversionException(
229:                            "Supplied number is not of type Short: "
230:                                    + parsed.longValue());
231:                }
232:
233:                // now returns property Short
234:                return new Short(parsed.shortValue());
235:            }
236:
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.