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.support.AbstractBeanDefinition; |
16 | |
import org.springframework.beans.factory.xml.ParserContext; |
17 | |
import org.w3c.dom.Element; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
public class AbstractFirstResultSerialDefinitionParser extends AbstractSerialDelegatingDefinitionParser |
24 | |
{ |
25 | |
|
26 | |
protected AbstractBeanDefinition firstDefinition; |
27 | 0 | private boolean returnFirstResult = true; |
28 | |
|
29 | |
public AbstractFirstResultSerialDefinitionParser() |
30 | |
{ |
31 | 0 | super(); |
32 | 0 | } |
33 | |
|
34 | |
public AbstractFirstResultSerialDefinitionParser(boolean doReset) |
35 | |
{ |
36 | 0 | super(doReset); |
37 | 0 | } |
38 | |
|
39 | |
public void setReturnFirstResult(boolean returnFirstResult) |
40 | |
{ |
41 | 0 | this.returnFirstResult = returnFirstResult; |
42 | 0 | } |
43 | |
|
44 | |
protected AbstractBeanDefinition doSingleBean(int index, MuleDefinitionParser parser, Element element, ParserContext parserContext) |
45 | |
{ |
46 | |
try |
47 | |
{ |
48 | 0 | AbstractBeanDefinition result = null; |
49 | |
try |
50 | |
{ |
51 | 0 | result = super.doSingleBean(index, parser, element, parserContext); |
52 | |
} |
53 | 0 | catch (RuntimeException e) |
54 | |
{ |
55 | 0 | if (!isExceptionHandled(e)) |
56 | |
{ |
57 | 0 | throw e; |
58 | |
} |
59 | 0 | } |
60 | 0 | if (0 == index) |
61 | |
{ |
62 | 0 | firstDefinition = result; |
63 | |
} |
64 | 0 | if (size() == index + 1) |
65 | |
{ |
66 | 0 | if (returnFirstResult) |
67 | |
{ |
68 | 0 | return firstDefinition; |
69 | |
} |
70 | |
else |
71 | |
{ |
72 | 0 | return result; |
73 | |
} |
74 | |
} |
75 | |
else |
76 | |
{ |
77 | 0 | return null; |
78 | |
} |
79 | |
} |
80 | 0 | catch (RuntimeException e) |
81 | |
{ |
82 | 0 | firstDefinition = null; |
83 | 0 | throw e; |
84 | |
} |
85 | |
} |
86 | |
|
87 | |
} |