| [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 resourcePropertyServices('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::adaptorInterfaceServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::domainSpecificationServices/] |
| |
| [query public javaName(aProperty: ResourceProperty, toUpperFirst : Boolean) : String = |
| javaString(aProperty.name, aProperty.definingDomainSpecification().namespacePrefix.name, toUpperFirst) |
| /] |
| |
| [comment TODO: "URI" should actually not be a valueType since it is not OSLC-standard. However, this is one way to allow user to specify a URI as a type. |
| Another approach would be to have a valueType as String, and the Range being set to "URI", hence creating a URI (local) resource? |
| But I really want the user to be able to map to java.net.URI, just like they can map to String or Boolean - without having to create a resource for that. /] |
| [query public hasOSLCSupportedValueType(aProperty: ResourceProperty) : Boolean = |
| not (Sequence{'URI'}->includes(aProperty.valueType.toString())) |
| /] |
| |
| [query public nameAnnotation(aProperty: ResourceProperty) : String = |
| '@OslcName("'.concat(javaName(aProperty, false)). concat('")') |
| /] |
| |
| [query public propertyDefinitionAnnotation(aProperty: ResourceProperty, aResource: Resource, anAdaptorInterface: AdaptorInterface) : String = |
| '@OslcPropertyDefinition('.concat(javaInterfaceNameForConstants(aProperty.definingDomainSpecification())).concat('.').concat(domainSpecificationNamespaceConstantName(aProperty.definingDomainSpecification())) . concat(' + "').concat(javaName(aProperty, false)).concat('")') |
| /] |
| |
| [query public descriptionAnnotation(aProperty: ResourceProperty) : String = |
| (if (not aProperty.description.oclIsUndefined()) then |
| '@OslcDescription("'.concat(aProperty.description).concat('")') |
| else |
| '' |
| endif) |
| /] |
| |
| [query public occursAnnotation(aProperty: ResourceProperty) : String = |
| (if (not aProperty.occurs.oclIsUndefined()) then |
| if (aProperty.occurs = ResourcePropertyOccurs::exactlyOne) then |
| '@OslcOccurs(Occurs.ExactlyOne)' |
| else |
| if (aProperty.occurs = ResourcePropertyOccurs::zeroOrOne) then |
| '@OslcOccurs(Occurs.ZeroOrOne)' |
| else |
| if (aProperty.occurs = ResourcePropertyOccurs::zeroOrMany) then |
| '@OslcOccurs(Occurs.ZeroOrMany)' |
| else |
| if (aProperty.occurs = ResourcePropertyOccurs::oneOrMany) then |
| '@OslcOccurs(Occurs.OneOrMany)' |
| else |
| '' |
| endif |
| endif |
| endif |
| endif |
| else |
| '' |
| endif) |
| /] |
| |
| [query public valueTypeAnnotation(aProperty: ResourceProperty) : String = |
| (if (not aProperty.valueType.oclIsUndefined()) then |
| if (hasOSLCSupportedValueType(aProperty)) then |
| '@OslcValueType(ValueType.'.concat(aProperty.valueType.toString()).concat(')') |
| else |
| '' |
| endif |
| else |
| '' |
| endif) |
| /] |
| |
| [comment Either not supported by OSLC4J /] |
| [query public representationAnnotation(aProperty: ResourceProperty) : String = |
| (if (not aProperty.representation.oclIsUndefined()) then |
| if (not aProperty.representation.toString().equalsIgnoreCase('n_a')) then |
| if (not aProperty.representation.toString().equalsIgnoreCase('either')) then |
| '@OslcRepresentation(Representation.'.concat(aProperty.representation.toString().toUpperFirst()).concat(')') |
| else |
| '' |
| endif |
| else |
| '' |
| endif |
| else |
| '' |
| endif) |
| /] |
| |
| [query public rangeAnnotation(aProperty: ResourceProperty, aResource: Resource, anAdaptorInterface: AdaptorInterface) : String = |
| (if (aProperty.range->size() > 0) then |
| '@OslcRange({' |
| .concat(concatenate(aProperty.range->collect(aRange : Resource | javaInterfaceNameForConstants(aRange.definingDomainSpecification()).concat('.').concat(resourceTypeConstantName(aRange))), ', ')) |
| .concat('})') |
| else |
| '' |
| endif) |
| /] |
| |
| [query public readOnlyAnnotation(aProperty: ResourceProperty) : String = |
| (if (not aProperty.readOnly.oclIsUndefined()) then |
| '@OslcReadOnly('.concat(aProperty.readOnly.toString()).concat(')') |
| else |
| '' |
| endif) |
| /] |
| |
| [query public titleAnnotation(aProperty: ResourceProperty) : String = |
| (if (not aProperty.title.oclIsUndefined()) then |
| '@OslcTitle("'.concat(aProperty.title).concat('")') |
| else |
| '' |
| endif) |
| /] |
| |
| [comment: It is not possible to have a boolean property which the user can leave undefined. Hence, we need to create an enum with a third option of "n_a"./] |
| [query public isMemberPropertyAnnotation(aProperty: ResourceProperty) : String = |
| if (aProperty.isMemberProperty.toString().equalsIgnoreCase('true')) then |
| '@OslcMemberProperty(true)' |
| else |
| if (aProperty.isMemberProperty.toString().equalsIgnoreCase('false')) then |
| '@OslcMemberProperty(false)' |
| else |
| '' |
| endif |
| endif |
| /] |
| |
| [query public allowedValueAnnotation(aProperty: ResourceProperty) : String = |
| (if (aProperty.allowedValue->size() > 0) then |
| '@OslcAllowedValue({"'.concat(concatenate((aProperty.allowedValue)->asSequence(), '", "')).concat('"})') |
| else |
| '' |
| endif) |
| /] |
| |
| [query public typeURI(aProperty: ResourceProperty) : String = |
| aProperty.definingDomainSpecification().namespaceURI.concat('#').concat(javaName(aProperty, false)) |
| /] |
| |
| [query public javaAttributeTypeNeedsConstruction(aProperty: ResourceProperty) : Boolean = |
| Sequence{'Resource', 'LocalResource'}->includes(aProperty.valueType.toString())._or(Sequence{'zeroOrMany', 'oneOrMany'}->includes(aProperty.occurs.toString())) |
| /] |
| |
| [query public javaAttributeBaseTypeCastFromString(aProperty: ResourceProperty, variable: String) : String = |
| (if (aProperty.valueType.toString() = 'String') then |
| variable |
| else |
| if (aProperty.valueType.toString() = 'XMLLiteral') then |
| variable |
| else |
| if(aProperty.valueType.toString() = 'DateTime') then |
| 'new SimpleDateFormat("M/D/y").parse(' + variable + ')' |
| else |
| if(aProperty.valueType.toString() = 'URI') then |
| 'new URI(' + variable + ')' |
| else |
| if(aProperty.valueType.toString() = 'Boolean') then |
| 'new Boolean(' + variable + ')' |
| else |
| if(aProperty.valueType.toString() = 'Double') then |
| 'Double.valueOf(' + variable + ')' |
| else |
| if(aProperty.valueType.toString() = 'Float') then |
| 'Float.valueOf(' + variable + ')' |
| else |
| if(aProperty.valueType.toString() = 'Integer') then |
| 'Integer.valueOf(' + variable + ')' |
| else |
| if(aProperty.valueType.toString() = 'Resource') then |
| 'new Link(new URI(' + variable + '))' |
| else |
| if(aProperty.valueType.toString() = 'LocalResource') then |
| if (aProperty.range->size() = 1) then |
| 'new ' + javaClassName(aProperty.range->first()) + '(new URI(' + variable + '))' |
| else |
| 'new Link(new URI(' + variable + '))' |
| endif |
| else |
| '' |
| endif |
| endif |
| endif |
| endif |
| endif |
| endif |
| endif |
| endif |
| endif |
| endif) |
| /] |
| |
| |
| [comment TODO: If occurs = 'zeroOrMany', it is not 100% clear when to use Set and when to use ArrayList, or TreeSet./] |
| [query public javaAttributeTypeDeclaration(aProperty: ResourceProperty) : String = |
| (if (Sequence{'zeroOrMany', 'oneOrMany'}->includes(aProperty.occurs.toString())) then |
| 'HashSet<' |
| else |
| '' |
| endif) |
| .concat(javaAttributeBaseType(aProperty)) |
| .concat( |
| (if (Sequence{'zeroOrMany', 'oneOrMany'}->includes(aProperty.occurs.toString())) then |
| '>' |
| else |
| '' |
| endif)) |
| /] |
| |
| [comment For Resource properties, we always have a Link type. That is how OSLC4 wants it. /] |
| [query public javaAttributeBaseType(aProperty: ResourceProperty) : String = |
| (if (aProperty.valueType.toString() = 'String') then |
| 'String' |
| else |
| if (aProperty.valueType.toString() = 'XMLLiteral') then |
| 'String' |
| else |
| if(aProperty.valueType.toString() = 'DateTime') then |
| 'Date' |
| else |
| if(aProperty.valueType.toString() = 'URI') then |
| 'URI' |
| else |
| if(aProperty.valueType.toString() = 'Boolean') then |
| 'Boolean' |
| else |
| if(aProperty.valueType.toString() = 'Double') then |
| 'Double' |
| else |
| if(aProperty.valueType.toString() = 'Float') then |
| 'Float' |
| else |
| if(aProperty.valueType.toString() = 'Integer') then |
| 'Integer' |
| else |
| if(aProperty.valueType.toString() = 'Resource') then |
| 'Link' |
| else |
| if(aProperty.valueType.toString() = 'LocalResource') then |
| if (aProperty.range->size() = 1) then |
| javaClassName(aProperty.range->first()) |
| else |
| 'Link' |
| endif |
| else |
| '' |
| endif |
| endif |
| endif |
| endif |
| endif |
| endif |
| endif |
| endif |
| endif |
| endif) |
| /] |
| |
| [query public javaAttributeName(aProperty: ResourceProperty, aResource: Resource) : String = |
| (if (allProperties(aResource)->collect(p : ResourceProperty | javaName(p, false))->count(javaName(aProperty, false)) = 1) then |
| javaName(aProperty, false) |
| else |
| aProperty.definingDomainSpecification().namespacePrefix.name.concat(javaName(aProperty, true)) |
| endif) |
| /] |
| |
| [query public propertyToHtmlForCreationMethodName(aProperty: ResourceProperty, aResource: Resource, aCreationDialog: Dialog) : String = |
| javaAttributeName(aProperty, aResource).concat('ToHtmlForCreation') |
| .concat( |
| (if (aCreationDialog.oclIsUndefined()) |
| then |
| '' |
| else |
| creationDialogs(containingAdaptorInterface(aCreationDialog), aResource)->indexOf(aCreationDialog).toString() |
| endif) |
| ) |
| /] |