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