blob: d0fb0858bcb207e79a1424078be6cd71f64fa63e [file] [log] [blame]
[comment encoding = UTF-8 /]
[comment
/*******************************************************************************
* Copyright (c) 2011, 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:
*
* Sam Padgett - initial API and implementation
* Michael Fiedler - adapted for OSLC4J
* 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 generateAdaptorManager('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::serviceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::adaptorInterfaceServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderServices/]
[import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderCatalogServices/]
[query public backendCode(backendCodeTemplate : String, resourceClassName : String, resourceInstanceName : String, compositeID : Sequence(String)) : String =
(if (not backendCodeTemplate.oclIsUndefined()) then
backendCodeTemplate
.substituteAll('[ResourceClassName/]', resourceClassName)
.substituteAll('[ResourceInstanceName/]', resourceInstanceName)
.substituteAll('[Parameter1/]', (if (compositeID->size() >=1) then compositeID->at(1) else '' endif))
.substituteAll('[Parameter2/]', (if (compositeID->size() >=2) then compositeID->at(2) else '' endif))
.substituteAll('[Parameter3/]', (if (compositeID->size() >=3) then compositeID->at(3) else '' endif))
.substituteAll('[Parameter4/]', (if (compositeID->size() >=4) then compositeID->at(4) else '' endif))
.substituteAll('[Parameter5/]', (if (compositeID->size() >=5) then compositeID->at(5) else '' endif))
else
''
endif)
/]
[query public backendCode(backendCodeTemplate : String) : String =
(if (not backendCodeTemplate.oclIsUndefined()) then
backendCodeTemplate
else
''
endif)
/]
[template public generateAdaptorManager(anAdaptorInterface : AdaptorInterface)]
[file (javaClassFullFileNameForAdaptorManager(anAdaptorInterface), false, 'UTF-8')]
// [protected ('Copyright')]
/*******************************************************************************
* Copyright (c) 2011, 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:
*
* Sam Padgett - initial API and implementation
* Michael Fiedler - adapted for OSLC4J
* 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
*******************************************************************************/
// [/protected]
package [javaClassPackageNameForAdaptorManager(anAdaptorInterface) /];
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletContextEvent;
import java.util.List;
import org.eclipse.lyo.oslc4j.core.model.ServiceProvider;
import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
[if (not anAdaptorInterface.serviceProviderCatalog.oclIsUndefined())]
import [javaClassFullNameForSingleton(anAdaptorInterface.serviceProviderCatalog) /];
[/if]
[for (aServiceProvider: ServiceProvider | anAdaptorInterface.serviceProviders())]
import [javaClassFullName(aServiceProvider) /];
[/for]
[for (aResource: Resource | relevantResources(anAdaptorInterface)->sortedBy(name))]
import [javaClassFullName(aResource, anAdaptorInterface, null) /];
[/for]
[backendCode(anAdaptorInterface.backendCodeTemplate_classImports)/]
// [protected ('imports')]
// [/protected]
// [protected ('pre_class_code')]
// [/protected]
public class [javaClassNameForAdaptorManager(anAdaptorInterface) /] {
// [protected ('class_attributes')]
// [/protected]
[backendCode(anAdaptorInterface.backendCodeTemplate_classMethods)/]
// [protected ('class_methods')]
// [/protected]
public static void contextInitializeServletListener(final ServletContextEvent servletContextEvent)
{
[backendCode(anAdaptorInterface.backendCodeTemplate_servletListenerInitialize)/]
// [protected ('contextInitializeServletListener')]
// TODO Implement code to establish connection to data backbone etc ...
// [/protected]
}
public static void contextDestroyServletListener(ServletContextEvent servletContextEvent)
{
[backendCode(anAdaptorInterface.backendCodeTemplate_servletListenerDestroy)/]
// [protected ('contextDestroyed')]
// TODO Implement code to shutdown connections to data backbone etc...
// [/protected]
}
[for (aServiceProvider: ServiceProvider | anAdaptorInterface.serviceProviders())]
public static [aServiceProvider.javaClassName()/]['[' ']'/] get[aServiceProvider.javaClassName()/]s(HttpServletRequest httpServletRequest)
{
[aServiceProvider.javaClassName() /][ '[' ']' /] serviceProviderInfos = {};
[backendCode(anAdaptorInterface.backendCodeTemplate_getServiceProviders)/]
// [protected ('"'.concat(aServiceProvider.javaClassName()).concat('[] get'.concat(aServiceProvider.javaClassName()).concat('s(...)"')))]
// TODO Implement code to return the set of ServiceProviders
// [/protected]
return serviceProviderInfos;
}
[/for]
[for (aService: Service | anAdaptorInterface.serviceProviders().services)]
[for (aQueryCapability: QueryCapability | aService.queryCapabilities)]
public static List<[queryMethodResourceType(aQueryCapability)/]> [queryMethodName(aQueryCapability, true)/](HttpServletRequest httpServletRequest[commaSeparate(queryMethodSignature(aQueryCapability, false), true, false)/], String where, int page, int limit)
{
List<[queryMethodResourceType(aQueryCapability)/]> resources = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_getResources, queryMethodResourceType(aQueryCapability), 'resources', queryCompositeID(aQueryCapability))/]
// [protected (queryMethodName(aQueryCapability, true))]
// TODO Implement code to return a set of resources
// [/protected]
return resources;
}
[/for]
[for (aSelectionDialog: Dialog | aService.selectionDialogs)]
public static List<[dialogMethodResourceType(aSelectionDialog)/]> [dialogMethodName(aSelectionDialog, true)/](HttpServletRequest httpServletRequest[commaSeparate(dialogMethodSignature(aSelectionDialog, true, false), true, false)/], String terms)
{
List<[dialogMethodResourceType(aSelectionDialog)/]> resources = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_searchResources, dialogMethodResourceType(aSelectionDialog), 'resources', dialogCompositeID(aSelectionDialog, true))/]
// [protected (dialogMethodName(aSelectionDialog, true))]
// TODO Implement code to return a set of resources, based on search criteria
// [/protected]
return resources;
}
[/for]
[for (aCreationFactory: CreationFactory | aService.creationFactories)]
public static [creationMethodResourceType(aCreationFactory)/] [creationMethodName(aCreationFactory)/](HttpServletRequest httpServletRequest, final [creationMethodResourceType(aCreationFactory)/] aResource[commaSeparate(creationMethodSignature(aCreationFactory, false), true, false)/])
{
[creationMethodResourceType(aCreationFactory)/] newResource = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_createResource, creationMethodResourceType(aCreationFactory), 'newResource', creationCompositeID(aCreationFactory))/]
// [protected (creationMethodName(aCreationFactory))]
// TODO Implement code to create a resource
// [/protected]
return newResource;
}
[/for]
[for (aCreationDialog: Dialog | aService.creationDialogs)]
[if (aService.creationFactories->select(f: CreationFactory | f.resourceTypes = aCreationDialog.resourceTypes)->isEmpty())]
public static [creationMethodResourceType(aCreationDialog)/] [creationMethodName(aCreationDialog)/](HttpServletRequest httpServletRequest, final [creationMethodResourceType(aCreationDialog)/] aResource[commaSeparate(dialogMethodSignature(aCreationDialog, false, false), true, false)/])
{
[creationMethodResourceType(aCreationDialog)/] newResource = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_createResource, creationMethodResourceType(aCreationDialog), 'newResource', dialogCompositeID(aCreationDialog, false))/]
// [protected (creationMethodName(aCreationDialog))]
// TODO Implement code to create a resource
// [/protected]
return newResource;
}
[/if]
[/for]
[for (aBasicCapability: BasicCapability | aService.basicCapabilities)]
[if (aBasicCapability.read)]
[for (aResource: Resource | aBasicCapability.resourceTypes)]
public static [getResourceMethodResourceType(aBasicCapability, aResource)/] [getResourceMethodName(aBasicCapability, aResource, true)/](HttpServletRequest httpServletRequest[commaSeparate(instanceMethodSignature(aResource, aBasicCapability, false), true, false)/])
{
[getResourceMethodResourceType(aBasicCapability, aResource)/] aResource = null;
[backendCode(anAdaptorInterface.backendCodeTemplate_getResource, getResourceMethodResourceType(aBasicCapability, aResource), 'aResource', instanceCompositeID(aResource, aBasicCapability))/]
// [protected (getResourceMethodName(aBasicCapability, aResource, true))]
// TODO Implement code to return a resource
// [/protected]
return aResource;
}
[/for]
[/if]
[if (aBasicCapability.delete)]
[for (aResource: Resource | aBasicCapability.resourceTypes)]
public static Boolean [deleteResourceMethodName(aBasicCapability, aResource)/](HttpServletRequest httpServletRequest[commaSeparate(instanceMethodSignature(aResource, aBasicCapability, false), true, false)/])
{
Boolean deleted = false;
// [protected (deleteResourceMethodName(aBasicCapability, aResource))]
// TODO Implement code to delete a resource
// [/protected]
return deleted;
}
[/for]
[/if]
[if (aBasicCapability.update)]
[for (aResource: Resource | aBasicCapability.resourceTypes)]
public static [updateResourceMethodResourceType(aBasicCapability, aResource)/] [updateResourceMethodName(aBasicCapability, aResource)/](HttpServletRequest httpServletRequest, final [updateResourceMethodResourceType(aBasicCapability, aResource)/] aResource[commaSeparate(instanceMethodSignature(aResource, aBasicCapability, false), true, false)/]) {
[updateResourceMethodResourceType(aBasicCapability, aResource)/] updatedResource = null;
// [protected (updateResourceMethodName(aBasicCapability, aResource))]
// TODO Implement code to update and return a resource
// [/protected]
return updatedResource;
}
[/for]
[/if]
[/for]
[/for]
[for (aResource: Resource | servicedResources(anAdaptorInterface))]
public static String [getResourceETagMethodName(aResource)/](final [javaClassName(aResource)/] aResource)
{
String eTag = null;
// [protected (getResourceETagMethodName(aResource))]
// TODO Implement code to return an ETag for a particular resource
// [/protected]
return eTag;
}
[/for]
[comment creationFactories that need to handle more than 1 resource need a special ETag method. See the method calls from the ServiceProvider Services classes./]
[for (aService: Service | anAdaptorInterface.serviceProviders().services)]
[for (aCreationFactory: CreationFactory | aService.creationFactories)]
[if (aCreationFactory.resourceTypes->size() > 1 )]
public static String [getResourceETagMethodName(aCreationFactory.resourceTypes)/](final [creationMethodResourceType(aCreationFactory)/] aResource)
{
String eTag = null;
// [protected (getResourceETagMethodName(aCreationFactory.resourceTypes))]
// TODO Implement code to return an ETag for a particular resource
// [/protected]
return eTag;
}
[/if]
[/for]
[/for]
}
[/file]
[/template]