Test5023557.java revision 2362
2181N/A/*
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2181N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2181N/A *
2181N/A * This code is free software; you can redistribute it and/or modify it
2181N/A * under the terms of the GNU General Public License version 2 only, as
2181N/A * published by the Free Software Foundation.
2181N/A *
2181N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2181N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2181N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2181N/A * version 2 for more details (a copy is included in the LICENSE file that
2181N/A * accompanied this code).
2181N/A *
2181N/A * You should have received a copy of the GNU General Public License version
2181N/A * 2 along with this work; if not, write to the Free Software Foundation,
2181N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2181N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2181N/A */
2181N/A
2181N/A/*
2181N/A * @test
2181N/A * @bug 5023557
2181N/A * @summary Tests complex references
2181N/A * @author Sergey Malenkov
2181N/A */
2181N/A
2181N/Aimport java.beans.DefaultPersistenceDelegate;
2181N/Aimport java.beans.Encoder;
2181N/Aimport java.beans.Expression;
2181N/Aimport java.beans.XMLEncoder;
2181N/A
2181N/Apublic class Test5023557 extends AbstractTest {
2181N/A public static void main(String[] args) {
2181N/A new Test5023557().test(true);
2181N/A }
2181N/A
2181N/A @Override
2181N/A protected void initialize(XMLEncoder encoder) {
2181N/A encoder.setPersistenceDelegate(B.class, new BDelegate());
2181N/A encoder.setPersistenceDelegate(C.class, new CDelegate());
2181N/A }
2181N/A
2181N/A protected Object getObject() {
2181N/A A a = new A();
2181N/A return a.newC(a.newB());
2181N/A }
2181N/A
2181N/A public static class A {
2181N/A public B newB() {
2181N/A return new B(this);
2181N/A }
2181N/A
2181N/A public C newC(B b) {
2181N/A return new C(b);
2181N/A }
2181N/A }
2181N/A
2181N/A public static class B {
2181N/A private final A a;
2181N/A
2181N/A private B(A a) {
2181N/A this.a = a;
2181N/A }
2181N/A
2181N/A public A getA() {
2181N/A return this.a;
2181N/A }
2181N/A }
2181N/A
2181N/A public static class C {
2181N/A private final B b;
2181N/A
2181N/A private C(B b) {
2181N/A this.b = b;
2181N/A }
2181N/A
2181N/A public B getB() {
2181N/A return this.b;
2181N/A }
2181N/A }
2181N/A
2181N/A public static class BDelegate extends DefaultPersistenceDelegate {
2181N/A protected Expression instantiate(Object old, Encoder out) {
2181N/A B b = (B) old;
2181N/A return new Expression(b, b.getA(), "newB", new Object[0]);
2181N/A }
2181N/A }
2181N/A
2181N/A public static class CDelegate extends DefaultPersistenceDelegate {
2181N/A protected Expression instantiate(Object old, Encoder out) {
2181N/A C c = (C) old;
2181N/A return new Expression(c, c.getB().getA(), "newC", new Object[] { c.getB() });
2181N/A }
2181N/A }
2181N/A}