Source Code Cross Referenced for LocaleConverter.java in  » Testing » PolePosition-0.20 » com » versant » core » jdbc » sql » conv » 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 » PolePosition 0.20 » com.versant.core.jdbc.sql.conv 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998 - 2005 Versant Corporation
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         * Versant Corporation - initial API and implementation
010:         */
011:        package com.versant.core.jdbc.sql.conv;
012:
013:        import com.versant.core.jdbc.JdbcConverter;
014:        import com.versant.core.jdbc.JdbcConverterFactory;
015:        import com.versant.core.jdbc.JdbcTypeRegistry;
016:        import com.versant.core.jdbc.metadata.JdbcColumn;
017:
018:        import java.sql.PreparedStatement;
019:        import java.sql.SQLException;
020:        import java.sql.ResultSet;
021:        import java.util.Locale;
022:
023:        import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws-clause
024:
025:        import com.versant.core.common.BindingSupportImpl;
026:
027:        /**
028:         * This converter converts Locale objects to and from SQL. It assumes that
029:         * the Locale is stored in a column compatible with ResultSet.getString and
030:         * PreparedStatement.setString. The Locale is stored as a 4 or 6 character
031:         * String (lang + country [+ variant]).
032:         * @keep-all
033:         */
034:        public class LocaleConverter extends JdbcConverterBase {
035:
036:            public static class Factory extends NoArgJdbcConverterFactory {
037:
038:                private LocaleConverter converter;
039:
040:                /**
041:                 * Create a converter for col using args as parameters. Return null if
042:                 * no converter is required.
043:                 */
044:                public JdbcConverter createJdbcConverter(JdbcColumn col,
045:                        Object args, JdbcTypeRegistry jdbcTypeRegistry) {
046:                    if (converter == null)
047:                        converter = new LocaleConverter();
048:                    return converter;
049:                }
050:
051:            }
052:
053:            /**
054:             * Get the value of col from rs at position index.
055:             * @exception SQLException on SQL errors
056:             * @exception JDOFatalDataStoreException if the ResultSet value is invalid
057:             */
058:            public Object get(ResultSet rs, int index, JdbcColumn col)
059:                    throws SQLException, JDOFatalDataStoreException {
060:                String s = rs.getString(index);
061:                if (s == null)
062:                    return null;
063:                s = s.trim();
064:                if (s.length() == 0)
065:                    return null;
066:                try {
067:                    String lang = s.substring(0, 2);
068:                    String country = null;
069:                    if (s.length() > 2) {
070:                        country = s.substring(2, 4);
071:                    } else {
072:                        country = "";
073:                    }
074:                    String variant = null;
075:                    if (s.length() > 4) {
076:                        variant = s.substring(4, 6);
077:                    } else {
078:                        variant = "";
079:                    }
080:                    return new Locale(lang, country, variant);
081:                } catch (IndexOutOfBoundsException x) {
082:                    throw BindingSupportImpl.getInstance()
083:                            .fatalDatastore(
084:                                    "Invalid Locale value for " + col + ": '"
085:                                            + s + "'", x);
086:                }
087:            }
088:
089:            /**
090:             * Set parameter index on ps to value (for col).
091:             * @exception SQLException on SQL errors
092:             * @exception JDOFatalDataStoreException if value is invalid
093:             */
094:            public void set(PreparedStatement ps, int index, JdbcColumn col,
095:                    Object value) throws SQLException,
096:                    JDOFatalDataStoreException {
097:                if (value == null) {
098:                    ps.setNull(index, col.jdbcType);
099:                } else {
100:                    Locale l = (Locale) value;
101:                    StringBuffer s = new StringBuffer();
102:                    s.append(l.getLanguage());
103:                    s.append(l.getCountry());
104:                    if (col.length >= 6) {
105:                        String v = l.getVariant();
106:                        if (v.length() == 0)
107:                            v = "  ";
108:                        s.append(v);
109:                    }
110:                    ps.setString(index, s.toString());
111:                }
112:            }
113:
114:            /**
115:             * Get the type of our expected value objects (e.g. java.util.Locale
116:             * for a converter for Locale's).
117:             */
118:            public Class getValueType() {
119:                return Locale.class;
120:            }
121:
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.