Skip to content

Commit

Permalink
Added automatic generation of properties of superclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasfruehwirth committed Apr 7, 2021
1 parent ce07668 commit 73862a4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
17 changes: 16 additions & 1 deletion QvtoTransformationRules/transforms/ClassDiagram/Classes.qvto
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,22 @@ mapping UML::Class::class2OPCUAObjectType(inout nodeset : OPCUA::UANodeSetType)
};

// transform properties of the class
self.transformPropertiesAndLinkToUANode(result, nodeset);
// if the class inherits from another class, also the properties of the parent class need to be added to the result
// transform primitive-type-properties of the corresponding class that are not defined as slots
// and repeat this for all superclasses

// self.transformPropertiesAndLinkToUANode(result, nodeset);
var element := self;
while(element <> null) {
element.transformPropertiesAndLinkToUANode(result, nodeset);

// if the class inherits from another class, also the properties of the parent class need to be added to the uanode
if(element.generalization->size() > 0 and element.generalization->asList()->first().general.oclIsTypeOf(UML::Class)) {
element := element.generalization->asList()->first().general.oclAsType(UML::Class);
} else {
element := null;
};
};

// transform operations of the class
nodeset.uAMethod += self.ownedElement->selectByType(UML::Operation)->map operation2UAMethod(result, nodeset);
Expand Down
42 changes: 32 additions & 10 deletions QvtoTransformationRules/transforms/ClassDiagram/Instances.qvto
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,44 @@ mapping UML::InstanceSpecification::instanceSpecification2OPCUAObject(inout node
nodeset.uAVariable += self.ownedElement->selectByType(UML::Slot)->select(
slot | slot.definingFeature.oclIsTypeOf(UML::Property) and slot.definingFeature.type.oclIsKindOf(UML::PrimitiveType)
)->map propertySlot2UAVariable(result);

// transform primitive-type-properties of the corresponding class that are not defined as slots
nodeset.uAVariable += classifier.ownedElement->selectByType(UML::Property)->select(
p | p.type.oclIsKindOf(UML::PrimitiveType) and self.slot.definingFeature->excludes(p)
)->map property2UAVariable(result);
// and repeat this for all superclasses
var element := classifier;
while(element <> null) {
nodeset.uAVariable += element.ownedElement->selectByType(UML::Property)->select(
p | p.type.oclIsKindOf(UML::PrimitiveType) and self.slot.definingFeature->excludes(p)
)->map property2UAVariable(result);

// if the class inherits from another class, also the properties of the parent class need to be added to the uanode
if(element.generalization->size() > 0 and element.generalization->asList()->first().general.oclIsTypeOf(UML::Class)) {
element := element.generalization->asList()->first().general.oclAsType(UML::Class);
} else {
element := null;
};
};

// transform non-primitive-type-property-slots of the Instance. This non-primitive-type-property is itself defined by an InstanceSpecification
_references.reference += self.ownedElement->selectByType(UML::Slot)->select(
slot | slot.definingFeature.oclIsTypeOf(UML::Property) and (not slot.definingFeature.type.oclIsKindOf(UML::PrimitiveType))
)->map propertySlot2UAReference(result);

// transform non-primitive-type-properties of the corresponding class that are not defined as slots
nodeset.uAObject += classifier.ownedElement->selectByType(UML::Property)->select(
p | (not p.type.oclIsKindOf(UML::PrimitiveType)) and self.slot.definingFeature->excludes(p)
and p.lower >= 1 // mandatory or mandatory placeholder
)->map property2UAObject(result, nodeset);

// transform primitive-type-properties of the corresponding class that are not defined as slots
// and repeat this for all superclasses
element := classifier;
while(element <> null) {
nodeset.uAObject += element.ownedElement->selectByType(UML::Property)->select(
p | (not p.type.oclIsKindOf(UML::PrimitiveType)) and self.slot.definingFeature->excludes(p)
and p.lower >= 1 // mandatory or mandatory placeholder
)->map property2UAObject(result, nodeset);

// if the class inherits from another class, also the properties of the parent class need to be added to the uanode
if(element.generalization->size() > 0 and element.generalization->asList()->first().general.oclIsTypeOf(UML::Class)) {
element := element.generalization->asList()->first().general.oclAsType(UML::Class);
} else {
element := null;
};
};
}

mapping UML::Slot::propertySlot2UAVariable(inout parent : OPCUA::UANode) : OPCUA::UAVariable {
Expand Down

0 comments on commit 73862a4

Please sign in to comment.