View Javadoc
1   package org.codehaus.plexus.interpolation.fixed;
2   
3   /*
4    * Copyright 2014 The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * 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, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.ArrayList;
20  import java.util.HashSet;
21  import java.util.List;
22  import java.util.Set;
23  
24  import org.codehaus.plexus.interpolation.RecursionInterceptor;
25  import org.codehaus.plexus.interpolation.SimpleRecursionInterceptor;
26  
27  /**
28   * AN error collector contains the errors accumulated during an interpolation.
29   * It is stateful.
30   */
31  public class InterpolationState {
32      private final List<String> messages = new ArrayList<String>();
33      private final List<Throwable> causes = new ArrayList<Throwable>();
34  
35      public void addFeedback(String message, Throwable cause) {
36          messages.add(message);
37          causes.add(cause);
38      }
39  
40      public List asList() {
41          ArrayList<Object> items = new ArrayList<Object>();
42          for (int i = 0; i < messages.size(); i++) {
43              String msg = messages.get(i);
44              if (msg != null) items.add(msg);
45              Throwable cause = causes.get(i);
46              if (cause != null) items.add(cause);
47          }
48          return items.size() > 0 ? items : null;
49      }
50  
51      public void clear() {
52          messages.clear();
53          causes.clear();
54          unresolvable.clear();
55          recursionInterceptor.clear();
56          root = null;
57      }
58  
59      final Set<String> unresolvable = new HashSet<String>();
60      RecursionInterceptor recursionInterceptor = new SimpleRecursionInterceptor();
61  
62      public void setRecursionInterceptor(RecursionInterceptor recursionInterceptor) {
63          this.recursionInterceptor = recursionInterceptor;
64      }
65  
66      FixedStringSearchInterpolator root = null;
67  }