| [comment encoding = UTF-8 /] |
| [comment |
| /******************************************************************************* |
| * Copyright (c) 2012 IBM Corporation and others. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * and Eclipse Distribution License v. 1.0 which accompanies this distribution. |
| * |
| * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| * and the Eclipse Distribution License is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * Contributors: |
| * |
| * Michael Fiedler - initial API and implementation for Bugzilla adapter |
| * Jad El-khoury - initial implementation of code generator (https://bugs.eclipse.org/bugs/show_bug.cgi?id=422448) |
| * Matthieu Helleboid - Support for multiple Service Providers. |
| * Anass Radouani - Support for multiple Service Providers. |
| * |
| *******************************************************************************/ |
| /] |
| |
| [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::serviceProviderServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderCatalogServices/] |
| |
| [template public generateAdaptorApplication(anAdaptorInterface : AdaptorInterface)] |
| [file (javaClassFullFileNameForAdaptorApplication(anAdaptorInterface), false, 'UTF-8')] |
| /******************************************************************************* |
| * Copyright (c) 2012 IBM Corporation and others. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * and Eclipse Distribution License v. 1.0 which accompanies this distribution. |
| * |
| * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| * and the Eclipse Distribution License is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * Contributors: |
| * |
| * Michael Fiedler - initial API and implementation for Bugzilla adapter |
| * Jad El-khoury - initial implementation of code generator (https://bugs.eclipse.org/bugs/show_bug.cgi?id=422448) |
| * Matthieu Helleboid - Support for multiple Service Providers. |
| * Anass Radouani - Support for multiple Service Providers. |
| * |
| * This file is generated by org.eclipse.lyo.oslc4j.codegenerator |
| *******************************************************************************/ |
| |
| package [javaClassPackageNameForAdaptorApplication(anAdaptorInterface) /]; |
| |
| import java.net.URISyntaxException; |
| import java.util.HashMap; |
| import java.util.HashSet; |
| import java.util.Map; |
| import java.util.Set; |
| |
| |
| import org.eclipse.lyo.oslc4j.application.OslcWinkApplication; |
| 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.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 (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) /];[/for] |
| [for (aDomainSpecification: DomainSpecification | relevantDomainSpecifications(anAdaptorInterface)->sortedBy(name)) separator(lineSeparator())]import [javaInterfaceFullNameForConstants(aDomainSpecification, anAdaptorInterface) /];[/for] |
| [for (aService: Service | anAdaptorInterface.serviceProviders().services) separator(lineSeparator())]import [javaClassFullName(aService) /];[/for] |
| |
| // [protected ('imports')] |
| // [/protected] |
| |
| // [protected ('pre_class_code')] |
| // [/protected] |
| |
| public class [javaClassNameForAdaptorApplication(anAdaptorInterface) /] extends OslcWinkApplication { |
| |
| 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] |
| |
| static |
| { |
| try |
| { |
| RESOURCE_CLASSES.addAll(JenaProvidersRegistry.getProviders()); |
| RESOURCE_CLASSES.addAll(Json4JProvidersRegistry.getProviders()); |
| [for (aService: Service | anAdaptorInterface.serviceProviders().services)] |
| RESOURCE_CLASSES.add([javaClassName(aService)/].class); |
| [/for] |
| [for (aResource: Resource | relevantResources(anAdaptorInterface)->sortedBy(name))] |
| RESOURCE_CLASSES.add([javaClassName(aResource)/].class); |
| [/for] |
| 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")); |
| |
| // 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); |
| |
| // [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); |
| } catch (ClassNotFoundException e) |
| { |
| e.printStackTrace(); |
| System.err.println("[javaClassNameForAdaptorApplication(anAdaptorInterface) /] failed to initialize"); |
| } |
| |
| [for (aResource: Resource | relevantResources(anAdaptorInterface)->sortedBy(name))] |
| RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP.put([javaInterfaceNameForConstants(aResource.definingDomainSpecification())/].[resourcePathConstantName(aResource) /], [javaClassName(aResource)/].class); |
| [/for] |
| } |
| |
| public [javaClassNameForAdaptorApplication(anAdaptorInterface) /]() |
| throws OslcCoreApplicationException, |
| URISyntaxException |
| { |
| super(RESOURCE_CLASSES, |
| OslcConstants.PATH_RESOURCE_SHAPES, |
| RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP); |
| } |
| |
| public static Map<String, Class<?>> getResourceShapePathToResourceClassMap() { |
| return RESOURCE_SHAPE_PATH_TO_RESOURCE_CLASS_MAP; |
| } |
| } |
| [/file] |
| [/template] |