diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index 16d2bff..0052cb2 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -173,7 +173,7 @@ updateStatements.put(entry.getKey(), entry.getValue()); } - // Declare the fields to refer to other resources in the parent/this component, and the state field in the parent component. + // Declare the fields to refer to other resources for push/pull transfer in the parent/this component, and the state field in the parent component. boolean bDeclareClientField = declareFieldsToReferToOtherResourcesAndStateFieldInParentComponent(resourceNode, component, parentComponent, constructorParams, platformSpec, langSpec); // (#2) Declare the getter method to obtain the resource state in an ancestor resource. (complementary to #1) @@ -696,33 +696,45 @@ String srcResName = getComponentName(srcRes.getResourceHierarchy(), langSpec); FieldDeclaration refFieldForPull = langSpec.newFieldDeclaration(new Type(srcResName, srcResName), langSpec.toVariableName(srcResName)); VariableDeclaration refVarForPull = langSpec.newVariableDeclaration(new Type(srcResName, srcResName), langSpec.toVariableName(srcResName)); - if (component != null) { - // A component is created for this resource. - if (resourceNode.getResourceHierarchy() != srcRes.getResourceHierarchy()) { - component.addField(refFieldForPull); - if (!outsideInputResource) { - Map nameToParam = constructorParams.get(resourceNode.getResourceHierarchy()); - if (nameToParam == null) { - nameToParam = new HashMap<>(); - constructorParams.put(resourceNode.getResourceHierarchy(), nameToParam); - } - if (nameToParam.get(srcResName) == null) { - nameToParam.put(srcResName, refVarForPull); - } - } + if (!platformSpec.isMonolithic() + && (outsideInputResource || (resourceNode.getInSideResource(ch).getCommonPrefix(srcRes) == null && platformSpec.isDifferentTreesAsDifferentServices()))) { + // Inter-service (for REST API) + if (!bDeclareClientField) { + // Declare a client field to connect to the destination resource of push transfer. + platformSpec.addClientFieldDeclaration(parentComponent); + bDeclareClientField = true; } } else { - // No component is created for this resource. - if (resourceNode.getParent().getResourceHierarchy() != srcRes.getResourceHierarchy()) { - parentComponent.addField(refFieldForPull); - if (!outsideInputResource) { - Map nameToParam = constructorParams.get(resourceNode.getParent().getResourceHierarchy()); - if (nameToParam == null) { - nameToParam = new HashMap<>(); - constructorParams.put(resourceNode.getParent().getResourceHierarchy(), nameToParam); + // Monolithic or Inner-service (for REST API) + // Declare a field to directly refer to the source resource of pull transfer. + if (component != null) { + // A component is created for this resource. + if (resourceNode.getResourceHierarchy() != srcRes.getResourceHierarchy()) { + component.addField(refFieldForPull); + if (!outsideInputResource) { + Map nameToParam = constructorParams.get(resourceNode.getResourceHierarchy()); + if (nameToParam == null) { + nameToParam = new HashMap<>(); + constructorParams.put(resourceNode.getResourceHierarchy(), nameToParam); + } + if (nameToParam.get(srcResName) == null) { + nameToParam.put(srcResName, refVarForPull); + } } - if (nameToParam.get(srcResName) == null) { - nameToParam.put(srcResName, refVarForPull); + } + } else { + // No component is created for this resource. + if (resourceNode.getParent().getResourceHierarchy() != srcRes.getResourceHierarchy()) { + parentComponent.addField(refFieldForPull); + if (!outsideInputResource) { + Map nameToParam = constructorParams.get(resourceNode.getParent().getResourceHierarchy()); + if (nameToParam == null) { + nameToParam = new HashMap<>(); + constructorParams.put(resourceNode.getParent().getResourceHierarchy(), nameToParam); + } + if (nameToParam.get(srcResName) == null) { + nameToParam.put(srcResName, refVarForPull); + } } } } @@ -778,13 +790,6 @@ } } } - if (!platformSpec.isMonolithic()) { - if (!bDeclareClientField) { - // Declare a client field to connect to the destination resource of push transfer. - platformSpec.addClientFieldDeclaration(parentComponent); - bDeclareClientField = true; - } - } } } } @@ -1207,7 +1212,7 @@ outsideInputResource = true; // Regarded as (collecting) pull transfer. } if ((((PushPullAttribute) re.getAttribute()).getSelectedOption() == PushPullValue.PUSH && !outsideInputResource) || outsideOutputResource) { - // for push data transfer + // For push data transfer // Declare an update method in the type of the destination resource. ArrayList parameters = new ArrayList<>();