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