Coverage Report - org.codehaus.plexus.lifecycle.AbstractLifecycleHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractLifecycleHandler
84 %
27/32
87 %
14/16
2,222
 
 1  
 package org.codehaus.plexus.lifecycle;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 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.classworlds.realm.ClassRealm;
 20  
 import org.codehaus.plexus.component.manager.ComponentManager;
 21  
 import org.codehaus.plexus.lifecycle.phase.Phase;
 22  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.Iterator;
 26  
 import java.util.List;
 27  
 
 28  333
 public abstract class AbstractLifecycleHandler
 29  
     implements LifecycleHandler
 30  
 {
 31  
     private List beginSegment;
 32  
 
 33  
     private List endSegment;
 34  
 
 35  
     // ----------------------------------------------------------------------
 36  
     // Begin Segment
 37  
     // ----------------------------------------------------------------------
 38  
 
 39  
     public void addBeginSegment( Phase phase )
 40  
     {
 41  966
         if ( beginSegment == null )
 42  
         {
 43  272
             beginSegment = new ArrayList();
 44  
         }
 45  
 
 46  966
         beginSegment.add( phase );
 47  966
     }
 48  
 
 49  
     public List getBeginSegment()
 50  
     {
 51  434
         return beginSegment;
 52  
     }
 53  
 
 54  
     public void addEndSegment( Phase phase )
 55  
     {
 56  549
         if ( endSegment == null )
 57  
         {
 58  183
             endSegment = new ArrayList();
 59  
         }
 60  
 
 61  549
         endSegment.add( phase );
 62  549
     }
 63  
 
 64  
     public List getEndSegment()
 65  
     {
 66  379
         return endSegment;
 67  
     }
 68  
 
 69  
     // ----------------------------------------------------------------------
 70  
     // Lifecylce Management
 71  
     // ----------------------------------------------------------------------
 72  
 
 73  
     /**
 74  
      * @deprecated
 75  
      */
 76  
     public void start( Object component, ComponentManager manager )
 77  
         throws PhaseExecutionException
 78  
     {
 79  0
         start( component, manager, manager.getContainer().getLookupRealm( component ) );
 80  0
     }
 81  
 
 82  
     /**
 83  
      * Start a component's lifecycle.
 84  
      */
 85  
     public void start( Object component, ComponentManager manager, ClassRealm realm  )
 86  
         throws PhaseExecutionException
 87  
     {
 88  217
         if ( segmentIsEmpty( getBeginSegment() ) )
 89  
         {
 90  0
             return;
 91  
         }
 92  
 
 93  217
         for (Object o : getBeginSegment()) {
 94  869
             Phase phase = (Phase) o;
 95  
 
 96  869
             phase.execute(component, manager, realm);
 97  868
         }
 98  216
     }
 99  
 
 100  
     /**
 101  
      * End a component's lifecycle.
 102  
      * @deprecated
 103  
      */
 104  
     public void end( Object component, ComponentManager manager )
 105  
         throws PhaseExecutionException
 106  
     {
 107  0
         end( component, manager, manager.getContainer().getLookupRealm( component ) );
 108  0
     }
 109  
 
 110  
     /**
 111  
      * End a component's lifecycle.
 112  
      */
 113  
     public void end( Object component, ComponentManager manager, ClassRealm contextRealm )
 114  
         throws PhaseExecutionException
 115  
     {
 116  190
         if ( segmentIsEmpty( getEndSegment() ) )
 117  
         {
 118  1
             return;
 119  
         }
 120  
 
 121  189
         for (Object o : getEndSegment()) {
 122  567
             Phase phase = (Phase) o;
 123  
 
 124  567
             phase.execute(component, manager, contextRealm);
 125  567
         }
 126  189
     }
 127  
 
 128  
     private boolean segmentIsEmpty( List segment )
 129  
     {
 130  407
         if ( segment == null || segment.size() == 0 )
 131  
         {
 132  1
             return true;
 133  
         }
 134  
 
 135  406
         return false;
 136  
     }
 137  
 }