| [comment encoding = UTF-8 /] |
| [comment |
| /******************************************************************************* |
| * Copyright (c) 2017 Jad El-khoury. |
| * |
| * 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: |
| * |
| * Jad El-khoury - initial implementation |
| * |
| *******************************************************************************/ |
| /] |
| |
| [module generateAdaptorResourcesFactory('http://org.eclipse.lyo/oslc4j/adaptorInterface')] |
| |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::services/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::serviceServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::resourceServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::adaptorInterfaceServices/] |
| |
| [template public generateImports(anAdaptorInterface : AdaptorInterface)] |
| import java.net.URI; |
| import java.net.URISyntaxException; |
| import java.util.HashMap; |
| import java.util.Map; |
| import javax.ws.rs.core.UriBuilder; |
| |
| import org.eclipse.lyo.oslc4j.core.model.Link; |
| import org.eclipse.lyo.oslc4j.core.OSLC4JUtils; |
| [for (aResource: Resource | relevantResources(anAdaptorInterface)->sortedBy(name))] |
| import [javaClassFullName(aResource, anAdaptorInterface, null) /]; |
| [/for] |
| |
| // [protected ('imports')] |
| // [/protected] |
| [/template] |
| |
| [template public generateFactoryMethods(aResource : Resource, anAdaptorInterface : AdaptorInterface)] |
| [for (aBasicCapability: BasicCapability | basicCapabilities(anAdaptorInterface, aResource))] |
| [let methodSuffix: String = (if (basicCapabilities(anAdaptorInterface, aResource)->size() = 1) then '' else basicCapabilities(anAdaptorInterface, aResource)->indexOf(aBasicCapability).toString() endif)] |
| [if (basicCapabilities(anAdaptorInterface, aResource)->indexOf(aBasicCapability) = 1)] |
| public static [javaClassName(aResource)/] create[javaName(aResource, true)/]([commaSeparate(aResource.instanceMethodSignature(aBasicCapability, false), false, false)/]) |
| throws URISyntaxException |
| { |
| return new [javaClassName(aResource)/](constructURIFor[javaName(aResource, true)/][methodSuffix/]([commaSeparate(aResource.instanceMethodParameterList(aBasicCapability), false, false)/])); |
| } |
| [/if] |
| |
| public static URI constructURIFor[javaName(aResource, true)/][methodSuffix/]([commaSeparate(aResource.instanceMethodSignature(aBasicCapability, false), false, false)/]) |
| { |
| String basePath = OSLC4JUtils.getServletURI(); |
| Map<String, Object> pathParameters = new HashMap<String, Object>(); |
| [for (instanceCompositeID: String | aResource.instanceCompositeID(aBasicCapability))] |
| pathParameters.put("[instanceCompositeID /]", [instanceCompositeID /]); |
| [/for] |
| String instanceURI = "[aResource.instanceURI(aBasicCapability) /]"; |
| |
| final UriBuilder builder = UriBuilder.fromUri(basePath); |
| return builder.path(instanceURI).buildFromMap(pathParameters); |
| } |
| |
| public static Link constructLinkFor[javaName(aResource, true)/][methodSuffix/]([commaSeparate(aResource.instanceMethodSignature(aBasicCapability, false), false, true)/] final String label) |
| { |
| return new Link(constructURIFor[javaName(aResource, true)/][methodSuffix/]([commaSeparate(aResource.instanceMethodParameterList(aBasicCapability), false, false)/]), label); |
| } |
| |
| public static Link constructLinkFor[javaName(aResource, true)/][methodSuffix/]([commaSeparate(aResource.instanceMethodSignature(aBasicCapability, false), false, false)/]) |
| { |
| return new Link(constructURIFor[javaName(aResource, true)/][methodSuffix/]([commaSeparate(aResource.instanceMethodParameterList(aBasicCapability), false, false)/])); |
| } |
| [/let] |
| [/for] |
| [/template] |
| |
| |
| [template public generateAdaptorResourcesFactory(anAdaptorInterface : AdaptorInterface)] |
| [file (javaClassFullFileNameForResourcesFactory(anAdaptorInterface), false, 'UTF-8')] |
| // [protected ('Copyright')] |
| /******************************************************************************* |
| * Copyright (c) 2017 Jad El-khoury. |
| * |
| * 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: |
| * |
| * Jad El-khoury - initial implementation |
| * |
| *******************************************************************************/ |
| // [/protected] |
| |
| package [javaClassPackageNameForResourcesFactory(anAdaptorInterface) /]; |
| |
| [generateImports(anAdaptorInterface)/] |
| |
| // [protected ('pre_class_code')] |
| // [/protected] |
| |
| public class [javaClassNameForResourcesFactory(anAdaptorInterface) /] { |
| |
| // [protected ('class_attributes')] |
| // [/protected] |
| |
| // [protected ('class_methods')] |
| // [/protected] |
| |
| [for (aResource: Resource | servicedResources(anAdaptorInterface)->sortedBy(name))] |
| //methods for [aResource.javaClassName()/] resource |
| [aResource.generateFactoryMethods(anAdaptorInterface) /] |
| |
| [/for] |
| } |
| [/file] |
| [/template] |