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