View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.lifecycle;
8   
9   import java.util.ArrayList;
10  import java.util.List;
11  
12  public class LifecycleTrackerCheckComponent extends LifecycleTrackerComponent
13  {
14  
15      private final List<String> tracker = new ArrayList<String>()
16      {
17          public boolean add(String phase)
18          {
19              if (isValidTransition(phase))
20              {
21                  return super.add(phase);
22              }
23              throw new IllegalStateException(String.format("Invalid phase transition: %s -> %s", this.toString(), phase));
24          }
25  
26          private boolean isValidTransition(String phase)
27          {
28              // just check if the same phase was already invoked
29              return !this.contains(phase);
30          }
31      };
32  
33      public List<String> getTracker()
34      {
35          return tracker;
36      }
37  
38  }
39  
40