1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.harmony.jpda.tests.jdwp.share.debuggee; 20 21 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 22 import org.apache.harmony.jpda.tests.share.SyncDebuggee; 23 24 import java.lang.reflect.InvocationHandler; 25 import java.lang.reflect.Method; 26 import java.lang.reflect.Proxy; 27 28 public class ProxyDebuggee extends SyncDebuggee { 29 public static Object checkedProxyObject = null; 30 31 public static final int ARG_INT = 5; 32 public static final long ARG_LONG = 135l; 33 public static final String ARG_OBJECT = "a string argument"; 34 breakpointMethodFromProxy()35 public void breakpointMethodFromProxy() { 36 System.out.println("breakpointMethodFromProxy"); 37 } 38 39 static interface InterfaceForProxy { call(int i, long l, Object obj)40 public void call(int i, long l, Object obj); 41 } 42 43 static class ProxyInvocationHandler implements InvocationHandler { 44 private final ProxyDebuggee mDebuggee; 45 ProxyInvocationHandler(ProxyDebuggee debuggee)46 public ProxyInvocationHandler(ProxyDebuggee debuggee) { 47 mDebuggee = debuggee; 48 } 49 50 @Override invoke(Object proxy, Method method, Object[] args)51 public Object invoke(Object proxy, Method method, Object[] args) 52 throws Throwable { 53 mDebuggee.breakpointMethodFromProxy(); 54 return null; 55 } 56 } 57 invokeBreakpointMethodFromProxy()58 public void invokeBreakpointMethodFromProxy() { 59 checkedProxyObject = Proxy.newProxyInstance(getClass().getClassLoader(), 60 new Class<?>[] { InterfaceForProxy.class }, 61 new ProxyInvocationHandler(this)); 62 InterfaceForProxy proxy = (InterfaceForProxy) checkedProxyObject; 63 proxy.call(ARG_INT, ARG_LONG, ARG_OBJECT); 64 } 65 66 @Override run()67 public void run() { 68 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 69 70 logWriter.println("ProxyDebuggee started"); 71 72 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 73 74 invokeBreakpointMethodFromProxy(); 75 76 logWriter.println("ProxyDebuggee finished"); 77 } 78 main(String[] args)79 public static void main(String[] args) { 80 runDebuggee(ProxyDebuggee.class); 81 } 82 83 } 84