Coverage Report - org.kuali.rice.krms.impl.provider.repository.LazyAction
 
Classes in this File Line Coverage Branch Coverage Complexity
LazyAction
0%
0/23
0%
0/6
1.429
LazyAction$1
0%
0/3
N/A
1.429
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.krms.impl.provider.repository;
 17  
 
 18  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 19  
 import org.kuali.rice.krms.api.repository.action.ActionDefinition;
 20  
 import org.kuali.rice.krms.framework.engine.Action;
 21  
 import org.kuali.rice.krms.framework.type.ActionTypeService;
 22  
 import org.kuali.rice.krms.impl.type.KrmsTypeResolver;
 23  
 
 24  
 /**
 25  
  * TODO... 
 26  
  * 
 27  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 28  
  *
 29  
  */
 30  
 final class LazyAction implements Action {
 31  
 
 32  
         private final ActionDefinition actionDefinition;
 33  
         private final KrmsTypeResolver typeResolver;
 34  
 
 35  0
         private final Object mutex = new Object();
 36  
         
 37  
         // volatile for double-checked locking idiom
 38  
         private volatile Action action;
 39  
         
 40  0
         LazyAction(ActionDefinition actionDefinition, KrmsTypeResolver typeResolver) {
 41  0
                 this.actionDefinition = actionDefinition;
 42  0
                 this.typeResolver = typeResolver;
 43  0
                 this.action = null;
 44  0
         }
 45  
         
 46  
         @Override
 47  
         public void execute(ExecutionEnvironment environment) {
 48  0
                 getAction().execute(environment);
 49  0
         }
 50  
 
 51  
         @Override
 52  
         public void executeSimulation(ExecutionEnvironment environment) {
 53  0
                 getAction().executeSimulation(environment);
 54  0
         }
 55  
         
 56  
         /**
 57  
          * Gets the action using a lazy double-checked locking mechanism as documented in Effective Java Item 71.
 58  
          */
 59  
         private Action getAction() {
 60  0
                 Action localAction = action;
 61  0
                 if (localAction == null) {
 62  0
                         synchronized (mutex) {
 63  0
                                 localAction = action;
 64  0
                                 if (localAction == null) {
 65  0
                                         action = localAction = constructAction();
 66  
                                 }
 67  0
                         }
 68  
                 }
 69  0
                 return localAction;
 70  
         }
 71  
         
 72  
         private Action constructAction() {
 73  0
                 ActionTypeService actionTypeService = typeResolver.getActionTypeService(actionDefinition);
 74  0
                 Action action = actionTypeService.loadAction(actionDefinition);
 75  0
                 if (action == null) {
 76  0
                         action = new Action() {
 77  
                                 @Override
 78  
                                 public void execute(ExecutionEnvironment environment) {
 79  0
                                 }
 80  
                                 public void executeSimulation(ExecutionEnvironment environment) {
 81  0
                                 }
 82  
                         };
 83  
                 }
 84  0
                 return action;
 85  
         }
 86  
 
 87  
         
 88  
 }