diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyMethodBodyGenerator.java index 86ee9d9..8eddeb8 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyMethodBodyGenerator.java @@ -98,9 +98,7 @@ param.setName(paramName + "_json"); paramConverter += paramType.getInterfaceTypeName() + " " + paramName + " = new " + paramType.getImplementationTypeName() + "();\n"; paramConverter += "for (String str: " + param.getName() + ") {\n"; - String mapTypeName = compType.getInterfaceTypeName(); - mapTypeName = mapTypeName.replace("Map.Entry", "Map"); - mapTypeName = "Map"; respConverter += srcResourceType.getInterfaceTypeName() + " " + srcResourceName + " = new " + srcResourceType.getImplementationTypeName() + "();\n"; respConverter += "for (" + mapTypeName + " i: " + varName + ") {\n"; @@ -194,13 +188,8 @@ } } else if (DataConstraintModel.typeTuple.isAncestorOf(srcResourceType)) { varName += "_json"; - respConverter += "{\n"; - String mapTypeName = srcResourceType.getInterfaceTypeName(); - mapTypeName = mapTypeName.replace("Map.Entry", "Map"); - mapTypeName = "Map 0) { @@ -252,29 +241,39 @@ return codes; } + private static String convertFromEntryToMapType(Type type) { + String mapTypeName = type.getInterfaceTypeName(); + mapTypeName = mapTypeName.replace("Map.Entry", "Map"); + for (int idx = mapTypeName.indexOf("<", 0); idx >= 0; idx = mapTypeName.indexOf("<", idx + 1)) { + int to = mapTypeName.indexOf(",", idx); + if (to > idx) { + mapTypeName = mapTypeName.substring(0, idx + 1) + "String" + mapTypeName.substring(to); // All elements except for the last one have the string type. + } + } + return mapTypeName; + } + private static String getCodeForConversionFromMapToTuple(Type tupleType, String mapVar) { String decoded = "$x"; List elementsTypes = TypeInference.getTupleComponentTypes(tupleType); String elementBase = mapVar + ".entrySet().iterator().next()"; - if (elementsTypes.get(0) == DataConstraintModel.typeBoolean) { - decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(" + elementBase + ".getKey()), $x)"); - } else if (elementsTypes.get(0) == DataConstraintModel.typeInt) { - decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(Integer.parseInt(" + elementBase + ".getKey()), $x)"); - } else if (elementsTypes.get(0) == DataConstraintModel.typeLong) { - decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(Long.parseLong(" + elementBase + ".getKey()), $x)"); - } else if (elementsTypes.get(0) == DataConstraintModel.typeFloat) { - decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(Float.parseFloat(" + elementBase + ".getKey()), $x)"); - } else if (elementsTypes.get(0) == DataConstraintModel.typeDouble) { - decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(Double.parseDouble(" + elementBase + ".getKey()), $x)"); - } else if (elementsTypes.get(0) == DataConstraintModel.typeString) { - decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(" + elementBase + ", $x)"); - } else { - // Future work. - } - elementBase += ".getValue()"; - for (Type elmType: elementsTypes.subList(1, elementsTypes.size() - 1)) { - decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(" + elementBase + ".getKey(), $x)"); - elementBase += ".getValue()"; + for (Type elmType: elementsTypes.subList(0, elementsTypes.size() - 1)) { + if (elmType == DataConstraintModel.typeBoolean) { + decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(" + elementBase + ".getKey()), $x)"); + } else if (elmType == DataConstraintModel.typeInt) { + decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(Integer.parseInt(" + elementBase + ".getKey()), $x)"); + } else if (elmType == DataConstraintModel.typeLong) { + decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(Long.parseLong(" + elementBase + ".getKey()), $x)"); + } else if (elmType == DataConstraintModel.typeFloat) { + decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(Float.parseFloat(" + elementBase + ".getKey()), $x)"); + } else if (elmType == DataConstraintModel.typeDouble) { + decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(Double.parseDouble(" + elementBase + ".getKey()), $x)"); + } else if (elmType == DataConstraintModel.typeString) { + decoded = decoded.replace("$x", "new AbstractMap.SimpleEntry<>(" + elementBase + ".getKey(), $x)"); + } else { + // To do. + } + elementBase += ".getValue().entrySet().iterator().next()"; } decoded = decoded.replace("$x", elementBase); return decoded;