Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLEncoder/Test8013416.java
38812 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 801341626* @summary Tests public synthetic methods27* @author Sergey Malenkov28*/2930import java.beans.DefaultPersistenceDelegate;31import java.beans.Encoder;32import java.beans.Expression;33import java.beans.Statement;34import java.beans.XMLEncoder;35import java.util.HashMap;36import java.util.Map.Entry;37import java.util.Set;3839public class Test8013416 extends AbstractTest {40public static void main(String[] args) {41new Test8013416().test(true);42}4344protected Object getObject() {45Public<String, String> map = new Public<String, String>();46map.put(" pz1 ", " pz2 ");47map.put(" pz3 ", " pz4 ");48return map;49}5051@Override52protected void initialize(XMLEncoder encoder) {53super.initialize(encoder);54encoder.setPersistenceDelegate(Public.class, new PublicPersistenceDelegate());55}5657private static final class PublicPersistenceDelegate extends DefaultPersistenceDelegate {58@Override59protected Expression instantiate(Object oldInstance, Encoder out) {60return new Expression(oldInstance, oldInstance.getClass(), "new", null);61}6263@Override64protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {65super.initialize(type, oldInstance, newInstance, out);6667Public<String, String> map = (Public) oldInstance;68for (Entry<String, String> entry : map.getAll()) {69String[] args = {entry.getKey(), entry.getValue()};70out.writeStatement(new Statement(oldInstance, "put", args));71}72}73}7475public static final class Public<K, V> extends Private<K, V> {76}7778private static class Private<K, V> {79private HashMap<K, V> map = new HashMap<K, V>();8081public void put(K key, V value) {82this.map.put(key, value);83}8485public Set<Entry<K, V>> getAll() {86return this.map.entrySet();87}88}89}909192