Source Code Cross Referenced for EnumType.java in  » Database-ORM » Ammentos » it » biobytes » ammentos » fieldtypes » 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 » Database ORM » Ammentos » it.biobytes.ammentos.fieldtypes 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   Copyright 2006 Davide Deidda
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:
017:        package it.biobytes.ammentos.fieldtypes;
018:
019:        import it.biobytes.ammentos.Field;
020:        import it.biobytes.ammentos.FieldType;
021:        import it.biobytes.ammentos.PersistenceException;
022:
023:        import java.lang.reflect.InvocationTargetException;
024:        import java.lang.reflect.Method;
025:        import java.sql.PreparedStatement;
026:        import java.sql.ResultSet;
027:        import java.sql.SQLException;
028:        import java.sql.Types;
029:
030:        /**
031:         * <P>Enum specific field type. This field type can encapsulate any java enum
032:         * constants.</P>
033:         * 
034:         * @author Mark Bednarczyk
035:         */
036:        public class EnumType implements  FieldType {
037:
038:            private Class mappedClass;
039:            private Method valueOfMethod;
040:            private Method valuesMethod;
041:
042:            public EnumType(Class mappedClass) throws Exception {
043:                this .mappedClass = mappedClass;
044:
045:                if (mappedClass.isEnum() == false) {
046:                    throw new IllegalArgumentException("mappedClass "
047:                            + mappedClass
048:                            + " needs to be declared using enum statement");
049:                }
050:
051:                valueOfMethod = mappedClass.getDeclaredMethod("valueOf",
052:                        String.class);
053:                valuesMethod = mappedClass.getDeclaredMethod("values");
054:            }
055:
056:            public void setParamValue(Object fieldValue,
057:                    PreparedStatement pstmt, int paramIndex)
058:                    throws SQLException {
059:                pstmt.setString(paramIndex, fieldValue.toString());
060:            }
061:
062:            /**
063:             * <P>Method which invokes the Enum.valueOf(String) static method.
064:             * All enums support this static method.</P>
065:             * @param str string value to be converted into an enum using the
066:             * Enum.valueOf(String) method.
067:             * 
068:             * @return a new instance of the object. Since these are enum singleton 
069:             * class, this is a globally shared instance of the enum instance.
070:             */
071:            private Object valueOf(String str) {
072:                try {
073:                    return valueOfMethod.invoke(null, str);
074:
075:                } catch (SecurityException e) {
076:                    // TODO Auto-generated catch block
077:                    e.printStackTrace();
078:                } catch (IllegalArgumentException e) {
079:                    // TODO Auto-generated catch block
080:                    e.printStackTrace();
081:                } catch (IllegalAccessException e) {
082:                    // TODO Auto-generated catch block
083:                    e.printStackTrace();
084:                } catch (InvocationTargetException e) {
085:                    // TODO Auto-generated catch block
086:                    e.printStackTrace();
087:                }
088:
089:                return null;
090:            }
091:
092:            /**
093:             * <P>Method which invokes the Enum.valueOf(String) static method.
094:             * All enums support this static method.</P>
095:             * @param str string value to be converted into an enum using the
096:             * Enum.valueOf(String) method.
097:             * 
098:             * @return a new instance of the object. Since these are enum singleton 
099:             * class, this is a globally shared instance of the enum instance.
100:             */
101:            private Object[] values() {
102:                try {
103:                    return (Object[]) valuesMethod.invoke(null);
104:
105:                } catch (SecurityException e) {
106:                    // TODO Auto-generated catch block
107:                    e.printStackTrace();
108:                } catch (IllegalArgumentException e) {
109:                    // TODO Auto-generated catch block
110:                    e.printStackTrace();
111:                } catch (IllegalAccessException e) {
112:                    // TODO Auto-generated catch block
113:                    e.printStackTrace();
114:                } catch (InvocationTargetException e) {
115:                    // TODO Auto-generated catch block
116:                    e.printStackTrace();
117:                }
118:
119:                return null;
120:            }
121:
122:            public Object loadValue(ResultSet rs, Field field)
123:                    throws SQLException {
124:                return valueOf(rs.getString(field.getName()));
125:            }
126:
127:            public Object parseValue(String stringValue)
128:                    throws PersistenceException {
129:                return valueOf(stringValue);
130:            }
131:
132:            public String formatValue(Object format) {
133:                return format.toString();
134:            }
135:
136:            public Object generateValue() throws PersistenceException {
137:                return new PersistenceException(
138:                        "unable to generate automatic value for enum type of "
139:                                + mappedClass);
140:            }
141:
142:            public boolean isNumeric() {
143:                return false;
144:            }
145:
146:            public Object[] getPossibleValues() {
147:                return values();
148:            }
149:
150:            public Class getMappedClass() {
151:                return this .mappedClass;
152:            }
153:
154:            public Object addValues(Object arg0, Object arg1) {
155:                return null;
156:            }
157:
158:            public int getSqlType() {
159:                return Types.VARCHAR;
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.