Skip to content
Snippets Groups Projects
Commit 0a015b7b authored by Ronny Böttger's avatar Ronny Böttger
Browse files

changed how to handle attributes

added Relationships and Irreflexive constraint
parent 95c85652
No related branches found
No related tags found
No related merge requests found
aspect AttributeGetters {
public String NaturalType.getAttributeByName(String attrString) {
String result = "";
// first check for Attributes in NaturalType itself
for (Attribute attr : this.getAttributes()) {
if (attr.getName() == attrString) result = attr.getValue();
}
// then check in Roles
for (Fulfillment f : this.getFulfillments()) {
for (Attribute a : f.getFilled().getAttributes()) {
if (a.getName() == attrString) result = a.getValue();
}
}
return result;
}
}
\ No newline at end of file
aspect AttributeTransfer {
public NaturalType NaturalType.plays(RoleType rt) {
// check for Irreflexive
java.util.ArrayList<Relationship> allRelationships = new java.util.ArrayList<Relationship>();
for (Fulfillment f : this.getFulfillments()) {
allRelationships.addAll(f.getFilled().getIncomings());
allRelationships.addAll(f.getFilled().getOutgoings());
for (Relationship rst : allRelationships) {
if ((rst.getFirst().equals(rt) || rst.getSecond().equals(rt)) && rst.hasIrreflexive()) {
//rst is irreflexive, thatswhy return and dont create a fulfillment
return this;
}
}
allRelationships.clear();
}
Fulfillment ff = new Fulfillment();
ff.setFiller(this);
ff.setFilled(rt);
this.addFulfillment(ff);
return this;
}
public NaturalType NaturalType.unplays(String rtString) {
Fulfillment fToRemove = new Fulfillment();
for (Fulfillment f : this.getFulfillments()) {
if (f.getFilled().getName() == rtString) {
fToRemove = f;
break;
//this.removeFulfillment(f);
}
}
this.removeFulfillment(fToRemove);
return this;
}
/*
public NaturalType NaturalType.plays(RoleType rt) {
// check for fulfillment
......@@ -77,5 +115,5 @@ aspect AttributeTransfer {
return this;
}
*/
}
\ No newline at end of file
......@@ -4,10 +4,7 @@ import beaver.Parser;
//import de.tudresden.inf.st.statemachine.jastadd.model.State;
//import de.tudresden.inf.st.statemachine.jastadd.model.StateMachine;
//import de.tudresden.inf.st.statemachine.jastadd.model.Transition;
import de.tudresden.inf.st.bank.jastadd.model.Attribute;
import de.tudresden.inf.st.bank.jastadd.model.Customer;
import de.tudresden.inf.st.bank.jastadd.model.Person;
import de.tudresden.inf.st.bank.jastadd.model.Consultant;
import de.tudresden.inf.st.bank.jastadd.model.*;
import java.io.IOException;
import java.nio.file.Paths;
......@@ -38,6 +35,18 @@ public class BankMain {
Customer Cu = new Customer();
Cu.setName("Cu");
// Relationship advices: Consultant advices Customer
Relationship advices = new Relationship();
advices.setName("advices");
advices.setFirst(Con);
advices.setSecond(Cu);
Con.addOutgoing(advices);
Cu.addIncoming(advices);
// Irreflexive for advices: Consultant --- Customer
//Irreflexive irreflexive = new Irreflexive();
//irreflexive.setRelation(advices);
Attribute phoneNumber1 = new Attribute();
phoneNumber1.setName("PhoneNumber");
phoneNumber1.setValue("123");
......@@ -53,29 +62,34 @@ public class BankMain {
addresse2.setValue("bcd");
Peter.addAttribute(phoneNumber1);
Peter.addOriginalAttributes(phoneNumber1);
//Peter.addOriginalAttributes(phoneNumber1);
Con.addAttribute(phoneNumber2);
Cu.addAttribute(phoneNumber3);
Con.addAttribute(addresse2);
//output
//System.out.println(Peter.getChild(0).getChild(0).dumpTree());
System.out.println(Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree());
Peter.plays(Con);
System.out.println("Peter plays Con \n");
System.out.println(Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree());
Peter.plays(Cu);
System.out.println("Peter plays Cu \n");
System.out.println(Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree());
Peter.unplays("Con");
System.out.println("Peter unplays Con \n");
System.out.println(Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree());
Peter.unplays("Cu");
System.out.println("Peter unplays Cu \n");
System.out.println(Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree());
}
......
RoleRag ::= NaturalType* RoleType* Fulfillment*;
Attribute ::= <Name> <Value>;
RoleType ::= <Name> Attribute*;
NaturalType ::= <Name> Attribute* OriginalAttributes:Attribute* Roles:RoleType*;
rel RoleType.Incoming* -> Relationship;
rel RoleType.Outgoing* -> Relationship;
NaturalType ::= <Name> Attribute*; // OriginalAttributes:Attribute* Roles:RoleType*;
rel NaturalType.Fulfillment* -> Fulfillment;
Fulfillment;
rel Fulfillment.Filler -> NaturalType;
rel Fulfillment.Filled -> RoleType;
Relationship ::= <Name>;
rel Relationship.First -> RoleType;
rel Relationship.Second -> RoleType;
Irreflexive;
rel Irreflexive.Relation <-> Relationship.Irreflexive?;
Person : NaturalType;
Consultant : RoleType;
Customer : RoleType;
PersonFillsConsultant : Fulfillment ::= Filler:Person Filled:Consultant;
//PersonFillsConsultant : Fulfillment ::= Filler:Person Filled:Consultant;
//PersonFillsConsultant;
//rel PersonFillsConsultant.Filler -> Person;
//rel PersonFillsConsultant.Filled -> Consultant;
PersonFillsCustomer : Fulfillment ::= Filler:Person Filled:Customer;
//PersonFillsCustomer : Fulfillment ::= Filler:Person Filled:Customer;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment