1 package org
.argeo
.slc
.core
.execution
.xml
;
3 import org
.argeo
.slc
.SlcException
;
4 import org
.springframework
.beans
.factory
.config
.BeanDefinition
;
5 import org
.springframework
.beans
.factory
.config
.RuntimeBeanReference
;
6 import org
.springframework
.beans
.factory
.xml
.ParserContext
;
7 import org
.springframework
.util
.xml
.DomUtils
;
8 import org
.w3c
.dom
.Element
;
9 import org
.w3c
.dom
.Node
;
10 import org
.w3c
.dom
.NodeList
;
13 * Utilities to simplify common tasks when interpreting a custom namespace and
14 * converting it into bean definitions.
16 public class NamespaceUtils
{
18 * Returns the value defined either: directly by the the 'value' attribute,
19 * as reference by the 'ref' attribute or as a nested bean.
21 public static Object
parseValue(Element element
,
22 ParserContext parserContext
,
23 BeanDefinition containingBeanDefintion
, String valueTagName
) {
25 if (element
.hasAttribute("value")) {
26 value
= element
.getAttribute("value");
29 if (element
.hasAttribute("ref")) {
31 throw new SlcException("Multiple value definition for "
33 value
= new RuntimeBeanReference(element
.getAttribute("ref"));
36 Element uniqueSubElem
= null;
37 if (valueTagName
!= null) {
38 Element valueElem
= DomUtils
.getChildElementByTagName(element
,
40 if (valueElem
!= null) {
41 uniqueSubElem
= findUniqueSubElement(valueElem
);
42 if (uniqueSubElem
== null)
43 throw new SlcException("No subelement found under "
46 } else {// no intermediary tag
47 uniqueSubElem
= findUniqueSubElement(element
);
50 if (uniqueSubElem
!= null) {
52 throw new SlcException("Multiple value definition for "
54 value
= parseBeanReference(uniqueSubElem
, parserContext
,
55 containingBeanDefintion
);
60 public static Element
findUniqueSubElement(Element element
) {
61 NodeList childNodes
= element
.getChildNodes();
63 Element uniqueSubElem
= null;
64 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
65 Node node
= childNodes
.item(i
);
66 if (node
!= null && node
instanceof Element
) {
67 if (uniqueSubElem
== null)
68 uniqueSubElem
= (Element
) node
;
70 throw new SlcException(
71 "There are more than one sub element under "
78 public static Object
parseBeanReference(Element element
,
79 ParserContext parserContext
, BeanDefinition beanDefinition
) {
80 return parserContext
.getDelegate().parsePropertySubElement(element
,