diff --git a/models/CustomerManagement.Json b/models/CustomerManagement.Json index eb7377e..aa6b0ce 100644 --- a/models/CustomerManagement.Json +++ b/models/CustomerManagement.Json @@ -1,10 +1,15 @@ { - "relations": [], - "transfer": { - "src": "Companies.{company}", - "dst": "customers.{customer}", - "data": {"type": "String", "name": "address"}, - "style": "PULL", - "multiplicity": "1:*" - } + "name" : "CustomerManagement", + "contexts" : [ + { + "relations": [], + "transfer": { + "src": "Companies.{company}", + "dst": "customers.{customer}", + "data": {"type": "String", "name": "address"}, + "style": "PULL", + "multiplicity": "1:*" + } + } + ] } \ No newline at end of file diff --git a/models/Memento.Json b/models/Memento.Json new file mode 100644 index 0000000..d521a4d --- /dev/null +++ b/models/Memento.Json @@ -0,0 +1,25 @@ +{ + "name" : "Memento", + "contexts" : [ + { + "relations": [], + "transfer": { + "src": "Main.Star", + "dst": "Main.States", + "data": {"type": "Memento", "name": "memento"}, + "style": "PULL", + "multiplicity": "1:1" + } + }, + { + "relations": [], + "transfer": { + "src": "Main.States", + "dst": "Main.Star", + "data": {"type": "Memento", "name": "memento"}, + "style": "PUSH", + "multiplicity": "1:1" + } + } + ] +} \ No newline at end of file diff --git a/src/main/java/models/objectOrientedTransfer/DataTransferDesign.java b/src/main/java/models/objectOrientedTransfer/DataTransferDesign.java index 9d8ccd1..6baa035 100644 --- a/src/main/java/models/objectOrientedTransfer/DataTransferDesign.java +++ b/src/main/java/models/objectOrientedTransfer/DataTransferDesign.java @@ -1,36 +1,50 @@ package models.objectOrientedTransfer; +import parser.*; +import parser.exceptions.ExpectedJsonValue; + import java.util.ArrayList; import java.util.List; import java.util.Stack; /** * The final data transfer designs containing delta algebra and dependency injection. - * + * * @author Nitta - * + * */ public class DataTransferDesign { private List transferContexts; private DeltaComplex deltaComplex; - + public DataTransferDesign(DataTransferContext transferContext) throws IllegalRelationException { this.transferContexts = new ArrayList<>(); this.transferContexts.add(transferContext); this.deltaComplex = createDefaultDeltaComlex(transferContext); } + public DataTransferDesign(JsonValue jsonValue) throws IllegalRelationException { + this.transferContexts = new ArrayList<>(); + for (StringValue keyValue : jsonValue.getJson().keySet()) { + String key = keyValue.getStringValue(); + if (key.equals("contexts")) { + ArrayValue arrayValue = (ArrayValue) jsonValue.getValue(keyValue); + setTransferContexts(arrayValue); + } + } + } + public DeltaComplex createDefaultDeltaComlex(DataTransferContext transferContext) throws IllegalRelationException { if (transferContext.getTransferStyle() == PushPullValue.PUSH) { // PUSH transfer if (transferContext.getTransferMultiplicity() == MultiplicityValue.ManyToOne || transferContext.getTransferMultiplicity() == MultiplicityValue.OneToOne) { // Simple PUSH - + // Construct all deltas. Stack deltaStack = new Stack<>(); ReferenceEdge bottomReference = constructDefaultDeltas(transferContext, deltaStack); - + // Add the data transfer delta. ObjectNode srcObj = (ObjectNode) bottomReference.getSource(); ObjectNode dstObj = (ObjectNode) transferContext.getDataType(); @@ -39,7 +53,7 @@ PrimitivePullPushDelta primDelta = new PrimitivePullPushDelta(dataEdge, bottomReference, dataName); // PUSH data transfer Delta dataTransferDelta = new Delta(primDelta); DeltaComplex deltaComplex = new DeltaComplex(dataTransferDelta); - + // Add initialization deltas. while (!deltaStack.isEmpty()) { deltaComplex.attach(deltaStack.pop()); @@ -56,7 +70,7 @@ // Construct all deltas. Stack deltaStack = new Stack<>(); ReferenceEdge bottomReference = constructDefaultDeltas(transferContext, deltaStack); - + // Add the data transfer delta. ObjectNode srcObj = (ObjectNode) bottomReference.getDestination(); ObjectNode dstObj = (ObjectNode) transferContext.getDataType(); @@ -65,7 +79,7 @@ PrimitivePullDelta primDelta = new PrimitivePullDelta(bottomReference, dataEdge, dataName); // PULL data transfer Delta dataTransferDelta = new Delta(primDelta); DeltaComplex deltaComplex = new DeltaComplex(dataTransferDelta); - + // Add initialization deltas. while (!deltaStack.isEmpty()) { deltaComplex.attach(deltaStack.pop()); @@ -128,7 +142,7 @@ } } } - + // 1) Create container passing deltas. List primitiveDeltaList = new ArrayList<>(); for (ReferenceEdge dstEdge: oneDestination) { @@ -164,13 +178,13 @@ prevReference = new ReferenceEdge(srcObj, dstObj, dataName); } } - - if (!toOne && + + if (!toOne && ((transferStyle == PushPullValue.PUSH && (relation.getMultiplicity() == MultiplicityValue.ManyToOne || relation.getMultiplicity() == MultiplicityValue.OneToOne)) || (transferStyle != PushPullValue.PUSH && (relation.getMultiplicity() == MultiplicityValue.OneToMany || relation.getMultiplicity() == MultiplicityValue.OneToOne)))) { // If the specified multiplicity of destination objects does not match to their potential multiplicity, // then the reference to select one destination object from potential multiple objects is needed. - + // 2) Create a component identifying delta. PrimitiveDelta componentSelectingDelta = null; for (ReferenceEdge dstEdge: manyDestinations) { @@ -201,7 +215,7 @@ prevReference = new ReferenceEdge(srcObj, dstObj, dataName); } } - + // 3) Create a component obtaining delta. if (primitiveDeltaList.size() > 0) { Delta delta = null; @@ -225,6 +239,23 @@ return prevReference; } + private void setTransferContexts(ArrayValue arrayValue) throws IllegalRelationException { + List values = arrayValue.getValues(); + for (int i = 0; i