Source Code Cross Referenced for Methods.java in  » Database-JDBC-Connection-Pool » HA-JDBC » net » sf » hajdbc » util » reflect » 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 JDBC Connection Pool » HA JDBC » net.sf.hajdbc.util.reflect 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * HA-JDBC: High-Availability JDBC
003:         * Copyright (c) 2004-2007 Paul Ferraro
004:         * 
005:         * This library is free software; you can redistribute it and/or modify it 
006:         * under the terms of the GNU Lesser General Public License as published by the 
007:         * Free Software Foundation; either version 2.1 of the License, or (at your 
008:         * option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful, but WITHOUT
011:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
012:         * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
013:         * for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public License
016:         * along with this library; if not, write to the Free Software Foundation, 
017:         * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         * 
019:         * Contact: ferraro@users.sourceforge.net
020:         */
021:        package net.sf.hajdbc.util.reflect;
022:
023:        import java.lang.reflect.InvocationTargetException;
024:        import java.lang.reflect.Method;
025:        import java.sql.SQLException;
026:        import java.util.HashSet;
027:        import java.util.LinkedList;
028:        import java.util.List;
029:        import java.util.Set;
030:        import java.util.regex.Pattern;
031:
032:        import net.sf.hajdbc.util.SQLExceptionFactory;
033:
034:        /**
035:         * @author Paul Ferraro
036:         */
037:        public final class Methods {
038:            /**
039:             * Helper method for <code>Method.invoke(Object, Object...)</code> that performs the necessary exception handling.
040:             * @param method a method to invoke
041:             * @param object the object on which to invoke the given method
042:             * @param parameters the method parameters
043:             * @return the return value of the method invocation
044:             * @throws SQLException the target exception of the method invocation
045:             * @throws IllegalArgumentException if the the underlying method is inaccessible
046:             */
047:            public static Object invoke(Method method, Object object,
048:                    Object... parameters) throws SQLException {
049:                try {
050:                    return method.invoke(object, parameters);
051:                } catch (IllegalAccessException e) {
052:                    throw new IllegalArgumentException(e);
053:                } catch (InvocationTargetException e) {
054:                    throw SQLExceptionFactory.createSQLException(e
055:                            .getTargetException());
056:                }
057:            }
058:
059:            /**
060:             * Returns a set of methods for the specified class whose names match the specified regular expression patterns.
061:             * @param sourceClass the class from which to find methods
062:             * @param patterns regular expression patterns
063:             * @return a set of methods
064:             */
065:            public static Set<Method> findMethods(Class<?> sourceClass,
066:                    String... patterns) {
067:                List<Method> list = new LinkedList<Method>();
068:
069:                Method[] methods = sourceClass.getMethods();
070:
071:                for (String regex : patterns) {
072:                    Pattern pattern = Pattern.compile(regex);
073:
074:                    for (Method method : methods) {
075:                        if (pattern.matcher(method.getName()).matches()) {
076:                            list.add(method);
077:                        }
078:                    }
079:                }
080:
081:                return new HashSet<Method>(list);
082:            }
083:
084:            /**
085:             * Helper method for {@link Class#getMethod(String, Class...)} where method is known to exist.
086:             * @param sourceClass the class from which to find methods
087:             * @param name the method name
088:             * @param types the parameter types
089:             * @return the method with the specified name and parameter types
090:             * @throws IllegalArgumentException if no such method exists
091:             */
092:            public static Method getMethod(Class<?> sourceClass, String name,
093:                    Class<?>... types) {
094:                try {
095:                    return sourceClass.getMethod(name, types);
096:                } catch (NoSuchMethodException e) {
097:                    throw new IllegalArgumentException(e);
098:                }
099:            }
100:
101:            /**
102:             * Helper method for {@link Class#getMethod(String, Class...)} that returns null if the method does not exist.
103:             * @param sourceClass the class from which to find methods
104:             * @param name the method name
105:             * @param types the parameter types
106:             * @return the method with the specified name and parameter types, or null if the method does not exist
107:             */
108:            public static Method findMethod(Class<?> sourceClass, String name,
109:                    Class<?>... types) {
110:                try {
111:                    return sourceClass.getMethod(name, types);
112:                } catch (NoSuchMethodException e) {
113:                    return null;
114:                }
115:            }
116:
117:            /**
118:             * Helper method for {@link Class#getMethod(String, Class...)} that returns null if the class or method does not exist.
119:             * @param className the name of the class containing the method
120:             * @param name the method name
121:             * @param types the parameter types
122:             * @return the method with the specified name and parameter types, or null if the class or method does not exist
123:             */
124:            public static Method findMethod(String className, String name,
125:                    Class<?>... types) {
126:                try {
127:                    return findMethod(Class.forName(className), name, types);
128:                } catch (ClassNotFoundException e) {
129:                    return null;
130:                }
131:            }
132:
133:            private Methods() {
134:                // Hide constructor
135:            }
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.