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 org.springframework.beans.factory.support.BeanDefinitionBuilder;
20  import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
21  import org.springframework.beans.factory.xml.ParserContext;
22  import org.springframework.core.JdkVersion;
23  import org.springframework.util.ClassUtils;
24  import org.springframework.util.StringUtils;
25  import org.w3c.dom.Element;
26  
27  /**
28   * Parser for the <code>&lt;sws:marshalling-endpoints/&gt; element.
29   *
30   * @author Arjen Poutsma
31   * @since 1.5.0
32   */
33  class MarshallingEndpointsBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
34  
35      private static final String GENERIC_MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME =
36              "org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter";
37  
38      private static final boolean genericAdapterPresent = ClassUtils.isPresent(GENERIC_MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME);    
39  
40      private static final String MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME =
41              "org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter";
42  
43      protected boolean shouldGenerateIdAsFallback() {
44          return true;
45      }
46  
47      protected String getBeanClassName(Element element) {
48          if (JdkVersion.isAtLeastJava15() && genericAdapterPresent) {
49                  return GENERIC_MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME;
50          }
51          return MARSHALLING_METHOD_ENDPOINT_ADAPTER_CLASS_NAME;
52      }
53  
54      protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
55          String marshallerName = element.getAttribute("marshaller");
56          if (StringUtils.hasText(marshallerName)) {
57              beanDefinitionBuilder.addPropertyReference("marshaller", marshallerName);
58          }
59          String unmarshallerName = element.getAttribute("unmarshaller");
60          if (StringUtils.hasText(unmarshallerName)) {
61              beanDefinitionBuilder.addPropertyReference("unmarshaller", unmarshallerName);
62          }
63      }
64  
65  }