Coverage Report - org.kuali.rice.krms.framework.engine.BasicExecutionEnvironment
 
Classes in this File Line Coverage Branch Coverage Complexity
BasicExecutionEnvironment
0%
0/27
0%
0/8
1.875
 
 1  
 package org.kuali.rice.krms.framework.engine;
 2  
 
 3  
 import java.util.Collections;
 4  
 import java.util.HashMap;
 5  
 import java.util.Map;
 6  
 
 7  
 import org.apache.commons.lang.ObjectUtils;
 8  
 import org.kuali.rice.krms.api.Asset;
 9  
 import org.kuali.rice.krms.api.AssetResolutionEngine;
 10  
 import org.kuali.rice.krms.api.AssetResolutionException;
 11  
 import org.kuali.rice.krms.api.AssetResolver;
 12  
 import org.kuali.rice.krms.api.EngineResults;
 13  
 import org.kuali.rice.krms.api.ExecutionEnvironment;
 14  
 import org.kuali.rice.krms.api.SelectionCriteria;
 15  
 
 16  
 public final class BasicExecutionEnvironment implements ExecutionEnvironment {
 17  
 
 18  
         private final SelectionCriteria selectionCriteria;
 19  
         private final Map<Asset, Object> facts;
 20  
         private final Map<String, String> executionOptions;
 21  
         private final EngineResults engineResults;
 22  
         private final AssetResolutionEngine assetResolutionService;
 23  
         
 24  0
         public BasicExecutionEnvironment(SelectionCriteria selectionCriteria, Map<Asset, Object> facts, Map<String, String> executionOptions) {
 25  0
                 if (selectionCriteria == null) {
 26  0
                         throw new IllegalArgumentException("Selection criteria must not be null.");
 27  
                 }
 28  0
                 if (facts == null) {
 29  0
                         throw new IllegalArgumentException("Facts must not be null.");
 30  
                 }
 31  0
                 this.selectionCriteria = selectionCriteria;
 32  0
                 this.facts = new HashMap<Asset, Object>(facts.size());
 33  0
                 this.facts.putAll(facts);
 34  0
                 this.executionOptions = new HashMap<String, String>(executionOptions.size());
 35  0
                 this.executionOptions.putAll(executionOptions);
 36  0
                 this.engineResults = new EngineResultsImpl();
 37  
                 // TODO: inject this (will have to make it non-final)
 38  0
                 this.assetResolutionService = new AssetResolutionEngineImpl();
 39  0
         }
 40  
         
 41  
         @Override
 42  
         public SelectionCriteria getSelectionCriteria() {
 43  0
                 return this.selectionCriteria;
 44  
         }
 45  
         
 46  
         @Override
 47  
         public Map<Asset, Object> getFacts() {
 48  0
                 return Collections.unmodifiableMap(facts);
 49  
         }
 50  
         
 51  
         @Override
 52  
         public void addAssetResolver(AssetResolver<?> assetResolver) {
 53  0
                 assetResolutionService.addAssetResolver(assetResolver);
 54  0
         }
 55  
         
 56  
         @Override
 57  
         public <T> T resolveTerm(Asset asset) throws AssetResolutionException {
 58  
                 T value;
 59  
                 
 60  
                 // This looks funny, but works around a javac bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
 61  
                 // Specifically, using <T> below works around it.
 62  0
                 value = assetResolutionService.<T>resolveAsset(asset);
 63  
                 
 64  0
                 publishFact(asset, value);
 65  0
                 return value;
 66  
         }
 67  
 
 68  
         @Override
 69  
         public boolean publishFact(Asset factName, Object factValue) {
 70  0
                 if (facts.containsKey(factName) && ObjectUtils.equals(facts.get(factName), factValue)) {
 71  0
                         return false;
 72  
                 }
 73  0
                 facts.put(factName, factValue);
 74  0
                 assetResolutionService.addAssetValue(factName, factValue);
 75  0
                 return true;
 76  
         }
 77  
 
 78  
         @Override
 79  
         public Map<String, String> getExecutionOptions() {
 80  0
                 return executionOptions;
 81  
         }
 82  
         
 83  
         @Override
 84  
         public EngineResults getEngineResults() {
 85  0
                 return engineResults;
 86  
         }
 87  
 
 88  
 }