/
data.ftl
349 lines (290 loc) · 12.1 KB
/
data.ftl
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<#ftl strip_whitespace=true>
package ${packageName};
import ch.dunes.vso.sdk.api.IPluginFactory;
import com.vmware.o11n.sdk.modeldriven.*;
import org.springframework.beans.factory.BeanFactory;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import java.util.stream.Collectors;
import net.juniper.contrail.vro.model.Connection;
import net.juniper.contrail.vro.model.Executor;
import net.juniper.contrail.vro.format.*;
import net.juniper.contrail.api.*;
import net.juniper.contrail.api.types.*;
<@compress single_line=true>
public class ${className}
<#if fullSuperClassName??>
extends ${fullSuperClassName}
<#else>
extends AbstractWrapper
</#if>
implements ModelWrapper <#if findable>, Findable<#elseif rootIdPropagated>, RootIdPropagator</#if> {
</@compress>
private static final long serialVersionUID = 1L;
<#if objectClass || connectionClass >
private ReferenceFormatter formatter;
private WrapperUtil util;
</#if>
@Override
public void setContext(PluginContext ctx) {
<#if interceptor??>
_ctx = new WrapperContext(ctx, ${interceptor.canonicalName}.class);
<#else>
_ctx = new WrapperContext(ctx, null);
</#if>
<#if objectClass || connectionClass >
BeanFactory beanFactory = _ctx.getPluginContext().getApplicationContext().getAutowireCapableBeanFactory();
IPluginFactory factory = beanFactory.getBean(IPluginFactory.class);
formatter = new ReferenceFormatter(factory);
util = new WrapperUtil(_ctx, factory);
</#if>
}
<#if findable>
private Sid _internalId;
public Sid getInternalId() {
return _internalId;
}
public void setInternalId(Sid id) {
this._internalId = id;
}
</#if>
@Override
public ${modelClass.canonicalName} __getTarget() {
return (${modelClass.canonicalName}) _target;
}
public String getObjectClassName() {
return __getTarget().getClass().getSimpleName();
}
<#list constructors as c> <#if !c.extensionClass??>
<#if !(c.params?has_content)><#assign defaultConstructor = true></#if>
<@compress single_line=true>public ${className}(<@params c />)<@thrown c /> {</@compress>
setContext(AnonymousPluginContext.get());
<@locals c />
__setTarget(new ${c.declaringClass.canonicalName}(<@localNames c />));
}
</#if></#list>
<#list constructors as c> <#if c.extensionClass??>
<#if !(c.params?has_content)><#assign defaultConstructor = true></#if>
<@compress single_line=true>public ${className}(<@params c />)<@thrown c /> {</@compress>
setContext(AnonymousPluginContext.get());
<@locals c />
__setTarget(_ctx.constructWith(${c.extensionClass.canonicalName}.class).${c.extensionMethod}(<@localNames c />));
}
</#if></#list>
<#if !defaultConstructor??>
public ${className}() {
// Empty default constructor
}</#if>
<#list methods as m> <#if !m.extensionClass?? && !interceptor?? && !m.inheritedWrapperMethod && (m.name != 'getDisplayName' || !objectClass)>
<@compress single_line=true>public ${m.returns.returnFriendlyClassName} ${m.name}(<@params m />)<@thrown m /> {</@compress>
<@locals m />
<#if m.returns.returnFriendlyClassName != 'void'>
Object _res$ = <#else> </#if><#if m.originalName == 'setModel'>__getTarget().${m.originalName}((__getTarget().getModel()).getClass().cast(<@localNames m />));
<#else>__getTarget().${m.originalName}(<@localNames m />);</#if>
<#if m.returns.returnFriendlyClassName != 'void'>
${m.returns.returnFriendlyClassName} _res$pl = _ctx.createPluginObject(_res$, ${m.returns.convertFriendlyClassName});
<#if findable>
_ctx.assignId(${m.returns.convertFriendlyClassName}, _res$pl, getInternalId());
<#elseif rootIdPropagated>
_ctx.assignId(${m.returns.convertFriendlyClassName}, _res$pl, getRootId());
</#if>
<#if pluginName=='ConnectionManager' && m.returns.modelType.simpleName=='Connection'>
Connection connection = (Connection) _res$;
Connection_Wrapper wrapper = (Connection_Wrapper) _res$pl;
wrapper.setInternalId(connection.getId());
</#if>
return _res$pl;
</#if>
}
</#if></#list>
<#list methods as m> <#if !m.extensionClass?? && interceptor??>
<@compress single_line=true>public ${m.returns.returnFriendlyClassName} ${m.name} (<@params m />) throws Throwable {</@compress>
<@locals m />
<@compress single_line=true><#if m.returns.returnFriendlyClassName != 'void'>Object _res$ = <#else> </#if>
_ctx.intercept(__getTarget(), <#if findable>getInternalId()<#else>null</#if>, "${m.originalName}", new Class<?>[] {<@types m />}<#if m.params?has_content>, new Object[]{<@localNames m />}</#if>);
</@compress>
<#if m.returns.returnFriendlyClassName != 'void'>
${m.returns.returnFriendlyClassName} _res$pl = _ctx.createPluginObject(_res$, ${m.returns.convertFriendlyClassName});
<#if findable>
_ctx.assignId(${m.returns.convertFriendlyClassName}, _res$pl, getInternalId());
<#elseif rootIdPropagated>
_ctx.assignId(${m.returns.convertFriendlyClassName}, _res$pl, getRootId());
</#if>
return _res$pl;
</#if>
}
</#if></#list>
<#list methods as m> <#if m.extensionClass??>
<@compress single_line=true>public ${m.returns.returnFriendlyClassName} ${m.name} (<@params m />)<@thrown m /> {</@compress>
<@locals m />
<@compress single_line=true><#if m.returns.returnFriendlyClassName != 'void'>Object _res$ = <#else> </#if>
_ctx.delegateTo(${m.extensionClass.canonicalName}.class, <#if findable>getInternalId()<#else>null</#if>, __getTarget()).${m.originalName}(<@localNames m />);
</@compress>
<#if m.returns.returnFriendlyClassName != 'void'>
${m.returns.returnFriendlyClassName} _res$pl = _ctx.createPluginObject(_res$, ${m.returns.convertFriendlyClassName});
<#if findable>
_ctx.assignId(${m.returns.convertFriendlyClassName}, _res$pl, getInternalId());
<#elseif rootIdPropagated>
_ctx.assignId(${m.returns.convertFriendlyClassName}, _res$pl, getRootId());
</#if>
return _res$pl;
</#if>
}
</#if></#list>
<#if singleton >
<@singletonMethod />
</#if>
<#if objectClass || connectionClass>
public Connection_Wrapper getConnection() {
<#if connectionClass>
<#-- This special case is here to provide consistent API for all findable objects. -->
return this;
<#else>
return (Connection_Wrapper) util.findConnectionWrapper(getInternalId());
</#if>
}
</#if>
<#list executorMethods as m>
<@compress single_line=true>public ${m.returns.typeName} ${m.name}(<@params m />)<@thrown m /> {</@compress>
<@locals m />
${m.returns.fullClassName} _res$ = util.executor(getInternalId()).${m.name}(__getTarget()<#if m.params?has_content>,</#if><@localNames m />);
<#if m.returns.fullClassName != 'boolean'>
if(_res$ == null) return null;
</#if>
${m.returns.typeName} _res$pl = _ctx.createPluginObject(_res$, ${m.returns.convertFriendlyClassName});
<#if m.returns.componentTypeName??>
<#if m.returns.componentClassName??>
for(int i = 0; i < _res$.size(); i++) {
_res$pl.get(i).setInternalId(getInternalId().with("${m.returns.componentTypeName}",_res$.get(i).getUuid()));
}
<#else>
_res$pl.setInternalId(getInternalId().with("${m.returns.componentTypeName}",_res$.getUuid()));
</#if>
</#if>
return _res$pl;
}
</#list>
<#if objectClass >
<#list parents as parent>
public void setParent${parent.simpleName}(${packageName}.${parent.simpleName}_Wrapper _parent) {
<#if parent.simpleName != 'Connection'>
__getTarget().setParent(_parent.__getTarget());
</#if>
String uuid = __getTarget().getUuid();
Sid parentId = _parent.getInternalId();
if (uuid == null)
_internalId = parentId;
else
_internalId = parentId.with("${pluginName}", uuid);
}
</#list>
public void create() {
util.create(getInternalId(), __getTarget());
// objects do not have valid uuid before create operation
_internalId = getInternalId().with("${pluginName}", __getTarget().getUuid());
}
public void update() {
util.update(getInternalId(), __getTarget());
}
public void read() {
util.read(getInternalId(), __getTarget());
}
public void delete() {
util.delete(getInternalId(), __getTarget());
}
<#list references as ref>
//List returned by this method is read-only. Changes to the list will not be reflected in the state of the object.
public java.util.List<${ref.className}_Wrapper> ${ref.pluginMethodName}() {
return util.references(_internalId, ${ref.className}.class, __getTarget().${ref.methodName}());
}
</#list>
<#list backrefs as bref>
public boolean isReferencedBy${bref.className}(${bref.className}_Wrapper reference) {
return ${bref.pluginMethodName}().stream().map(it -> it.getUuid()).collect(Collectors.toList()).contains(reference.getUuid());
}
</#list>
public Integer backrefCount() {
int count = 0;
<#list backrefs as bref>
count += ${bref.pluginMethodName}().size();
</#list>
return count;
}
<#list referenceProperties as prop>
public String ${prop.wrapperMethodName}() {
return formatter.format(this, __getTarget().${prop.methodName}(), "${prop.refObjectPluginType}");
}
</#list>
</#if>
<#list connectionFindClasses as clazz>
public ${clazz.simpleName}_Wrapper find${clazz.pluginName}(String id) {
return util.find(__getTarget(), ${clazz.simpleName}.class, id);
}
public ${clazz.simpleName}_Wrapper find${clazz.pluginName}ByFQName(String fqName) {
return util.findByFQName(__getTarget(), ${clazz.simpleName}.class, fqName);
}
</#list>
<#if nodeClass >
public String getDisplayName() {
return DisplayNameFormatter.INSTANCE.format(__getTarget());
}
</#if>
<#list propertyViews as property>
public String ${property.viewMethodName}() {
${property.propertyType} prop = __getTarget().${property.methodName}();
if (prop != null) {
return PropertyFormatter.INSTANCE.format(prop);
} else {
return null;
}
}
</#list>
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
setContext(AnonymousPluginContext.get());
}
}
<@compress single_line=true>
<#macro params m>
<#list m.params as p>
${p.returnFriendlyClassName} ${p.name}<#if p_has_next>, </#if>
</#list>
</#macro>
</@compress>
<@compress single_line=true>
<#macro locals m>
<#list m.params as p>
${p.modelType.canonicalName} _local$${p.name} = _ctx.extractModelObject(${p.name}, ${p.modelType.canonicalName}.class);
</#list>
</#macro>
</@compress>
<@compress single_line=true>
<#macro types m>
<#list m.params as p>
${p.modelType.canonicalName}.class<#if p_has_next>, </#if>
</#list>
</#macro>
</@compress>
<@compress single_line=true>
<#macro signature m>
<#list m.params as p>
${p.modelType.canonicalName}.class<#if p_has_next>, </#if>
</#list>
</#macro>
</@compress>
<@compress single_line=true>
<#macro localNames m>
<#list m.params as p>
_local$${p.name}<#if p_has_next>, </#if></#list></#macro>
</@compress>
<#macro singletonMethod>
public static ${className} createScriptingSingleton(ch.dunes.vso.sdk.api.IPluginFactory f) {
return ((AbstractModelDrivenFactory) f).createScriptingSingleton(${modelClass.canonicalName}.class);
}
</#macro>
<#macro thrown c><#if c.thrown?has_content> throws <#list c.thrown as e>${e.canonicalName}<#if e_has_next>, <#else> </#if></#list><#else> </#if></#macro>