KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > services > reflect > LoadedGeneratedClass


1 /*
2
3    Derby - Class org.apache.derby.impl.services.reflect.LoadedGeneratedClass
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.services.reflect;
23
24 import org.apache.derby.iapi.services.loader.GeneratedByteCode;
25 import org.apache.derby.iapi.services.loader.GeneratedClass;
26 import org.apache.derby.iapi.services.loader.ClassFactory;
27
28 import org.apache.derby.iapi.services.context.Context;
29
30 import org.apache.derby.iapi.error.StandardException;
31 import org.apache.derby.iapi.reference.SQLState;
32
33 import org.apache.derby.iapi.services.loader.ClassInfo;
34
35
36 public abstract class LoadedGeneratedClass
37     implements GeneratedClass
38 {
39
40     /*
41     ** Fields
42     */

43
44     private final ClassInfo ci;
45     private final int classLoaderVersion;
46
47     /*
48     ** Constructor
49     */

50
51     public LoadedGeneratedClass(ClassFactory cf, Class JavaDoc jvmClass) {
52         ci = new ClassInfo(jvmClass);
53         classLoaderVersion = cf.getClassLoaderVersion();
54     }
55
56     /*
57     ** Public methods from Generated Class
58     */

59
60     public String JavaDoc getName() {
61         return ci.getClassName();
62     }
63
64     public Object JavaDoc newInstance(Context context) throws StandardException {
65
66         Throwable JavaDoc t;
67         try {
68             GeneratedByteCode ni = (GeneratedByteCode) ci.getNewInstance();
69             ni.initFromContext(context);
70             ni.setGC(this);
71             ni.postConstructor();
72             return ni;
73
74         } catch (InstantiationException JavaDoc ie) {
75             t = ie;
76         } catch (IllegalAccessException JavaDoc iae) {
77             t = iae;
78         } catch (java.lang.reflect.InvocationTargetException JavaDoc ite) {
79             t = ite;
80         } catch (LinkageError JavaDoc le) {
81             t = le;
82         }
83
84         throw StandardException.newException(SQLState.GENERATED_CLASS_INSTANCE_ERROR, t, getName());
85     }
86
87     public final int getClassLoaderVersion() {
88         return classLoaderVersion;
89     }
90
91     /*
92     ** Methods for subclass
93     */

94     protected Class JavaDoc getJVMClass() {
95         return ci.getClassObject();
96     }
97 }
98
Popular Tags