Skip to main content
summaryrefslogtreecommitdiffstats
blob: dc454c26e5c619e5ba9eaab4ad8b948272b0c16e (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
/*******************************************************************************
 * Copyright (c) 2015 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.provider;

import java.util.Dictionary;
import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.ContainerTypeDescription;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.provider.IContainerInstantiator;

/**
 * Basic implementation of IRemoteServiceDistributionProvider.  Intended to be subclassed by distribution
 * provider implementations and or use Builder static inner class to create/build instances.
 * 
 * @since 8.7
 */
public class RemoteServiceDistributionProvider implements IRemoteServiceDistributionProvider {

	private String name;
	private IContainerInstantiator instantiator;
	private String description;
	private boolean server;
	private boolean hidden;
	private Dictionary<String, ?> ctdProperties;
	private Namespace namespace;
	private Dictionary<String, ?> nsProperties;
	private AdapterConfig adapterConfig;

	/**
	 * Builder for RemoteServiceDistributionProvider instances
	 *
	 */
	public static class Builder {

		private final RemoteServiceDistributionProvider instance;

		public Builder() {
			this.instance = new RemoteServiceDistributionProvider();
		}

		public Builder setName(String name) {
			this.instance.setName(name);
			return this;
		}

		public Builder setInstantiator(IContainerInstantiator instantiator) {
			this.instance.setInstantiator(instantiator);
			return this;
		}

		public Builder setDescription(String desc) {
			this.instance.setDescription(desc);
			return this;
		}

		public Builder setServer(boolean server) {
			this.instance.setServer(server);
			return this;
		}

		public Builder setHidden(boolean hidden) {
			this.instance.setHidden(hidden);
			return this;
		}

		public Builder setNamespace(Namespace ns) {
			this.instance.setNamespace(ns);
			return this;
		}

		public Builder setContainerTypeDescriptionProperties(Dictionary<String, ?> props) {
			this.instance.setContainerTypeDescriptionProperties(props);
			return this;
		}

		public Builder setNamespaceProperties(Dictionary<String, ?> props) {
			this.instance.setNamespaceProperties(props);
			return this;
		}

		public Builder setAdapterConfig(AdapterConfig adapterConfig) {
			this.instance.setAdapterConfig(adapterConfig);
			return this;
		}

		public RemoteServiceDistributionProvider build() {
			this.instance.validateComplete();
			return this.instance;
		}
	}

	RemoteServiceDistributionProvider() {
	}

	protected RemoteServiceDistributionProvider(String name, IContainerInstantiator instantiator) {
		setName(name).setInstantiator(instantiator);
	}

	protected RemoteServiceDistributionProvider(String name, IContainerInstantiator instantiator, String description) {
		setName(name).setInstantiator(instantiator).setDescription(description);
	}

	protected RemoteServiceDistributionProvider(String name, IContainerInstantiator instantiator, String description, boolean server) {
		setName(name).setInstantiator(instantiator).setDescription(description).setServer(server);
	}

	protected String getName() {
		return this.name;
	}

	protected RemoteServiceDistributionProvider setName(String name) {
		Assert.isNotNull(name);
		this.name = name;
		return this;
	}

	protected IContainerInstantiator getInstantiator() {
		return instantiator;
	}

	protected RemoteServiceDistributionProvider setInstantiator(IContainerInstantiator instantiator) {
		Assert.isNotNull(instantiator);
		this.instantiator = instantiator;
		return this;
	}

	protected String getDescription() {
		return this.description;
	}

	protected RemoteServiceDistributionProvider setDescription(String desc) {
		this.description = desc;
		return this;
	}

	protected boolean isServer() {
		return this.server;
	}

	protected RemoteServiceDistributionProvider setServer(boolean server) {
		this.server = server;
		return this;
	}

	protected boolean isHidden() {
		return this.hidden;
	}

	protected RemoteServiceDistributionProvider setHidden(boolean hidden) {
		this.hidden = hidden;
		return this;
	}

	protected RemoteServiceDistributionProvider setNamespace(Namespace ns) {
		this.namespace = ns;
		Assert.isNotNull(ns);
		return this;
	}

	protected RemoteServiceDistributionProvider setContainerTypeDescriptionProperties(Dictionary<String, ?> props) {
		this.ctdProperties = props;
		Assert.isNotNull(this.ctdProperties);
		return this;
	}

	protected RemoteServiceDistributionProvider setNamespaceProperties(Dictionary<String, ?> props) {
		this.nsProperties = props;
		Assert.isNotNull(this.nsProperties);
		return this;
	}

	protected RemoteServiceDistributionProvider setAdapterConfig(AdapterConfig adapterConfig) {
		this.adapterConfig = adapterConfig;
		Assert.isNotNull(this.adapterConfig);
		return this;
	}

	protected void validateComplete() throws NullPointerException {
		String ctdName = getName();
		if (ctdName == null)
			throw new NullPointerException("Container type description name cannot be null"); //$NON-NLS-1$
		IContainerInstantiator ctdInstantiator = getInstantiator();
		if (ctdInstantiator == null)
			throw new NullPointerException("Container type description instantiator cannot be null"); //$NON-NLS-1$
	}

	public ContainerTypeDescription createContainerTypeDescription() {
		validateComplete();
		return new ContainerTypeDescription(getName(), getInstantiator(), getDescription(), isServer(), isHidden());
	}

	public Dictionary<String, ?> getContainerTypeDescriptionProperties() {
		return ctdProperties;
	}

	public Namespace createNamespace() {
		return namespace;
	}

	public Dictionary<String, ?> getNamespaceProperties() {
		return nsProperties;
	}

	public AdapterConfig createAdapterConfig() {
		return adapterConfig;
	}
}

Back to the top