Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/XMLEncoder/Test5023550.java
41149 views
1
/*
2
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 5023550
27
* @summary Tests complex references to owner
28
* @run main/othervm -Djava.security.manager=allow Test5023550
29
* @author Sergey Malenkov
30
*/
31
32
import java.beans.DefaultPersistenceDelegate;
33
import java.beans.Encoder;
34
import java.beans.Expression;
35
import java.beans.XMLDecoder;
36
import java.beans.XMLEncoder;
37
38
public class Test5023550 extends AbstractTest {
39
public static void main(String[] args) {
40
new Test5023550().test(true);
41
}
42
43
private final Owner owner = new Owner();
44
45
@Override
46
protected void initialize(XMLEncoder encoder) {
47
encoder.setOwner(this.owner);
48
encoder.setPersistenceDelegate(A.class, new ADelegate());
49
encoder.setPersistenceDelegate(B.class, new BDelegate());
50
encoder.setPersistenceDelegate(C.class, new CDelegate());
51
}
52
53
@Override
54
protected void initialize(XMLDecoder decoder) {
55
decoder.setOwner(this.owner);
56
}
57
58
protected Object getObject() {
59
return this.owner.newA(this.owner.newB().newC());
60
}
61
62
public static class Owner {
63
public A newA(C c) {
64
return new A(c);
65
}
66
67
public B newB() {
68
return new B();
69
}
70
}
71
72
public static class A {
73
private final C c;
74
75
private A(C c) {
76
this.c = c;
77
}
78
79
public C getC() {
80
return this.c;
81
}
82
}
83
84
public static class B {
85
public C newC() {
86
return new C(this);
87
}
88
}
89
90
public static class C {
91
private final B b;
92
93
private C(B b) {
94
this.b = b;
95
}
96
97
public B getB() {
98
return this.b;
99
}
100
}
101
102
public static class ADelegate extends DefaultPersistenceDelegate {
103
protected Expression instantiate(Object old, Encoder out) {
104
XMLEncoder encoder = (XMLEncoder) out;
105
A a = (A) old;
106
return new Expression(old, encoder.getOwner(), "newA", new Object[] { a.getC() });
107
}
108
}
109
110
public static class BDelegate extends DefaultPersistenceDelegate {
111
protected Expression instantiate(Object old, Encoder out) {
112
XMLEncoder encoder = (XMLEncoder) out;
113
return new Expression(old, encoder.getOwner(), "newB", new Object[0]);
114
}
115
}
116
117
public static class CDelegate extends DefaultPersistenceDelegate {
118
protected Expression instantiate(Object old, Encoder out) {
119
C c = (C) old;
120
return new Expression(c, c.getB(), "newC", new Object[0]);
121
}
122
}
123
}
124
125