Coverage Report - org.mule.module.xml.config.XPathAnnotationParser
 
Classes in this File Line Coverage Branch Coverage Complexity
XPathAnnotationParser
0%
0/18
0%
0/22
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.xml.config;
 8  
 
 9  
 import org.mule.api.annotations.expression.XPath;
 10  
 import org.mule.api.annotations.meta.Evaluator;
 11  
 import org.mule.api.expression.ExpressionAnnotationParser;
 12  
 import org.mule.expression.ExpressionConfig;
 13  
 import org.mule.expression.transformers.ExpressionArgument;
 14  
 import org.mule.module.xml.i18n.XmlMessages;
 15  
 
 16  
 import java.lang.annotation.Annotation;
 17  
 
 18  
 import org.w3c.dom.Document;
 19  
 import org.w3c.dom.Element;
 20  
 import org.w3c.dom.Node;
 21  
 import org.w3c.dom.NodeList;
 22  
 
 23  
 /**
 24  
  * Used to parse Bean parameter annotations. Note this annotation only supports the Jaxp API and w3c Dom.  There is
 25  
  * not Dom4J support.
 26  
  *
 27  
  * @see org.mule.api.annotations.expression.XPath
 28  
  * @see org.mule.module.xml.expression.XPathExpressionEvaluator
 29  
  */
 30  0
 public class XPathAnnotationParser implements ExpressionAnnotationParser
 31  
 {
 32  
     public ExpressionArgument parse(Annotation annotation, Class<?> parameterType)
 33  
     {
 34  0
         Evaluator evaluator = annotation.annotationType().getAnnotation(Evaluator.class);
 35  0
         String eval = "xpath2";
 36  
         String type;
 37  0
         if (evaluator != null)
 38  
         {
 39  0
             if (parameterType.equals(Node.class) || parameterType.equals(org.dom4j.Node.class) ||
 40  
                     parameterType.equals(Element.class) || parameterType.equals(org.dom4j.Element.class) ||
 41  
                     parameterType.equals(Document.class) || parameterType.equals(org.dom4j.Document.class))
 42  
             {
 43  0
                 type = "[node]";
 44  
             }
 45  0
             else if(NodeList.class.isAssignableFrom(parameterType))
 46  
             {
 47  0
                 type = "[nodeset]";
 48  
             }
 49  0
             else if(Boolean.class.isAssignableFrom(parameterType))
 50  
             {
 51  0
                 type = "[boolean]";
 52  
             }
 53  0
             else if(Double.class.isAssignableFrom(parameterType))
 54  
             {
 55  0
                 type = "[number]";
 56  
             }
 57  0
             else if(String.class.isAssignableFrom(parameterType))
 58  
             {
 59  0
                 type = "[string]";
 60  
             }
 61  
             else
 62  
             {
 63  0
                 throw new IllegalArgumentException(XmlMessages.xpathResultTypeNotSupported(parameterType).getMessage());
 64  
             }
 65  0
             return new ExpressionArgument(null, new ExpressionConfig(type + ((XPath) annotation).value(),
 66  
                     eval, null), ((XPath) annotation).optional(), parameterType);
 67  
         }
 68  
         else
 69  
         {
 70  0
             throw new IllegalArgumentException("The @Evaluator annotation must be set on an Expression Annotation");
 71  
         }
 72  
     }
 73  
 
 74  
     public boolean supports(Annotation annotation)
 75  
     {
 76  0
         return annotation instanceof XPath;
 77  
     }
 78  
 }