Mercurial > hg > release > icedtea7-forest-2.6 > jdk
changeset 8284:3c743031578a jdk7u76-b02
8036981: JAXB not preserving formatting for xsd:any Mixed content
Reviewed-by: lancea, mkos
author | aefimov |
---|---|
date | Tue, 02 Sep 2014 13:57:25 +0400 |
parents | 1f914460ca11 |
children | 5e3a73518863 |
files | test/javax/xml/bind/marshal/8036981/Good.java test/javax/xml/bind/marshal/8036981/Main.java test/javax/xml/bind/marshal/8036981/ObjectFactory.java test/javax/xml/bind/marshal/8036981/Root.java test/javax/xml/bind/marshal/8036981/Test.java test/javax/xml/bind/marshal/8036981/test.xml |
diffstat | 6 files changed, 449 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/marshal/8036981/Good.java Tue Sep 02 13:57:25 2014 +0400 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package testjaxbcontext; + +import org.w3c.dom.Element; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlType; +import java.util.ArrayList; +import java.util.List; + +/** + * <p> + * Java class for Good complex type. + * + * <p> + * The following schema fragment specifies the expected content contained within + * this class. + * + * <pre> + * <complexType name="Good"> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <any processContents='skip' maxOccurs="70"/> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> + * </pre> + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "Good", propOrder = { + "any" +}) +public class Good { + + @XmlAnyElement + protected List<Element> any; + + /** + * Gets the value of the any property. + * + * <p> + * This accessor method returns a reference to the live list, not a + * snapshot. Therefore any modification you make to the returned list will + * be present inside the JAXB object. This is why there is not a + * <CODE>set</CODE> method for the any property. + * + * <p> + * For example, to add a new item, do as follows: + * <pre> + * getAny().add(newItem); + * </pre> + * + * + * <p> + * Objects of the following type(s) are allowed in the list + * {@link org.w3c.dom.Element } + * + * + */ + public List<Element> getAny() { + if (any == null) { + any = new ArrayList<Element>(); + } + return this.any; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/marshal/8036981/Main.java Tue Sep 02 13:57:25 2014 +0400 @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package testjaxbcontext; + +import javax.xml.bind.annotation.*; + +/** + * <p> + * Java class for main complex type. + * + * <p> + * The following schema fragment specifies the expected content contained within + * this class. + * + * <pre> + * <complexType name="main"> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <element name="Root" type="{}Root"/> + * <element name="Good" type="{}Good"/> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> + * </pre> + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "main", propOrder = { + "root", + "good" +}) +@XmlRootElement +public class Main { + + @XmlElement(name = "Root", required = true) + protected Root root; + @XmlElement(name = "Good", required = true) + protected Good good; + + /** + * Gets the value of the root property. + * + * @return possible object is {@link Root } + * + */ + public Root getRoot() { + return root; + } + + /** + * Sets the value of the root property. + * + * @param value allowed object is {@link Root } + * + */ + public void setRoot(Root value) { + this.root = value; + } + + /** + * Gets the value of the good property. + * + * @return possible object is {@link Good } + * + */ + public Good getGood() { + return good; + } + + /** + * Sets the value of the good property. + * + * @param value allowed object is {@link Good } + * + */ + public void setGood(Good value) { + this.good = value; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/marshal/8036981/ObjectFactory.java Tue Sep 02 13:57:25 2014 +0400 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package testjaxbcontext; + +import javax.xml.bind.annotation.XmlRegistry; + +/** + * This object contains factory methods for each Java content interface and Java + * element interface generated in the generated package. + * <p> + * An ObjectFactory allows you to programatically construct new instances of the + * Java representation for XML content. The Java representation of XML content + * can consist of schema derived interfaces and classes representing the binding + * of schema type definitions, element declarations and model groups. Factory + * methods for each of these are provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + /** + * Create a new ObjectFactory that can be used to create new instances of + * schema derived classes for package: generated + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Root } + * + */ + public Root createRoot() { + return new Root(); + } + + /** + * Create an instance of {@link Good } + * + */ + public Good createGood() { + return new Good(); + } + + /** + * Create an instance of {@link Main } + * + */ + public Main createMain() { + return new Main(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/marshal/8036981/Root.java Tue Sep 02 13:57:25 2014 +0400 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package testjaxbcontext; + +import javax.xml.bind.annotation.*; +import java.util.ArrayList; +import java.util.List; + +/** + * <p> + * Java class for Root complex type. + * + * <p> + * The following schema fragment specifies the expected content contained within + * this class. + * + * <pre> + * <complexType name="Root"> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <any processContents='skip' maxOccurs="70"/> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> + * </pre> + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "Root", propOrder = { + "content" +}) +public class Root { + + @XmlMixed + @XmlAnyElement + protected List<Object> content; + + /** + * Gets the value of the content property. + * + * <p> + * This accessor method returns a reference to the live list, not a + * snapshot. Therefore any modification you make to the returned list will + * be present inside the JAXB object. This is why there is not a + * <CODE>set</CODE> method for the content property. + * + * <p> + * For example, to add a new item, do as follows: + * <pre> + * getContent().add(newItem); + * </pre> + * + * + * <p> + * Objects of the following type(s) are allowed in the list {@link org.w3c.dom.Element } + * {@link String } + * + * + */ + public List<Object> getContent() { + if (content == null) { + content = new ArrayList<Object>(); + } + return this.content; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/marshal/8036981/Test.java Tue Sep 02 13:57:25 2014 +0400 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test Test.java + * @bug 8036981 + * @summary JAXB not preserving formatting during unmarshalling/marshalling + * @compile Good.java Main.java ObjectFactory.java Root.java + * @run main/othervm Test + */ + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import java.io.File; +import java.io.StringWriter; + +/** + * Test for marshalling and unmarshalling mixed and unmixed content + */ +public class Test { + + private static final String EXPECTED = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><main><Root>\n" + + " <SomeTag>\n" + + " <AChildTag>\n" + + " <AnotherChildTag/>\n" + + " <AnotherChildTag/>\n" + + " </AChildTag>\n" + + " </SomeTag>\n" + + " </Root><Good><VeryGood><TheBest><MegaSuper/><MegaSuper/>\n" + + " </TheBest>\n" + + " </VeryGood></Good></main>"; + + public static void main(String[] args) throws Exception { + JAXBContext jc = JAXBContext.newInstance("testjaxbcontext"); + Unmarshaller u = jc.createUnmarshaller(); + Object result = u.unmarshal(new File(System.getProperty("test.src", ".") + "/test.xml")); + StringWriter sw = new StringWriter(); + Marshaller m = jc.createMarshaller(); + m.marshal(result, sw); + System.out.println("Expected:" + EXPECTED); + System.out.println("Observed:" + sw.toString()); + if (!EXPECTED.equals(sw.toString())) { + throw new Exception("Unmarshal/Marshal generates different content"); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/xml/bind/marshal/8036981/test.xml Tue Sep 02 13:57:25 2014 +0400 @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<main> + <Root> + <SomeTag> + <AChildTag> + <AnotherChildTag/> + <AnotherChildTag/> + </AChildTag> + </SomeTag> + </Root> + <Good> + <VeryGood> + <TheBest> + <MegaSuper/> + <MegaSuper/> + </TheBest> + </VeryGood> + </Good> +</main>