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 implements Strategy {
32
33 protected ClassRealm realm;
34
35 public AbstractStrategy(ClassRealm realm) {
36 this.realm = realm;
37 }
38
39 protected String getNormalizedResource(String name) {
40 return UrlUtils.normalizeUrlPath(name);
41 }
42
43 protected Enumeration<URL> combineResources(Enumeration<URL> en1, Enumeration<URL> en2, Enumeration<URL> en3) {
44 Collection<URL> urls = new LinkedHashSet<>();
45
46 addAll(urls, en1);
47 addAll(urls, en2);
48 addAll(urls, en3);
49
50 return Collections.enumeration(urls);
51 }
52
53 private void addAll(Collection<URL> target, Enumeration<URL> en) {
54 if (en != null) {
55 while (en.hasMoreElements()) {
56 target.add(en.nextElement());
57 }
58 }
59 }
60
61 public ClassRealm getRealm() {
62 return realm;
63 }
64 }