Coverage Report - org.kuali.rice.krms.api.engine.TermResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
TermResolver
N/A
N/A
1
 
 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.api.engine;
 17  
 
 18  
 import java.util.Map;
 19  
 import java.util.Set;
 20  
 
 21  
 /**
 22  
  * <p>An {@link TermResolver} implementor is a utility class used for resolution (reification) of {@link Term}s.  There are a
 23  
  * few key concepts to understand how {@link TermResolver}s function and work together.
 24  
  * </p>
 25  
  * <ul>
 26  
  * <li><b>they can require prerequisite {@link Term}s (which must not have any parameters)</b>.  If they do, when the {@link TermResolutionEngine} calls 
 27  
  * {@link #resolve(Map, Map)} it will pass the resolved prerequisites in the first argument.
 28  
  * <li><b>they can be chained.</b>  This means that if the {@link TermResolutionEngine} has {@link TermResolver}s (a &lt;- b) and 
 29  
  * (b &lt;- c), and you have the fact 'c', you can ask for term 'a' and the engine will chain the resolvers together
 30  
  * to resolve it correctly.</li>
 31  
  * <li><b>they can be parameterized.</b> If an TermResolver takes parameters, they must be declared via the
 32  
  * {@link #getParameterNames()} method.  All declared parameters are considered to be required.  Parameters can be set
 33  
  * on the {@link Term} (via the constructor) that you are asking to resolve. When the {@link TermResolutionEngine} calls 
 34  
  * {@link #resolve(Map, Map)}, the parameters will be passed in to the second argument.</li>
 35  
  * <li><b>Parameterized {@link TermResolver}s can not be intermediates in a resolution plan.</b>  Another way to say 
 36  
  * this is that they can only be the last resolver in a chain.  For example, say
 37  
  * the {@link TermResolutionEngine} has {@link TermResolver}s (a &lt;- b) which takes no parameters, 
 38  
  * (b &lt;- c) which takes a parameter "foo", and you have the fact 'c'.  If you ask for Term 'a', the engine will not be able to resolve
 39  
  * it because it would need to use a parameterized Term as an intermediate step in resolution, and that isn't allowed.</li>
 40  
  * 
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  *
 43  
  * @param <T> the class of the resolved object 
 44  
  */
 45  
 public interface TermResolver <T> {
 46  
         
 47  
         /**
 48  
          * @return the names of the terms that this resolver requires to resolve its output, or an empty set if it has no prereqs;
 49  
          */
 50  
         Set<String> getPrerequisites();
 51  
         
 52  
         /**
 53  
          * @return the name of the term that the implementor resolves
 54  
          */
 55  
         String getOutput();
 56  
         
 57  
         /**
 58  
          * 
 59  
          * @return the names of any parameters that this {@link TermResolver} requires to churn out values for multiple {@link Term}s.  This may 
 60  
          * be null if no parameters are required.  If this is non-null/non-empty, then this resolver can not be used as an intermediate
 61  
          * in a term resolution chain.
 62  
          */
 63  
         Set<String> getParameterNames();
 64  
         
 65  
         /**
 66  
          * @return an integer representing the cost of resolving the term. 1 is cheap, Integer.MAX_INT is expensive.
 67  
          */
 68  
         int getCost();
 69  
         
 70  
         /**
 71  
          * @param resolvedPrereqs the resolved prereqs
 72  
          * @param parameters any parameters on the {@link Term} to be resolved (which must match those declared via {@link #getParameterNames()} 
 73  
          * @return the resolved fact value for the specified {@link Term}
 74  
          * @throws TermResolutionException if something bad happens during the term resolution process
 75  
          */
 76  
         T resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException;
 77  
 }