1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.spring.parsers.delegate; |
12 | |
|
13 | |
import org.mule.config.spring.parsers.MuleDefinitionParser; |
14 | |
|
15 | |
import org.springframework.beans.factory.xml.ParserContext; |
16 | |
import org.w3c.dom.Element; |
17 | |
|
18 | |
public class BooleanAttributeSelectionDefinitionParser extends AbstractParallelDelegatingDefinitionParser |
19 | |
{ |
20 | |
|
21 | |
private String attribute; |
22 | |
private boolean dflt; |
23 | |
private MuleDefinitionParser whenTrue; |
24 | |
private MuleDefinitionParser whenFalse; |
25 | |
|
26 | |
public BooleanAttributeSelectionDefinitionParser(String attribute, boolean dflt, MuleDefinitionParser whenTrue, MuleDefinitionParser whenFalse) |
27 | |
{ |
28 | 0 | super(new MuleDefinitionParser[]{whenTrue, whenFalse}); |
29 | 0 | this.attribute = attribute; |
30 | 0 | this.dflt = dflt; |
31 | 0 | this.whenTrue = whenTrue; |
32 | 0 | this.whenFalse = whenFalse; |
33 | 0 | addIgnored(attribute); |
34 | 0 | } |
35 | |
|
36 | |
protected MuleDefinitionParser getDelegate(Element element, ParserContext parserContext) |
37 | |
{ |
38 | 0 | boolean value = dflt; |
39 | 0 | if (null != element && element.hasAttribute(attribute)) |
40 | |
{ |
41 | 0 | value = Boolean.valueOf(element.getAttribute(attribute)).booleanValue(); |
42 | |
} |
43 | 0 | if (value) |
44 | |
{ |
45 | 0 | return whenTrue; |
46 | |
} |
47 | |
else |
48 | |
{ |
49 | 0 | return whenFalse; |
50 | |
} |
51 | |
} |
52 | |
|
53 | |
} |