View Javadoc

1   /*
2    * $Id: OrphanDefinitionParser.java 10256 2008-01-08 15:20:25Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  package org.mule.config.spring.parsers.generic;
11  
12  import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
13  
14  import org.w3c.dom.Element;
15  
16  /**
17   * Contructs a single, standalone bean from an element - it is not injected into any other object.
18   * This parser can be configured to automatically set the class of the object, the init and destroy methods
19   * and whether this object is a singleton.
20   *
21   * <p>Typically, you should use {@link MuleOrphanDefinitionParser}
22   * instead of this class, since these elements occur in the <mule> top level element.</p>
23   */
24  public class OrphanDefinitionParser extends AbstractMuleBeanDefinitionParser
25  {
26  
27      private Class beanClass = null;
28      private boolean dynamicClass = false;
29  
30      /**
31       * This constructor assumes that the class name will be explicitly specified as an attribute on the element.
32       */
33      public OrphanDefinitionParser(boolean singleton)
34      {
35          this.singleton = singleton;
36          dynamicClass = true;
37      }
38  
39      public OrphanDefinitionParser(Class beanClass, boolean singleton)
40      {
41          this.beanClass = beanClass;
42          this.singleton = singleton;
43      }
44  
45      // @Override
46      protected void preProcess(Element element)
47      {
48          super.preProcess(element);
49          // top level beans need an ID element
50          AutoIdUtils.ensureUniqueId(element, "bean");
51          if (dynamicClass)
52          {
53              beanClass = null;
54          }
55      }
56  
57      // @Override
58      protected Class getBeanClass(Element element)
59      {
60          return beanClass;
61      }
62  
63  }