1 /*
2 * $Id: ObjectFactoryWrapper.java 19191 2010-08-25 21:05:23Z tcarlson $
3 * --------------------------------------------------------------------------------------
4 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
5 *
6 * The software in this package is published under the terms of the CPAL v1.0
7 * license, a copy of which has been included with this distribution in the
8 * LICENSE.txt file.
9 */
10
11 package org.mule.config.spring.parsers.specific;
12
13 import org.mule.config.spring.parsers.assembly.BeanAssembler;
14 import org.mule.config.spring.parsers.generic.ParentDefinitionParser;
15
16 import org.springframework.beans.factory.config.BeanDefinition;
17 import org.springframework.beans.factory.xml.ParserContext;
18 import org.w3c.dom.Element;
19
20 /**
21 * Use this BeanDefinitionParser when you need a "wrapper" element for an ObjectFactory.
22 * For example, suppose we have the following class:
23 *
24 * class Car
25 * {
26 * private ObjectFactory<Wheel> wheel;
27 * }
28 *
29 * The following registration in the namespace:
30 *
31 * registerBeanDefinitionParser("wheel", new ObjectFactoryWrapper("wheel"));
32 *
33 * would allow a config such as:
34 *
35 * <car>
36 * <wheel>
37 * <prototype-object class="com.wheelsrus.BigWheel">
38 * <properties>
39 * <spring:property name="tire" value="goodyear"/>
40 * <spring:property name="diameter" value="35R"/>
41 * </properties>
42 * </prototype-object>
43 * </wheel>
44 * </car>
45 */
46 public class ObjectFactoryWrapper extends ParentDefinitionParser
47 {
48 public static final String OBJECT_FACTORY_SETTER = "objectFactoryPropertyName";
49
50 private String objectFactoryPropertyName;
51
52 public ObjectFactoryWrapper(String objectFactoryPropertyName)
53 {
54 super();
55 this.objectFactoryPropertyName = objectFactoryPropertyName;
56 }
57
58 protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
59 {
60 super.postProcess(context, assembler, element);
61 BeanDefinition parent = getParentBeanDefinition(element);
62 parent.setAttribute(OBJECT_FACTORY_SETTER, objectFactoryPropertyName);
63 }
64 }