01 /*
02 * CustomisableBeanDefinitionParser.java
03 *
04 * Copyright (c) 1995-2010, The University of Sheffield. See the file
05 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
06 *
07 * This file is part of GATE (see http://gate.ac.uk/), and is free
08 * software, licenced under the GNU Library General Public License,
09 * Version 2, June 1991 (in the distribution as file licence.html,
10 * and also available at http://gate.ac.uk/gate/licence.html).
11 *
12 * Ian Roberts, 22/Jan/2008
13 *
14 * $Id: CustomisableBeanDefinitionParser.java 12006 2009-12-01 17:24:28Z thomas_heitz $
15 */
16
17 package gate.util.spring.xml;
18
19 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
20 import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
21 import org.springframework.beans.factory.xml.ParserContext;
22 import org.springframework.util.xml.DomUtils;
23 import org.w3c.dom.Element;
24 import org.w3c.dom.NodeList;
25
26 /**
27 * Common superclass for BeanDefinitionParsers for elements that support
28 * a nested <code><gate:customisers></code> element mapping to a
29 * "customisers" property in the parsed definition.
30 */
31 public abstract class CustomisableBeanDefinitionParser
32 extends
33 AbstractSingleBeanDefinitionParser {
34
35 public CustomisableBeanDefinitionParser() {
36 super();
37 }
38
39 /**
40 * Processes the customisers sub-element of the given element. If no
41 * such sub-element exists, does nothing.
42 */
43 protected void extractCustomisers(Element element,
44 ParserContext parserContext, BeanDefinitionBuilder builder) {
45 Element customisersElement = DomUtils.getChildElementByTagName(element,
46 "customisers");
47 if(customisersElement != null) {
48 if(customisersElement.hasAttribute("ref")) {
49 NodeList childNodes = customisersElement.getChildNodes();
50 for(int i = 0; i < childNodes.getLength(); i++) {
51 if(childNodes.item(i) instanceof Element) {
52 parserContext.getReaderContext().error(
53 "customisers element in saved-application cannot "
54 + "have both children and a 'ref' attribute",
55 customisersElement);
56 break;
57 }
58 }
59
60 builder.addPropertyReference("customisers", customisersElement
61 .getAttribute("ref"));
62 }
63 else {
64 builder.addPropertyValue("customisers", parserContext.getDelegate()
65 .parseListElement(customisersElement,
66 builder.getRawBeanDefinition()));
67 }
68 }
69 }
70
71 }
|