Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / iapi / services / loader / ClassInfo.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/services/loader/ClassInfo.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/services/loader/ClassInfo.java
new file mode 100644 (file)
index 0000000..59f523f
--- /dev/null
@@ -0,0 +1,117 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.services.loader.ClassInfo\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.iapi.services.loader;\r
+\r
+import java.lang.reflect.Constructor;\r
+import java.lang.reflect.InvocationTargetException;\r
+\r
+public class ClassInfo implements InstanceGetter {\r
+\r
+       private static final Class[] noParameters = new Class[0];\r
+       private static final Object[] noArguments = new Object[0];\r
+\r
+       private final Class clazz;\r
+       private boolean useConstructor = true;\r
+       private Constructor noArgConstructor;\r
+\r
+       public ClassInfo(Class clazz) {\r
+               this.clazz = clazz;\r
+       }\r
+\r
+       /**\r
+               Return the name of this class.\r
+       */\r
+       public final String getClassName() {\r
+               return clazz.getName();\r
+       }\r
+\r
+       /**\r
+               Return the class object for this class.\r
+\r
+       */\r
+       public final Class getClassObject() {\r
+\r
+               return clazz;\r
+       }\r
+\r
+       /**\r
+               Create an instance of this class. Assumes that clazz has already been\r
+               initialized. Optimizes Class.newInstance() by caching and using the\r
+               no-arg Constructor directly. Class.newInstance() looks up the constructor\r
+               each time.\r
+\r
+               @exception InstantiationException Zero arg constructor can not be executed\r
+               @exception IllegalAccessException Class or zero arg constructor is not public.\r
+               @exception InvocationTargetException Exception throw in zero-arg constructor.\r
+\r
+       */\r
+       \r
+//     public Object getNewInstance()\r
+//                     throws InstantiationException, IllegalAccessException, InvocationTargetException  {\r
+//             System.out.println("LOCK");\r
+//             try{\r
+//                     return _getNewInstance();\r
+//             } catch(Exception e) {\r
+//                     throw e;\r
+//             } finally {\r
+//                     System.out.println("UNLOCK");\r
+//             }\r
+//     }\r
+       \r
+       public Object getNewInstance()\r
+               throws InstantiationException, IllegalAccessException, InvocationTargetException  {\r
+\r
+               if (!useConstructor) {\r
+                       return clazz.newInstance();\r
+                       //Added by Jeff Huang\r
+                       //TODO: FIXIT\r
+               }\r
+\r
+               if (noArgConstructor == null) {\r
+\r
+                       try {\r
+                               noArgConstructor =  clazz.getConstructor(noParameters);\r
+\r
+                       } catch (NoSuchMethodException nsme) {\r
+                               // let Class.newInstace() generate the exception\r
+                               useConstructor = false;\r
+                               return getNewInstance();\r
+\r
+                       } catch (SecurityException se) {\r
+                               // not allowed to to get a handle on the constructor\r
+                               // just use the standard mechanism.\r
+                               useConstructor = false;\r
+                               return getNewInstance();\r
+                       }\r
+               }\r
+\r
+               try {\r
+                       return noArgConstructor.newInstance(noArguments);\r
+                       //Added by Jeff Huang\r
+                       //return new org.apache.derby.impl.sql.compile.TableName();\r
+                       //NO! TODO: FIXIT\r
+               } catch (IllegalArgumentException iae) {\r
+                       // can't happen since no arguments are passed.\r
+                       return null;\r
+               } \r
+       }\r
+}\r