1 /* 2 * Copyright (c) 2013, 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 8013416 27 * @summary Tests public synthetic methods 28 * @author Sergey Malenkov 29 */ 30 31 import java.beans.DefaultPersistenceDelegate; 32 import java.beans.Encoder; 33 import java.beans.Expression; 34 import java.beans.Statement; 35 import java.beans.XMLEncoder; 36 import java.util.HashMap; 37 import java.util.Map.Entry; 38 import java.util.Set; 39 40 public class Test8013416 extends AbstractTest { 41 public static void main(String[] args) { 42 new Test8013416().test(true); 43 } 44 45 protected Object getObject() { 46 Public<String, String> map = new Public<String, String>(); 47 map.put(" pz1 ", " pz2 "); 48 map.put(" pz3 ", " pz4 "); 49 return map; 50 } 51 52 @Override 53 protected void initialize(XMLEncoder encoder) { 54 super.initialize(encoder); 55 encoder.setPersistenceDelegate(Public.class, new PublicPersistenceDelegate()); 56 } 57 58 private static final class PublicPersistenceDelegate extends DefaultPersistenceDelegate { 59 @Override 60 protected Expression instantiate(Object oldInstance, Encoder out) { 61 return new Expression(oldInstance, oldInstance.getClass(), "new", null); 62 } 63 64 @Override 65 protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) { 66 super.initialize(type, oldInstance, newInstance, out); 67 68 Public<String, String> map = (Public) oldInstance; 69 for (Entry<String, String> entry : map.getAll()) { 70 String[] args = {entry.getKey(), entry.getValue()}; 71 out.writeStatement(new Statement(oldInstance, "put", args)); 72 } 73 } 74 } 75 76 public static final class Public<K, V> extends Private<K, V> { 77 } 78 79 private static class Private<K, V> { 80 private HashMap<K, V> map = new HashMap<K, V>(); 81 82 public void put(K key, V value) { 83 this.map.put(key, value); 84 } 85 86 public Set<Entry<K, V>> getAll() { 87 return this.map.entrySet(); 88 } 89 } 90 }