From d202573e1a582cd1c3b48d0ee75110a458a4da89 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 2 Sep 2013 22:02:11 +0200 Subject: [PATCH] Revised spring-oxm for 4.0 Added "target-package" to the jibx-marshaller element. Also fixed "context-path" and "binding-name" to follow Spring's usual attribute naming convention. Issue: SPR-10882 --- .../CastorMarshallerBeanDefinitionParser.java | 7 +- .../Jaxb2MarshallerBeanDefinitionParser.java | 21 +++-- .../JibxMarshallerBeanDefinitionParser.java | 6 +- ...mlBeansMarshallerBeanDefinitionParser.java | 6 +- .../oxm/config/spring-oxm-4.0.xsd | 92 ++++++++++--------- 5 files changed, 69 insertions(+), 63 deletions(-) diff --git a/spring-oxm/src/main/java/org/springframework/oxm/config/CastorMarshallerBeanDefinitionParser.java b/spring-oxm/src/main/java/org/springframework/oxm/config/CastorMarshallerBeanDefinitionParser.java index e2f6a3f25b..f59effac2f 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/config/CastorMarshallerBeanDefinitionParser.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/config/CastorMarshallerBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,10 +28,9 @@ import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; */ public class CastorMarshallerBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser { - private static final String CASTOR_MARSHALLER_CLASS_NAME = "org.springframework.oxm.castor.CastorMarshaller"; - @Override protected String getBeanClassName(Element element) { - return CASTOR_MARSHALLER_CLASS_NAME; + return "org.springframework.oxm.castor.CastorMarshaller"; } + } diff --git a/spring-oxm/src/main/java/org/springframework/oxm/config/Jaxb2MarshallerBeanDefinitionParser.java b/spring-oxm/src/main/java/org/springframework/oxm/config/Jaxb2MarshallerBeanDefinitionParser.java index 2529b9ca07..0dc8092ee1 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/config/Jaxb2MarshallerBeanDefinitionParser.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/config/Jaxb2MarshallerBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* -* Copyright 2002-2012 the original author or authors. +* Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package org.springframework.oxm.config; -import java.util.Iterator; import java.util.List; import org.w3c.dom.Element; @@ -36,24 +35,26 @@ import org.springframework.util.xml.DomUtils; */ class Jaxb2MarshallerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { - private static final String JAXB2_MARSHALLER_CLASS_NAME = "org.springframework.oxm.jaxb.Jaxb2Marshaller"; - @Override protected String getBeanClassName(Element element) { - return JAXB2_MARSHALLER_CLASS_NAME; + return "org.springframework.oxm.jaxb.Jaxb2Marshaller"; } @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) { - String contextPath = element.getAttribute("contextPath"); + String contextPath = element.getAttribute("context-path"); + if (!StringUtils.hasText(contextPath)) { + // Backwards compatibility with 3.x version of the xsd + contextPath = element.getAttribute("contextPath"); + } if (StringUtils.hasText(contextPath)) { beanDefinitionBuilder.addPropertyValue("contextPath", contextPath); } - List classes = DomUtils.getChildElementsByTagName(element, "class-to-be-bound"); + + List classes = DomUtils.getChildElementsByTagName(element, "class-to-be-bound"); if (!classes.isEmpty()) { - ManagedList classesToBeBound = new ManagedList(classes.size()); - for (Iterator iterator = classes.iterator(); iterator.hasNext();) { - Element classToBeBound = (Element) iterator.next(); + ManagedList classesToBeBound = new ManagedList(classes.size()); + for (Element classToBeBound : classes) { String className = classToBeBound.getAttribute("name"); classesToBeBound.add(className); } diff --git a/spring-oxm/src/main/java/org/springframework/oxm/config/JibxMarshallerBeanDefinitionParser.java b/spring-oxm/src/main/java/org/springframework/oxm/config/JibxMarshallerBeanDefinitionParser.java index a83051b9b0..1ba7e975b3 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/config/JibxMarshallerBeanDefinitionParser.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/config/JibxMarshallerBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,11 +28,9 @@ import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; */ class JibxMarshallerBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser { - private static final String JIBX_MARSHALLER_CLASS_NAME = "org.springframework.oxm.jibx.JibxMarshaller"; - @Override protected String getBeanClassName(Element element) { - return JIBX_MARSHALLER_CLASS_NAME; + return "org.springframework.oxm.jibx.JibxMarshaller"; } } diff --git a/spring-oxm/src/main/java/org/springframework/oxm/config/XmlBeansMarshallerBeanDefinitionParser.java b/spring-oxm/src/main/java/org/springframework/oxm/config/XmlBeansMarshallerBeanDefinitionParser.java index 0f5dc4c0f1..580c7c09db 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/config/XmlBeansMarshallerBeanDefinitionParser.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/config/XmlBeansMarshallerBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,11 +31,9 @@ import org.springframework.util.StringUtils; */ class XmlBeansMarshallerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { - public static final String XML_BEANS_MARSHALLER_CLASS_NAME = "org.springframework.oxm.xmlbeans.XmlBeansMarshaller"; - @Override protected String getBeanClassName(Element element) { - return XML_BEANS_MARSHALLER_CLASS_NAME; + return "org.springframework.oxm.xmlbeans.XmlBeansMarshaller"; } @Override diff --git a/spring-oxm/src/main/resources/org/springframework/oxm/config/spring-oxm-4.0.xsd b/spring-oxm/src/main/resources/org/springframework/oxm/config/spring-oxm-4.0.xsd index 35739ca48b..353b1b4bae 100644 --- a/spring-oxm/src/main/resources/org/springframework/oxm/config/spring-oxm-4.0.xsd +++ b/spring-oxm/src/main/resources/org/springframework/oxm/config/spring-oxm-4.0.xsd @@ -1,9 +1,10 @@ + xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:tool="http://www.springframework.org/schema/tool" + targetNamespace="http://www.springframework.org/schema/oxm" + elementFormDefault="qualified" + attributeFormDefault="unqualified"> @@ -35,9 +36,9 @@ - + - The JAXB Context path + The JAXB context path. @@ -59,42 +60,19 @@ - - + - The binding name used by this marshaller. + The target class to be bound with JiBX. - - - - - - - - - - Defines a XMLBeans Marshaller. - - - - - - - - - - + - - The bean name of the XmlOptions that is to be used for this marshaller. Typically a - XmlOptionsFactoryBean definition. - - - - - - + The target package for the JiBX binding. + + + + + The binding name used by this marshaller. @@ -124,7 +102,7 @@ - The target class to be bound with Castor marshaller. + The target class to be bound with the Castor marshaller. @@ -134,7 +112,39 @@ - The path to Castor mapping file. + The path to the Castor mapping file. + + + + + + + + + + + + Defines a XMLBeans Marshaller. + + + + + + + + + + + + + The bean name of the XmlOptions that is to be used for this marshaller. Typically a + XmlOptionsFactoryBean definition. + + + + + + @@ -148,7 +158,7 @@ - +