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.oxm.config;
18  
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.support.ManagedList;
24  import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
25  import org.springframework.beans.factory.xml.ParserContext;
26  import org.springframework.util.StringUtils;
27  import org.springframework.util.xml.DomUtils;
28  import org.w3c.dom.Element;
29  
30  /**
31   * Parser for the <code>&lt;oxm:jaxb2-marshaller/&gt; element.
32   *
33   * @author Arjen Poutsma
34   * @since 1.5.0
35   */
36  class Jaxb2MarshallerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
37  
38      private static final String JAXB2_MARSHALLER_CLASS_NAME = "org.springframework.oxm.jaxb.Jaxb2Marshaller";
39  
40      protected String getBeanClassName(Element element) {
41          return JAXB2_MARSHALLER_CLASS_NAME;
42      }
43  
44      protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
45          String contextPath = element.getAttribute("contextPath");
46          if (StringUtils.hasText(contextPath)) {
47              beanDefinitionBuilder.addPropertyValue("contextPath", contextPath);
48          }
49          List classes = DomUtils.getChildElementsByTagName(element, "class-to-be-bound");
50          if (!classes.isEmpty()) {
51              ManagedList classesToBeBound = new ManagedList(classes.size());
52              for (Iterator iterator = classes.iterator(); iterator.hasNext();) {
53                  Element classToBeBound = (Element) iterator.next();
54                  String className = classToBeBound.getAttribute("name");
55                  classesToBeBound.add(className);
56              }
57              beanDefinitionBuilder.addPropertyValue("classesToBeBound", classesToBeBound);
58          }
59      }
60  
61  }