KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > config > RegistryBeanDefinitionParser


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
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 JavaDoc;
29
30 /**
31  * {@link BeanDefinitionParser} for the <code>&lt;registry&gt;</code> tag.
32  *
33  * @author Ben Hale
34  */

35 class RegistryBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
36     
37     // elements and attributes
38

39     private static final String JavaDoc LOCATION_ELEMENT = "location";
40
41     // properties
42

43     private static final String JavaDoc FLOW_LOCATIONS_PROPERTY = "flowLocations";
44
45     private static final String JavaDoc PATH_ATTRIBUTE = "path";
46
47     protected Class JavaDoc getBeanClass(Element JavaDoc element) {
48         return XmlFlowRegistryFactoryBean.class;
49     }
50
51     protected void doParse(Element JavaDoc element, BeanDefinitionBuilder definitionBuilder) {
52         List JavaDoc locationElements = DomUtils.getChildElementsByTagName(element, LOCATION_ELEMENT);
53         List JavaDoc locations = getLocations(locationElements);
54         definitionBuilder.addPropertyValue(FLOW_LOCATIONS_PROPERTY, locations.toArray(new String JavaDoc[locations.size()]));
55     }
56
57     /**
58      * Parse location definitions from given list of location elements.
59      */

60     private List JavaDoc getLocations(List JavaDoc locationElements) {
61         List JavaDoc locations = new ArrayList JavaDoc(locationElements.size());
62         for (Iterator JavaDoc i = locationElements.iterator(); i.hasNext();) {
63             Element JavaDoc locationElement = (Element JavaDoc)i.next();
64             String JavaDoc path = locationElement.getAttribute(PATH_ATTRIBUTE);
65             if (StringUtils.hasText(path)) {
66                 locations.add(path);
67             }
68         }
69         return locations;
70     }
71 }
Popular Tags