01: /*
02:
03: Derby - Class org.apache.derby.impl.services.reflect.LoadedGeneratedClass
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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: public abstract class LoadedGeneratedClass implements GeneratedClass {
36:
37: /*
38: ** Fields
39: */
40:
41: private final ClassInfo ci;
42: private final int classLoaderVersion;
43:
44: /*
45: ** Constructor
46: */
47:
48: public LoadedGeneratedClass(ClassFactory cf, Class jvmClass) {
49: ci = new ClassInfo(jvmClass);
50: classLoaderVersion = cf.getClassLoaderVersion();
51: }
52:
53: /*
54: ** Public methods from Generated Class
55: */
56:
57: public String getName() {
58: return ci.getClassName();
59: }
60:
61: public Object newInstance(Context context) throws StandardException {
62:
63: Throwable t;
64: try {
65: GeneratedByteCode ni = (GeneratedByteCode) ci
66: .getNewInstance();
67: ni.initFromContext(context);
68: ni.setGC(this );
69: ni.postConstructor();
70: return ni;
71:
72: } catch (InstantiationException ie) {
73: t = ie;
74: } catch (IllegalAccessException iae) {
75: t = iae;
76: } catch (java.lang.reflect.InvocationTargetException ite) {
77: t = ite;
78: } catch (LinkageError le) {
79: t = le;
80: }
81:
82: throw StandardException.newException(
83: 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: }
|