Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLEncoder/Test5023550.java
38812 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 502355026* @summary Tests complex references to owner27* @author Sergey Malenkov28*/2930import java.beans.DefaultPersistenceDelegate;31import java.beans.Encoder;32import java.beans.Expression;33import java.beans.XMLDecoder;34import java.beans.XMLEncoder;3536public class Test5023550 extends AbstractTest {37public static void main(String[] args) {38new Test5023550().test(true);39}4041private final Owner owner = new Owner();4243@Override44protected void initialize(XMLEncoder encoder) {45encoder.setOwner(this.owner);46encoder.setPersistenceDelegate(A.class, new ADelegate());47encoder.setPersistenceDelegate(B.class, new BDelegate());48encoder.setPersistenceDelegate(C.class, new CDelegate());49}5051@Override52protected void initialize(XMLDecoder decoder) {53decoder.setOwner(this.owner);54}5556protected Object getObject() {57return this.owner.newA(this.owner.newB().newC());58}5960public static class Owner {61public A newA(C c) {62return new A(c);63}6465public B newB() {66return new B();67}68}6970public static class A {71private final C c;7273private A(C c) {74this.c = c;75}7677public C getC() {78return this.c;79}80}8182public static class B {83public C newC() {84return new C(this);85}86}8788public static class C {89private final B b;9091private C(B b) {92this.b = b;93}9495public B getB() {96return this.b;97}98}99100public static class ADelegate extends DefaultPersistenceDelegate {101protected Expression instantiate(Object old, Encoder out) {102XMLEncoder encoder = (XMLEncoder) out;103A a = (A) old;104return new Expression(old, encoder.getOwner(), "newA", new Object[] { a.getC() });105}106}107108public static class BDelegate extends DefaultPersistenceDelegate {109protected Expression instantiate(Object old, Encoder out) {110XMLEncoder encoder = (XMLEncoder) out;111return new Expression(old, encoder.getOwner(), "newB", new Object[0]);112}113}114115public static class CDelegate extends DefaultPersistenceDelegate {116protected Expression instantiate(Object old, Encoder out) {117C c = (C) old;118return new Expression(c, c.getB(), "newC", new Object[0]);119}120}121}122123124