View Javadoc
1   package org.apache.maven.plugins.assembly.io;
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  /**
27   * The Locator.
28   *
29   */
30  final class Locator
31  {
32  
33      private List<LocatorStrategy> strategies;
34      private final MessageHolder messageHolder;
35  
36      /**
37       * @param strategies List of strategies
38       * @param messageHolder {@link MessageHolder}
39       */
40      Locator( List<LocatorStrategy> strategies, MessageHolder messageHolder )
41      {
42          this.messageHolder = messageHolder;
43          this.strategies = new ArrayList<LocatorStrategy>( strategies );
44      }
45  
46      /**
47       * Create instance.
48       */
49      Locator()
50      {
51          this.messageHolder = new DefaultMessageHolder();
52          this.strategies = new ArrayList<LocatorStrategy>();
53      }
54  
55      /**
56       * @return {@link MessageHolder}
57       */
58      MessageHolder getMessageHolder()
59      {
60          return messageHolder;
61      }
62  
63      /**
64       * @param strategy The strategy to be added.
65       */
66      void addStrategy( LocatorStrategy strategy )
67      {
68          this.strategies.add( strategy );
69      }
70  
71      /**
72       * @param strategy the strategy to remove.
73       */
74      void removeStrategy( LocatorStrategy strategy )
75      {
76          this.strategies.remove( strategy );
77      }
78  
79      /**
80       * @param strategies the strategies to be set.
81       */
82      void setStrategies( List<LocatorStrategy> strategies )
83      {
84          this.strategies.clear();
85          this.strategies.addAll( strategies );
86      }
87  
88      /**
89       * @return list of strategies.
90       */
91      List<LocatorStrategy> getStrategies()
92      {
93          return strategies;
94      }
95  
96      /**
97       * @param locationSpecification location spec
98       * @return {@link Location}
99       */
100     Location resolve( String locationSpecification )
101     {
102         Location location = null;
103 
104         for ( Iterator<LocatorStrategy> it = strategies.iterator(); location == null && it.hasNext(); )
105         {
106             LocatorStrategy strategy = (LocatorStrategy) it.next();
107 
108             location = strategy.resolve( locationSpecification, messageHolder );
109         }
110 
111         return location;
112     }
113 
114 }