Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLEncoder/Test5023557.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 502355726* @summary Tests complex references27* @author Sergey Malenkov28*/2930import java.beans.DefaultPersistenceDelegate;31import java.beans.Encoder;32import java.beans.Expression;33import java.beans.XMLEncoder;3435public class Test5023557 extends AbstractTest {36public static void main(String[] args) {37new Test5023557().test(true);38}3940@Override41protected void initialize(XMLEncoder encoder) {42encoder.setPersistenceDelegate(B.class, new BDelegate());43encoder.setPersistenceDelegate(C.class, new CDelegate());44}4546protected Object getObject() {47A a = new A();48return a.newC(a.newB());49}5051public static class A {52public B newB() {53return new B(this);54}5556public C newC(B b) {57return new C(b);58}59}6061public static class B {62private final A a;6364private B(A a) {65this.a = a;66}6768public A getA() {69return this.a;70}71}7273public static class C {74private final B b;7576private C(B b) {77this.b = b;78}7980public B getB() {81return this.b;82}83}8485public static class BDelegate extends DefaultPersistenceDelegate {86protected Expression instantiate(Object old, Encoder out) {87B b = (B) old;88return new Expression(b, b.getA(), "newB", new Object[0]);89}90}9192public static class CDelegate extends DefaultPersistenceDelegate {93protected Expression instantiate(Object old, Encoder out) {94C c = (C) old;95return new Expression(c, c.getB().getA(), "newC", new Object[] { c.getB() });96}97}98}99100101