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 { 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) { public NaturalType NaturalType.plays(RoleType rt) {
// check for fulfillment // check for fulfillment
...@@ -77,5 +115,5 @@ aspect AttributeTransfer { ...@@ -77,5 +115,5 @@ aspect AttributeTransfer {
return this; return this;
} }
*/
} }
\ No newline at end of file
...@@ -4,10 +4,7 @@ import beaver.Parser; ...@@ -4,10 +4,7 @@ import beaver.Parser;
//import de.tudresden.inf.st.statemachine.jastadd.model.State; //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.StateMachine;
//import de.tudresden.inf.st.statemachine.jastadd.model.Transition; //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.*;
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 java.io.IOException; import java.io.IOException;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -38,6 +35,18 @@ public class BankMain { ...@@ -38,6 +35,18 @@ public class BankMain {
Customer Cu = new Customer(); Customer Cu = new Customer();
Cu.setName("Cu"); 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(); Attribute phoneNumber1 = new Attribute();
phoneNumber1.setName("PhoneNumber"); phoneNumber1.setName("PhoneNumber");
phoneNumber1.setValue("123"); phoneNumber1.setValue("123");
...@@ -53,29 +62,34 @@ public class BankMain { ...@@ -53,29 +62,34 @@ public class BankMain {
addresse2.setValue("bcd"); addresse2.setValue("bcd");
Peter.addAttribute(phoneNumber1); Peter.addAttribute(phoneNumber1);
Peter.addOriginalAttributes(phoneNumber1); //Peter.addOriginalAttributes(phoneNumber1);
Con.addAttribute(phoneNumber2); Con.addAttribute(phoneNumber2);
Cu.addAttribute(phoneNumber3); Cu.addAttribute(phoneNumber3);
Con.addAttribute(addresse2); Con.addAttribute(addresse2);
//output //output
//System.out.println(Peter.getChild(0).getChild(0).dumpTree()); //System.out.println(Peter.getChild(0).getChild(0).dumpTree());
System.out.println(Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree()); System.out.println(Peter.dumpTree());
Peter.plays(Con); Peter.plays(Con);
System.out.println("Peter plays Con \n"); System.out.println("Peter plays Con \n");
System.out.println(Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree()); System.out.println(Peter.dumpTree());
Peter.plays(Cu); Peter.plays(Cu);
System.out.println("Peter plays Cu \n"); System.out.println("Peter plays Cu \n");
System.out.println(Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree()); System.out.println(Peter.dumpTree());
Peter.unplays("Con"); Peter.unplays("Con");
System.out.println("Peter unplays Con \n"); System.out.println("Peter unplays Con \n");
System.out.println(Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree()); System.out.println(Peter.dumpTree());
Peter.unplays("Cu"); Peter.unplays("Cu");
System.out.println("Peter unplays Cu \n"); System.out.println("Peter unplays Cu \n");
System.out.println(Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree()); System.out.println(Peter.dumpTree());
} }
......
RoleRag ::= NaturalType* RoleType* Fulfillment*; RoleRag ::= NaturalType* RoleType* Fulfillment*;
Attribute ::= <Name> <Value>; Attribute ::= <Name> <Value>;
RoleType ::= <Name> Attribute*; 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; 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; Person : NaturalType;
Consultant : RoleType; Consultant : RoleType;
Customer : RoleType; Customer : RoleType;
PersonFillsConsultant : Fulfillment ::= Filler:Person Filled:Consultant; //PersonFillsConsultant : Fulfillment ::= Filler:Person Filled:Consultant;
//PersonFillsConsultant; //PersonFillsConsultant;
//rel PersonFillsConsultant.Filler -> Person; //rel PersonFillsConsultant.Filler -> Person;
//rel PersonFillsConsultant.Filled -> Consultant; //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