View Javadoc

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