1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.spring.parsers.specific; |
8 | |
|
9 | |
import org.mule.config.spring.parsers.delegate.ParentContextDefinitionParser; |
10 | |
import org.mule.config.spring.parsers.generic.ChildDefinitionParser; |
11 | |
import org.mule.config.spring.parsers.generic.MuleOrphanDefinitionParser; |
12 | |
import org.mule.config.spring.parsers.processors.CheckExclusiveAttributesAndChildren; |
13 | |
import org.mule.config.spring.parsers.processors.CheckRequiredAttributesWhenNoChildren; |
14 | |
import org.mule.expression.ExpressionConfig; |
15 | |
import org.mule.expression.transformers.ExpressionArgument; |
16 | |
|
17 | |
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
18 | |
import org.springframework.beans.factory.support.GenericBeanDefinition; |
19 | |
import org.springframework.beans.factory.support.ManagedList; |
20 | |
import org.springframework.beans.factory.xml.ParserContext; |
21 | |
import org.w3c.dom.Element; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class ExpressionTransformerDefinitionParser extends ParentContextDefinitionParser |
28 | |
{ |
29 | |
|
30 | |
public ExpressionTransformerDefinitionParser(Class messageProcessor) |
31 | |
{ |
32 | 0 | super(MuleOrphanDefinitionParser.ROOT_ELEMENT, new ExpressionTransformerOrphanDefinitionParser( |
33 | |
messageProcessor, false)); |
34 | 0 | otherwise(new ExpressionTransformerChildDefinitionParser("messageProcessor", messageProcessor)); |
35 | |
|
36 | 0 | registerPreProcessor( |
37 | |
new CheckRequiredAttributesWhenNoChildren(new String[][]{{"evaluator", "expression"}}, |
38 | |
"return-argument")).registerPreProcessor( |
39 | |
new CheckExclusiveAttributesAndChildren(new String[]{"evaluator", "expression"}, |
40 | |
new String[]{"return-argument"})) |
41 | |
.addIgnored("evaluator") |
42 | |
.addIgnored("expression") |
43 | |
.addIgnored("custom-evaluator"); |
44 | 0 | } |
45 | |
|
46 | |
protected static void addExpressionArgumentFromAttributes(Element element, BeanDefinitionBuilder builder) |
47 | |
{ |
48 | 0 | if (element.getAttributeNode("expression") != null) |
49 | |
{ |
50 | 0 | GenericBeanDefinition objectFactoryBeanDefinition = new GenericBeanDefinition(); |
51 | 0 | objectFactoryBeanDefinition.setBeanClass(ExpressionArgument.class); |
52 | 0 | objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("name", "single"); |
53 | 0 | objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("optional", false); |
54 | 0 | GenericBeanDefinition objectFactoryBeanDefinition2 = new GenericBeanDefinition(); |
55 | 0 | objectFactoryBeanDefinition2.setBeanClass(ExpressionConfig.class); |
56 | 0 | objectFactoryBeanDefinition2.getPropertyValues().addPropertyValue("evaluator", |
57 | |
element.getAttribute("evaluator")); |
58 | 0 | objectFactoryBeanDefinition2.getPropertyValues().addPropertyValue("customEvaluator", |
59 | |
element.getAttribute("custom-evaluator")); |
60 | 0 | objectFactoryBeanDefinition2.getPropertyValues().addPropertyValue("expression", |
61 | |
element.getAttribute("expression")); |
62 | 0 | objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("expressionConfig", |
63 | |
objectFactoryBeanDefinition2); |
64 | 0 | ManagedList list = new ManagedList<ExpressionArgument>(1); |
65 | 0 | list.add(objectFactoryBeanDefinition2); |
66 | 0 | builder.getBeanDefinition().getPropertyValues().addPropertyValue("arguments", |
67 | |
objectFactoryBeanDefinition); |
68 | |
} |
69 | 0 | } |
70 | |
|
71 | |
static class ExpressionTransformerChildDefinitionParser extends ChildDefinitionParser |
72 | |
{ |
73 | |
|
74 | |
public ExpressionTransformerChildDefinitionParser(String string, Class messageProcessor) |
75 | |
{ |
76 | 0 | super(string, messageProcessor); |
77 | 0 | } |
78 | |
|
79 | |
@Override |
80 | |
protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) |
81 | |
{ |
82 | 0 | addExpressionArgumentFromAttributes(element, builder); |
83 | 0 | super.parseChild(element, parserContext, builder); |
84 | 0 | } |
85 | |
}; |
86 | |
|
87 | |
static class ExpressionTransformerOrphanDefinitionParser extends MuleOrphanDefinitionParser |
88 | |
{ |
89 | |
|
90 | |
public ExpressionTransformerOrphanDefinitionParser(Class<?> beanClass, boolean singleton) |
91 | |
{ |
92 | 0 | super(beanClass, singleton); |
93 | 0 | } |
94 | |
|
95 | |
@Override |
96 | |
protected void doParse(Element element, ParserContext context, BeanDefinitionBuilder builder) |
97 | |
{ |
98 | 0 | addExpressionArgumentFromAttributes(element, builder); |
99 | 0 | super.doParse(element, context, builder); |
100 | 0 | } |
101 | |
}; |
102 | |
|
103 | |
} |