Skip to main content
summaryrefslogtreecommitdiffstats
blob: b99a5968a3ff08c371f6479aaf9411fc25d3af16 (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
/*******************************************************************************
 * 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.Commands;

final class REMFieldProxy extends REMAccessibleObjectProxy implements IFieldProxy {
	private IBeanTypeProxy fFieldType;

	REMFieldProxy(REMProxyFactoryRegistry aRegistry, Integer anID) {
		super(aRegistry, anID);
	}

	/**
	 * Return the type of the field.
	 */
	public IBeanTypeProxy getFieldType() {
		if (fFieldType == null)
			fFieldType =
				(IBeanTypeProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getFieldGetType().invokeCatchThrowableExceptions(
					this);

		return fFieldType;
	}

	/**
	 * Release the proxy, i.e. mark it invalid.
	 */
	public void release() {
		fFieldType = null;
		super.release();
	}

	/**
	 * Get the value of this field from the subject
	 */
	public IBeanProxy get(IBeanProxy subject) throws ThrowableProxy {
		// Format of getter parms is: (Object (subject)).
		// If the component type is primitive, we need to use the correct getter so that a valid value is returned,
		// if we just used the standard get, if the type was "int" the value returned would be an java.lang.Integer.
		IBeanTypeProxy fieldType = getFieldType();
		if (!fieldType.isPrimitive()) {
			// Use standard getter.
			return ((IREMMethodProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getFieldGet()).invoke(this, subject);
		} else {
			// Use the correct primitive getter.
			int id = ((IREMBeanProxy) fieldType).getID().intValue();
			switch (id) {
				case Commands.BYTE_TYPE :
					return ((IREMMethodProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getFieldGetByte()).invoke(this, subject);
				case Commands.BOOLEAN_TYPE :
					return ((IREMMethodProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getFieldGetBoolean()).invoke(
						this,
						subject);
				case Commands.CHARACTER_TYPE :
					return ((IREMMethodProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getFieldGetChar()).invoke(this, subject);
				case Commands.DOUBLE_TYPE :
					return ((IREMMethodProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getFieldGetDouble()).invoke(
						this,
						subject);
				case Commands.FLOAT_TYPE :
					return ((IREMMethodProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getFieldGetFloat()).invoke(
						this,
						subject);
				case Commands.INTEGER_TYPE :
					return ((IREMMethodProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getFieldGetInt()).invoke(this, subject);
				case Commands.LONG_TYPE :
					return ((IREMMethodProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getFieldGetLong()).invoke(this, subject);
				case Commands.SHORT_TYPE :
					return ((IREMMethodProxy) REMStandardBeanProxyConstants.getConstants(fFactory).getFieldGetShort()).invoke(
						this,
						subject);
			}
		}

		return null;
	}

	/**
	 * Set the value of this field in this subject to this value.
	 */
	public void set(IBeanProxy subject, IBeanProxy value) throws ThrowableProxy {
		REMStandardBeanProxyConstants.getConstants(fFactory).getFieldSet().invoke(this, new IBeanProxy[] { subject, value });
	}

	/**
	 * The type proxy is constant proxy out of the method factory.
	 */
	public IBeanTypeProxy getTypeProxy() {
		return ((REMMethodProxyFactory) fFactory.getMethodProxyFactory()).fieldType;
	}

}

Back to the top