Path: blob/master/test/jdk/java/beans/XMLEncoder/Test8013416.java
41149 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* @run main/othervm -Djava.security.manager=allow Test801341628* @author Sergey Malenkov29*/3031import java.beans.DefaultPersistenceDelegate;32import java.beans.Encoder;33import java.beans.Expression;34import java.beans.Statement;35import java.beans.XMLEncoder;36import java.util.HashMap;37import java.util.Map.Entry;38import java.util.Set;3940public class Test8013416 extends AbstractTest {41public static void main(String[] args) {42new Test8013416().test(true);43}4445protected Object getObject() {46Public<String, String> map = new Public<String, String>();47map.put(" pz1 ", " pz2 ");48map.put(" pz3 ", " pz4 ");49return map;50}5152@Override53protected void initialize(XMLEncoder encoder) {54super.initialize(encoder);55encoder.setPersistenceDelegate(Public.class, new PublicPersistenceDelegate());56}5758private static final class PublicPersistenceDelegate extends DefaultPersistenceDelegate {59@Override60protected Expression instantiate(Object oldInstance, Encoder out) {61return new Expression(oldInstance, oldInstance.getClass(), "new", null);62}6364@Override65protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {66super.initialize(type, oldInstance, newInstance, out);6768Public<String, String> map = (Public) oldInstance;69for (Entry<String, String> entry : map.getAll()) {70String[] args = {entry.getKey(), entry.getValue()};71out.writeStatement(new Statement(oldInstance, "put", args));72}73}74}7576public static final class Public<K, V> extends Private<K, V> {77}7879private static class Private<K, V> {80private HashMap<K, V> map = new HashMap<K, V>();8182public void put(K key, V value) {83this.map.put(key, value);84}8586public Set<Entry<K, V>> getAll() {87return this.map.entrySet();88}89}90}919293