0N/A/*
2362N/A * Copyright (c) 2007, 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 *
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.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4936682
0N/A * @summary Tests encoding of reference to target
0N/A * @author Sergey Malenkov
0N/A */
0N/A
0N/Aimport java.beans.DefaultPersistenceDelegate;
0N/Aimport java.beans.Encoder;
0N/Aimport java.beans.Expression;
0N/Aimport java.beans.XMLEncoder;
0N/A
0N/Apublic final class Test4936682 extends AbstractTest<Object[]> {
0N/A public static void main(String[] args) {
0N/A new Test4936682().test(true);
0N/A }
0N/A
0N/A protected Object[] getObject() {
0N/A OuterClass outer = new OuterClass();
0N/A return new Object [] {outer.getInner(), outer};
0N/A }
0N/A
0N/A protected void initialize(XMLEncoder encoder) {
0N/A encoder.setPersistenceDelegate(
0N/A OuterClass.InnerClass.class,
0N/A new DefaultPersistenceDelegate() {
0N/A protected Expression instantiate(Object oldInstance, Encoder out) {
0N/A OuterClass.InnerClass inner = (OuterClass.InnerClass) oldInstance;
0N/A OuterClass outer = inner.getOuter();
0N/A return new Expression(inner, outer, "getInner", new Object[0]);
0N/A }
0N/A }
0N/A );
0N/A }
0N/A
0N/A protected void validate(Object[] before, Object[] after) {
0N/A validate(before);
0N/A validate(after);
0N/A }
0N/A
0N/A private static void validate(Object[] array) {
0N/A if (2 != array.length) {
0N/A throw new Error("unexpected array length: " + array.length);
0N/A }
0N/A OuterClass outer = (OuterClass) array[1];
0N/A if (!outer.getInner().equals(array[0])) {
0N/A throw new Error("unexpected array content");
0N/A }
0N/A }
0N/A
0N/A public static final class OuterClass {
0N/A private final InnerClass inner = new InnerClass();
0N/A
0N/A public InnerClass getInner() {
0N/A return this.inner;
0N/A }
0N/A
0N/A public class InnerClass {
0N/A private InnerClass() {
0N/A }
0N/A
0N/A public OuterClass getOuter() {
0N/A return OuterClass.this;
0N/A }
0N/A }
0N/A }
0N/A}