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