1 /*
2 * Copyright 2003-2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.codehaus.groovy.runtime.callsite;
17
18 import org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts;
19
20 import java.util.Set;
21 import java.util.HashSet;
22 import java.util.Collections;
23
24 public class CallSiteClassLoader extends ClassLoaderForClassArtifacts {
25
26 private static final Set<String> knownClasses = new HashSet<String>();
27 static {
28 Collections.addAll(knownClasses
29 , "org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite"
30 , "org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite"
31 , "org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite"
32 , "org.codehaus.groovy.runtime.callsite.CallSite"
33 , "org.codehaus.groovy.runtime.callsite.CallSiteArray"
34 , "groovy.lang.MetaMethod"
35 , "groovy.lang.MetaClassImpl"
36 );
37 }
38
39 public CallSiteClassLoader(Class klazz) {
40 super(klazz);
41 }
42
43 protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
44 if (knownClasses.contains(name))
45 return getClass().getClassLoader().loadClass(name);
46 else {
47 try {
48 return super.loadClass(name, resolve);
49 }
50 catch (ClassNotFoundException e) {
51 return getClass().getClassLoader().loadClass(name);
52 }
53 }
54 }
55
56 }