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 | |
import org.mule.config.spring.parsers.MuleDefinitionParserConfiguration; |
15 | |
import org.mule.config.spring.parsers.PostProcessor; |
16 | |
import org.mule.config.spring.parsers.PreProcessor; |
17 | |
import org.mule.config.spring.parsers.assembly.configuration.ValueMap; |
18 | |
import org.mule.config.spring.parsers.generic.AutoIdUtils; |
19 | |
import org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate; |
20 | |
import org.mule.util.ArrayUtils; |
21 | |
|
22 | |
import java.util.Map; |
23 | |
|
24 | |
import org.springframework.beans.factory.support.AbstractBeanDefinition; |
25 | |
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; |
26 | |
import org.springframework.beans.factory.xml.ParserContext; |
27 | |
import org.w3c.dom.Element; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public abstract class AbstractDelegatingDefinitionParser extends AbstractBeanDefinitionParser |
39 | |
implements MuleDefinitionParser |
40 | |
{ |
41 | |
|
42 | |
private MuleDefinitionParser[] delegates; |
43 | |
|
44 | |
protected AbstractDelegatingDefinitionParser() |
45 | |
{ |
46 | 0 | this(new MuleDefinitionParser[0]); |
47 | 0 | } |
48 | |
|
49 | |
protected AbstractDelegatingDefinitionParser(MuleDefinitionParser[] delegates) |
50 | 0 | { |
51 | 0 | this.delegates = delegates; |
52 | 0 | addBeanFlag(MuleHierarchicalBeanDefinitionParserDelegate.MULE_FORCE_RECURSE); |
53 | 0 | } |
54 | |
|
55 | |
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) |
56 | |
{ |
57 | 0 | return muleParse(element, parserContext); |
58 | |
} |
59 | |
|
60 | |
protected MuleDefinitionParserConfiguration addDelegate(MuleDefinitionParser delegate) |
61 | |
{ |
62 | 0 | delegates = (MuleDefinitionParser[]) ArrayUtils.add(delegates, delegate); |
63 | 0 | return delegate; |
64 | |
} |
65 | |
|
66 | |
protected int size() |
67 | |
{ |
68 | 0 | return delegates.length; |
69 | |
} |
70 | |
|
71 | |
protected MuleDefinitionParser getDelegate(int index) |
72 | |
{ |
73 | 0 | return delegates[index]; |
74 | |
} |
75 | |
|
76 | |
public MuleDefinitionParserConfiguration registerPreProcessor(PreProcessor preProcessor) |
77 | |
{ |
78 | 0 | for (int i = 0; i < delegates.length; ++i) |
79 | |
{ |
80 | 0 | delegates[i].registerPreProcessor(preProcessor); |
81 | |
} |
82 | 0 | return this; |
83 | |
} |
84 | |
|
85 | |
public MuleDefinitionParserConfiguration registerPostProcessor(PostProcessor postProcessor) |
86 | |
{ |
87 | 0 | for (int i = 0; i < delegates.length; ++i) |
88 | |
{ |
89 | 0 | delegates[i].registerPostProcessor(postProcessor); |
90 | |
} |
91 | 0 | return this; |
92 | |
} |
93 | |
|
94 | |
public MuleDefinitionParserConfiguration addReference(String propertyName) |
95 | |
{ |
96 | 0 | for (int i = 0; i < delegates.length; ++i) |
97 | |
{ |
98 | 0 | delegates[i].addReference(propertyName); |
99 | |
} |
100 | 0 | return this; |
101 | |
} |
102 | |
|
103 | |
public MuleDefinitionParserConfiguration addMapping(String propertyName, Map mappings) |
104 | |
{ |
105 | 0 | for (int i = 0; i < delegates.length; ++i) |
106 | |
{ |
107 | 0 | delegates[i].addMapping(propertyName, mappings); |
108 | |
} |
109 | 0 | return this; |
110 | |
} |
111 | |
|
112 | |
public MuleDefinitionParserConfiguration addMapping(String propertyName, String mappings) |
113 | |
{ |
114 | 0 | for (int i = 0; i < delegates.length; ++i) |
115 | |
{ |
116 | 0 | delegates[i].addMapping(propertyName, mappings); |
117 | |
} |
118 | 0 | return this; |
119 | |
} |
120 | |
|
121 | |
public MuleDefinitionParserConfiguration addMapping(String propertyName, ValueMap mappings) |
122 | |
{ |
123 | 0 | for (int i = 0; i < delegates.length; ++i) |
124 | |
{ |
125 | 0 | delegates[i].addMapping(propertyName, mappings); |
126 | |
} |
127 | 0 | return this; |
128 | |
} |
129 | |
|
130 | |
public MuleDefinitionParserConfiguration addAlias(String alias, String propertyName) |
131 | |
{ |
132 | 0 | for (int i = 0; i < delegates.length; ++i) |
133 | |
{ |
134 | 0 | delegates[i].addAlias(alias, propertyName); |
135 | |
} |
136 | 0 | return this; |
137 | |
} |
138 | |
|
139 | |
public MuleDefinitionParserConfiguration addCollection(String propertyName) |
140 | |
{ |
141 | 0 | for (int i = 0; i < delegates.length; ++i) |
142 | |
{ |
143 | 0 | delegates[i].addCollection(propertyName); |
144 | |
} |
145 | 0 | return this; |
146 | |
} |
147 | |
|
148 | |
public MuleDefinitionParserConfiguration addIgnored(String propertyName) |
149 | |
{ |
150 | 0 | for (int i = 0; i < delegates.length; ++i) |
151 | |
{ |
152 | 0 | delegates[i].addIgnored(propertyName); |
153 | |
} |
154 | 0 | return this; |
155 | |
} |
156 | |
|
157 | |
public MuleDefinitionParserConfiguration removeIgnored(String propertyName) |
158 | |
{ |
159 | 0 | for (int i = 0; i < delegates.length; ++i) |
160 | |
{ |
161 | 0 | delegates[i].removeIgnored(propertyName); |
162 | |
} |
163 | 0 | return this; |
164 | |
} |
165 | |
|
166 | |
public MuleDefinitionParserConfiguration setIgnoredDefault(boolean ignoreAll) |
167 | |
{ |
168 | 0 | for (int i = 0; i < delegates.length; ++i) |
169 | |
{ |
170 | 0 | delegates[i].setIgnoredDefault(ignoreAll); |
171 | |
} |
172 | 0 | return this; |
173 | |
} |
174 | |
|
175 | |
public String getBeanName(Element element) |
176 | |
{ |
177 | 0 | return AutoIdUtils.getUniqueName(element, "delegate"); |
178 | |
} |
179 | |
|
180 | |
public MuleDefinitionParserConfiguration addBeanFlag(String flag) |
181 | |
{ |
182 | 0 | for (int i = 0; i < delegates.length; ++i) |
183 | |
{ |
184 | 0 | delegates[i].addBeanFlag(flag); |
185 | |
} |
186 | 0 | return this; |
187 | |
} |
188 | |
|
189 | |
} |