View Javadoc

1   /*
2    * Copyright 2007 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  
17  package org.springframework.ws.config;
18  
19  import java.util.Iterator;
20  import java.util.List;
21  import java.util.Properties;
22  
23  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
24  import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
25  import org.springframework.beans.factory.xml.ParserContext;
26  import org.springframework.util.xml.DomUtils;
27  import org.w3c.dom.Element;
28  
29  /**
30   * Parser for the <code>&lt;sws:xpath-endpoints/&gt; element.
31   *
32   * @author Arjen Poutsma
33   * @since 1.5.0
34   */
35  class XPathEndpointsBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
36  
37      private static final String XPATH_PARAM_ANNOTATION_METHOD_ENDPOINT_ADAPTER_CLASS_NAME =
38              "org.springframework.ws.server.endpoint.adapter.XPathParamAnnotationMethodEndpointAdapter";
39  
40      protected boolean shouldGenerateIdAsFallback() {
41          return true;
42      }
43  
44      protected String getBeanClassName(Element element) {
45          return XPATH_PARAM_ANNOTATION_METHOD_ENDPOINT_ADAPTER_CLASS_NAME;
46      }
47  
48      protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
49          List namespaceElements = DomUtils.getChildElementsByTagName(element, "namespace");
50          if (!namespaceElements.isEmpty()) {
51              Properties namespaces = new Properties();
52              for (Iterator iterator = namespaceElements.iterator(); iterator.hasNext();) {
53                  Element namespaceElement = (Element) iterator.next();
54                  String prefix = namespaceElement.getAttribute("prefix");
55                  String uri = namespaceElement.getAttribute("uri");
56                  namespaces.setProperty(prefix, uri);
57              }
58              beanDefinitionBuilder.addPropertyValue("namespaces", namespaces);
59          }
60      }
61  
62  }