Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1b45591f43f417ea43d46a7e24863901ed1b8600 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*******************************************************************************
 * 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.remote;
/*


 */


import org.eclipse.jem.internal.proxy.core.*;
import org.eclipse.jem.internal.proxy.common.remote.*;
/**
 * Exception Proxy for exception on Remote.
 * NOTE: This one is unusual in that it doesn't inherit from
 *       IDEBeanProxy because it needs to be an exception, and
 *       exceptions are not an interface.
 */
public class REMThrowableBeanProxy extends ThrowableProxy implements IREMBeanProxy {

	/**
	 * Comment for <code>serialVersionUID</code>
	 * 
	 * @since 1.1.0
	 */
	private static final long serialVersionUID = 2076777336810215206L;
	private Integer fID;
	protected final REMProxyFactoryRegistry fFactory;
	private IBeanTypeProxy fTypeProxy;

	/**
	 * Set the bean we are proxying.  We are a proxy for a bean running on the remote VM. 
	 */
	protected REMThrowableBeanProxy(REMProxyFactoryRegistry aRegistry, Integer anID, IBeanTypeProxy aType){
		fFactory = aRegistry;
		fID = anID;
		fTypeProxy = aType;
	}
	
	/**
	 * equals: Equal if:
	 *         1) This proxy == (identity) to the other object
	 *         2) Else if other is an IBeanProxy and not a constant one, then if
	 *            equals on the server.
	 *         3) If this is a constant proxy and the other is too or is a constant
	 *            value (e.g. IStringBeanProxy.equals(String), then true if values are equals.
	 */
	public boolean equals(Object anObject) {
		if (super.equals(anObject))
			return true;	// Identity
		if (anObject instanceof IBeanProxy && !(anObject instanceof IREMConstantBeanProxy) && fFactory.isValid() && ((IBeanProxy) anObject).getProxyFactoryRegistry() == fFactory)
			try {
				// The other is a bean proxy and is not a constant one, let the server do the check.
				return ((IBooleanBeanProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getObjectEquals().invoke(this, (IBeanProxy) anObject)).booleanValue();
			} catch (ThrowableProxy e) {
			}
		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jem.internal.proxy.core.IBeanProxy#sameAs(org.eclipse.jem.internal.proxy.core.IBeanProxy)
	 */
	public boolean sameAs(IBeanProxy aBeanProxy) {
		return this == aBeanProxy;	// We can be assured in Remote Proxy that identity of proxy and identity of object are the same.
	}
	
	
	/**
	 * Get ID. An internal method to be used only within the ProxyFactory family.
	 */
	public Integer getID() {
		return fID;
	}
	
	/**
	 * isValid - has this bean been released.
	 */
	public boolean isValid() {
		return fID != null;
	}
	
	/**
	 * release - The bean is being released.
	 */
	public void release() {
		fID = null;
		fTypeProxy = null;
	} 
		
	/**
	 * Return the registry this proxy was created with.
	 */
	public ProxyFactoryRegistry getProxyFactoryRegistry() {
		return fFactory;
	}
	
	/**
	 * Return the proxied class of the bean
	 * Creation date: (12/3/99 11:37:01 AM)
	 * @author: Joe Winchester
	 */
	public IBeanTypeProxy getTypeProxy() {
		return fTypeProxy;
	}
	
	/**
	 * Return the toString of the actual bean on the remote side.
	 */
	public String toBeanString() {
		IStringBeanProxy string = (IStringBeanProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getObjectToString().invokeCatchThrowableExceptions(this);
		return (string != null) ? string.stringValue() : null;
	}
	
	public String getProxyLocalizedMessage() {
		IStringBeanProxy msg = (IStringBeanProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getThrowableLocalizedMessage().invokeCatchThrowableExceptions(this);
		return msg != null ? msg.stringValue() : null;
	}
	
	public String getProxyMessage() {
		IStringBeanProxy msg = (IStringBeanProxy)  REMStandardBeanProxyConstants.getConstants(fFactory).getThrowableMessage().invokeCatchThrowableExceptions(this);
		return msg != null ? msg.stringValue() : null;
	}
	
	/**
	 * Temporary way to get the string value of the stacktrace.
	 */
	private String getProxyStackTrace() {
		IMethodProxy tempGetStackTrace = fFactory.getMethodProxyFactory().getMethodProxy("org.eclipse.jem.internal.proxy.vm.remote.StackTraceUtility", "printStackTrace", new String[] {"java.lang.Throwable"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		IStringBeanProxy trace = (IStringBeanProxy) tempGetStackTrace.invokeCatchThrowableExceptions(null, this);
		return trace != null ? trace.stringValue() : ""; //$NON-NLS-1$
	}
		
	public void printProxyStackTrace(java.io.PrintWriter writer) {
		String trace = getProxyStackTrace();
		synchronized(writer) {
			writer.print(trace);
		}
	}
	
	public void printProxyStackTrace(java.io.PrintStream stream) {
		String trace = getProxyStackTrace();
		synchronized(stream) {
			stream.print(trace);
		}

	}
	
	public void printProxyStackTrace() {
		String trace = getProxyStackTrace();
		synchronized(System.err) {
			System.err.print(trace);
		}
	}


	/**
	 * Below are the actual printStackTrace. They are set up to first call
	 * the proxy trace so that it can show where it occurred on the server,
	 * and then it will do a super to show where it occurred on this side.
	 */
	public void printStackTrace() { 
		synchronized (System.err) {
			System.err.println(ProxyRemoteMessages.REMOTE_VM_TRACE_INFO_); 
			printProxyStackTrace();
			System.err.println(ProxyRemoteMessages.REMOTE_VM_LOCAL_TRACE_INFO_); 
			super.printStackTrace();
		}
	}

	public void printStackTrace(java.io.PrintWriter s) { 
		synchronized (s) {
			s.println(ProxyRemoteMessages.REMOTE_VM_TRACE_INFO_); 
			printProxyStackTrace(s);
			s.println(ProxyRemoteMessages.REMOTE_VM_LOCAL_TRACE_INFO_); 
			super.printStackTrace(s);
		}
	}

	public void printStackTrace(java.io.PrintStream s) { 
		synchronized (s) {
			s.println(ProxyRemoteMessages.REMOTE_VM_TRACE_INFO_); 
			printProxyStackTrace(s);
			s.println(ProxyRemoteMessages.REMOTE_VM_LOCAL_TRACE_INFO_); 
			super.printStackTrace(s);
		}
	}

	/**
	 * Render the bean into value object.
	 */
	public void renderBean(Commands.ValueObject value) {
		value.setObjectID(getID().intValue());
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jem.internal.proxy.core.IProxy#isBeanProxy()
	 */
	public final boolean isBeanProxy() {
		return true;
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jem.internal.proxy.core.IProxy#isExpressionProxy()
	 */
	public final boolean isExpressionProxy() {
		return false;
	}
}

Back to the top