| [comment encoding = UTF-8 /] |
| [comment |
| /******************************************************************************* |
| * Copyright (c) 2014 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 of code generator (https://bugs.eclipse.org/bugs/show_bug.cgi?id=422448) |
| * |
| *******************************************************************************/ |
| /] |
| |
| [module adaptorInterfaceServices('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::serviceProviderServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::serviceServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::domainSpecificationServices/] |
| |
| [comment TODO: we should avoid relying on "eContainer", since objects that come from a composing emf file, will not have the eContainer relationship setup as expected. |
| This method should be able to work even for objects that come from a differnet emf file than that containing the AdaptorInterface. |
| You should also question any other use of "eContainer" in this whole project /] |
| [query public containingAdaptorInterface(obj : OclAny) : AdaptorInterface = |
| (if (not obj.eContainer(AdaptorInterface).oclIsUndefined()) then |
| obj.eContainer(AdaptorInterface).oclAsType(AdaptorInterface) |
| else |
| null |
| endif) |
| /] |
| |
| [query public javaName(anAdaptorInterface : AdaptorInterface, toUpperFirst : Boolean) : String = |
| javaString(anAdaptorInterface.name, 'oslc', toUpperFirst) |
| /] |
| |
| [query public serviceProviders(anAdaptorInterface : AdaptorInterface) : Sequence(ServiceProvider) = |
| (if (not anAdaptorInterface.serviceProviderCatalog.oclIsUndefined()) then |
| anAdaptorInterface.serviceProviderCatalog.serviceProviders |
| else |
| Sequence{} |
| endif) |
| /] |
| |
| [query public managingServiceProviders(anAdaptorInterface : AdaptorInterface, aResource: Resource) : Set(ServiceProvider) = |
| anAdaptorInterface.serviceProviders()->select(aServiceProvider : ServiceProvider | |
| aServiceProvider.services.queryCapabilities->exists(aQueryCapability : QueryCapability | aQueryCapability.resourceTypes->includes(aResource)) |
| ._or(aServiceProvider.services.basicCapabilities->exists(aBasicCapability : BasicCapability | aBasicCapability.resourceTypes->includes(aResource))) |
| ._or(aServiceProvider.services.creationFactories->exists(aCreationFactory : CreationFactory | aCreationFactory.resourceTypes->includes(aResource))) |
| ._or(aServiceProvider.services.selectionDialogs->exists(aDialog : Dialog | aDialog.resourceTypes->includes(aResource))) |
| ._or(aServiceProvider.services.creationDialogs->exists(aDialog : Dialog | aDialog.resourceTypes->includes(aResource))) |
| )->asSet() |
| /] |
| |
| [query public queryCapabilities(anAdaptorInterface : AdaptorInterface, aResource: Resource) : Sequence(QueryCapability) = |
| anAdaptorInterface.serviceProviders().services.queryCapabilities->select(aQueryCapability : QueryCapability | aQueryCapability.resourceTypes->includes(aResource)) |
| /] |
| |
| [query public basicCapabilities(anAdaptorInterface : AdaptorInterface, aResource: Resource) : Sequence(BasicCapability) = |
| anAdaptorInterface.serviceProviders().services.basicCapabilities->select(aBasicCapability : BasicCapability | aBasicCapability.resourceTypes->includes(aResource)) |
| /] |
| |
| [query public creationFactories(anAdaptorInterface : AdaptorInterface, aResource: Resource) : Sequence(CreationFactory) = |
| anAdaptorInterface.serviceProviders().services.creationFactories->select(aCreationFactory : CreationFactory | aCreationFactory.resourceTypes->includes(aResource)) |
| /] |
| |
| [query public selectionDialogs(anAdaptorInterface : AdaptorInterface, aResource: Resource) : Sequence(Dialog) = |
| anAdaptorInterface.serviceProviders().services.selectionDialogs->select(aDialog : Dialog | aDialog.resourceTypes->includes(aResource)) |
| /] |
| |
| [query public creationDialogs(anAdaptorInterface : AdaptorInterface, aResource: Resource) : Sequence(Dialog) = |
| anAdaptorInterface.serviceProviders().services.creationDialogs->select(aDialog : Dialog | aDialog.resourceTypes->includes(aResource)) |
| /] |
| |
| [query public servicedResources(anAdaptorInterface : AdaptorInterface) : Set(Resource) = |
| anAdaptorInterface.serviceProviders()->collectNested(aServiceProvider : ServiceProvider | |
| servicedResources(aServiceProvider) |
| )->flatten()->asSet() |
| /] |
| |
| [query public relevantResources(anAdaptorInterface : AdaptorInterface) : Set(Resource) = |
| anAdaptorInterface.serviceProviders()->collectNested(aServiceProvider : ServiceProvider | |
| relevantResources(aServiceProvider) |
| )->flatten()->asSet() |
| ->union( |
| anAdaptorInterface.requiredAdaptors->collectNested(aRequiredAdaptor : RequiredAdaptor | |
| relevantResources(aRequiredAdaptor) |
| )->flatten()->asSet() |
| ) |
| /] |
| |
| [query public relevantDomainSpecifications(anAdaptorInterface : AdaptorInterface) : Set(DomainSpecification) = |
| anAdaptorInterface.serviceProviders()->collectNested(aServiceProvider : ServiceProvider | |
| relevantDomainSpecifications(aServiceProvider) |
| )->flatten()->asSet() |
| ->union( |
| anAdaptorInterface.requiredAdaptors->collectNested(aRequiredAdaptor : RequiredAdaptor | |
| relevantDomainSpecifications(aRequiredAdaptor) |
| )->flatten()->asSet() |
| ) |
| /] |
| |
| [comment Services for AdaptorPackageInfo /] |
| [query public javaClassPackageNameForAdaptorPackageInfo(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassBaseNamespace(anAdaptorInterface).concat('.resources') |
| /] |
| |
| [query public javaClassFullFileNameForAdaptorPackageInfo(anAdaptorInterface : AdaptorInterface) : String = |
| javaFilesBasePath(anAdaptorInterface).concatenatePaths(javaClassPackageNameForAdaptorPackageInfo(anAdaptorInterface).substituteAll('.', '/')).concat('/').concat('package-info').concat('.java') |
| /] |
| |
| [comment Services for ClientOnlyMainApplication /] |
| [query public javaClassPackageNameForClientOnlyMainApplication(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassBaseNamespace(anAdaptorInterface) |
| /] |
| |
| [query public javaClassNameForClientOnlyMainApplication(anAdaptorInterface : AdaptorInterface) : String = |
| 'OslcMainApplication' |
| /] |
| |
| [query public javaClassFullNameForClientOnlyMainApplication(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassPackageNameForClientOnlyMainApplication(anAdaptorInterface).concat('.').concat(javaClassNameForClientOnlyMainApplication(anAdaptorInterface)) |
| /] |
| |
| [query public javaClassFullFileNameForClientOnlyMainApplication(anAdaptorInterface : AdaptorInterface) : String = |
| javaFilesBasePath(anAdaptorInterface).concatenatePaths(javaClassPackageNameForClientOnlyMainApplication(anAdaptorInterface).substituteAll('.', '/')).concat('/').concat(javaClassNameForClientOnlyMainApplication(anAdaptorInterface)).concat('.java') |
| /] |
| |
| [comment Services for AdaptorApplication /] |
| [query public javaClassPackageNameForAdaptorApplication(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassBaseNamespace(anAdaptorInterface).concat('.servlet') |
| /] |
| |
| [query public javaClassNameForAdaptorApplication(anAdaptorInterface : AdaptorInterface) : String = |
| 'Application' |
| /] |
| |
| [query public javaClassFullNameForAdaptorApplication(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassPackageNameForAdaptorApplication(anAdaptorInterface).concat('.').concat(javaClassNameForAdaptorApplication(anAdaptorInterface)) |
| /] |
| |
| [query public javaClassFullFileNameForAdaptorApplication(anAdaptorInterface : AdaptorInterface) : String = |
| javaFilesBasePath(anAdaptorInterface).concatenatePaths(javaClassPackageNameForAdaptorApplication(anAdaptorInterface).substituteAll('.', '/')).concat('/').concat(javaClassNameForAdaptorApplication(anAdaptorInterface)).concat('.java') |
| /] |
| |
| [comment Services for AdaptorServletListener /] |
| [query public javaClassPackageNameForAdaptorServletListener(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassBaseNamespace(anAdaptorInterface).concat('.servlet') |
| /] |
| |
| [query public javaClassNameForAdaptorServletListener(anAdaptorInterface : AdaptorInterface) : String = |
| 'ServletListener' |
| /] |
| |
| [query public javaClassFullNameForAdaptorServletListener(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassPackageNameForAdaptorServletListener(anAdaptorInterface).concat('.').concat(javaClassNameForAdaptorServletListener(anAdaptorInterface)) |
| /] |
| |
| [query public javaClassFullFileNameForAdaptorServletListener(anAdaptorInterface : AdaptorInterface) : String = |
| javaFilesBasePath(anAdaptorInterface).concatenatePaths(javaClassPackageNameForAdaptorServletListener(anAdaptorInterface).substituteAll('.', '/')).concat('/').concat(javaClassNameForAdaptorServletListener(anAdaptorInterface)).concat('.java') |
| /] |
| |
| [comment Services for ResourcesFactory /] |
| [query public javaClassPackageNameForResourcesFactory(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassBaseNamespace(anAdaptorInterface) |
| /] |
| |
| [query public javaClassNameForResourcesFactory(anAdaptorInterface : AdaptorInterface) : String = |
| javaName(anAdaptorInterface, true).concat('ResourcesFactory') |
| /] |
| |
| [query public javaClassFullNameForResourcesFactory(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassPackageNameForResourcesFactory(anAdaptorInterface).concat('.').concat(javaClassNameForResourcesFactory(anAdaptorInterface)) |
| /] |
| |
| [query public javaClassFullFileNameForResourcesFactory(anAdaptorInterface : AdaptorInterface) : String = |
| javaFilesBasePath(anAdaptorInterface).concatenatePaths(javaClassPackageNameForResourcesFactory(anAdaptorInterface).substituteAll('.', '/')).concat('/').concat(javaClassNameForResourcesFactory(anAdaptorInterface)).concat('.java') |
| /] |
| |
| [comment Services for AdaptorManager /] |
| [query public javaClassPackageNameForAdaptorManager(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassBaseNamespace(anAdaptorInterface) |
| /] |
| |
| [query public javaClassNameForAdaptorManager(anAdaptorInterface : AdaptorInterface) : String = |
| javaName(anAdaptorInterface, true).concat('Manager') |
| /] |
| |
| [query public javaClassFullNameForAdaptorManager(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassPackageNameForAdaptorManager(anAdaptorInterface).concat('.').concat(javaClassNameForAdaptorManager(anAdaptorInterface)) |
| /] |
| |
| [query public javaClassFullFileNameForAdaptorManager(anAdaptorInterface : AdaptorInterface) : String = |
| javaFilesBasePath(anAdaptorInterface).concatenatePaths(javaClassPackageNameForAdaptorManager(anAdaptorInterface).substituteAll('.', '/')).concat('/').concat(javaClassNameForAdaptorManager(anAdaptorInterface)).concat('.java') |
| /] |
| |
| [comment Services for ResourceShapeService /] |
| [query public javaClassPackageNameForResourceShapeService(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassBaseNamespace(anAdaptorInterface).concat('.services') |
| /] |
| |
| [query public javaClassNameForResourceShapeService(anAdaptorInterface : AdaptorInterface) : String = |
| 'ResourceShapeService' |
| /] |
| |
| [query public javaClassFullNameForResourceShapeService(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassPackageNameForResourceShapeService(anAdaptorInterface).concat('.').concat(javaClassNameForResourceShapeService(anAdaptorInterface)) |
| /] |
| |
| [query public javaClassFullFileNameForResourceShapeService(anAdaptorInterface : AdaptorInterface) : String = |
| javaFilesBasePath(anAdaptorInterface).concatenatePaths(javaClassPackageNameForResourceShapeService(anAdaptorInterface).substituteAll('.', '/')).concat('/').concat(javaClassNameForResourceShapeService(anAdaptorInterface)).concat('.java') |
| /] |
| |
| [comment Services for AdaptorConstants /] |
| [query public javaInterfacePackageNameForAdaptorConstants(anAdaptorInterface : AdaptorInterface) : String = |
| javaClassBaseNamespace(anAdaptorInterface) |
| /] |
| |
| [query public javaInterfaceNameForAdaptorConstants(anAdaptorInterface : AdaptorInterface) : String = |
| javaName(anAdaptorInterface, true).concat('Constants') |
| /] |
| |
| [query public javaInterfaceFullNameForAdaptorConstants(anAdaptorInterface : AdaptorInterface) : String = |
| javaInterfacePackageNameForAdaptorConstants(anAdaptorInterface).concat('.').concat(javaInterfaceNameForAdaptorConstants(anAdaptorInterface)) |
| /] |
| |
| [query public javaInterfaceFullFileNameForAdaptorConstants(anAdaptorInterface : AdaptorInterface) : String = |
| javaFilesBasePath(anAdaptorInterface).concatenatePaths(javaInterfacePackageNameForAdaptorConstants(anAdaptorInterface).substituteAll('.', '/')).concat('/').concat(javaInterfaceNameForAdaptorConstants(anAdaptorInterface)).concat('.java') |
| /] |
| |
| [query public javaConstantName(aDomainSpecification : DomainSpecification) : String = |
| javaConstantString(aDomainSpecification.name) |
| /] |
| |
| [query public domainSpecificationConstantName(aDomainSpecification : DomainSpecification) : String = |
| javaConstantName(aDomainSpecification).concat('_DOMAIN') |
| /] |
| |
| [query public domainSpecificationNamespaceConstantName(aDomainSpecification : DomainSpecification) : String = |
| javaConstantName(aDomainSpecification).concat('_NAMSPACE') |
| /] |
| |
| [query public domainSpecificationNamespacePrefixConstantName(aDomainSpecification : DomainSpecification) : String = |
| javaConstantName(aDomainSpecification).concat('_NAMSPACE_PREFIX') |
| /] |
| |
| [query public resourceConstantName(aResource : Resource) : String = |
| aResource.javaName(true).toUpperCase() |
| /] |
| |
| [query public resourcePathConstantName(aResource : Resource) : String = |
| 'PATH_'.concat(aResource.javaName(true).toUpperCase()) |
| /] |
| |
| [query public resourceTypeConstantName(aResource : Resource) : String = |
| 'TYPE_'.concat(aResource.javaName(true).toUpperCase()) |
| /] |
| |
| [comment Services for RequiredAdaptor /] |
| [query public servicedResources(aRequiredAdaptor : RequiredAdaptor) : Set(Resource) = |
| if (aRequiredAdaptor.oclIsTypeOf(GenericRequiredAdaptor)) then |
| servicedResourcesForGenericRequiredAdaptor(aRequiredAdaptor.oclAsType(GenericRequiredAdaptor)) |
| else |
| servicedResourcesForModelledRequiredAdaptor(aRequiredAdaptor.oclAsType(ModelledRequiredAdaptor)) |
| endif |
| /] |
| |
| [query private servicedResourcesForGenericRequiredAdaptor(aGenericRequiredAdaptor : GenericRequiredAdaptor) : Set(Resource) = |
| aGenericRequiredAdaptor.servicedResources |
| /] |
| |
| [query private servicedResourcesForModelledRequiredAdaptor(aModelledRequiredAdaptor : ModelledRequiredAdaptor) : Set(Resource) = |
| servicedResources(aModelledRequiredAdaptor.adaptorInterface) |
| /] |
| |
| [query public relevantResources(aRequiredAdaptor : RequiredAdaptor) : Set(Resource) = |
| servicedResources(aRequiredAdaptor) |
| ->union(servicedResources(aRequiredAdaptor)->collectNested(aResource : Resource | aResource.allRelatedResources())->flatten()->asSet()) |
| /] |
| |
| [query public relevantDomainSpecifications(aRequiredAdaptor : RequiredAdaptor) : Set(DomainSpecification) = |
| relevantResources(aRequiredAdaptor)->collectNested(aResource : Resource | |
| definingDomainSpecification(aResource) |
| ->union(aResource.allProperties()->asSet()->collectNested(aResourceProperty : ResourceProperty | aResourceProperty.definingDomainSpecification())) |
| )->flatten()->asSet() |
| /] |