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 ParentFirstStrategy |
27 | |
extends AbstractStrategy |
28 | |
{ |
29 | |
|
30 | |
public ParentFirstStrategy( ClassRealm realm ) |
31 | |
{ |
32 | 0 | super( realm ); |
33 | 0 | } |
34 | |
|
35 | |
public Class<?> loadClass( String name ) |
36 | |
throws ClassNotFoundException |
37 | |
{ |
38 | 0 | Class<?> clazz = realm.loadClassFromImport( name ); |
39 | |
|
40 | 0 | if ( clazz == null ) |
41 | |
{ |
42 | 0 | clazz = realm.loadClassFromParent( name ); |
43 | |
|
44 | 0 | if ( clazz == null ) |
45 | |
{ |
46 | 0 | clazz = realm.loadClassFromSelf( name ); |
47 | |
|
48 | 0 | if ( clazz == null ) |
49 | |
{ |
50 | 0 | throw new ClassNotFoundException( name ); |
51 | |
} |
52 | |
} |
53 | |
} |
54 | |
|
55 | 0 | return clazz; |
56 | |
} |
57 | |
|
58 | |
public URL getResource( String name ) |
59 | |
{ |
60 | 0 | URL resource = realm.loadResourceFromImport( name ); |
61 | |
|
62 | 0 | if ( resource == null ) |
63 | |
{ |
64 | 0 | resource = realm.loadResourceFromParent( name ); |
65 | |
|
66 | 0 | if ( resource == null ) |
67 | |
{ |
68 | 0 | resource = realm.loadResourceFromSelf( name ); |
69 | |
} |
70 | |
} |
71 | |
|
72 | 0 | return resource; |
73 | |
} |
74 | |
|
75 | |
public Enumeration<URL> getResources( String name ) |
76 | |
throws IOException |
77 | |
{ |
78 | 0 | Enumeration<URL> imports = realm.loadResourcesFromImport( name ); |
79 | 0 | Enumeration<URL> parent = realm.loadResourcesFromParent( name ); |
80 | 0 | Enumeration<URL> self = realm.loadResourcesFromSelf( name ); |
81 | |
|
82 | 0 | return combineResources( imports, parent, self ); |
83 | |
} |
84 | |
|
85 | |
} |