1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.spring.parsers.cache; |
8 | |
|
9 | |
import org.mule.config.spring.parsers.assembly.BeanAssembler; |
10 | |
import org.mule.config.spring.parsers.assembly.BeanAssemblerFactory; |
11 | |
import org.mule.config.spring.parsers.assembly.DefaultBeanAssembler; |
12 | |
import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration; |
13 | |
import org.mule.config.spring.parsers.assembly.configuration.SingleProperty; |
14 | |
import org.mule.config.spring.parsers.generic.ChildDefinitionParser; |
15 | |
import org.mule.config.spring.parsers.processors.CheckExclusiveAttributes; |
16 | |
import org.mule.routing.filters.ExpressionFilter; |
17 | |
|
18 | |
import org.springframework.beans.MutablePropertyValues; |
19 | |
import org.springframework.beans.factory.config.BeanDefinition; |
20 | |
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
21 | |
|
22 | |
public class CacheDefinitionParser extends ChildDefinitionParser |
23 | |
{ |
24 | |
|
25 | |
public CacheDefinitionParser(String setterMethod, Class<?> clazz) |
26 | |
{ |
27 | 0 | super(setterMethod, clazz); |
28 | 0 | setBeanAssemblerFactory(new LocalBeanAssemblerFactory()); |
29 | 0 | registerPreProcessor(new CheckExclusiveAttributes(new String[][] { |
30 | |
new String[] {"filterExpression"}, new String[] {"filter-ref"}})); |
31 | 0 | } |
32 | |
|
33 | |
private class LocalBeanAssembler extends DefaultBeanAssembler |
34 | |
{ |
35 | |
|
36 | |
public LocalBeanAssembler(PropertyConfiguration beanConfig, BeanDefinitionBuilder bean, |
37 | |
PropertyConfiguration targetConfig, BeanDefinition target) |
38 | 0 | { |
39 | 0 | super(beanConfig, bean, targetConfig, target); |
40 | 0 | } |
41 | |
|
42 | |
protected void addPropertyWithReference(MutablePropertyValues properties, SingleProperty config, String name, Object value) |
43 | |
{ |
44 | 0 | if ("filterExpression".equals(name)) |
45 | |
{ |
46 | 0 | BeanDefinitionBuilder wrapper = BeanDefinitionBuilder.genericBeanDefinition(ExpressionFilter.class); |
47 | 0 | wrapper.addConstructorArgValue(value); |
48 | |
|
49 | 0 | super.addPropertyWithReference(properties, config, "filter", wrapper.getBeanDefinition()); |
50 | 0 | } |
51 | |
else |
52 | |
{ |
53 | 0 | super.addPropertyWithReference(properties, config, name, value); |
54 | |
} |
55 | 0 | } |
56 | |
} |
57 | |
|
58 | 0 | private class LocalBeanAssemblerFactory implements BeanAssemblerFactory |
59 | |
{ |
60 | |
|
61 | |
public BeanAssembler newBeanAssembler(PropertyConfiguration beanConfig, BeanDefinitionBuilder bean, |
62 | |
PropertyConfiguration targetConfig, BeanDefinition target) |
63 | |
{ |
64 | 0 | return new LocalBeanAssembler(beanConfig, bean, targetConfig, target); |
65 | |
} |
66 | |
|
67 | |
} |
68 | |
} |