summaryrefslogtreecommitdiff
path: root/org.genivi.commonapi.core/src/org/genivi/commonapi/core/deployment/PropertyAccessor.java
blob: 734292bfa923dc224263c58eb495afa409b13070 (plain)
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/* Copyright (C) 2015 BMW Group
 * Author: Lutz Bichler (lutz.bichler@bmw.de)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.genivi.commonapi.core.deployment;

import java.util.List;

import org.franca.core.franca.FEnumerationType;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FMethod;
import org.franca.deploymodel.core.FDeployedInterface;
import org.franca.deploymodel.core.FDeployedProvider;
import org.franca.deploymodel.core.FDeployedTypeCollection;
import org.franca.deploymodel.dsl.fDeploy.FDInterfaceInstance;
import org.franca.deploymodel.dsl.fDeploy.FDProvider;
import org.genivi.commonapi.core.DeploymentInterfacePropertyAccessor;
import org.genivi.commonapi.core.DeploymentProviderPropertyAccessor;
import org.genivi.commonapi.core.DeploymentTypeCollectionPropertyAccessor;

public class PropertyAccessor {
	
	protected static Integer defaultTimeout_ = new Integer(0);
	
	protected enum DeploymentType { NONE, INTERFACE, TYPE_COLLECTION, PROVIDER };
	protected DeploymentType type_;
	
	DeploymentInterfacePropertyAccessor interface_;
	DeploymentTypeCollectionPropertyAccessor typeCollection_;
	DeploymentProviderPropertyAccessor provider_;

	// The following definitions are contained in the specific accessors
	// for interfaces and type collections. We will simply cast them...
	public enum DefaultEnumBackingType {
		UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64
	}
	
	public enum EnumBackingType {
		UseDefault, UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64
	}
	
	public PropertyAccessor() {
		type_ = DeploymentType.NONE;
		interface_ = null;
		typeCollection_ = null;
		provider_ = null;		
	}
	
	public PropertyAccessor(FDeployedInterface _target) {
		type_ = (_target == null ? DeploymentType.NONE : DeploymentType.INTERFACE);
		interface_ = new DeploymentInterfacePropertyAccessor(_target);
		typeCollection_ = null;
		provider_ = null;
	}

	public PropertyAccessor(FDeployedTypeCollection _target) {
		type_ = (_target == null ? DeploymentType.NONE : DeploymentType.TYPE_COLLECTION);
		interface_ = null;
		typeCollection_ = new DeploymentTypeCollectionPropertyAccessor(_target);
		provider_ = null;
	}
	
	public PropertyAccessor(FDeployedProvider _target) {
		type_ = (_target == null ? DeploymentType.NONE : DeploymentType.PROVIDER);
		interface_ = null;
		typeCollection_ = null;
		provider_ = new DeploymentProviderPropertyAccessor(_target);
	}

	public DefaultEnumBackingType getDefaultEnumBackingType(FInterface obj) {
		try {
			switch (type_) {
			case INTERFACE:
				return from(interface_.getDefaultEnumBackingType(obj));
			case TYPE_COLLECTION:
				return from(typeCollection_.getDefaultEnumBackingType(obj));
			case PROVIDER:
			case NONE:
			default:
			}
		}
		catch (java.lang.NullPointerException e) {}
		return DefaultEnumBackingType.Int32;
	}

	public EnumBackingType getEnumBackingType (FEnumerationType obj) {
		try {
			switch (type_) {
			case INTERFACE:
				return from(interface_.getEnumBackingType(obj));
			case TYPE_COLLECTION:
				return from(typeCollection_.getEnumBackingType(obj));
			case PROVIDER:
			case NONE:
			default:
				return EnumBackingType.Int32;
			}
		}
		catch (java.lang.NullPointerException e) {}
		return EnumBackingType.Int32;
	}

	public Integer getTimeout(FMethod obj) {
		try {
			if (type_ == DeploymentType.INTERFACE)
				return interface_.getTimeout(obj);
		}
		catch (java.lang.NullPointerException e) {}
		return defaultTimeout_;
	}

	public List<FInterface> getClientInstanceReferences (FDProvider obj) {
		try {
			if (type_ == DeploymentType.PROVIDER)
				return provider_.getClientInstanceReferences(obj);
		}
		catch (java.lang.NullPointerException e) {}
		return null;
	}
	
	public String getDomain (FDInterfaceInstance obj) {
		try {
			if (type_ == DeploymentType.PROVIDER)
				return provider_.getDomain(obj);
		}
		catch (java.lang.NullPointerException e) {}
		return null;
	}
	
	public String getInstanceId (FDInterfaceInstance obj) {
		try {
			if (type_ == DeploymentType.PROVIDER)
				return provider_.getInstanceId(obj);
		}
		catch (java.lang.NullPointerException e) {}
		return null;
	}
	
	public Integer getDefaultMethodTimeout (FDInterfaceInstance obj) {
		try {
			if (type_ == DeploymentType.PROVIDER)
				return provider_.getDefaultTimeout(obj);
		}
		catch (java.lang.NullPointerException e) {}
		return null;
	}
	
	public List<String> getPreregisteredProperties (FDInterfaceInstance obj) {
		try {
			if (type_ == DeploymentType.PROVIDER)
				return provider_.getPreregisteredProperties(obj);
		}
		catch (java.lang.NullPointerException e) {}
		return null;
	}

	private DefaultEnumBackingType from(DeploymentInterfacePropertyAccessor.DefaultEnumBackingType _source) {
		switch (_source) {
		case UInt8:
			return DefaultEnumBackingType.UInt8;
		case UInt16:
			return DefaultEnumBackingType.UInt16;
		case UInt32:
			return DefaultEnumBackingType.UInt8;
		case UInt64:
			return DefaultEnumBackingType.UInt8;
		case Int8:
			return DefaultEnumBackingType.Int8;
		case Int16:
			return DefaultEnumBackingType.Int16;
		case Int32:
			return DefaultEnumBackingType.Int32;
		case Int64:
			return DefaultEnumBackingType.Int64;
		default:
			return DefaultEnumBackingType.Int32;
		}
	}
	
	private EnumBackingType from(DeploymentInterfacePropertyAccessor.EnumBackingType _source) {
		switch (_source) {
		case UInt8:
			return EnumBackingType.UInt8;
		case UInt16:
			return EnumBackingType.UInt16;
		case UInt32:
			return EnumBackingType.UInt8;
		case UInt64:
			return EnumBackingType.UInt8;
		case Int8:
			return EnumBackingType.Int8;
		case Int16:
			return EnumBackingType.Int16;
		case Int32:
			return EnumBackingType.Int32;
		case Int64:
			return EnumBackingType.Int64;
		default:
			return EnumBackingType.UseDefault;
		}
	}
	
	private DefaultEnumBackingType from(DeploymentTypeCollectionPropertyAccessor.DefaultEnumBackingType _source) {
		if (_source != null) {
			switch (_source) {
			case UInt8:
				return DefaultEnumBackingType.UInt8;
			case UInt16:
				return DefaultEnumBackingType.UInt16;
			case UInt32:
				return DefaultEnumBackingType.UInt8;
			case UInt64:
				return DefaultEnumBackingType.UInt8;
			case Int8:
				return DefaultEnumBackingType.Int8;
			case Int16:
				return DefaultEnumBackingType.Int16;
			case Int32:
				return DefaultEnumBackingType.Int32;
			case Int64:
				return DefaultEnumBackingType.Int64;
			default:
				return DefaultEnumBackingType.Int32;
			}
		}
		return DefaultEnumBackingType.Int32;
	}
	
	private EnumBackingType from(DeploymentTypeCollectionPropertyAccessor.EnumBackingType _source) {
		if (_source != null) {
			switch (_source) {
			case UInt8:
				return EnumBackingType.UInt8;
			case UInt16:
				return EnumBackingType.UInt16;
			case UInt32:
				return EnumBackingType.UInt8;
			case UInt64:
				return EnumBackingType.UInt8;
			case Int8:
				return EnumBackingType.Int8;
			case Int16:
				return EnumBackingType.Int16;
			case Int32:
				return EnumBackingType.Int32;
			case Int64:
				return EnumBackingType.Int64;
			default:
				return EnumBackingType.UseDefault;
			}
		}
		return EnumBackingType.UseDefault;
	}
}