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.generic;
8
9 import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
10
11 import org.w3c.dom.Element;
12
13 /**
14 * <p>
15 * Contructs a single, standalone bean from an element - it is not injected into any
16 * other object. This parser can be configured to automatically set the class of the
17 * object, the init and destroy methods and whether this object is a singleton.
18 * </p>
19 * <p>
20 * Typically, you should use {@link MuleOrphanDefinitionParser} instead of this
21 * class, since these elements occur in the <mule> top level element.
22 * </p>
23 */
24 public class OrphanDefinitionParser extends AbstractMuleBeanDefinitionParser
25 {
26 private Class<?> beanClass = null;
27 private boolean dynamicClass = false;
28
29 /**
30 * This constructor assumes that the class name will be explicitly specified as
31 * 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 }