1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.services.reflect.LoadedGeneratedClass |
4 | |
5 | Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.services.reflect; |
22 | |
23 | import org.apache.derby.iapi.services.loader.GeneratedByteCode; |
24 | import org.apache.derby.iapi.services.loader.GeneratedClass; |
25 | import org.apache.derby.iapi.services.loader.ClassFactory; |
26 | |
27 | import org.apache.derby.iapi.services.context.Context; |
28 | |
29 | import org.apache.derby.iapi.error.StandardException; |
30 | import org.apache.derby.iapi.reference.SQLState; |
31 | |
32 | import org.apache.derby.iapi.services.loader.ClassInfo; |
33 | |
34 | |
35 | public abstract class LoadedGeneratedClass |
36 | implements GeneratedClass |
37 | { |
38 | |
39 | /* |
40 | ** Fields |
41 | */ |
42 | |
43 | private final ClassInfo ci; |
44 | private final int classLoaderVersion; |
45 | |
46 | /* |
47 | ** Constructor |
48 | */ |
49 | |
50 | public LoadedGeneratedClass(ClassFactory cf, Class jvmClass) { |
51 | ci = new ClassInfo(jvmClass); |
52 | classLoaderVersion = cf.getClassLoaderVersion(); |
53 | } |
54 | |
55 | /* |
56 | ** Public methods from Generated Class |
57 | */ |
58 | |
59 | public String getName() { |
60 | return ci.getClassName(); |
61 | } |
62 | |
63 | public Object newInstance(Context context) throws StandardException { |
64 | |
65 | Throwable t; |
66 | try { |
67 | GeneratedByteCode ni = (GeneratedByteCode) ci.getNewInstance(); |
68 | ni.initFromContext(context); |
69 | ni.setGC(this); |
70 | ni.postConstructor(); |
71 | return ni; |
72 | |
73 | } catch (InstantiationException ie) { |
74 | t = ie; |
75 | } catch (IllegalAccessException iae) { |
76 | t = iae; |
77 | } catch (java.lang.reflect.InvocationTargetException ite) { |
78 | t = ite; |
79 | } catch (LinkageError le) { |
80 | t = le; |
81 | } |
82 | |
83 | throw StandardException.newException(SQLState.GENERATED_CLASS_INSTANCE_ERROR, t, getName()); |
84 | } |
85 | |
86 | public final int getClassLoaderVersion() { |
87 | return classLoaderVersion; |
88 | } |
89 | |
90 | /* |
91 | ** Methods for subclass |
92 | */ |
93 | protected Class getJVMClass() { |
94 | return ci.getClassObject(); |
95 | } |
96 | } |