View Javadoc

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