diff --git a/statemachine.solution/src/main/jastadd/AttributeGetters.jadd b/statemachine.solution/src/main/jastadd/AttributeGetters.jadd new file mode 100644 index 0000000000000000000000000000000000000000..b6b77dada35eaa9e4689fa2d6cfe90f1dd1f8243 --- /dev/null +++ b/statemachine.solution/src/main/jastadd/AttributeGetters.jadd @@ -0,0 +1,20 @@ +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 diff --git a/statemachine.solution/src/main/jastadd/AttributeTransfer.jadd b/statemachine.solution/src/main/jastadd/AttributeTransfer.jadd index c001c5e3752964e21e2c824966d3f4cf12e6c149..bec1311b8df04a1bbb0874c67009621b690819c7 100644 --- a/statemachine.solution/src/main/jastadd/AttributeTransfer.jadd +++ b/statemachine.solution/src/main/jastadd/AttributeTransfer.jadd @@ -1,5 +1,43 @@ 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 diff --git a/statemachine.solution/src/main/java/de/tudresden/inf/st/bank/BankMain.java b/statemachine.solution/src/main/java/de/tudresden/inf/st/bank/BankMain.java index 163537e8ad5bd9240e9042d7164f6c18d5de301a..1d0cd741dbcedcc26488790ae5142762abd8b8d5 100644 --- a/statemachine.solution/src/main/java/de/tudresden/inf/st/bank/BankMain.java +++ b/statemachine.solution/src/main/java/de/tudresden/inf/st/bank/BankMain.java @@ -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()); } diff --git a/statemachine.solution/src/main/resources/Bank.relast b/statemachine.solution/src/main/resources/Bank.relast index c96b21fd79058a29a17ef2a6f82cdd22892232b8..bf49d96f268adef39f547b5a7597c903a620aa04 100644 --- a/statemachine.solution/src/main/resources/Bank.relast +++ b/statemachine.solution/src/main/resources/Bank.relast @@ -1,16 +1,26 @@ 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;