View Javadoc

1   /*
2    * $Id: ObjectFactoryDefinitionParser.java 20297 2010-11-22 18:49:18Z aperepel $
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.AbstractChildDefinitionParser;
14  import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
15  import org.mule.object.AbstractObjectFactory;
16  
17  import org.springframework.beans.factory.config.BeanDefinition;
18  import org.w3c.dom.Element;
19  
20  public class ObjectFactoryDefinitionParser extends AbstractChildDefinitionParser
21  {
22      
23      protected Class beanClass = null;
24      protected String setterMethod = null;
25  
26      public ObjectFactoryDefinitionParser(Class beanClass, String setterMethod)
27      {
28          this(beanClass);
29          this.setterMethod = setterMethod;
30      }                                                             
31      
32      public ObjectFactoryDefinitionParser(Class beanClass)
33      {
34          super();
35          this.beanClass = beanClass;
36          setAllowClassAttribute(false);
37          addAlias(AbstractMuleBeanDefinitionParser.ATTRIBUTE_CLASS, AbstractObjectFactory.ATTRIBUTE_OBJECT_CLASS_NAME);
38          addAlias(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF, "factoryBean");
39      }
40  
41      public String getPropertyName(Element element)
42      {
43          if (setterMethod != null)
44          {
45              return setterMethod;
46          }
47          else
48          {
49              BeanDefinition parent = getParentBeanDefinition(element);
50              String setter = (String) parent.getAttribute(ObjectFactoryWrapper.OBJECT_FACTORY_SETTER);
51              return setter;
52          }
53      }
54  
55      protected Class getBeanClass(Element element)
56      {
57          return beanClass;
58      }                                                                 
59  }