blob: f7a57aa58ff035081345a2c6c99cd50ac539a7a6 [file] [log] [blame]
@GenModel(fileExtensions="dto", modelDirectory="/org.eclipse.osbp.dsl.dto.xtext/emf-gen", editDirectory="/org.eclipse.osbp.dsl.dto.xtext.edit/src", childCreationExtenders="true")
@GenModel(modelName="DTO")
@GenModel(prefix="OSBPDto")
@GenModel(suppressEMFModelTags="true")
@GenModel(runtimeVersion="2.9")
@GenModel(loadInitialization="false")
@GenModel(literalsInterface="true")
@GenModel(copyrightText="Copyright (c) 2011, 2016 - Lunifera GmbH (Gross Enzersdorf), Loetz GmbH&Co.KG (Heidelberg)
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
which accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
Contributors:
Florian Pirchner - Initial implementation
")
@GenModel(operationReflection="false")
@Ecore(nsURI="http://osbp.eclipse.org/dsl/dto/v1")
@Ecore(nsPrefix="dto")
@Ecore(rootPackage="dto")
package org.eclipse.osbp.dsl.semantic.dto
import java.util.ArrayList
import java.util.Collections
import java.util.List
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.InternalEObject
import org.eclipse.osbp.dsl.semantic.common.types.FeaturesList
import org.eclipse.osbp.dsl.semantic.common.types.LAttribute
import org.eclipse.osbp.dsl.semantic.common.types.LClass
import org.eclipse.osbp.dsl.semantic.common.types.LFeature
import org.eclipse.osbp.dsl.semantic.common.types.LFeaturesHolder
import org.eclipse.osbp.dsl.semantic.common.types.LKeyAndValue
import org.eclipse.osbp.dsl.semantic.common.types.LLazyResolver
import org.eclipse.osbp.dsl.semantic.common.types.LMultiplicity
import org.eclipse.osbp.dsl.semantic.common.types.LReference
import org.eclipse.osbp.dsl.semantic.common.types.LScalarType
import org.eclipse.osbp.dsl.semantic.common.types.LType
import org.eclipse.osbp.dsl.semantic.common.types.LTypedPackage
import org.eclipse.osbp.xtext.oxtype.resource.EcoreUtil3
import org.eclipse.xtext.xbase.XExpression
import org.eclipse.xtext.xtype.XImportSection
class LDtoModel {
contains XImportSection importSection
contains LTypedPackage[] packages
op EObject eResolveProxy(InternalEObject proxy) {
return EcoreUtil3.resolve(proxy, this.eResource().resourceSet);
}
}
/**
* A bean is an embeddable element that may become added to a entity using the @embedd annotation.
*/
class LDto extends LClass, LFeaturesHolder, LScalarType {
contains LDtoFeature[] features
refers LDto superType opposite subTypes
refers LDto[] subTypes opposite superType
refers LType wrappedType
/**
* Returns all features of type LOperation
*/
op OperationsList getOperations() {
features.filter(typeof(LDtoOperation)).toList
}
/**
* Returns all features of type LDtoReference
*/
op DtoReferenceList getReferences() {
features.filter(typeof(LDtoAbstractReference)).toList
}
/**
* Returns all features of type LDtoAttribute
*/
op DtoAttributeList getAttributes() {
features.filter(typeof(LDtoAbstractAttribute)).toList
}
/**
* Returns all features of the holder and from super types
*/
op FeaturesList getAllFeatures() {
val List<LDtoFeature> result = newArrayList()
collectAllOSBPFeatures(result)
return result
}
op LAttribute getIdAttribute() {
val LDtoAbstractAttribute feature = allFeatures.filter(typeof(LDtoAbstractAttribute)).findFirst [
switch (it) {
LDtoInheritedAttribute: {
return it.inheritedFeature?.id || it.inheritedFeature?.uuid
}
LDtoAttribute: {
return it.id || it.uuid
}
}
return false
]
switch (feature) {
LDtoAttribute:
return feature
LDtoInheritedAttribute:
return feature.inheritedFeature
}
return null
}
op void collectAllOSBPFeatures(LDto current, DtoFeatureList result) {
if (current === null) {
return
}
// collect from current feature
result.addAll(current.features)
// call for super class
current.superType.collectAllOSBPFeatures(result)
}
op LDtoAbstractAttribute getPrimaryKeyAttribute() {
return allFeatures.filter(typeof(LDtoAbstractAttribute)).findFirst [
switch (it) {
LDtoInheritedAttribute:
return it.inheritedFeature?.id || it.inheritedFeature?.uuid
LDtoAttribute:
return it.id || it.uuid
}
return false
]
}
op String getIdAttributeName() {
var attribute = getPrimaryKeyAttribute()
switch (attribute) {
LDtoInheritedAttribute:
return attribute.inheritedFeature.name
LDtoAttribute:
return attribute.name
}
return null
}
op LScalarType getIdAttributeType() {
var attribute = getPrimaryKeyAttribute()
switch (attribute) {
LDtoInheritedAttribute:
return attribute.inheritedFeature.^type
case LDtoAttribute:
return attribute.^type
}
return null
}
}
class LAutoInheritDto extends LDto {
}
class LDtoMapper extends LLazyResolver {
contains XExpression toDTO
contains XExpression fromDTO
}
class LDtoFeature extends LFeature {
contains LDtoMapper mapper
op LDto getDTO() {
// if (eContainer instanceof LFeature) {
// return null // this happens since the feature may be the annotation info
// }
return eContainer as LDto
}
}
abstract class LDtoAbstractAttribute extends LDtoFeature, LAttribute {
op PropertiesList getResolvedProperties() {
if (this instanceof LDtoInheritedAttribute) {
val temp = this as LDtoInheritedAttribute
if (temp.inheritedFeature === null) {
return Collections.emptyList()
}
val result = new ArrayList<LKeyAndValue>(temp.inheritedFeature.properties)
result.addAll(properties)
return result
} else {
return properties
}
}
op boolean isVersionAttr() {
if (this instanceof LDtoInheritedAttribute) {
val temp = this as LDtoInheritedAttribute
return temp.inheritedFeature.version
} else {
return this.version
}
}
}
class LDtoInheritedAttribute extends LDtoAbstractAttribute{
refers LAttribute inheritedFeature
op LScalarType getInheritedType() {
return inheritedFeature.^type
}
op LMultiplicity getInheritedMultiplicity() {
return inheritedFeature.multiplicity
}
}
class LDtoAttribute extends LDtoAbstractAttribute {
}
abstract class LDtoAbstractReference extends LDtoFeature, LReference {
refers LDto ^type
op PropertiesList getResolvedProperties() {
if (this instanceof org.eclipse.osbp.dsl.semantic.dto.LDtoInheritedReference) {
val temp = this as LDtoInheritedReference
if (temp.inheritedFeature === null) {
return Collections.emptyList()
}
val result = new ArrayList<LKeyAndValue>(temp.inheritedFeature.properties)
result.addAll(properties)
return result
} else {
return properties
}
}
}
class LDtoInheritedReference extends LDtoAbstractReference{
refers LReference inheritedFeature
op LMultiplicity getInheritedMultiplicity() {
return inheritedFeature.multiplicity
}
}
class LDtoReference extends LDtoAbstractReference {
refers LDtoReference ^opposite
}
class LDtoOperation extends org.eclipse.osbp.dsl.semantic.common.types.LOperation, LDtoFeature {
}
type DtoFeatureList wraps java.util.List<LDtoFeature>
type OperationsList wraps java.util.List<LDtoOperation>
type DtoReferenceList wraps java.util.List<LDtoAbstractReference>
type DtoAttributeList wraps java.util.List<LDtoAbstractAttribute>
type DtoAbstractAttributeList wraps java.util.List<LDtoAbstractAttribute>
type InternalEObject wraps InternalEObject
type PropertiesList wraps java.util.List<LKeyAndValue>