01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.springframework.webflow.config;
17:
18: import java.util.ArrayList;
19: import java.util.Iterator;
20: import java.util.List;
21:
22: import org.springframework.beans.factory.support.BeanDefinitionBuilder;
23: import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
24: import org.springframework.beans.factory.xml.BeanDefinitionParser;
25: import org.springframework.util.StringUtils;
26: import org.springframework.util.xml.DomUtils;
27: import org.springframework.webflow.engine.builder.xml.XmlFlowRegistryFactoryBean;
28: import org.w3c.dom.Element;
29:
30: /**
31: * {@link BeanDefinitionParser} for the <code><registry></code> tag.
32: *
33: * @author Ben Hale
34: */
35: class RegistryBeanDefinitionParser extends
36: AbstractSingleBeanDefinitionParser {
37:
38: // elements and attributes
39:
40: private static final String LOCATION_ELEMENT = "location";
41:
42: // properties
43:
44: private static final String FLOW_LOCATIONS_PROPERTY = "flowLocations";
45:
46: private static final String PATH_ATTRIBUTE = "path";
47:
48: protected Class getBeanClass(Element element) {
49: return XmlFlowRegistryFactoryBean.class;
50: }
51:
52: protected void doParse(Element element,
53: BeanDefinitionBuilder definitionBuilder) {
54: List locationElements = DomUtils.getChildElementsByTagName(
55: element, LOCATION_ELEMENT);
56: List locations = getLocations(locationElements);
57: definitionBuilder.addPropertyValue(FLOW_LOCATIONS_PROPERTY,
58: locations.toArray(new String[locations.size()]));
59: }
60:
61: /**
62: * Parse location definitions from given list of location elements.
63: */
64: private List getLocations(List locationElements) {
65: List locations = new ArrayList(locationElements.size());
66: for (Iterator i = locationElements.iterator(); i.hasNext();) {
67: Element locationElement = (Element) i.next();
68: String path = locationElement.getAttribute(PATH_ATTRIBUTE);
69: if (StringUtils.hasText(path)) {
70: locations.add(path);
71: }
72: }
73: return locations;
74: }
75: }
|