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