View Javadoc
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   * Copyright 2001-2006 Codehaus Foundation.
14   *
15   * Licensed under the Apache License, Version 2.0 (the "License");
16   * you may not use this file except in compliance with the License.
17   * You may obtain a copy of the License at
18   *
19   *      http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing, software
22   * distributed under the License is distributed on an "AS IS" BASIS,
23   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24   * See the License for the specific language governing permissions and
25   * limitations under the License.
26   */
27  
28  /**
29   * @author Jason van Zyl
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  }