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
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  }