View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.spring.parsers.specific;
8   
9   import org.mule.config.spring.parsers.AbstractChildDefinitionParser;
10  import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
11  import org.mule.object.AbstractObjectFactory;
12  
13  import org.springframework.beans.factory.config.BeanDefinition;
14  import org.w3c.dom.Element;
15  
16  public class ObjectFactoryDefinitionParser extends AbstractChildDefinitionParser
17  {
18      
19      protected Class beanClass = null;
20      protected String setterMethod = null;
21  
22      public ObjectFactoryDefinitionParser(Class beanClass, String setterMethod)
23      {
24          this(beanClass);
25          this.setterMethod = setterMethod;
26      }                                                             
27      
28      public ObjectFactoryDefinitionParser(Class beanClass)
29      {
30          super();
31          this.beanClass = beanClass;
32          setAllowClassAttribute(false);
33          addAlias(AbstractMuleBeanDefinitionParser.ATTRIBUTE_CLASS, AbstractObjectFactory.ATTRIBUTE_OBJECT_CLASS_NAME);
34          addAlias(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF, "factoryBean");
35      }
36  
37      public String getPropertyName(Element element)
38      {
39          if (setterMethod != null)
40          {
41              return setterMethod;
42          }
43          else
44          {
45              BeanDefinition parent = getParentBeanDefinition(element);
46              String setter = (String) parent.getAttribute(ObjectFactoryWrapper.OBJECT_FACTORY_SETTER);
47              return setter;
48          }
49      }
50  
51      protected Class getBeanClass(Element element)
52      {
53          return beanClass;
54      }                                                                 
55  }