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