|  1 |     | 
   package org.kuali.rice.krms.api.engine;  | 
  |  2 |     | 
     | 
  |  3 |     | 
   import java.util.Collections;  | 
  |  4 |     | 
   import java.util.HashMap;  | 
  |  5 |     | 
   import java.util.HashSet;  | 
  |  6 |     | 
   import java.util.Map;  | 
  |  7 |     | 
   import java.util.Map.Entry;  | 
  |  8 |     | 
   import java.util.Set;  | 
  |  9 |     | 
     | 
  |  10 |     | 
   import org.kuali.rice.core.api.exception.RiceRuntimeException;  | 
  |  11 |     | 
   import org.springframework.util.CollectionUtils;  | 
  |  12 |     | 
     | 
  |  13 |     | 
   public class TermResolutionException extends RiceRuntimeException { | 
  |  14 |     | 
     | 
  |  15 |     | 
           private static final long serialVersionUID = 1L;  | 
  |  16 |     | 
     | 
  |  17 |     | 
           public final String termResolverClassName;  | 
  |  18 |     | 
           public final TermSpecification outputTerm;  | 
  |  19 |     | 
           public final Set<TermSpecification> prereqs;  | 
  |  20 |     | 
           public final Set<String> parameterNames;  | 
  |  21 |     | 
           public final Map<String, String> parameters;  | 
  |  22 |     | 
             | 
  |  23 |     | 
           private static String buildResolutionInfoString(TermResolver<?> tr, Map<String, String> parameters) { | 
  |  24 |    0 |                    StringBuilder result = new StringBuilder();  | 
  |  25 |     | 
                     | 
  |  26 |    0 |                    result.append("["); | 
  |  27 |    0 |                    result.append(TermResolver.class.getSimpleName() + "=");  | 
  |  28 |     | 
     | 
  |  29 |    0 |                    if (tr == null) {  | 
  |  30 |    0 |                            result.append("null"); | 
  |  31 |     | 
                   } else { | 
  |  32 |    0 |                            result.append(tr.toString());  | 
  |  33 |     | 
                   }  | 
  |  34 |     | 
                     | 
  |  35 |    0 |                    result.append(", parameters={"); | 
  |  36 |     | 
     | 
  |  37 |    0 |                    boolean firstEntry = true;  | 
  |  38 |    0 |                    if (!CollectionUtils.isEmpty(parameters)) { | 
  |  39 |     | 
                             | 
  |  40 |    0 |                            for (Entry<String,String> parameter : parameters.entrySet()){ | 
  |  41 |     | 
     | 
  |  42 |    0 |                                    if (firstEntry) { | 
  |  43 |    0 |                                            firstEntry = false;  | 
  |  44 |     | 
                                   } else {  | 
  |  45 |    0 |                                            result.append(","); | 
  |  46 |     | 
                                   }  | 
  |  47 |     | 
     | 
  |  48 |    0 |                                    result.append(parameter.getKey());  | 
  |  49 |    0 |                                    result.append("="); | 
  |  50 |    0 |                                    result.append(parameter.getValue());  | 
  |  51 |     | 
                           }  | 
  |  52 |     | 
                   }  | 
  |  53 |     | 
                     | 
  |  54 |    0 |                    result.append("}]"); | 
  |  55 |    0 |                    return result.toString();  | 
  |  56 |     | 
           }  | 
  |  57 |     | 
     | 
  |  58 |     | 
           public TermResolutionException(String message, TermResolver<?> tr, Map<String, String> parameters, Throwable cause) { | 
  |  59 |    0 |                    super(message + " " + buildResolutionInfoString(tr, parameters), cause);  | 
  |  60 |    0 |                    if (tr == null) { | 
  |  61 |    0 |                            termResolverClassName = "";  | 
  |  62 |    0 |                            outputTerm = null;  | 
  |  63 |    0 |                            prereqs = null;  | 
  |  64 |    0 |                            parameterNames = null;  | 
  |  65 |     | 
                   } else { | 
  |  66 |    0 |                            termResolverClassName = tr.getClass().getName();  | 
  |  67 |    0 |                            outputTerm = tr.getOutput();  | 
  |  68 |    0 |                            prereqs = tr.getPrerequisites();  | 
  |  69 |    0 |                            parameterNames = Collections.unmodifiableSet(new HashSet<String>(tr.getParameterNames()));  | 
  |  70 |     | 
                   }  | 
  |  71 |    0 |                    if (parameters != null){ | 
  |  72 |    0 |                            this.parameters = Collections.unmodifiableMap(new HashMap<String, String>(parameters));  | 
  |  73 |     | 
                   } else { | 
  |  74 |    0 |                            this.parameters = null;  | 
  |  75 |     | 
                   }  | 
  |  76 |    0 |            }  | 
  |  77 |     | 
     | 
  |  78 |     | 
           public TermResolutionException(String message, TermResolver<?> tr, Map<String, String> parameters) { | 
  |  79 |    0 |                    super(message + " " + buildResolutionInfoString(tr, parameters));  | 
  |  80 |    0 |                    if (tr == null) { | 
  |  81 |    0 |                            termResolverClassName = "";  | 
  |  82 |    0 |                            outputTerm = null;  | 
  |  83 |    0 |                            prereqs = null;  | 
  |  84 |    0 |                            parameterNames = null;  | 
  |  85 |     | 
                   } else { | 
  |  86 |    0 |                            termResolverClassName = tr.getClass().getName();  | 
  |  87 |    0 |                            outputTerm = tr.getOutput();  | 
  |  88 |    0 |                            prereqs = tr.getPrerequisites();  | 
  |  89 |    0 |                            parameterNames = Collections.unmodifiableSet(new HashSet<String>(tr.getParameterNames()));  | 
  |  90 |     | 
                   }  | 
  |  91 |    0 |                    if (parameters != null){ | 
  |  92 |    0 |                            this.parameters = Collections.unmodifiableMap(new HashMap<String, String>(parameters));  | 
  |  93 |     | 
                   } else { | 
  |  94 |    0 |                            this.parameters = null;  | 
  |  95 |     | 
                   }  | 
  |  96 |    0 |            }  | 
  |  97 |     | 
     | 
  |  98 |     | 
   }  |