1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.spring.handlers; |
8 | |
|
9 | |
import org.mule.config.spring.parsers.generic.OrphanDefinitionParser; |
10 | |
import org.mule.config.spring.parsers.specific.InvokerMessageProcessorDefinitionParser; |
11 | |
import org.mule.config.spring.util.ParamReader; |
12 | |
|
13 | |
import java.io.IOException; |
14 | |
import java.lang.reflect.Method; |
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | 0 | public abstract class AbstractPojoNamespaceHandler extends AbstractMuleNamespaceHandler |
21 | |
{ |
22 | |
public void registerPojo(String configElementName, Class<?> cls) |
23 | |
{ |
24 | |
|
25 | 0 | OrphanDefinitionParser parser = new OrphanDefinitionParser(cls, true); |
26 | 0 | parser.addIgnored("name"); |
27 | 0 | registerMuleBeanDefinitionParser(configElementName, parser); |
28 | |
|
29 | |
|
30 | |
try |
31 | |
{ |
32 | 0 | ParamReader paramReader = new ParamReader(cls); |
33 | |
|
34 | 0 | for (Method m : cls.getDeclaredMethods()) |
35 | |
{ |
36 | |
|
37 | 0 | if (!m.getName().startsWith("set")) |
38 | |
{ |
39 | 0 | String[] parameterNames = paramReader.getParameterNames(m); |
40 | |
|
41 | 0 | registerMuleBeanDefinitionParser(splitCamelCase(m.getName()), |
42 | |
new InvokerMessageProcessorDefinitionParser("messageProcessor", cls, m.getName(), |
43 | |
parameterNames)); |
44 | |
} |
45 | |
} |
46 | |
} |
47 | 0 | catch (IOException e) |
48 | |
{ |
49 | 0 | throw new RuntimeException(e); |
50 | 0 | } |
51 | 0 | } |
52 | |
|
53 | |
protected static String splitCamelCase(String s) |
54 | |
{ |
55 | 0 | if (s.contains("get")) |
56 | |
{ |
57 | 0 | s = s.substring(3); |
58 | |
} |
59 | 0 | return s.replaceAll( |
60 | |
String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z][0-9])", "(?<=[^A-Z])(?=[A-Z])", |
61 | |
"(?<=[A-Za-z0-9])(?=[^A-Za-z0-9])"), "-").toLowerCase(); |
62 | |
} |
63 | |
|
64 | |
} |