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