KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.services.reflect.ReflectLoaderJava2
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.util.ByteArray;
25 import org.apache.derby.iapi.sql.compile.CodeGeneration;
26
27 final class ReflectLoaderJava2 extends ClassLoader JavaDoc {
28
29     /*
30     ** Fields
31     */

32
33     private final DatabaseClasses cf;
34     
35     /*
36     ** Constructor
37     */

38
39     ReflectLoaderJava2(ClassLoader JavaDoc parent, DatabaseClasses cf) {
40         super(parent);
41         this.cf = cf;
42     }
43
44     protected Class JavaDoc findClass(String JavaDoc name)
45         throws ClassNotFoundException JavaDoc {
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 JavaDoc name, ByteArray classData) {
60
61         Class JavaDoc jvmClass = defineClass(name, classData.getArray(), classData.getOffset(), classData.getLength());
62
63         resolveClass(jvmClass);
64
65         /*
66             DJD - not enabling this yet, need more memory testing, may only
67             create a factory instance when a number of instances are created.
68             This would avoid a factory instance for DDL
69
70         // now generate a factory class that loads instances
71         int lastDot = name.lastIndexOf('.');
72         String factoryName = name.substring(lastDot + 1, name.length()).concat("_F");
73
74         classData = cf.buildSpecificFactory(name, factoryName);
75         Class factoryClass = defineClass(CodeGeneration.GENERATED_PACKAGE_PREFIX.concat(factoryName),
76             classData.getArray(), classData.getOffset(), classData.getLength());
77         resolveClass(factoryClass);
78         
79           */

80         Class JavaDoc factoryClass = null;
81
82         return new ReflectGeneratedClass(cf, jvmClass, factoryClass);
83     }
84 }
85
Popular Tags