Source Code Cross Referenced for ConstructorUtil.java in  » Database-JDBC-Connection-Pool » Connection-Pool-DBCP » org » apache » commons » jocl » 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 » Connection Pool DBCP » org.apache.commons.jocl 
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.jocl;
019:
020:        import java.lang.reflect.Constructor;
021:        import java.lang.reflect.InvocationTargetException;
022:
023:        /**
024:         * Miscellaneous {@link Constructor} related utility functions.
025:         *
026:         * @author Rodney Waldhoff
027:         * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
028:         */
029:        public class ConstructorUtil {
030:            /**
031:             * Returns a {@link Constructor} for the given method signature, or <tt>null</tt>
032:             * if no such <tt>Constructor</tt> can be found.
033:             *
034:             * @param type     the (non-<tt>null</tt>) type of {@link Object} the returned {@link Constructor} should create
035:             * @param argTypes a non-<tt>null</tt> array of types describing the parameters to the {@link Constructor}.
036:             * @return a {@link Constructor} for the given method signature, or <tt>null</tt>
037:             *         if no such <tt>Constructor</tt> can be found.
038:             * @see #invokeConstructor
039:             */
040:            public static Constructor getConstructor(Class type,
041:                    Class[] argTypes) {
042:                if (null == type || null == argTypes) {
043:                    throw new NullPointerException();
044:                }
045:                Constructor ctor = null;
046:                try {
047:                    ctor = type.getConstructor(argTypes);
048:                } catch (Exception e) {
049:                    ctor = null;
050:                }
051:                if (null == ctor) {
052:                    // no directly declared matching constructor,
053:                    // look for something that will work
054:                    // XXX this should really be more careful to
055:                    //     adhere to the jls mechanism for late binding
056:                    Constructor[] ctors = type.getConstructors();
057:                    for (int i = 0; i < ctors.length; i++) {
058:                        Class[] paramtypes = ctors[i].getParameterTypes();
059:                        if (paramtypes.length == argTypes.length) {
060:                            boolean canuse = true;
061:                            for (int j = 0; j < paramtypes.length; j++) {
062:                                if (paramtypes[j].isAssignableFrom(argTypes[j])) {
063:                                    continue;
064:                                } else {
065:                                    canuse = false;
066:                                    break;
067:                                }
068:                            }
069:                            if (canuse == true) {
070:                                ctor = ctors[i];
071:                                break;
072:                            }
073:                        }
074:                    }
075:                }
076:                return ctor;
077:            }
078:
079:            /**
080:             * Creates a new instance of the specified <tt><i>type</i></tt>
081:             * using a {@link Constructor} described by the given parameter types
082:             * and values.
083:             *
084:             * @param type      the type of {@link Object} to be created
085:             * @param argTypes  a non-<tt>null</tt> array of types describing the parameters to the {@link Constructor}.
086:             * @param argValues a non-<tt>null</tt> array containing the values of the parameters to the {@link Constructor}.
087:             * @return a new instance of the specified <tt><i>type</i></tt>
088:             *         using a {@link Constructor} described by the given parameter types
089:             *         and values.
090:             * @exception InstantiationException
091:             * @exception IllegalAccessException
092:             * @exception InvocationTargetException
093:             */
094:            public static Object invokeConstructor(Class type,
095:                    Class[] argTypes, Object[] argValues)
096:                    throws InstantiationException, IllegalAccessException,
097:                    InvocationTargetException {
098:                return ConstructorUtil.getConstructor(type, argTypes)
099:                        .newInstance(argValues);
100:            }
101:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.