-
Notifications
You must be signed in to change notification settings - Fork 10
/
generateAdaptorClient.mtl
113 lines (94 loc) · 4.25 KB
/
generateAdaptorClient.mtl
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
[comment encoding = UTF-8 /]
[comment
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License 1.0
* which is available at http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Simple
*/
/]
[module generateAdaptorClient('http://org.eclipse.lyo/oslc4j/adaptorInterface')]
[import org::eclipse::lyo::oslc4j::codegenerator::services::services/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::resourceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::resourcePropertyServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::adaptorInterfaceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::domainSpecificationServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::requiredAdaptorServices/]
[template public generateAdaptorClient(aRequiredAdaptor: RequiredAdaptor, anAdaptorInterface : AdaptorInterface)]
[file (javaClassFullFileNameForClient(aRequiredAdaptor, anAdaptorInterface), false, 'UTF-8')]
// [protected ('Copyright')]
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Simple
*
* This file is generated by Lyo Designer (https://www.eclipse.org/lyo/)
*/
// [/protected]
package [javaClassPackageNameForClient(aRequiredAdaptor, anAdaptorInterface) /];
import jakarta.ws.rs.core.Response;
import org.eclipse.lyo.client.OSLCConstants;
import org.eclipse.lyo.client.OslcClient;
import org.eclipse.lyo.oslc4j.core.model.ServiceProviderCatalog;
[for (aResource: Resource | servicedResources(aRequiredAdaptor)->sortedBy(name))]
import [javaClassFullName(aResource, anAdaptorInterface, null) /];
[/for]
// [protected ('imports')]
// [/protected]
// [protected ('pre_class_code')]
// [/protected]
public class [javaClassNameForClient(aRequiredAdaptor) /]
{
[comment TODO The very basic functionality of a client is generated. a more complete set of functions (query, C.R.U.D., etc) ought to be generated. /]
// [protected ('class_attributes')]
// [/protected]
// [protected ('class_methods')]
// [/protected]
static String serviceProviderCatalogURI = "[aRequiredAdaptor.serviceProviderCatalogURI/]";
public static ServiceProviderCatalog getServiceProviderCatalog() throws Exception {
OslcClient client = new OslcClient();
Response response = null;
ServiceProviderCatalog catalog = null;
// [protected ('getServiceProviderCatalog'.concat('_init'))]
// [/protected]
response = client.getResource(serviceProviderCatalogURI,OSLCConstants.CT_RDF);
if (response != null) {
catalog = response.readEntity(ServiceProviderCatalog.class);
}
// [protected ('getServiceProviderCatalog'.concat('_final'))]
// [/protected]
return catalog;
}
[for (aResource: Resource | servicedResources(aRequiredAdaptor)->sortedBy(name)) separator(lineSeparator()) ]
public static [javaClassName(aResource) /] get[javaName(aResource, true)/](String resourceURI) throws Exception {
OslcClient client = new OslcClient();
Response response = null;
[javaClassName(aResource) /] resource = null;
// [protected ('get'.concat(javaName(aResource, true)).concat('_init'))]
// [/protected]
response = client.getResource(resourceURI, OSLCConstants.CT_RDF);
if (response != null) {
resource = response.readEntity([javaClassName(aResource) /].class);
}
// [protected ('get'.concat(javaName(aResource, true)).concat('_final'))]
// [/protected]
return resource;
}
[/for]
}
[/file]
[/template]