Debian Codegraph @

src/main/java/org/apache/maven/shared/io/location/Locator.java

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