Source Code Cross Referenced for JavaBean.java in  » Database-ORM » jaxor-3.5 » net » sourceforge » jaxor » util » 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 » jaxor 3.5 » net.sourceforge.jaxor.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.jaxor.util;
002:
003:        import java.lang.reflect.InvocationTargetException;
004:        import java.lang.reflect.Method;
005:
006:        /*
007:         * User: Mike
008:         * Date: Sep 2, 2003
009:         * Time: 10:12:30 PM
010:         */
011:
012:        public class JavaBean {
013:
014:            private final Object _bean;
015:
016:            public JavaBean(Object bean) {
017:                _bean = bean;
018:            }
019:
020:            public JavaBean(Class clzz) {
021:                try {
022:                    _bean = clzz.newInstance();
023:                } catch (InstantiationException e) {
024:                    throw new SystemException(e);
025:                } catch (IllegalAccessException e) {
026:                    throw new SystemException(e);
027:                }
028:            }
029:
030:            public void add(String propertyName, Object value) {
031:                Method found = findMethod("add" + propertyName);
032:                try {
033:                    found.invoke(_bean, new Object[] { value });
034:                } catch (IllegalAccessException e) {
035:                    throw new SystemException(e);
036:                } catch (IllegalArgumentException e) {
037:                    throw new SystemException(e);
038:                } catch (InvocationTargetException e) {
039:                    throw new SystemException(e);
040:                }
041:            }
042:
043:            public void set(String property, String value) {
044:                Method found = findMethod("set" + property);
045:                Converter converter = this .findConverter(found
046:                        .getParameterTypes()[0]);
047:                try {
048:                    found.invoke(_bean, new Object[] { converter
049:                            .getValue(value) });
050:                } catch (IllegalAccessException e) {
051:                    throw new SystemException(e);
052:                } catch (IllegalArgumentException e) {
053:                    throw new SystemException(e);
054:                } catch (InvocationTargetException e) {
055:                    throw new SystemException(e);
056:                }
057:            }
058:
059:            private Method findMethod(String methodName) {
060:                Method[] methods = _bean.getClass().getMethods();
061:                for (int i = 0; i < methods.length; i++) {
062:                    Method method = methods[i];
063:                    String name = method.getName();
064:                    int length = method.getParameterTypes().length;
065:                    if (name.equalsIgnoreCase(methodName) && length == 1) {
066:                        method.setAccessible(true);
067:                        return method;
068:                    }
069:                }
070:                throw new MethodNotFound(methodName, _bean);
071:            }
072:
073:            public Object get(String propertyName) {
074:                String name = "get" + propertyName;
075:                try {
076:                    Method m = _bean.getClass().getMethod(name, new Class[0]);
077:                    m.setAccessible(true);
078:                    return m.invoke(_bean, new Object[0]);
079:                } catch (NoSuchMethodException e) {
080:                    throw new MethodNotFound(name, _bean);
081:                } catch (SecurityException e) {
082:                    throw new SystemException(e);
083:                } catch (IllegalAccessException e) {
084:                    throw new SystemException(e);
085:                } catch (IllegalArgumentException e) {
086:                    throw new SystemException(e);
087:                } catch (InvocationTargetException e) {
088:                    throw new SystemException(e);
089:                }
090:            }
091:
092:            private Converter findConverter(Class param) {
093:                if (param.equals(String.class))
094:                    return new StringMethod();
095:                if (param.equals(boolean.class) || param.equals(Boolean.class))
096:                    return new BooleanMethod();
097:                if (param.equals(int.class))
098:                    return new IntMethod();
099:                throw new SystemException(
100:                        "Failed to find converter method for class: " + param);
101:            }
102:
103:            public Object getWrappedObject() {
104:                return _bean;
105:            }
106:
107:            private static class IntMethod implements  Converter {
108:                public Object getValue(String value) {
109:                    return new Integer(value);
110:                }
111:            }
112:
113:            private static class BooleanMethod implements  Converter {
114:                public Object getValue(String value) {
115:                    return new Boolean(value);
116:                }
117:            }
118:
119:            private static class StringMethod implements  Converter {
120:                public Object getValue(String value) {
121:                    return value;
122:                }
123:            }
124:
125:            private interface Converter {
126:                Object getValue(String value);
127:            }
128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.