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 5023550
2181N/A * @summary Tests complex references to owner
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.XMLDecoder;
2181N/Aimport java.beans.XMLEncoder;
2181N/A
2181N/Apublic class Test5023550 extends AbstractTest {
2181N/A public static void main(String[] args) {
2181N/A new Test5023550().test(true);
2181N/A }
2181N/A
2181N/A private final Owner owner = new Owner();
2181N/A
2181N/A @Override
2181N/A protected void initialize(XMLEncoder encoder) {
2181N/A encoder.setOwner(this.owner);
2181N/A encoder.setPersistenceDelegate(A.class, new ADelegate());
2181N/A encoder.setPersistenceDelegate(B.class, new BDelegate());
2181N/A encoder.setPersistenceDelegate(C.class, new CDelegate());
2181N/A }
2181N/A
2181N/A @Override
2181N/A protected void initialize(XMLDecoder decoder) {
2181N/A decoder.setOwner(this.owner);
2181N/A }
2181N/A
2181N/A protected Object getObject() {
2181N/A return this.owner.newA(this.owner.newB().newC());
2181N/A }
2181N/A
2181N/A public static class Owner {
2181N/A public A newA(C c) {
2181N/A return new A(c);
2181N/A }
2181N/A
2181N/A public B newB() {
2181N/A return new B();
2181N/A }
2181N/A }
2181N/A
2181N/A public static class A {
2181N/A private final C c;
2181N/A
2181N/A private A(C c) {
2181N/A this.c = c;
2181N/A }
2181N/A
2181N/A public C getC() {
2181N/A return this.c;
2181N/A }
2181N/A }
2181N/A
2181N/A public static class B {
2181N/A public C newC() {
2181N/A return new C(this);
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 ADelegate extends DefaultPersistenceDelegate {
2181N/A protected Expression instantiate(Object old, Encoder out) {
2181N/A XMLEncoder encoder = (XMLEncoder) out;
2181N/A A a = (A) old;
2181N/A return new Expression(old, encoder.getOwner(), "newA", new Object[] { a.getC() });
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 XMLEncoder encoder = (XMLEncoder) out;
2181N/A return new Expression(old, encoder.getOwner(), "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(), "newC", new Object[0]);
2181N/A }
2181N/A }
2181N/A}