Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLEncoder/Test5023559.java
38812 views
/*1* Copyright (c) 2007, 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 502355926* @summary Tests encoding of the object with nested target27* @author Sergey Malenkov28*/2930import java.beans.Encoder;31import java.beans.Expression;32import java.beans.PersistenceDelegate;33import java.beans.XMLEncoder;3435public final class Test5023559 extends AbstractTest {36public static void main(String[] args) {37new Test5023559().test(true);38}3940protected Object getObject() {41return new GrandParent().create().create();42}4344protected void initialize(XMLEncoder encoder) {45encoder.setPersistenceDelegate(Parent.class, new PersistenceDelegate() {46protected Expression instantiate(Object old, Encoder out) {47Parent parent = (Parent) old;48return new Expression(old, parent.getParent(), "create", new Object[] {});49}50});51encoder.setPersistenceDelegate(Child.class, new PersistenceDelegate() {52protected Expression instantiate(Object old, Encoder out) {53Child child = (Child) old;54return new Expression(old, child.getParent(), "create", new Object[] {});55}56});57}5859public static final class GrandParent {60public Parent create() {61return new Parent(this);62}63}6465public static final class Parent {66private final GrandParent parent;6768private Parent(GrandParent parent) {69this.parent = parent;70}7172public GrandParent getParent() {73return this.parent;74}7576public Child create() {77return new Child(this);78}79}8081public static final class Child {82private final Parent parent;8384private Child(Parent parent) {85this.parent = parent;86}8788public Parent getParent() {89return this.parent;90}91}92}939495