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 org.codehaus.plexus.interpolation.RecursionInterceptor;
20  import org.codehaus.plexus.interpolation.SimpleRecursionInterceptor;
21  
22  import java.util.ArrayList;
23  import java.util.HashSet;
24  import java.util.List;
25  import java.util.Set;
26  
27  /**
28   * AN error collector contains the errors accumulated during an interpolation.
29   * It is stateful.
30   */
31  public class InterpolationState
32  {
33      private final List<String> messages = new ArrayList<String>(  );
34      private final List<Throwable> causes = new ArrayList<Throwable>(  );
35  
36      public void addFeedback( String message, Throwable cause )
37      {
38          messages.add( message);
39          causes.add(cause);
40      }
41  
42      public List asList(){
43          ArrayList<Object> items = new ArrayList<Object>(  );
44          for (int i = 0; i < messages.size(); i++){
45              String msg = messages.get(i);
46              if (msg != null ) items.add( msg);
47              Throwable cause = causes.get(i);
48              if (cause != null) items.add(cause);
49          }
50          return items.size() > 0 ? items: null;
51      }
52  
53      public void clear()
54      {
55          messages.clear();
56          causes.clear();
57          unresolvable.clear();
58          recursionInterceptor.clear();
59          root = null;
60      }
61  
62      final Set<String> unresolvable = new HashSet<String>(  );
63      RecursionInterceptor recursionInterceptor = new SimpleRecursionInterceptor();
64  
65      public void setRecursionInterceptor( RecursionInterceptor recursionInterceptor )
66      {
67          this.recursionInterceptor = recursionInterceptor;
68      }
69  
70      FixedStringSearchInterpolator root = null;
71  }