Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9ada5230bc3e292317f489d124b65fcee54fc19e (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
/*******************************************************************************
 * 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.*;
/**
 * An abstract base class of IREMBeanProxy that doesn't
 * have the bean type stored in it. The subclasses will
 * supply it. It does however have an ID because it does
 * exist over on the remote VM.
 */
public abstract class REMAbstractBeanProxy implements IREMBeanProxy {
	protected final REMProxyFactoryRegistry fFactory;
	private Integer fID;
	
	/**
	 * Set the bean we are proxying.  We are a proxy for a bean running on the remote VM. 
	 */
	protected REMAbstractBeanProxy(REMProxyFactoryRegistry aRegistry, Integer anID){
		fFactory = aRegistry;
		fID = anID;
	}
	
	/**
	 * 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.
	}
		
	public ProxyFactoryRegistry getProxyFactoryRegistry() {
		return fFactory;
	}
	
	/**
	 * Get ID. An internal method to be used only within the ProxyFactory family.
	 */
	public Integer getID() {
		return fID;
	}
	
	/**
	 * isValid.
	 */
	public boolean isValid() {
		return fID != null;
	}
	
	/**
	 * Proxy is about to be released, MUST mark it invalid.
	 * This is required. Resources can also be cleaned up
	 * if they are being held and need to be cleaned up.
	 *
	 * NOTE: This method will only be called when the proxy
	 * is explicitly released. If it is simply garbage collected,
	 * then this method will not be called. Simple garbage collection
	 * means that no one is referencing this proxy. The proxy factory
	 * will know what id this proxy was referencing and will release it
	 * on the server at GC time.
	 *
	 * If there are resources
	 * that absolutely must be released, then the finalize method
	 * should be implemented to do the clean up. However, try not
	 * to have this be the case. Finalize methods add overhead that is
	 * usually better not to have. The better way is for any users
	 * that get this kind of proxy object know to call release on
	 * ProxyFactoryRegistry to release it before garbage collection.	 
	 */
	public void release() {
		fID = null;
	}
			
	/**
	 * 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;
	}
	
	/**
	 * Render the bean proxy into the value field.
	 */
	public void renderBean(Commands.ValueObject value) {
		value.setObjectID(isValid() ? getID().intValue() : Commands.VOID);	// No longer exists, so send over null.
	}

	/* (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