1 /* 2 * Copyright (c) 2015, 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 8051636 27 @summary DataTransferer optional dependency on RMI 28 @author Semyon Sadetsky 29 @library ../../regtesthelpers/process 30 @build ProcessResults ProcessCommunicator 31 @run main DataFlavorRemoteTest 32 */ 33 34 import test.java.awt.regtesthelpers.process.ProcessCommunicator; 35 import test.java.awt.regtesthelpers.process.ProcessResults; 36 37 import java.awt.*; 38 import java.awt.datatransfer.Clipboard; 39 import java.awt.datatransfer.DataFlavor; 40 import java.awt.datatransfer.Transferable; 41 import java.awt.datatransfer.UnsupportedFlavorException; 42 import java.io.IOException; 43 import java.io.Serializable; 44 45 interface Hello extends java.rmi.Remote { 46 String sayHello(); 47 } 48 49 public class DataFlavorRemoteTest { 50 51 public static void main(String[] args) throws Exception { 52 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 53 Producer contents = new Producer(); 54 clipboard.setContents(contents, null); 55 ProcessResults processResults = 56 ProcessCommunicator 57 .executeChildProcess(Consumer.class, new String[0]); 58 if (!"Hello".equals(processResults.getStdErr())) { 59 throw new RuntimeException("transfer of remote object failed"); 60 } 61 System.out.println("ok"); 62 } 63 64 static class Consumer { 65 public static void main(String[] args) throws Exception { 66 Clipboard clipboard = 67 Toolkit.getDefaultToolkit().getSystemClipboard(); 68 DataFlavor dataFlavor = new DataFlavor(DataFlavor.javaRemoteObjectMimeType + 69 ";class=Hello" ); 70 Object data = clipboard.getData(dataFlavor); 71 System.err.print(((Hello) data).sayHello()); 72 } 73 74 } 75 } 76 77 class Producer implements Transferable { 78 79 private final DataFlavor dataFlavor; 80 private final HelloImpl impl; 81 82 private static class HelloImpl implements Hello, Serializable { 83 @Override 84 public String sayHello() { 85 return "Hello"; 86 } 87 } 88 89 public Producer() throws Exception { 90 dataFlavor = new DataFlavor(DataFlavor.javaRemoteObjectMimeType + 91 ";class=Hello" ); 92 impl = new HelloImpl(); 93 System.out.println(impl.hashCode()); 94 } 95 96 Hello getImpl() { 97 return impl; 98 } 99 100 @Override 101 public DataFlavor[] getTransferDataFlavors() { 102 return new DataFlavor[]{dataFlavor}; 103 } 104 105 @Override 106 public boolean isDataFlavorSupported(DataFlavor flavor) { 107 return flavor.equals(dataFlavor); 108 } 109 110 @Override 111 public Object getTransferData(DataFlavor flavor) 112 throws UnsupportedFlavorException, IOException { 113 return impl; 114 } 115 116 }