1 package org.codehaus.plexus.classworlds.strategy;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import java.io.IOException;
18 import java.net.URL;
19 import java.util.Enumeration;
20
21 import org.codehaus.plexus.classworlds.realm.ClassRealm;
22
23
24
25
26 public class SelfFirstStrategy
27 extends AbstractStrategy
28 {
29
30 public SelfFirstStrategy( ClassRealm realm )
31 {
32 super( realm );
33 }
34
35 public Class<?> loadClass( String name )
36 throws ClassNotFoundException
37 {
38 Class<?> clazz = realm.loadClassFromImport( name );
39
40 if ( clazz == null )
41 {
42 clazz = realm.loadClassFromSelf( name );
43
44 if ( clazz == null )
45 {
46 clazz = realm.loadClassFromParent( name );
47
48 if ( clazz == null )
49 {
50 throw new ClassNotFoundException( name );
51 }
52 }
53 }
54
55 return clazz;
56 }
57
58 public URL getResource( String name )
59 {
60 URL resource = realm.loadResourceFromImport( name );
61
62 if ( resource == null )
63 {
64 resource = realm.loadResourceFromSelf( name );
65
66 if ( resource == null )
67 {
68 resource = realm.loadResourceFromParent( name );
69 }
70 }
71
72 return resource;
73 }
74
75 public Enumeration<URL> getResources( String name )
76 throws IOException
77 {
78 Enumeration<URL> imports = realm.loadResourcesFromImport( name );
79 Enumeration<URL> self = realm.loadResourcesFromSelf( name );
80 Enumeration<URL> parent = realm.loadResourcesFromParent( name );
81
82 return combineResources( imports, self, parent );
83 }
84
85 }