Skip to content
Snippets Groups Projects
Commit 9743e0f3 authored by Kevin Kassin's avatar Kevin Kassin
Browse files

Commit 9.9 20:30

added transformation package
parent 7cfc9f45
No related branches found
No related tags found
No related merge requests found
Showing
with 731 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.framed.orm.transformation</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Transformation
Bundle-SymbolicName: org.framed.orm.transformation;singleton:=true
Bundle-Version: 2.0.3
Bundle-Activator: org.framed.orm.transformation.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.epsilon.eol.engine,
org.eclipse.epsilon.emc.emf,
org.eclipse.epsilon.eol.dt;bundle-version="1.2.0",
org.eclipse.epsilon.etl.engine,
org.rosi.crom.metamodel;bundle-version="0.1.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.framed.orm.transformation
source.. = src/
output.. = target/classes/
bin.includes = META-INF/,\
.,\
epsilon/
//Set of all available features
operation getAllFeatures() : Set {
var set : Set;
set.add("Role_Types");
set.add("Role_Structure");
set.add("Role_Properties");
set.add("Role_Behavior");
set.add("Role_Inheritance");
set.add("Playable");
set.add("Players");
set.add("Naturals");
set.add("Compartments");
set.add("Dates");
set.add("Roles");
set.add("Dependent");
set.add("On_Compartments");
set.add("On_Relationships");
set.add("Role_Constraints");
set.add("Role_Implication");
set.add("Role_Prohibition");
set.add("Role_Equivalence");
set.add("Group_Constraints");
set.add("Occurrence_Constraints");
set.add("Relationships");
set.add("Relationship_Constraints");
set.add("Relationship_Cardinality");
set.add("Intra_Relationship_Constraints");
set.add("Parthood_Constraints");
set.add("Inter_Relationship_Constraints");
set.add("Contains_Compartments");
set.add("Compartment_Types");
set.add("Compartment_Structure");
set.add("Compartment_Properties");
set.add("Compartment_Behavior");
set.add("Compartment_Inheritance");
set.add("Participants");
set.add("Playable_by_Defining_Compartment");
set.add("Data_Types");
set.add("Data_Type_Inheritance");
return set;
}
\ No newline at end of file
operation parseCardinality(card : String) : Sequence(Integer) {
var result = new Sequence(Integer);
if(card.matches(".*\\(.*\\).*")) {
card = card.substring(card.indexOf("(") + 1, card.indexOf(")"));
}
if (card.matches("[0-9]+\\.\\.[0-9]+")) {
var cards = card.split("\\.\\.");
result.add(new Native("java.lang.Integer")(cards[0]));
result.add(new Native("java.lang.Integer")(cards[1]));
} else if (card.matches("[0-9]+\\.\\.\\*")) {
var cards = card.split("\\.\\.");
result.add(new Native("java.lang.Integer")(cards[0]));
} else if (card.matches("[0-9]+")) {
var x = new Native("java.lang.Integer")(card);
result.add(x);
result.add(x);
}
return result;
}
\ No newline at end of file
import "Type.etl";
import "CardinalityParser.eol";
pre CompartmentType {
var compartmentTypes : OrderedSet(source!Shape);
}
/**
* Transforms a shape with type COMPARTMENT_TYPE.
*/
@lazy
rule CompartmentType
transform t : source!Shape
to n : target!CompartmentType {
guard : t.getType.getValue == 0 // enum value COMPARTMENT_TYPE
compartmentTypes.add(t);
var children = t.getModel();
if (not (children == null)) {
for(e in children.elements) e.~features=t.~features;
// iterate over all children of the compartment type
for (elem : source!ModelElement in children.elements) {
var e = elem.equivalent();
if (e == null) { continue; }
if (e.instanceOf(target!AbstractRole)) { // ROLE
// create a new part with the role
var part = new target!Part;
part.role = e;
part.whole = n;
// parse the lower and upper bound from the role
var desc = elem.description;
if (not (desc == null) and t.~features.get("Occurrence_Constraints")) {
var card = desc.name;
var cards = parseCardinality(card);
if(cards.size()>0) {
part.lower = cards[0];
if(cards.size()>1) {
part.upper = cards[1];
}
}
}
// add the new part to the compartment
n.getParts().add(part);
} else if (e.instanceOf(target!CompartmentType)) { //COMPARTMENT_TYPE
n.getContains.add(e);
if(not(t.~features.get("Contains_Compartments"))) n.getContains.remove(e);
} else if (e.instanceOf(target!RelationshipImplication) or e.instanceOf(target!RelationshipExclusion)) { // INTER_RELATIONSHIP_CONSTRAINT
for (rst : source!Relation in children.elements){
if (rst.getType.getValue == 7){ // RELATIONSHIP
//Discover source and target Relationships of the inter relationship constraint
if (rst.connectionAnchor == elem.source)
e.first = rst.equivalent();
if (rst.connectionAnchor == elem.target)
e.second = rst.equivalent();
}
}
n.getConstraints().add(e); //add CONSTRAINTS as well
} else if ( e.instanceOf(target!Constraint)) { // CONSTRAINT
n.getConstraints().add(e);
} else if ( e.instanceOf(target!Relationship)) { // RELATIONSHIP
n.getRelationships().add(e);
} else if ( e.instanceOf(target!RoleInheritance)) {
t.~parent.relations.add(e);
}
}
}
n.name = t.name;
}
/**
* Add operations and attributes in the post processing step.
*
* This separation is necessary as the type references in attributes and operations may form cycles between
* types/shapes. The post block ensures that these cycles can be resolved.
*/
post CompartmentType {
for (t : source!Shape in compartmentTypes) {
var n = t.equivalent();
if (not n.isDefined() or not t.isDefined()) {
continue;
}
if(t.~features.get("Compartment_Behavior")) { //feature Compartment_Behavior implies feature Compartment_Properties (not to check)
t.addAttributes(n);
t.addOperations(n);
}
}
}
import "Type.etl";
pre DataType {
var dataTypes : OrderedSet(source!Shape);
}
/**
* Transforms a shape with type DATA_TYPE.
*/
@lazy
rule DataType
transform t : source!Shape
to n : target!DataType {
guard : t.getType.getValue == 3 and t.~features.get("Data_Types") // enum value DATA_TYPE
n.name = t.name;
dataTypes.add(t);
}
/**
* Add operations and attributes in the post processing step.
*
* This separation is necessary as the type references in attributes and operations may form cycles between
* types/shapes. The post block ensures that these cycles can be resolved.
*/
post DataType {
for (t : source!Shape in dataTypes) {
var n = t.equivalent();
if (not n.isDefined() or not t.isDefined()) {
continue;
}
t.addAttributes(n);
t.addOperations(n);
}
}
operation toTransform(t : source!Relation) : Boolean {
//check source of fulfillment and fitting feature
switch(t.source.getType.getValue) {
case 0: if(t.~features.get("Compartments")) {
if(not(t.source==t.target)) return true;
if((t.source==t.target and t.~features.get("Playable_by_Defining_Compartment"))) return true;
}
case 1: return true;
//case 2: if(t.~features.get("Roles")) return true;
case 3: if(t.~features.get("Dates")) return true;
}
return false;
}
@lazy
rule Fulfillment
transform t : source!Relation
to n : Sequence(target!Fulfillment) {
guard : t.getType.getValue == 14 // enum value Fulfillment
if(toTransform(t)){
for(role : source!Shape in t.referencedRoles) {
var fulfillment = new target!Fulfillment;
fulfillment.filler ::= t.source;
fulfillment.filled ::= role;
n.add(fulfillment);
}
}
}
\ No newline at end of file
@lazy
rule Group
transform s : source!Shape
to t : target!Group {
guard : s.getType.value == 13 // GROUP
t.name = s.name;
var children = s.`model`;
if (not (children == null)) {
for(e in children.elements) e.~features=s.~features;
for (elem : source!ModelElement in children.elements) {
var e = elem.equivalent();
if(not(e==null))t.getElements().add(e);
}
}
}
\ No newline at end of file
/**
* Sets the source and target attributes of the inheritance relation and adds the relation to
* the incoming and outgoing relations of its source and target.
*
* It is assumed that source and target reference are valid, i.e., are of the same type and correspond
* to the inheritance. For instance, a NaturalInheritance has source and target elements of type NaturalType.
*/
operation Any transformInheritance(s : source!Relation, t : target!Inheritance) {
var relationSource = s.getSource.equivalent();
var relationTarget = s.getTarget.equivalent();
t.sub = relationSource;
t.super = relationTarget;
relationSource.getOutgoing.add(t);
relationTarget.getIncoming.add(t);
}
/**
* Transforms a relation with type INHERITANCE between two elements of type COMPARTMENT_TYPE.
*/
@lazy
rule CompartmentInheritance
transform s : source!Relation
to t : target!CompartmentInheritance {
guard : s.getType.getValue == 6 //enum value INHERITANCE
and s.getSource.getType.getValue == 0 // COMPARTMENT_TYPE
and s.getTarget.getType.getValue == 0 // COMPARTMENT_TYPE
and s.~features.get("Compartment_Inheritance") // FEATURES
transformInheritance(s, t);
}
/**
* Transforms a relation with type INHERITANCE between two elements of type NATURAL_TYPE.
*/
@lazy
rule NaturalInheritance
transform s : source!Relation
to t : target!NaturalInheritance {
guard : s.getType.getValue == 6 // enum value INHERITANCE
and s.getSource.getType.getValue == 1 // NATURAL_TYPE
and s.getTarget.getType.getValue == 1 // NATURAL_TYPE
transformInheritance(s, t);
}
/**
* Transforms a relation with type INHERITANCE between two elements of type ROLE_TYPE.
*/
@lazy
rule RoleInheritance
transform s : source!Relation
to t : target!RoleInheritance {
guard : s.getType.getValue == 6 // enum value INHERITANCE
and s.getSource.getType.getValue == 2 // ROLE_TYPE
and s.getTarget.getType.getValue == 2 // ROLE_TYPE
and s.~features.get("Role_Inheritance") // FEATURES
transformInheritance(s, t);
}
/**
* Transforms a relation with type INHERITANCE between two elements of type DATA_TYPE.
*/
@lazy
rule DataInheritance
transform s : source!Relation
to t : target!DataInheritance {
guard : s.getType.getValue == 6 // enum value INHERITANCE
and s.getSource.getType.getValue == 3 // DATA_TYPE
and s.getTarget.getType.getValue == 3 // DATA_TYPE
and s.~features.get("Data_Type_Inheritance") //FEATURES
transformInheritance(s, t);
}
\ No newline at end of file
import "Type.etl";
pre NaturalType {
var naturalTypes : OrderedSet(source!Shape);
}
/**
* Transforms a shape with type NATURAL_TYPE.
*/
@lazy
rule NaturalType
transform t : source!Shape
to n : target!NaturalType {
guard : t.getType.getValue == 1
n.name = t.name;
naturalTypes.add(t);
}
/**
* Add operations and attributes in the post processing step.
*
* This separation is necessary as the type references in attributes and operations may form cycles between
* types/shapes. The post block ensures that these cycles can be resolved.
*/
post NaturalType {
for (t : source!Shape in naturalTypes) {
var n = t.equivalent();
if (not n.isDefined() or not t.isDefined()) {
continue;
}
t.addAttributes(n);
t.addOperations(n);
}
}
import "CompartmentType.etl";
import "DataType.etl";
import "NaturalType.etl";
import "RoleType.etl";
import "RoleGroup.etl";
import "Group.etl";
import "RoleConstraints.etl";
import "RelationshipImplication.etl";
import "RelationshipExclusion.etl";
import "Inheritance.etl";
import "Relationship.etl";
import "Fulfillment.etl";
import "AllFeatures.eol";
operation Any println() : Any {
("Printing : " + self)->println();
}
operation Any setFeatureMap() : Map {
for(s : String in getAllFeatures()) self.put(s, false);
}
rule ORM2CROM
transform mym : source!Model
to crom : target!Model {
guard : mym.parent == null
var featureMap : Map;
featureMap.setFeatureMap();
for(f in mym.framedConfiguration.features) {
featureMap.put(f.getName().asString(), true);
}
for(e in mym.elements) {
e.~features=featureMap;
e.~parent=crom;
}
for(shape : source!Shape in mym.elements) {
var x = shape.equivalent();
if(not ((x == null) or x.instanceOf(target!AbstractRole))) {
crom.elements.add(x);
}
}
for (relation : source!Relation in mym.elements) {
var r = relation.equivalent();
if (not (r == null)) {
if(not(r.isKindOf(Sequence))) {
crom.relations.add(r);
} else {
for(ob in r) {
crom.relations.add(ob);
}
}
}
}
}
/**
* Transforms a relation with type INHERITANCE.
*/
operation getPlace(card : String,holder:target!RoleType) : target!Place {
var place = new target!Place;
place.lower = 0;
place.upper = -1;
if(card.isDefined()) {
var cards = parseCardinality(card);
if(cards.size()==1)
place.lower = cards[0];
if(cards.size()>1){
place.lower = cards[0];
place.upper = cards[1];
}
}
if(holder.isDefined()){
place.holder = holder;
}
return place;
}
operation getPlace(card : String,holder:target!RigidType) : target!Place {
fail("Place can only reference role types as placeholders!");
}
@lazy
rule Relationship
transform s : source!Relation
to t : target!Relationship {
guard : s.getType.getValue == 7 and s.~features.get("Relationships") // enum value RELATIONSHIP
t.name = s.name;
if(s.~features.get("Relationship_Cardinality")) { // feature Relationship_Cardinality implies feature Relationship_Constraints (not to check)
//Place should always be defined
var card = "0..*";
if(s.sourceLabel.isDefined()){
card=s.sourceLabel.name;
}
var place = getPlace(card,s.getSource.equivalent());
if(not(place==null)) {
t.setFirst(place);
}
//Place should always be defined
card="0..*";
if(s.targetLabel.isDefined()){
card=s.targetLabel.name;
}
place = getPlace(card,s.getTarget.equivalent());
if(not(place==null)) {
t.setSecond(place);
}
} else {
var place = getPlace("0...*",s.getSource.equivalent());
t.setFirst(place);
place = getPlace("0...*",s.getTarget.equivalent());
t.setSecond(place);
}
//t.first - place from label
//t.second - place from label
s.getSource.equivalent().getOutgoing.add(t);
s.getTarget.equivalent().getIncoming.add(t);
for (r : source!Relation in s.referencedRelation) {
var referenced = r.equivalent();
if(not(referenced == null))referenced.setRelation(t);
}
}
@lazy
rule TotalRelation
transform s : source!Relation
to t : target!Total {
guard : s.getType.getValue == 8 and s.~features.get("Intra_Relationship_Constraints")
}
@lazy
rule CyclicRelation
transform s : source!Relation
to t : target!Cyclic {
guard : s.getType.getValue == 9 and s.~features.get("Intra_Relationship_Constraints")
}
@lazy
rule IrreflexiveRelation
transform s : source!Relation
to t : target!Irreflexive {
guard : s.getType.getValue == 10 and s.~features.get("Intra_Relationship_Constraints")
}
@lazy
rule AcyclicRelation
transform s : source!Relation
to t : target!Acyclic {
guard : s.getType.getValue == 17 and s.~features.get("Intra_Relationship_Constraints")
}
@lazy
rule ReflexiveRelation
transform s : source!Relation
to t : target!Reflexive {
guard : s.getType.getValue == 18 and s.~features.get("Intra_Relationship_Constraints")
}
\ No newline at end of file
@lazy
rule RelationshipExclusion
transform s : source!Relation
to t : target!RelationshipExclusion {
guard : s.getType.getValue == 19 and s.~features.get("Inter_Relationship_Constraints") // enum value RelationshipExclusion
//does not work as RelationshipShapeChild has no ref to the actual Relationship
//t.first ::= s.source;
//t.second ::= s.target;
}
\ No newline at end of file
@lazy
rule RelationshipImplication
transform s : source!Relation
to t : target!RelationshipImplication {
guard : s.getType.getValue == 15 and s.~features.get("Inter_Relationship_Constraints") // enum value RelationshipImplication
//does not work as RelationshipShapeChild has no ref to the actual Relationship
//t.first = s.source.equivalent();
//t.second = s.target.equivalent();
}
\ No newline at end of file
@abstract
@lazy
rule RoleConstraint
transform t : source!Relation
to n : target!RoleConstraint {
n.first ::= t.source;
n.second ::= t.target;
}
// RoleImplication
@lazy
rule RoleImplication
transform t : source!Relation
to n : target!RoleImplication
extends RoleConstraint {
guard : t.getType.getValue == 4 // enum value RoleImplication
and t.~features.get("Role_Implication") //feature
}
// RoleProhibition
@lazy
rule RoleProhibition
transform t : source!Relation
to n : target!RoleProhibition
extends RoleConstraint {
guard : t.getType.getValue == 11 // enum value RoleImplication
and t.~features.get("Role_Prohibition") //feature
}
// RoleEquivalence
@lazy
rule RoleEquivalence
transform t : source!Relation
to n : target!RoleEquivalence
extends RoleConstraint {
guard : t.getType.getValue == 5 // enum value RoleEquivalence
and t.~features.get("Role_Equivalence") //feature
}
\ No newline at end of file
import "CardinalityParser.eol";
@lazy
rule RoleGroup
transform s : source!Shape
to t : target!RoleGroup {
guard : s.getType.value == 12 // ROLEGROUP
t.name = s.name;
if(s.name.indexOf("(")>-1) {
t.name = s.name.substring(0,s.name.indexOf("(")).trim();
}
var desc = s.name;
if (not (desc == null) and s.~features.get("Group_Constraints")) { //feature Group_Constraints implies feature Role_Constraints (not to check)
var cards = parseCardinality(desc);
if(cards.size()>0) {
t.lower = cards[0];
}
if(cards.size()>1) {
t.upper = cards[1];
}
}
var children = s.`model`;
if (not (children == null)) {
for(c in children.elements) c.~features=s.~features;
for (elem : source!ModelElement in children.elements) {
var e = elem.equivalent();
if (e.instanceOf(target!RoleGroupElement)) {
t.getElements().add(e);
} else if(e.instanceOf(target!Relation)) {
var compTypeFound = false;
var compType = s;
while(not(compTypeFound)) {
compType = compType.eContainer();
compTypeFound = not(compType.instanceOf(source!Model)) and compType.getType.getValue == 0;
}
if(e.instanceOf(target!Constraint)) {
compType.equivalent().getConstraints().add(e);
} else {
compType.equivalent().getRelationships().add(e);
}
} else {
// TODO: print warning or throw exception
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment