1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
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 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
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 | |
} |