Path: blob/master/test/jdk/java/beans/XMLEncoder/Test5023557.java
41149 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* @run main/othervm -Djava.security.manager=allow Test502355728* @author Sergey Malenkov29*/3031import java.beans.DefaultPersistenceDelegate;32import java.beans.Encoder;33import java.beans.Expression;34import java.beans.XMLEncoder;3536public class Test5023557 extends AbstractTest {37public static void main(String[] args) {38new Test5023557().test(true);39}4041@Override42protected void initialize(XMLEncoder encoder) {43encoder.setPersistenceDelegate(B.class, new BDelegate());44encoder.setPersistenceDelegate(C.class, new CDelegate());45}4647protected Object getObject() {48A a = new A();49return a.newC(a.newB());50}5152public static class A {53public B newB() {54return new B(this);55}5657public C newC(B b) {58return new C(b);59}60}6162public static class B {63private final A a;6465private B(A a) {66this.a = a;67}6869public A getA() {70return this.a;71}72}7374public static class C {75private final B b;7677private C(B b) {78this.b = b;79}8081public B getB() {82return this.b;83}84}8586public static class BDelegate extends DefaultPersistenceDelegate {87protected Expression instantiate(Object old, Encoder out) {88B b = (B) old;89return new Expression(b, b.getA(), "newB", new Object[0]);90}91}9293public static class CDelegate extends DefaultPersistenceDelegate {94protected Expression instantiate(Object old, Encoder out) {95C c = (C) old;96return new Expression(c, c.getB().getA(), "newC", new Object[] { c.getB() });97}98}99}100101102