View Javadoc

1   package org.apache.maven.shared.io.location;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Iterator;
24  import java.util.List;
25  
26  import org.apache.maven.shared.io.logging.DefaultMessageHolder;
27  import org.apache.maven.shared.io.logging.MessageHolder;
28  
29  public final class Locator
30  {
31  
32      private List strategies;
33      private final MessageHolder messageHolder;
34  
35      public Locator( List strategies, MessageHolder messageHolder )
36      {
37          this.messageHolder = messageHolder;
38          this.strategies = new ArrayList( strategies );
39      }
40  
41      public Locator()
42      {
43          this.messageHolder = new DefaultMessageHolder();
44          this.strategies = new ArrayList();
45      }
46  
47      public MessageHolder getMessageHolder()
48      {
49          return messageHolder;
50      }
51  
52      public void addStrategy( LocatorStrategy strategy )
53      {
54          this.strategies.add( strategy );
55      }
56  
57      public void removeStrategy( LocatorStrategy strategy )
58      {
59          this.strategies.remove( strategy );
60      }
61  
62      public void setStrategies( List strategies )
63      {
64          this.strategies.clear();
65          this.strategies.addAll( strategies );
66      }
67  
68      public List getStrategies()
69      {
70          return strategies;
71      }
72  
73      public Location resolve( String locationSpecification )
74      {
75          Location location = null;
76  
77          for ( Iterator it = strategies.iterator(); location == null && it.hasNext(); )
78          {
79              LocatorStrategy strategy = (LocatorStrategy) it.next();
80  
81              location = strategy.resolve( locationSpecification, messageHolder );
82          }
83  
84          return location;
85      }
86  
87  }