1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.spring.parsers.specific; |
12 | |
|
13 | |
import org.mule.api.lifecycle.Disposable; |
14 | |
import org.mule.api.lifecycle.Initialisable; |
15 | |
import org.mule.component.DefaultJavaComponent; |
16 | |
import org.mule.object.AbstractObjectFactory; |
17 | |
import org.mule.object.SingletonObjectFactory; |
18 | |
|
19 | |
import org.springframework.beans.factory.support.AbstractBeanDefinition; |
20 | |
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
21 | |
import org.springframework.beans.factory.support.GenericBeanDefinition; |
22 | |
import org.springframework.beans.factory.xml.ParserContext; |
23 | |
import org.w3c.dom.Element; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class SimpleComponentDefinitionParser extends ComponentDefinitionParser |
38 | |
{ |
39 | 0 | private static Class OBJECT_FACTORY_TYPE = SingletonObjectFactory.class; |
40 | |
private Class componentInstanceClass; |
41 | |
|
42 | |
public SimpleComponentDefinitionParser(Class component, Class componentInstanceClass) |
43 | |
{ |
44 | 0 | super(DefaultJavaComponent.class); |
45 | 0 | this.componentInstanceClass = componentInstanceClass; |
46 | 0 | } |
47 | |
|
48 | |
protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) |
49 | |
{ |
50 | 0 | Element parent = (Element) element.getParentNode(); |
51 | 0 | String serviceName = parent.getAttribute(ATTRIBUTE_NAME); |
52 | 0 | builder.addPropertyReference("service", serviceName); |
53 | |
|
54 | |
|
55 | |
|
56 | 0 | AbstractBeanDefinition objectFactoryBeanDefinition = new GenericBeanDefinition(); |
57 | 0 | objectFactoryBeanDefinition.setBeanClass(OBJECT_FACTORY_TYPE); |
58 | 0 | objectFactoryBeanDefinition.getPropertyValues().addPropertyValue(AbstractObjectFactory.ATTRIBUTE_OBJECT_CLASS, |
59 | |
componentInstanceClass); |
60 | 0 | objectFactoryBeanDefinition.setInitMethodName(Initialisable.PHASE_NAME); |
61 | 0 | objectFactoryBeanDefinition.setDestroyMethodName(Disposable.PHASE_NAME); |
62 | |
|
63 | 0 | builder.addPropertyValue("objectFactory", objectFactoryBeanDefinition); |
64 | |
|
65 | 0 | super.parseChild(element, parserContext, builder); |
66 | 0 | } |
67 | |
|
68 | |
} |