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