Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7ded239c5282378b872e058b7eb230edcfd7b97c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*******************************************************************************
 * Copyright (c) 2001, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jem.internal.proxy.ide;
/*


 */

import java.io.OutputStream;

import org.eclipse.jem.internal.proxy.common.*;

public class IDEVMServer implements IVMCallbackServer {
	
	IDECallbackRegistry fCallbackRegistry;
	IDEStandardBeanProxyFactory fBeanProxyFactory;
	
IDEVMServer(IDECallbackRegistry aCallbackRegistry){
	fCallbackRegistry = aCallbackRegistry;
	fBeanProxyFactory = (IDEStandardBeanProxyFactory)fCallbackRegistry.fProxyFactoryRegistry.getBeanProxyFactory();
	
}	
public Object doCallback(ICallbackRunnable aRunnable){
	try {
		return aRunnable.run(new ICallbackHandler(){
			public Object callbackWithParms(int callbackID, int msgID, Object[] parms){
				// We are running in the same IDE so just call the registry directly
				// although we must convert the parms to bean proxies
				Object[] proxyParms = null;
				// If we have any parms then convert them to bean proxies
				if ( parms != null ) {
					proxyParms = new Object[parms.length];
					for ( int i=0;i<parms.length;i++){
						Object p = parms[i];
						proxyParms[i] = createNextParm(p);
					}
				}
				return fCallbackRegistry.vmCallback(callbackID,msgID,proxyParms);
			}

			private Object createNextParm(Object p) {
				if (!(p instanceof ICallbackHandler.TransmitableArray)) {
					return fBeanProxyFactory.createIDEBeanProxyWith(p);
				} else {
					Object[] array = ((ICallbackHandler.TransmitableArray) p).getArray();
					Object[] parm = new Object[array.length];
					for (int i = 0; i < array.length; i++) {
						parm[i] = createNextParm(array[i]);
					}
					return parm;
				}
			}
			
			/* (non-Javadoc)
			 * @see org.eclipse.jem.internal.proxy.common.ICallbackHandler#callbackAsConstants(int, int, java.lang.Object)
			 */
			public Object callbackAsConstants(int callbackID, int msgID, Object parm) throws CommandException {
				return fCallbackRegistry.vmCallback(callbackID,msgID,parm);
			}
		});
		
	} catch ( CommandException exc ) {
		return null;	
	}
}

public OutputStream requestStream(int callbackID, int msgID) throws CommandException {
	return fCallbackRegistry.requestStream(callbackID,msgID);
}
public IVMServer getIVMServer() {
	return fCallbackRegistry.fProxyFactoryRegistry;
}


}

Back to the top