Skip to main content
summaryrefslogtreecommitdiffstats
blob: f5c0c33cdedc6b1e30e3092021cd0021c9ee97b2 (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
/*******************************************************************************
* Copyright (c) 2009 Composent, Inc. 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:
*   Composent, Inc. - initial API and implementation
******************************************************************************/
package org.eclipse.ecf.remoteservice.client;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Assert;

/**
 * Implementation of {@link IRemoteCallParameter}.
 * 
 * @since 4.0
 */
public class RemoteCallParameter implements IRemoteCallParameter {

	private String name;
	private Object value;

	public RemoteCallParameter(String name, Object value) {
		this.name = name;
		Assert.isNotNull(this.name);
		this.value = value;
	}

	public RemoteCallParameter(String name) {
		this(name, null);
	}

	public String getName() {
		return name;
	}

	public Object getValue() {
		return value;
	}

	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("RemoteCallParameter[name="); //$NON-NLS-1$
		buffer.append(name);
		buffer.append(", value="); //$NON-NLS-1$
		buffer.append(value);
		buffer.append("]"); //$NON-NLS-1$
		return buffer.toString();
	}

	/**
	 * @since 8.5
	 */
	public static class Builder {

		private final List<IRemoteCallParameter> parameters;

		public Builder() {
			this.parameters = new ArrayList<IRemoteCallParameter>();
		}

		public Builder addParameter(String name, Object defaultValue) {
			if (name == null)
				return this;
			this.parameters.add(new RemoteCallParameter(name, defaultValue));
			return this;
		}

		public Builder addParameter(String name) {
			return addParameter(name, null);
		}

		/**
		 * @param param remote call parameter to add
		 * @return Builder the builder
		 * @since 8.8
		 */
		public Builder addParameter(IRemoteCallParameter param) {
			if (param == null)
				return this;
			this.parameters.add(param);
			return this;
		}

		public IRemoteCallParameter[] build() {
			return this.parameters.toArray(new IRemoteCallParameter[this.parameters.size()]);
		}
	}
}

Back to the top