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

RoleRag with AttributeTransfer, Plays, Containment

parent 0a015b7b
No related branches found
No related tags found
No related merge requests found
Showing
with 561 additions and 150 deletions
aspect AttributeGetters { aspect AttributeGetters {
public Attribute Type.getAttributeByName(String name) {
for (Attribute a : getAttributeList()) {
if (a.getName().equals(name)) return a;
}
return null;
}
public Attribute RigidType.getNewestAttribute(String name) {
Attribute match = null;
for (Fulfillment f : roles()) {
Attribute a = f.getFilled().getAttributeByName(name);
if (a != null) match = a;
}
if (roles().isEmpty() || match == null) return getAttributeByName(name);
return match;
}
/*
public String NaturalType.getAttributeByName(String attrString) { public String NaturalType.getAttributeByName(String attrString) {
String result = ""; String result = "";
// first check for Attributes in NaturalType itself // first check for Attributes in NaturalType itself
...@@ -16,5 +34,6 @@ aspect AttributeGetters { ...@@ -16,5 +34,6 @@ aspect AttributeGetters {
return result; return result;
} }
*/
} }
\ No newline at end of file
aspect AttributeTransfer { aspect AttributeTransfer {
syn Attribute RigidType.PhoneNumber() = null;
eq Person.PhoneNumber() = getNewestAttribute("PhoneNumber");
//Attribute a = getNewestAttribute("PhoneNumber");
//return (a != null) ? a.getValue() : "";
/*------------------------------------------------------------------------------------------------------------------
public NaturalType NaturalType.plays(RoleType rt) { public NaturalType NaturalType.plays(RoleType rt) {
// check for Irreflexive // check for Irreflexive
java.util.ArrayList<Relationship> allRelationships = new java.util.ArrayList<Relationship>(); java.util.ArrayList<Relationship> allRelationships = new java.util.ArrayList<Relationship>();
...@@ -15,6 +21,7 @@ aspect AttributeTransfer { ...@@ -15,6 +21,7 @@ aspect AttributeTransfer {
allRelationships.clear(); allRelationships.clear();
} }
// add Fulfillment
Fulfillment ff = new Fulfillment(); Fulfillment ff = new Fulfillment();
ff.setFiller(this); ff.setFiller(this);
ff.setFilled(rt); ff.setFilled(rt);
...@@ -36,8 +43,9 @@ aspect AttributeTransfer { ...@@ -36,8 +43,9 @@ aspect AttributeTransfer {
return this; return this;
} }
*/
/* /*------------------------------------------------------------------------------------------------------------------
public NaturalType NaturalType.plays(RoleType rt) { public NaturalType NaturalType.plays(RoleType rt) {
// check for fulfillment // check for fulfillment
......
aspect CreateCompartmentType {
//public RoleType RoleRag.CreateRoleType() {
//return new RoleType().setWhole();
//}
public Bank RoleRag.CreateBank(String name) {
Bank b = new Bank();
b.setName(name);
addCompartmentType(b);
//c.setWhole(getCompartmentByName("Bank"));
return b; //new Consultant().setWhole(getCompartmentByName("Bank"));
}
}
aspect CreateNaturalType {
//public RoleType RoleRag.CreateRoleType() {
//return new RoleType().setWhole();
//}
public Person RoleRag.CreatePerson(String name) {
Person p = new Person();
p.setName(name);
addNaturalType(p);
//c.setWhole(getCompartmentByName("Bank"));
return p; //new Consultant().setWhole(getCompartmentByName("Bank"));
}
}
aspect CreateRoleType {
//public RoleType RoleRag.CreateRoleType() {
//return new RoleType().setWhole();
//}
public Consultant RoleRag.CreateConsultant(String name) {
Consultant r = new Consultant();
r.setName("Consultant");
addRoleType(r);
//c.setWhole(getCompartmentByName("Bank"));
//resolveCompartmentType("Bank").addParts(r);
/*
//check for existing relationship
Boolean rsExists = false;
//for (Relationship rs : resolveCompartmentType("Bank").rels()) {
for (Relationship rs : resolveCompartmentType("Bank").getRelationshipsList()) {
if (rs.getFirst().getName().equals("Customer")) {
rsExists = true;
rs.setSecond(r);
}
}
// add Relationship
if (!rsExists) {
Relationship rs = new Relationship().setFirst(r);
resolveCompartmentType("Bank").addRelationships(rs);
}
*/
return r; //new Consultant().setWhole(getCompartmentByName("Bank"));
}
public Customer RoleRag.CreateCustomer(String name) {
Customer r = new Customer();
r.setName("Customer");
addRoleType(r);
//c.setWhole(getCompartmentByName("Bank"));
//resolveCompartmentType("Bank").addParts(r);
/*
//check for existing relationship
Boolean rsExists = false;
//for (Relationship rs : resolveCompartmentType("Bank").rels()) {
for (Relationship rs : resolveCompartmentType("Bank").getRelationshipsList()) {
if (rs.getFirst().getName().equals("Consultant")) {
rsExists = true;
rs.setSecond(r);
}
}
// add Relationship
if (!rsExists) {
Relationship rs = new Relationship().setFirst(r);
resolveCompartmentType("Bank").addRelationships(rs);
}
*/
return r; //new Consultant().setWhole(getCompartmentByName("Bank"));
}
}
aspect NameResolution {
syn RoleType RoleRag.resolveRoleType(String name) {
for (RoleType r : getRoleTypeList()) {
if (r.getName().equals(name)) return r;
}
//return null;
throw new RuntimeException("RoleType " + name + " could not be resolved.");
}
syn CompartmentType RoleRag.resolveCompartmentType(String name) {
for (CompartmentType c : getCompartmentTypeList()) {
if (c.getName().equals(name)) return c;
}
//return null;
throw new RuntimeException("CompartmentType " + name + " could not be resolved.");
}
}
aspect Plays {
coll ArrayList<Fulfillment> RigidType.roles()
[new ArrayList<Fulfillment>()] with add;
//PersonConsultantFulfillment contributes this
Fulfillment contributes this
to RigidType.roles()
for getFiller();
public void Person.plays(Consultant r, Bank c) {
new Fulfillment().setFiller(this).setFilled(r);
c.addParts(r);
}
public void Person.plays(Customer r, Bank c) {
new Fulfillment().setFiller(this).setFilled(r);
c.addParts(r);
}
//public void RigidType.plays(RoleType rt) {
//}
public void RigidType.unplays(RoleType rt) {
roles().removeIf(element -> (element.getFilled().equals(rt)));
}
/*------------------------------------------------------------------------------------------------------------------
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();
}
// add Fulfillment
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
// add roletype to roles
this.getRolesList().insertChild(rt, 0);
// transfer attributes
int attributeIndex;
for (Attribute rtAttribute : rt.getAttributeList()) {
attributeIndex = 0;
for (Attribute ntAttribute : this.getAttributeList()) {
if (ntAttribute.getName() == rtAttribute.getName()) {
this.getAttributeList().removeChild(attributeIndex);
break;
}
attributeIndex++;
}
this.getAttributeList().insertChild(rtAttribute, 0);
}
return this;
}
public NaturalType NaturalType.unplays(String rtString) {
// find removeRt and rtIndex
RoleType removeRt = new RoleType();
int removeRtIndex = -1;
int rtCounter = 0;
for (RoleType r : this.getRolesList()) {
if (r.getName() == rtString) {
removeRtIndex = rtCounter;
removeRt = r;
}
rtCounter++;
}
if (removeRtIndex == -1) return null; //rt not found
// remove rt
this.getRolesList().removeChild(removeRtIndex);
// roll back attributes
Attribute newestAttribute;
int attrIndex = 0;
for (Attribute attrRemoveRt : removeRt.getAttributeList()) {
// find newest attribute
newestAttribute = null;
for (RoleType r : this.getRolesList()) {
for (Attribute a : r.getAttributeList()) {
if (a.getName() == attrRemoveRt.getName()) {
newestAttribute = a;
}
}
}
// look for NaturalTypes original Attributes
if (newestAttribute == null) {
for (Attribute originalAttr : this.getOriginalAttributesList()) {
if (originalAttr.getName() == attrRemoveRt.getName()) {
newestAttribute = originalAttr;
}
}
}
// insert newestAttribute into AttributeList
for (Attribute attr : getAttributeList()) {
if (attr.getName() == attrRemoveRt.getName()) {
this.getAttributeList().removeChild(attrIndex);
attrIndex++;
if (newestAttribute != null) {
this.getAttributeList().insertChild(newestAttribute, 0);
}
}
}
}
return this;
}
*/
}
aspect Printing { aspect Printing {
syn String RoleRag.prettyPrint() {
StringBuilder sb = new StringBuilder();
sb.append("\n---RoleRag---\n");
getNaturalTypeList().forEach(n -> sb.append(n.prettyPrint()));
getRoleTypeList().forEach(r -> sb.append(r.prettyPrint()));
getCompartmentTypeList().forEach(c -> sb.append(c.prettyPrint()));
//getFulfillmentList().forEach(f -> sb.append(f.prettyPrint()));
sb.append("-------------\n");
return sb.toString();
}
syn String NamedElement.prettyPrint() = null;
eq TypedElement.prettyPrint() = null;
eq NaturalType.prettyPrint() {
StringBuilder sb = new StringBuilder();
sb.append("NT " + getName());
if (!roles().isEmpty())
sb.append("\n\tPlays ");
for (Fulfillment f : roles()) {
sb.append("\n\t\t" + f.getFilled().getName() + " ");
}
if (getAttributeList().getNumChild() != 0)
sb.append("\n\tAttributes ");
for (Attribute a : getAttributeList()) {
sb.append("\n\t\t" + a.getName() + " " + getNewestAttribute(a.getName()).getValue());
}
sb.append("\n");
return sb.toString();
}
eq RoleType.prettyPrint() {
StringBuilder sb = new StringBuilder();
sb.append("RT " + getName());
if (getAttributeList().getNumChild() != 0)
sb.append("\n\tAttributes ");
for (Attribute a : getAttributeList()) {
sb.append("\n\t\t" + a.getName() + " " + a.getValue());
}
sb.append("\n");
return sb.toString();
}
eq CompartmentType.prettyPrint() {
StringBuilder sb = new StringBuilder();
sb.append("CT " + getName());
if (getPartsList().getNumChild() != 0)
sb.append("\n\tContains ");
for (RoleType r : getPartsList()) {
sb.append("\n\t\t" + r.getName());
}
for (CompartmentType c : getContainsList()) {
sb.append("\n\t\t" + c.getName());
}
if (getAttributeList().getNumChild() != 0)
sb.append("\n\tAttributes ");
for (Attribute a : getAttributeList()) {
sb.append("\n\t\t" + a.getName() + " " + a.getValue());
}
sb.append("\n");
return sb.toString();
}
//syn String Fulfillment.prettyPrint() = getFiller().getName() + " fills " + getFilled().getName() + ";\n";
/** Return a textual representation of the state machine */ /** Return a textual representation of the state machine */
/* /*
syn String StateMachine.prettyPrint() { syn String StateMachine.prettyPrint() {
......
aspect Rel {
/*
coll ArrayList<Relationship> CompartmentType.rels()
[new ArrayList<Relationship>()] with add;
//PersonConsultantFulfillment contributes this
Relationship contributes this
to CompartmentType.rels()
for getFirst();
*/
}
\ No newline at end of file
...@@ -28,21 +28,29 @@ public class BankMain { ...@@ -28,21 +28,29 @@ public class BankMain {
} }
private static void createExample() { private static void createExample() {
Person Peter = new Person(); RoleRag rag = new RoleRag();
Peter.setName("Peter"); //Consultant con2 = rag.CreateConsultant();
Consultant Con = new Consultant(); /*
Con.setName("Con"); Person peter = new Person();
Customer Cu = new Customer(); peter.setName("Peter");
Cu.setName("Cu"); Consultant con = new Consultant();
con.setName("Con");
Customer cu = new Customer();
cu.setName("Cu");
//Fulfillment
//PersonConsultantFulfillment f1 = new PersonConsultantFulfillment();
//f1.setFiller(peter);
//f1.setFilled(con);
// Relationship advices: Consultant advices Customer // Relationship advices: Consultant advices Customer
Relationship advices = new Relationship(); Relationship advices = new Relationship();
advices.setName("advices"); advices.setName("advices");
advices.setFirst(Con); advices.setFirst(con);
advices.setSecond(Cu); advices.setSecond(cu);
Con.addOutgoing(advices); con.addOutgoing(advices);
Cu.addIncoming(advices); cu.addIncoming(advices);
*/
// Irreflexive for advices: Consultant --- Customer // Irreflexive for advices: Consultant --- Customer
//Irreflexive irreflexive = new Irreflexive(); //Irreflexive irreflexive = new Irreflexive();
//irreflexive.setRelation(advices); //irreflexive.setRelation(advices);
...@@ -58,40 +66,72 @@ public class BankMain { ...@@ -58,40 +66,72 @@ public class BankMain {
phoneNumber3.setValue("345"); phoneNumber3.setValue("345");
Attribute addresse2 = new Attribute(); Attribute addresse2 = new Attribute();
addresse2.setName("addresse"); addresse2.setName("Addresse");
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.PNr " + Peter.getAttributeByName("PhoneNumber"));
System.out.println(Peter.dumpTree()); //System.out.println(peter.dumpTree());
Peter.plays(Con); System.out.println("peter.PhoneNumber: " + peter.PhoneNumber().getValue());
System.out.println("Peter plays Con \n");
System.out.println(Peter.getAttributeByName("PhoneNumber")); peter.plays(con);
System.out.println(Peter.dumpTree()); System.out.println("peter.plays(Con)");
//System.out.println("Peter.plays(Con) -> Peter.PNr " + Peter.getAttributeByName("PhoneNumber"));
Peter.plays(Cu); //System.out.println(Peter.dumpTree());
System.out.println("Peter plays Cu \n");
System.out.println(Peter.getAttributeByName("PhoneNumber")); //System.out.println(peter.roles().get(0).dumpTree());
System.out.println(Peter.dumpTree()); //peter.roles().forEach(role -> System.out.println(role.dumpTree()));
System.out.println("peter.PhoneNumber: " + peter.PhoneNumber().getValue());
Peter.unplays("Con");
System.out.println("Peter unplays Con \n"); peter.plays(cu);
System.out.println(Peter.getAttributeByName("PhoneNumber")); System.out.println("peter.plays(Cu)");
System.out.println(Peter.dumpTree()); //System.out.println("Peter.plays(Cu) -> Peter.PNr " + Peter.getAttributeByName("PhoneNumber"));
//System.out.println(Peter.dumpTree());
Peter.unplays("Cu"); System.out.println("peter.PhoneNumber: " + peter.PhoneNumber().getValue());
System.out.println("Peter unplays Cu \n");
System.out.println(Peter.getAttributeByName("PhoneNumber")); peter.unplays(con);
System.out.println(Peter.dumpTree()); System.out.println("peter.unplays(Con)");
//System.out.println("Peter.unplays(Con) -> Peter.PNr " + Peter.getAttributeByName("PhoneNumber"));
//System.out.println(Peter.dumpTree());
//peter.roles().forEach(role -> System.out.println(role.dumpTree()));
System.out.println("peter.PhoneNumber: " + peter.PhoneNumber().getValue());
peter.unplays(cu);
System.out.println("peter.unplays(Cu)");
//System.out.println("Peter.unplays(Cu) -> Peter.PNr " + Peter.getAttributeByName("PhoneNumber"));
//System.out.println(Peter.dumpTree());
System.out.println("peter.PhoneNumber: " + peter.PhoneNumber().getValue());
//Bank b = new Bank();
//rag.addCompartmentType(b);
*/
//System.out.println("new");
Bank b2 = rag.CreateBank("Bank");
Consultant con2 = rag.CreateConsultant("Con2");
Customer cus2 = rag.CreateCustomer("Cus2");
Person peter2 = rag.CreatePerson("Peter2");
peter2.addAttribute(phoneNumber1);
con2.addAttribute(phoneNumber2);
System.out.println(rag.prettyPrint());
//System.out.println("peter2.PhoneNumber: " + peter2.PhoneNumber().getValue());
System.out.println("peter2.plays(con2, b2)");
peter2.plays(con2, b2);
//System.out.println("peter2.PhoneNumber: " + peter2.PhoneNumber().getValue());
System.out.println(rag.prettyPrint());
} }
} }
RoleRag ::= NaturalType* RoleType* Fulfillment*; RoleRag ::= NaturalType* RoleType* CompartmentType* Fulfillment*;
Attribute ::= <Name> <Value>; NamedElement ::= <Name>;
RoleType ::= <Name> Attribute*; TypedElement : NamedElement;
rel TypedElement.Type? -> RigidType;
Type : NamedElement ::= Attribute*;
Attribute : TypedElement ::= <Value>;
RigidType : Type;
RoleType : Type;
rel RoleType.Incoming* -> Relationship; rel RoleType.Incoming* -> Relationship;
rel RoleType.Outgoing* -> Relationship; rel RoleType.Outgoing* -> Relationship;
NaturalType ::= <Name> Attribute*; // OriginalAttributes:Attribute* Roles:RoleType*; NaturalType : RigidType;
rel NaturalType.Fulfillment* -> Fulfillment; CompartmentType : RigidType ::= Parts:RoleType* Contains:CompartmentType* Relationships:Relationship*;
Fulfillment; //rel CompartmentType.Parts* <-> RoleType.Whole;
rel Fulfillment.Filler -> NaturalType; Fulfillment ::= Filler:RigidType Filled:RoleType;
rel Fulfillment.Filled -> RoleType; //rel Fulfillment.Filler <-> NaturalType.Fulfillment*;
Relationship ::= <Name>; //rel Fulfillment.Filled -> RoleType;
rel Relationship.First -> RoleType; Relationship ::= <Name> [First:RoleType] [Second:RoleType];
rel Relationship.Second -> RoleType; //rel Relationship.First -> RoleType;
//rel Relationship.Second -> RoleType;
Irreflexive; Irreflexive;
rel Irreflexive.Relation <-> Relationship.Irreflexive?; rel Irreflexive.Relation <-> Relationship.Irreflexive?;
//----------------------------------------------------------------------------------------------------------------------
Person : NaturalType; Person : NaturalType;
Consultant : RoleType; Consultant : RoleType;
Customer : RoleType; Customer : RoleType;
Bank : CompartmentType;
//rel Bank.Parts* <-> RoleType.Whole;
//PersonFillsConsultant : Fulfillment ::= Filler:Person Filled:Consultant; //PersonConsultantFulfillment : Fulfillment ::= Filler:Person Filled:Consultant;
//PersonFillsConsultant; //PersonConsultantFulfillment : Fulfillment;
//rel PersonFillsConsultant.Filler -> Person; //rel PersonConsultantFulfillment.Filler -> Person;
//rel PersonFillsConsultant.Filled -> Consultant; //rel PersonConsultantFulfillment.Filled -> Consultant;
//PersonFillsCustomer : Fulfillment ::= Filler:Person Filled:Customer; //PersonCustomerFulfillment : Fulfillment ::= Filler:Person Filled:Customer;
//rel PersonCustomerFulfillment.Filler -> Person;
//rel PersonCustomerFulfillment.Filled -> Customer;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment