Skip to main content
summaryrefslogtreecommitdiffstats
blob: ca53a1cd8ba363d62cbd2fcbab70e524f4c3f008 (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
/*******************************************************************************
 * 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;
/*
 *  $RCSfile: IDEBeanProxy.java,v $
 *  $Revision: 1.7 $  $Date: 2005/08/24 20:39:06 $ 
 */

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

public abstract class IDEBeanProxy implements IBeanProxy, IIDEBeanProxy {

	protected Object fBean;
	protected final IDEProxyFactoryRegistry fProxyFactoryRegistry;

	protected IDEBeanProxy(IDEProxyFactoryRegistry aProxyFactoryRegistry) {
		fProxyFactoryRegistry = aProxyFactoryRegistry;
	}
	protected IDEBeanProxy(IDEProxyFactoryRegistry aProxyFactoryRegistry, Object anObject) {
		fProxyFactoryRegistry = aProxyFactoryRegistry;
		fBean = anObject;
	}
	public boolean isValid() {
		return true;
	}
	public ProxyFactoryRegistry getProxyFactoryRegistry() {
		return fProxyFactoryRegistry;
	}
	/**
	 * USE with extreme care
	 */
	public final Object getBean() {
		return fBean;
	}
	/**
	 * Return the toString() of the bean
	 */
	public String toBeanString() {
		return (fBean != null ? fBean.toString() : "null"); //$NON-NLS-1$
	}
	/**
	 Append the bean's to string to our own name if we have one
	 */
	public String toString() {

		if (fBean == null)
			return super.toString();
		else
			return super.toString() + "(" + fBean.toString() + ")"; //$NON-NLS-2$//$NON-NLS-1$

	}
	/**
	 * equals: If there are identical or if they wrapper the same bean. In the IDE VM this
	 * can happen if bean proxies are created from a Bean, since proxies aren't cached in
	 * the beanproxy factory, more than one proxy can be created for the same bean.
	 */
	public boolean equals(Object obj) {
		if (super.equals(obj))
			return true;
		if (obj instanceof IIDEBeanProxy) {
			return fBean.equals(((IIDEBeanProxy) obj).getBean());
		}
		return false;
	}
	
	public int hashCode() {
		return 12345 + (getBean() != null ? getBean().hashCode() : 0); 
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jem.internal.proxy.core.IBeanProxy#sameAs(org.eclipse.jem.internal.proxy.core.IBeanProxy)
	 */
	public boolean sameAs(IBeanProxy aBeanProxy) {
		if (this == aBeanProxy)
			return true;
		if (aBeanProxy instanceof IIDEBeanProxy)
			return getBean() == ((IIDEBeanProxy) aBeanProxy).getBean();
		return false;
	}

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