diff --git a/statemachine.solution/src/main/jastadd/AttributeGetters.jadd b/statemachine.solution/src/main/jastadd/AttributeGetters.jadd index b6b77dada35eaa9e4689fa2d6cfe90f1dd1f8243..e21a7d477845c83277587b2b3ef8b3cb8baa6187 100644 --- a/statemachine.solution/src/main/jastadd/AttributeGetters.jadd +++ b/statemachine.solution/src/main/jastadd/AttributeGetters.jadd @@ -1,5 +1,23 @@ 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) { String result = ""; // first check for Attributes in NaturalType itself @@ -16,5 +34,6 @@ aspect AttributeGetters { 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 bec1311b8df04a1bbb0874c67009621b690819c7..52719f4e97a9be8e8ba85c8c22c2a1b27f75a570 100644 --- a/statemachine.solution/src/main/jastadd/AttributeTransfer.jadd +++ b/statemachine.solution/src/main/jastadd/AttributeTransfer.jadd @@ -1,119 +1,127 @@ 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; + 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) { + // 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(); } - } - allRelationships.clear(); + + // add Fulfillment + Fulfillment ff = new Fulfillment(); + ff.setFiller(this); + ff.setFilled(rt); + this.addFulfillment(ff); + + return this; } - 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); - } + 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; } - 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; + */ + + /*------------------------------------------------------------------------------------------------------------------ + 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++; } - attributeIndex++; + this.getAttributeList().insertChild(rtAttribute, 0); } - this.getAttributeList().insertChild(rtAttribute, 0); + + return this; } - 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; + 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++; } - rtCounter++; - } - if (removeRtIndex == -1) return null; //rt not found + if (removeRtIndex == -1) return null; //rt not found - // remove rt - this.getRolesList().removeChild(removeRtIndex); + // 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; + // 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; + // 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); + // 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; - } - */ + return this; + } + */ } \ No newline at end of file diff --git a/statemachine.solution/src/main/jastadd/CreateCompartmentType.jadd b/statemachine.solution/src/main/jastadd/CreateCompartmentType.jadd new file mode 100644 index 0000000000000000000000000000000000000000..d208b6e2ef9a1ce4e7b5bc05e5a9af527ee32e55 --- /dev/null +++ b/statemachine.solution/src/main/jastadd/CreateCompartmentType.jadd @@ -0,0 +1,15 @@ +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")); + } + +} diff --git a/statemachine.solution/src/main/jastadd/CreateNaturalType.jadd b/statemachine.solution/src/main/jastadd/CreateNaturalType.jadd new file mode 100644 index 0000000000000000000000000000000000000000..c6fe049a499739ac451376adb59fd4fb910483cc --- /dev/null +++ b/statemachine.solution/src/main/jastadd/CreateNaturalType.jadd @@ -0,0 +1,15 @@ +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")); + } + +} diff --git a/statemachine.solution/src/main/jastadd/CreateRoleType.jadd b/statemachine.solution/src/main/jastadd/CreateRoleType.jadd new file mode 100644 index 0000000000000000000000000000000000000000..113e399c81cca984f360efb1248e35e5aa994b57 --- /dev/null +++ b/statemachine.solution/src/main/jastadd/CreateRoleType.jadd @@ -0,0 +1,61 @@ +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")); + } + +} diff --git a/statemachine.solution/src/main/jastadd/NameResolution.jadd b/statemachine.solution/src/main/jastadd/NameResolution.jadd new file mode 100644 index 0000000000000000000000000000000000000000..80ded32ac4495e6839c948ba86a854351bbe085b --- /dev/null +++ b/statemachine.solution/src/main/jastadd/NameResolution.jadd @@ -0,0 +1,19 @@ +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."); + } + +} diff --git a/statemachine.solution/src/main/jastadd/Plays.jadd b/statemachine.solution/src/main/jastadd/Plays.jadd new file mode 100644 index 0000000000000000000000000000000000000000..f10a5064c544995fa8c0fea7e3ff0dd93e029c25 --- /dev/null +++ b/statemachine.solution/src/main/jastadd/Plays.jadd @@ -0,0 +1,150 @@ +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; + } + */ +} diff --git a/statemachine.solution/src/main/jastadd/Printing.jrag b/statemachine.solution/src/main/jastadd/Printing.jrag index c97dcc64b69aef70d8a7b82bf5226ffa912191f2..ac18338d0c76a8d79b413b941e66b316a5de49d3 100644 --- a/statemachine.solution/src/main/jastadd/Printing.jrag +++ b/statemachine.solution/src/main/jastadd/Printing.jrag @@ -1,5 +1,66 @@ 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 */ /* syn String StateMachine.prettyPrint() { diff --git a/statemachine.solution/src/main/jastadd/Rel.jadd b/statemachine.solution/src/main/jastadd/Rel.jadd new file mode 100644 index 0000000000000000000000000000000000000000..342032ba24be55032081165304e39b8186613012 --- /dev/null +++ b/statemachine.solution/src/main/jastadd/Rel.jadd @@ -0,0 +1,11 @@ +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 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 1d0cd741dbcedcc26488790ae5142762abd8b8d5..a285806a0e37559bc644cf62317335902c1f9dc2 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 @@ -28,21 +28,29 @@ public class BankMain { } private static void createExample() { - Person Peter = new Person(); - Peter.setName("Peter"); - Consultant Con = new Consultant(); - Con.setName("Con"); - Customer Cu = new Customer(); - Cu.setName("Cu"); + RoleRag rag = new RoleRag(); + //Consultant con2 = rag.CreateConsultant(); + /* + Person peter = new Person(); + peter.setName("Peter"); + 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 = new Relationship(); advices.setName("advices"); - advices.setFirst(Con); - advices.setSecond(Cu); - Con.addOutgoing(advices); - Cu.addIncoming(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); @@ -58,40 +66,72 @@ public class BankMain { phoneNumber3.setValue("345"); Attribute addresse2 = new Attribute(); - addresse2.setName("addresse"); + addresse2.setName("Addresse"); addresse2.setValue("bcd"); - Peter.addAttribute(phoneNumber1); + /* + peter.addAttribute(phoneNumber1); //Peter.addOriginalAttributes(phoneNumber1); - Con.addAttribute(phoneNumber2); - Cu.addAttribute(phoneNumber3); - Con.addAttribute(addresse2); + 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()); - + //System.out.println("Peter.PNr " + Peter.getAttributeByName("PhoneNumber")); + //System.out.println(peter.dumpTree()); + + System.out.println("peter.PhoneNumber: " + peter.PhoneNumber().getValue()); + + peter.plays(con); + System.out.println("peter.plays(Con)"); + //System.out.println("Peter.plays(Con) -> Peter.PNr " + Peter.getAttributeByName("PhoneNumber")); + //System.out.println(Peter.dumpTree()); + + //System.out.println(peter.roles().get(0).dumpTree()); + //peter.roles().forEach(role -> System.out.println(role.dumpTree())); + System.out.println("peter.PhoneNumber: " + peter.PhoneNumber().getValue()); + + peter.plays(cu); + System.out.println("peter.plays(Cu)"); + //System.out.println("Peter.plays(Cu) -> Peter.PNr " + Peter.getAttributeByName("PhoneNumber")); + //System.out.println(Peter.dumpTree()); + System.out.println("peter.PhoneNumber: " + peter.PhoneNumber().getValue()); + + peter.unplays(con); + 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()); } } diff --git a/statemachine.solution/src/main/resources/Bank.relast b/statemachine.solution/src/main/resources/Bank.relast index bf49d96f268adef39f547b5a7597c903a620aa04..eeba253a2791cdee668ebecaa070ed6df724dc87 100644 --- a/statemachine.solution/src/main/resources/Bank.relast +++ b/statemachine.solution/src/main/resources/Bank.relast @@ -1,26 +1,38 @@ -RoleRag ::= NaturalType* RoleType* Fulfillment*; -Attribute ::= <Name> <Value>; -RoleType ::= <Name> Attribute*; +RoleRag ::= NaturalType* RoleType* CompartmentType* Fulfillment*; +NamedElement ::= <Name>; +TypedElement : NamedElement; +rel TypedElement.Type? -> RigidType; +Type : NamedElement ::= Attribute*; +Attribute : TypedElement ::= <Value>; +RigidType : Type; +RoleType : Type; 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; +NaturalType : RigidType; +CompartmentType : RigidType ::= Parts:RoleType* Contains:CompartmentType* Relationships:Relationship*; +//rel CompartmentType.Parts* <-> RoleType.Whole; +Fulfillment ::= Filler:RigidType Filled:RoleType; +//rel Fulfillment.Filler <-> NaturalType.Fulfillment*; +//rel Fulfillment.Filled -> RoleType; +Relationship ::= <Name> [First:RoleType] [Second:RoleType]; +//rel Relationship.First -> RoleType; +//rel Relationship.Second -> RoleType; Irreflexive; rel Irreflexive.Relation <-> Relationship.Irreflexive?; +//---------------------------------------------------------------------------------------------------------------------- + Person : NaturalType; Consultant : RoleType; Customer : RoleType; +Bank : CompartmentType; +//rel Bank.Parts* <-> RoleType.Whole; -//PersonFillsConsultant : Fulfillment ::= Filler:Person Filled:Consultant; -//PersonFillsConsultant; -//rel PersonFillsConsultant.Filler -> Person; -//rel PersonFillsConsultant.Filled -> Consultant; +//PersonConsultantFulfillment : Fulfillment ::= Filler:Person Filled:Consultant; +//PersonConsultantFulfillment : Fulfillment; +//rel PersonConsultantFulfillment.Filler -> Person; +//rel PersonConsultantFulfillment.Filled -> Consultant; -//PersonFillsCustomer : Fulfillment ::= Filler:Person Filled:Customer; +//PersonCustomerFulfillment : Fulfillment ::= Filler:Person Filled:Customer; +//rel PersonCustomerFulfillment.Filler -> Person; +//rel PersonCustomerFulfillment.Filled -> Customer;