Coverage Report - org.mule.config.spring.MissingParserProblemReporter
 
Classes in this File Line Coverage Branch Coverage Complexity
MissingParserProblemReporter
0%
0/13
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: MissingParserProblemReporter.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.config.spring;
 12  
 
 13  
 import org.springframework.beans.factory.parsing.FailFastProblemReporter;
 14  
 import org.springframework.beans.factory.parsing.Problem;
 15  
 import org.w3c.dom.Element;
 16  
 
 17  
 /**
 18  
  * A very simple extension to {@link org.springframework.beans.factory.parsing.FailFastProblemReporter}
 19  
  * that intercepts errors related to missing definition parsers to give a more helpful message.
 20  
  * In the future we may want to replace this by something more sophisticated that allows
 21  
  * different problems to be resolved by different "pluggable" components...
 22  
  */
 23  0
 public class MissingParserProblemReporter extends FailFastProblemReporter
 24  
 {
 25  
 
 26  
     public static final String NO_PARSER_PREFIX = "Cannot locate BeanDefinitionParser";
 27  
 
 28  
     @Override
 29  
     public void fatal(Problem problem)
 30  
     {
 31  0
         if (isMissingParser(problem))
 32  
         {
 33  0
             problem = extendProblemDetails(problem);
 34  
         }
 35  0
         super.fatal(problem);
 36  0
     }
 37  
 
 38  
     protected boolean isMissingParser(Problem problem)
 39  
     {
 40  
         // Spring doesn't give us much useful data here - parseState and rootCause are null
 41  0
         String message = problem.getMessage();
 42  0
         return (null != message && message.startsWith(NO_PARSER_PREFIX));
 43  
     }
 44  
 
 45  
     protected Problem extendProblemDetails(Problem problem)
 46  
     {
 47  
         try
 48  
         {
 49  0
             String element = ((Element) problem.getLocation().getSource()).getLocalName();
 50  0
             String namespace = ((Element) problem.getLocation().getSource()).getNamespaceURI();
 51  0
             String message = "The element '" + element + "' does not have an associated Bean Definition Parser."
 52  
                     +"  Is the module or transport associated with " + namespace + " present on the classpath?";
 53  0
             return new Problem(message, problem.getLocation(), problem.getParseState(), problem.getRootCause());
 54  
         }
 55  0
         catch (Exception e)
 56  
         {
 57  
             // fall back to previous message
 58  0
             return problem;
 59  
         }
 60  
     }
 61  
 
 62  
 }