01: /*
02:
03: Derby - Class org.apache.derby.impl.services.reflect.ReflectLoaderJava2
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.util.ByteArray;
25: import org.apache.derby.iapi.sql.compile.CodeGeneration;
26:
27: final class ReflectLoaderJava2 extends ClassLoader {
28:
29: /*
30: ** Fields
31: */
32:
33: private final DatabaseClasses cf;
34:
35: /*
36: ** Constructor
37: */
38:
39: ReflectLoaderJava2(ClassLoader parent, DatabaseClasses cf) {
40: super (parent);
41: this .cf = cf;
42: }
43:
44: protected Class findClass(String name)
45: throws ClassNotFoundException {
46: return cf.loadApplicationClass(name);
47: }
48:
49: /*
50: ** Implementation specific methods
51: ** NOTE these are COPIED from ReflectLoader as the two classes cannot be made into
52: a super/sub class pair. Because the Java2 one needs to call super(ClassLoader)
53: that was added in Java2 and it needs to not implement loadClass()
54: */
55:
56: /**
57: Load a generated class from the passed in class data.
58: */
59: public LoadedGeneratedClass loadGeneratedClass(String name,
60: ByteArray classData) {
61:
62: Class jvmClass = defineClass(name, classData.getArray(),
63: classData.getOffset(), classData.getLength());
64:
65: resolveClass(jvmClass);
66:
67: /*
68: DJD - not enabling this yet, need more memory testing, may only
69: create a factory instance when a number of instances are created.
70: This would avoid a factory instance for DDL
71:
72: // now generate a factory class that loads instances
73: int lastDot = name.lastIndexOf('.');
74: String factoryName = name.substring(lastDot + 1, name.length()).concat("_F");
75:
76: classData = cf.buildSpecificFactory(name, factoryName);
77: Class factoryClass = defineClass(CodeGeneration.GENERATED_PACKAGE_PREFIX.concat(factoryName),
78: classData.getArray(), classData.getOffset(), classData.getLength());
79: resolveClass(factoryClass);
80:
81: */
82: Class factoryClass = null;
83:
84: return new ReflectGeneratedClass(cf, jvmClass, factoryClass);
85: }
86: }
|