diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index a9f4355..08739af 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -492,7 +492,7 @@ } finally { graph.getModel().endUpdate(); } -// setTreeLayout(); + setDAGLayout(); bReflectingArchitectureModel = false; return graph; diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java index 00d86f6..871630a 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java @@ -129,8 +129,8 @@ Map resourceComponents = new HashMap<>(); Map resourceConstructors = new HashMap<>(); List> getters = new ArrayList<>(); - List> updates = new ArrayList<>(); - List> inputs = new ArrayList<>(); + Map> updates = new HashMap<>(); + Map> inputs = new HashMap<>(); List> fields = new ArrayList<>(); List> constructorParams = new ArrayList<>(); @@ -561,8 +561,16 @@ } else { // No component is created for this resource. String resourceName = getComponentName(resourceNode.getResourceHierarchy()); - update = new MethodDeclaration("update" + resourceName + "From" + srcResName, false, typeVoid, vars); - updates.add(new AbstractMap.SimpleEntry<>(resourceNode.getParent().getResourceHierarchy(), update)); + String updateMethodName = "update" + resourceName + "From" + srcResName; + Map nameToMethod = updates.get(resourceNode.getParent().getResourceHierarchy()); + if (nameToMethod == null) { + nameToMethod = new HashMap<>(); + updates.put(resourceNode.getParent().getResourceHierarchy(), nameToMethod); + } + if (nameToMethod.get(updateMethodName) == null) { + update = new MethodDeclaration(updateMethodName, false, typeVoid, vars); + nameToMethod.put(updateMethodName, update); + } } } } @@ -689,7 +697,14 @@ component.addMethod(input); } else { // No component is created for this resource. - inputs.add(new AbstractMap.SimpleEntry<>(resourceNode.getParent().getResourceHierarchy(), input)); + Map nameToMethod = inputs.get(resourceNode.getParent().getResourceHierarchy()); + if (nameToMethod == null) { + nameToMethod = new HashMap<>(); + inputs.put(resourceNode.getParent().getResourceHierarchy(), nameToMethod); + } + if (nameToMethod.get(inputMethodName) == null) { + nameToMethod.put(inputMethodName, input); + } } // In the main type. @@ -755,7 +770,14 @@ component.addMethod(input); } else { // No component is created for this resource. - inputs.add(new AbstractMap.SimpleEntry<>(resourceNode.getParent().getResourceHierarchy(), input)); + Map nameToMethod = inputs.get(resourceNode.getParent().getResourceHierarchy()); + if (nameToMethod == null) { + nameToMethod = new HashMap<>(); + inputs.put(resourceNode.getParent().getResourceHierarchy(), nameToMethod); + } + if (nameToMethod.get(inputMethodName) == null) { + nameToMethod.put(inputMethodName, input); + } } // In the main type. @@ -781,13 +803,17 @@ } // Add leaf update methods to the parent components. - for (Map.Entry entry: updates) { - resourceComponents.get(entry.getKey()).addMethod(entry.getValue()); + for (Map.Entry> entry: updates.entrySet()) { + for (MethodDeclaration update: entry.getValue().values()) { + resourceComponents.get(entry.getKey()).addMethod(update); + } } // Add leaf input methods to the parent components. - for (Map.Entry entry: inputs) { - resourceComponents.get(entry.getKey()).addMethod(entry.getValue()); + for (Map.Entry> entry: inputs.entrySet()) { + for (MethodDeclaration input: entry.getValue().values()) { + resourceComponents.get(entry.getKey()).addMethod(input); + } } // Add leaf reference fields to the parent components. diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java index be40bf7..26cb8c8 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java @@ -133,12 +133,12 @@ Map resourceComponents = new HashMap<>(); Map resourceConstructors = new HashMap<>(); List> getters = new ArrayList<>(); - List> updates = new ArrayList<>(); - List> inputs = new ArrayList<>(); + Map> updates = new HashMap<>(); + Map> inputs = new HashMap<>(); List> fields = new ArrayList<>(); Map getterAccessors = new HashMap<>(); Map inputAccessors = new HashMap<>(); - List> constructorParams = new ArrayList<>(); + Map> constructorParams = new HashMap<>(); Map priorMemberForInputChannel = new HashMap<>(); // For each resource node. @@ -180,7 +180,15 @@ // leaf resource. Type fieldType = getImplStateType(res.getResourceHierarchy()); component.addField(new FieldDeclaration(fieldType, "value", getInitializer(res))); - constructorParams.add(new AbstractMap.SimpleEntry<>(resourceNode.getResourceHierarchy(), new VariableDeclaration(fieldType, toVariableName(resourceName)))); + Map nameToParam = constructorParams.get(resourceNode.getResourceHierarchy()); + if (nameToParam == null) { + nameToParam = new HashMap<>(); + constructorParams.put(resourceNode.getResourceHierarchy(), nameToParam); + } + String varName = toVariableName(resourceName); + if (nameToParam.get(varName) == null) { + nameToParam.put(varName, new VariableDeclaration(fieldType, varName)); + } } else { ResourceHierarchy child = children.iterator().next(); if (children.size() == 1 && child.getNumParameters() > 0) { @@ -349,7 +357,17 @@ String resName = getComponentName(res); FieldDeclaration stateField = new FieldDeclaration(res.getResourceStateType(), toVariableName(resName)); fields.add(new AbstractMap.SimpleEntry<>(resourceNode.getParent().getResourceHierarchy(), stateField)); - constructorParams.add(new AbstractMap.SimpleEntry<>(resourceNode.getParent().getResourceHierarchy(), new VariableDeclaration(res.getResourceStateType(), toVariableName(resName)))); + + + Map nameToParam = constructorParams.get(resourceNode.getParent().getResourceHierarchy()); + if (nameToParam == null) { + nameToParam = new HashMap<>(); + constructorParams.put(resourceNode.getParent().getResourceHierarchy(), nameToParam); + } + String varName = toVariableName(resName); + if (nameToParam.get(varName) == null) { + nameToParam.put(varName, new VariableDeclaration(res.getResourceStateType(), varName)); + } } } @@ -573,7 +591,15 @@ component.addMethod(update); } else { // No component is created for this resource. - updates.add(new AbstractMap.SimpleEntry<>(resourceNode.getParent().getResourceHierarchy(), update)); + String updateMethodName = update.getName(); + Map nameToMethod = updates.get(resourceNode.getParent().getResourceHierarchy()); + if (nameToMethod == null) { + nameToMethod = new HashMap<>(); + updates.put(resourceNode.getParent().getResourceHierarchy(), nameToMethod); + } + if (nameToMethod.get(updateMethodName) == null) { + nameToMethod.put(updateMethodName, update); + } } } } @@ -641,7 +667,14 @@ component.addMethod(input); } else { // No component is created for this resource. - inputs.add(new AbstractMap.SimpleEntry<>(resourceNode.getParent().getResourceHierarchy(), input)); + Map nameToMethod = inputs.get(resourceNode.getParent().getResourceHierarchy()); + if (nameToMethod == null) { + nameToMethod = new HashMap<>(); + inputs.put(resourceNode.getParent().getResourceHierarchy(), nameToMethod); + } + if (nameToMethod.get(inputMethodName) == null) { + nameToMethod.put(inputMethodName, input); + } } } @@ -691,7 +724,14 @@ component.addMethod(input); } else { // No component is created for this resource. - inputs.add(new AbstractMap.SimpleEntry<>(cm.getResource().getParent().getResourceHierarchy(), input)); + Map nameToMethod = inputs.get(cm.getResource().getParent().getResourceHierarchy()); + if (nameToMethod == null) { + nameToMethod = new HashMap<>(); + inputs.put(cm.getResource().getParent().getResourceHierarchy(), nameToMethod); + } + if (nameToMethod.get(inputMethodName) == null) { + nameToMethod.put(inputMethodName, input); + } } } @@ -730,13 +770,17 @@ } // Add leaf update methods to the parent components. - for (Map.Entry entry: updates) { - resourceComponents.get(entry.getKey()).addMethod(entry.getValue()); + for (Map.Entry> entry: updates.entrySet()) { + for (MethodDeclaration update: entry.getValue().values()) { + resourceComponents.get(entry.getKey()).addMethod(update); + } } // Add leaf input methods to the parent components. - for (Map.Entry entry: inputs) { - resourceComponents.get(entry.getKey()).addMethod(entry.getValue()); + for (Map.Entry> entry: inputs.entrySet()) { + for (MethodDeclaration input: entry.getValue().values()) { + resourceComponents.get(entry.getKey()).addMethod(input); + } } // Add leaf reference fields to the parent components. @@ -837,14 +881,14 @@ private static List addConstructorParameters(ResourceHierarchy resource, Map resourceComponents, Map resourceConstructors, - List> constructorParams) { + Map> constructorParams) { List params = new ArrayList<>(); for (ResourceHierarchy child: resource.getChildren()) { params.addAll(addConstructorParameters(child, resourceComponents, resourceConstructors, constructorParams)); } - for (Map.Entry paramEnt: constructorParams) { - if (paramEnt.getKey().equals(resource)) { - params.add(paramEnt.getValue()); + if (constructorParams.get(resource) != null) { + for (VariableDeclaration param: constructorParams.get(resource).values()) { + params.add(param); } } if (params.size() > 0) { diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java index efc172a..fd766cc 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java @@ -321,10 +321,6 @@ } } } - String srcResName = null; - if (dst.getIndegree() > 1) { - srcResName = srcResourceName; - } if (!chainedCalls.contains(srcUpdate)) { // The first call to an update method in this method // Value of the source side (input side) resource. @@ -333,7 +329,7 @@ srcUpdate.addStatement(getHttpMethodParamsStatement(srcComponent.getTypeName(), params, true)); srcUpdate.addStatement("String result = " + getHttpMethodCallStatement(baseURL, JerseyCodeGenerator.toVariableName(dstResourceName), - JerseyCodeGenerator.toVariableName(srcResName), + JerseyCodeGenerator.toVariableName(srcResourceName), httpMethod)); chainedCalls.add(srcUpdate); } else { @@ -344,7 +340,7 @@ srcUpdate.addStatement(getHttpMethodParamsStatement(srcComponent.getTypeName(), params, false)); srcUpdate.addStatement("result = " + getHttpMethodCallStatement(baseURL, JerseyCodeGenerator.toVariableName(dstResourceName), - JerseyCodeGenerator.toVariableName(srcResName), + JerseyCodeGenerator.toVariableName(srcResourceName), httpMethod)); } srcUpdate.addThrow("JsonProcessingException"); @@ -371,10 +367,6 @@ params.add(new AbstractMap.SimpleEntry<>(refResourceType, new AbstractMap.SimpleEntry<>(refResourceName, refResourceName))); } } - String srcResName = null; - if (dst.getIndegree() > 1) { - srcResName = srcResourceName; - } if (!chainedCalls.contains(srcInput)) { // First call to an update method in this method // Value of the source side (input side) resource. @@ -383,7 +375,7 @@ srcInput.addStatement(getHttpMethodParamsStatement(srcComponent.getTypeName(), params, true)); srcInput.addStatement("String result = " + getHttpMethodCallStatement(baseURL, JerseyCodeGenerator.toVariableName(dstResourceName), - JerseyCodeGenerator.toVariableName(srcResName), + JerseyCodeGenerator.toVariableName(srcResourceName), httpMethod)); chainedCalls.add(srcInput); } else { @@ -394,7 +386,7 @@ srcInput.addStatement(getHttpMethodParamsStatement(srcComponent.getTypeName(), params, false)); srcInput.addStatement("result = " + getHttpMethodCallStatement(baseURL, JerseyCodeGenerator.toVariableName(dstResourceName), - JerseyCodeGenerator.toVariableName(srcResName), + JerseyCodeGenerator.toVariableName(srcResourceName), httpMethod)); } srcInput.addThrow("JsonProcessingException");