-
Notifications
You must be signed in to change notification settings - Fork 10
/
generateAdaptorApplication.mtl
229 lines (204 loc) · 11.6 KB
/
generateAdaptorApplication.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
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
[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 generateAdaptorApplication('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::domainSpecificationServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::adaptorInterfaceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::serviceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::webServiceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderCatalogServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::osgiServices/]
[template public additionalResourceClasses(traceabilityContext : OclAny) post (trim())]
[/template]
[template public generateAdaptorApplication(anAdaptorInterface : AdaptorInterface)]
[file (javaClassFullFileNameForAdaptorApplication(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 [javaClassPackageNameForAdaptorApplication(anAdaptorInterface) /];
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
import org.eclipse.lyo.oslc4j.core.exception.OslcCoreApplicationException;
import org.eclipse.lyo.oslc4j.core.model.AllowedValues;
import org.eclipse.lyo.oslc4j.core.model.Compact;
import org.eclipse.lyo.oslc4j.core.model.CreationFactory;
import org.eclipse.lyo.oslc4j.core.model.Dialog;
import org.eclipse.lyo.oslc4j.core.model.Error;
import org.eclipse.lyo.oslc4j.core.model.ExtendedError;
import org.eclipse.lyo.oslc4j.core.model.OAuthConfiguration;
import org.eclipse.lyo.oslc4j.core.model.OslcConstants;
import org.eclipse.lyo.oslc4j.core.model.PrefixDefinition;
import org.eclipse.lyo.oslc4j.core.model.Preview;
import org.eclipse.lyo.oslc4j.core.model.Property;
import org.eclipse.lyo.oslc4j.core.model.Publisher;
import org.eclipse.lyo.oslc4j.core.model.QueryCapability;
import org.eclipse.lyo.oslc4j.core.model.ResourceShape;
import org.eclipse.lyo.oslc4j.core.model.ResourceShapeFactory;
import org.eclipse.lyo.oslc4j.core.model.Service;
import org.eclipse.lyo.oslc4j.core.model.ServiceProvider;
import org.eclipse.lyo.oslc4j.core.model.ServiceProviderCatalog;
import org.eclipse.lyo.oslc4j.provider.jena.JenaProvidersRegistry;
import org.eclipse.lyo.oslc4j.provider.json4j.Json4JProvidersRegistry;
[if (anAdaptorInterface.swaggerDocumentationEnabled())]
import io.swagger.v3.jaxrs2.integration.resources.AcceptHeaderOpenApiResource;
import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.servers.Server;
[/if]
[if (anAdaptorInterface.authenticationEnabled())]
import [anAdaptorInterface.javaClassFullNameForRootServicesService() /];
[/if]
[if (not anAdaptorInterface.serviceProviderCatalog.oclIsUndefined())]
import [javaClassFullNameForService(anAdaptorInterface.serviceProviderCatalog) /];
[/if]
[for (aServiceProvider: ServiceProvider | anAdaptorInterface.serviceProviders()->sortedBy(x: ServiceProvider | javaClassFullNameForService(x)))]
import [javaClassFullNameForService(aServiceProvider)/];
[/for]
import [javaClassFullNameForResourceShapeService(anAdaptorInterface) /];
[for (aResource: Resource | relevantResources(anAdaptorInterface)->sortedBy(name)) separator(lineSeparator())]import [javaClassFullName(aResource, anAdaptorInterface, null) /];[/for]
[for (aDomainSpecification: DomainSpecification | relevantDomainSpecifications(anAdaptorInterface)->sortedBy(name)) separator(lineSeparator())]import [javaInterfaceFullNameForConstants(aDomainSpecification, anAdaptorInterface, null) /];[/for]
[for (aService: Service | anAdaptorInterface.serviceProviders().services) separator(lineSeparator())]import [javaClassFullName(aService) /];[/for]
[for (aWebService: WebService | anAdaptorInterface.webServices) separator(lineSeparator())]import [javaClassFullName(aWebService) /];[/for]
[if (anAdaptorInterface.trsServiceEnabled())]
import org.eclipse.lyo.oslc4j.trs.server.service.TrackedResourceSetService;
[/if]
// [protected ('imports')]
// [/protected]
// [protected ('pre_class_code')]
// [/protected]
/**
* Generated by Lyo Designer [getOSGiBundleVersion(anAdaptorInterface)/]
*/
[if (anAdaptorInterface.swaggerDocumentationEnabled())]
@OpenAPIDefinition(info = @Info(title = "[anAdaptorInterface.name/]", version = "1.0.0"), servers = @Server(url = "[anAdaptorInterface.getServletFullPath()/]"))
[/if]
public class [javaClassNameForAdaptorApplication(anAdaptorInterface) /] extends javax.ws.rs.core.Application {
private static final Set<Class<?>> RESOURCE_CLASSES = new HashSet<Class<?>>();
private static final Map<String, Class<?>> RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP = new HashMap<String, Class<?>>();
// [protected ('class_attributes')]
// [/protected]
// [protected ('class_methods')]
// [/protected]
@Override
public Set<Object> getSingletons() {
return Collections.singleton(new ApplicationBinder());
}
static
{
RESOURCE_CLASSES.addAll(JenaProvidersRegistry.getProviders());
RESOURCE_CLASSES.addAll(Json4JProvidersRegistry.getProviders());
[for (aService: Service | anAdaptorInterface.serviceProviders().services)]
RESOURCE_CLASSES.add([javaClassName(aService)/].class);
[/for]
[for (aWebService: WebService | anAdaptorInterface.webServices)]
RESOURCE_CLASSES.add([javaClassName(aWebService)/].class);
[/for]
// Catalog resources
[if (not anAdaptorInterface.serviceProviderCatalog.oclIsUndefined())]
RESOURCE_CLASSES.add([javaClassNameForService(anAdaptorInterface.serviceProviderCatalog) /].class);
[/if]
[for (aServiceProvider: ServiceProvider | anAdaptorInterface.serviceProviders()->sortedBy(x: ServiceProvider | javaClassFullNameForService(x)))]
RESOURCE_CLASSES.add([javaClassNameForService(aServiceProvider)/].class);
[/for]
RESOURCE_CLASSES.add([javaClassNameForResourceShapeService(anAdaptorInterface)/].class);
[if (anAdaptorInterface.swaggerDocumentationEnabled())]
// Swagger resources
RESOURCE_CLASSES.add(OpenApiResource.class);
RESOURCE_CLASSES.add(AcceptHeaderOpenApiResource.class);
[/if]
[if anAdaptorInterface.authenticationEnabled()]
// OAuth resources
RESOURCE_CLASSES.add([anAdaptorInterface.javaClassNameForRootServicesService() /].class);
try {
RESOURCE_CLASSES.add(Class.forName("org.eclipse.lyo.server.oauth.webapp.services.ConsumersService"));
RESOURCE_CLASSES.add(Class.forName("org.eclipse.lyo.server.oauth.webapp.services.OAuthService"));
} catch (ClassNotFoundException e) {
// [protected ('OAuthServiceClasses_notFound')]
// [/protected]
}
[/if]
[if (anAdaptorInterface.trsServiceEnabled())]
// TRS Server resources
RESOURCE_CLASSES.add(TrackedResourceSetService.class);
[/if]
[additionalResourceClasses()/]
// [protected ('Custom Resource Classes')]
// [/protected]
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_ALLOWED_VALUES, AllowedValues.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_COMPACT, Compact.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_CREATION_FACTORY, CreationFactory.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_DIALOG, Dialog.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_ERROR, Error.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_EXTENDED_ERROR, ExtendedError.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_OAUTH_CONFIGURATION, OAuthConfiguration.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_PREFIX_DEFINITION, PrefixDefinition.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_PREVIEW, Preview.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_PROPERTY, Property.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_PUBLISHER, Publisher.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_QUERY_CAPABILITY, QueryCapability.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_RESOURCE_SHAPE, ResourceShape.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_SERVICE, Service.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_SERVICE_PROVIDER, ServiceProvider.class);
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put(OslcConstants.PATH_SERVICE_PROVIDER_CATALOG, ServiceProviderCatalog.class);
[for (aResource: Resource | relevantResources(anAdaptorInterface)->sortedBy(name))]
RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put([javaInterfaceNameForConstants(aResource.definingDomainSpecification())/].[resourcePathConstantName(aResource) /], [javaClassName(aResource)/].class);
[/for]
}
@Inject
public [javaClassNameForAdaptorApplication(anAdaptorInterface) /](ServiceLocator locator)
throws OslcCoreApplicationException,
URISyntaxException
{
ServiceLocatorUtilities.enableImmediateScope(locator);
final String BASE_URI = "http://localhost/validatingResourceShapes";
for (final Map.Entry<String, Class<?>> entry : RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.entrySet()) {
ResourceShapeFactory.createResourceShape(BASE_URI, OslcConstants.PATH_RESOURCE_SHAPES, entry.getKey(), entry.getValue());
}
}
@Override
public Set<Class<?>> getClasses() {
return RESOURCE_CLASSES;
}
public static Map<String, Class<?>> getResourceShapePathToResourceClassMap() {
return RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP;
}
}
[/file]
[/template]