1 package org.codehaus.plexus.classworlds.strategy;
2
3 import java.net.URL;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.Enumeration;
7 import java.util.LinkedHashSet;
8
9 import org.codehaus.plexus.classworlds.UrlUtils;
10 import org.codehaus.plexus.classworlds.realm.ClassRealm;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public abstract class AbstractStrategy
32 implements Strategy
33 {
34
35 protected ClassRealm realm;
36
37 public AbstractStrategy( ClassRealm realm )
38 {
39 this.realm = realm;
40 }
41
42 protected String getNormalizedResource( String name )
43 {
44 return UrlUtils.normalizeUrlPath( name );
45 }
46
47 protected Enumeration<URL> combineResources( Enumeration<URL> en1, Enumeration<URL> en2, Enumeration<URL> en3 )
48 {
49 Collection<URL> urls = new LinkedHashSet<URL>();
50
51 addAll( urls, en1 );
52 addAll( urls, en2 );
53 addAll( urls, en3 );
54
55 return Collections.enumeration( urls );
56 }
57
58 private void addAll( Collection<URL> target, Enumeration<URL> en )
59 {
60 if ( en != null )
61 {
62 while ( en.hasMoreElements() )
63 {
64 target.add( en.nextElement() );
65 }
66 }
67 }
68
69 public ClassRealm getRealm()
70 {
71 return realm;
72 }
73
74 }