From c842d7df7dcfcad8bc7fc4bc43664163ba120f88 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Thu, 17 Nov 2016 14:59:08 -0800 Subject: [PATCH] Refactoring policy writing --- iotjava/iotpolicy/IoTCompiler.java | 134 +++++++++++------------------ 1 file changed, 49 insertions(+), 85 deletions(-) diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index a43be1d..3fb425f 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -355,6 +355,35 @@ public class IoTCompiler { } + /** + * HELPER: writePropertiesJavaPermission() writes the permission in properties + */ + private void writePropertiesJavaPermission(String intface, InterfaceDecl intDecl) { + + Map> mapNewIntMethods = mapInt2NewInts.get(intface); + for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { + String newIntface = intMeth.getKey(); + int newObjectId = mapNewIntfaceObjId.get(newIntface); + println("private final static int object" + newObjectId + "Id = " + + newObjectId + ";\t//" + newIntface); + Set methodIds = intMeth.getValue(); + print("private static Integer[] object" + newObjectId + "Permission = { "); + int i = 0; + for (String methodId : methodIds) { + int methodNumId = intDecl.getMethodNumId(methodId); + print(Integer.toString(methodNumId)); + // Check if this is the last element (don't print a comma) + if (i != methodIds.size() - 1) { + print(", "); + } + i++; + } + println(" };"); + println("private List set" + newObjectId + "Allowed;"); + } + } + + /** * HELPER: writePropertiesJavaStub() writes the properties of the stub class */ @@ -379,27 +408,7 @@ public class IoTCompiler { // Generate permission stuff for callback stubs DeclarationHandler decHandler = mapIntDeclHand.get(callbackType); InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType); - Map> mapNewIntMethods = mapInt2NewInts.get(callbackType); - for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { - String newCallbackIntface = intMeth.getKey(); - int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface); - println("private final static int object" + newObjectId + "Id = " + - newObjectId + ";\t//" + newCallbackIntface); - Set methodIds = intMeth.getValue(); - print("private static Integer[] object" + newObjectId + "Permission = { "); - int i = 0; - for (String methodId : methodIds) { - int methodNumId = intDecl.getMethodNumId(methodId); - print(Integer.toString(methodNumId)); - // Check if this is the last element (don't print a comma) - if (i != methodIds.size() - 1) { - print(", "); - } - i++; - } - println(" };"); - println("private List set" + newObjectId + "Allowed;"); - } + writePropertiesJavaPermission(callbackType, intDecl); } println("\n"); } @@ -745,27 +754,7 @@ public class IoTCompiler { // Generate permission stuff for callback stubs DeclarationHandler decHandler = mapIntDeclHand.get(callbackType); InterfaceDecl intDecl = (InterfaceDecl) decHandler.getInterfaceDecl(callbackType); - Map> mapNewIntMethods = mapInt2NewInts.get(callbackType); - for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { - String newCallbackIntface = intMeth.getKey(); - int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface); - println("private final static int object" + newObjectId + "Id = " + - newObjectId + ";\t//" + newCallbackIntface); - Set methodIds = intMeth.getValue(); - print("private static Integer[] object" + newObjectId + "Permission = { "); - int i = 0; - for (String methodId : methodIds) { - int methodNumId = intDecl.getMethodNumId(methodId); - print(Integer.toString(methodNumId)); - // Check if this is the last element (don't print a comma) - if (i != methodIds.size() - 1) { - print(", "); - } - i++; - } - println(" };"); - println("private List set" + newObjectId + "Allowed;"); - } + writePropertiesJavaPermission(callbackType, intDecl); } println("\n"); } @@ -859,28 +848,7 @@ public class IoTCompiler { println("private static int objIdCnt = 0;"); println("private IoTRMICall rmiCall;"); } - // Keep track of object Ids of all stubs registered to this interface - Map> mapNewIntMethods = mapInt2NewInts.get(intface); - for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { - String newIntface = intMeth.getKey(); - int newObjectId = mapNewIntfaceObjId.get(newIntface); - println("private final static int object" + newObjectId + "Id = " + - newObjectId + ";\t//" + newIntface); - Set methodIds = intMeth.getValue(); - print("private static Integer[] object" + newObjectId + "Permission = { "); - int i = 0; - for (String methodId : methodIds) { - int methodNumId = intDecl.getMethodNumId(methodId); - print(Integer.toString(methodNumId)); - // Check if this is the last element (don't print a comma) - if (i != methodIds.size() - 1) { - print(", "); - } - i++; - } - println(" };"); - println("private List set" + newObjectId + "Allowed;"); - } + writePropertiesJavaPermission(intface, intDecl); println("\n"); } @@ -1747,6 +1715,20 @@ public class IoTCompiler { } + /** + * HELPER: writePropertiesCplusStub() writes the properties of the stub class + */ + private void writePropertiesCplusPermission(String intface) { + + Map> mapNewIntMethods = mapInt2NewInts.get(intface); + for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { + String newIntface = intMeth.getKey(); + int newObjectId = mapNewIntfaceObjId.get(newIntface); + println("const static int object" + newObjectId + "Id = " + newObjectId + ";"); + println("const static set set" + newObjectId + "Allowed;"); + } + } + /** * HELPER: writePropertiesCplusStub() writes the properties of the stub class */ @@ -1770,13 +1752,7 @@ public class IoTCompiler { println("vector<" + callbackType + "*> vecCallbackObj;"); println("static int objIdCnt;"); // Generate permission stuff for callback stubs - Map> mapNewIntMethods = mapInt2NewInts.get(callbackType); - for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { - String newCallbackIntface = intMeth.getKey(); - int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface); - println("const static int object" + newObjectId + "Id = " + newObjectId + ";"); - println("const static set set" + newObjectId + "Allowed;"); - } + writePropertiesCplusPermission(callbackType); } println("\n"); } @@ -1967,13 +1943,7 @@ public class IoTCompiler { // TODO: Need to initialize address and ports if we want to have callback-in-callback println("string address;"); println("vector ports;\n"); - Map> mapNewIntMethods = mapInt2NewInts.get(callbackType); - for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { - String newCallbackIntface = intMeth.getKey(); - int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface); - println("const static int object" + newObjectId + "Id = " + newObjectId + ";"); - println("const static set set" + newObjectId + "Allowed;"); - } + writePropertiesCplusPermission(callbackType); } println("\n"); } @@ -2067,13 +2037,7 @@ public class IoTCompiler { } println("IoTRMIObject *rmiObj;\n"); // Keep track of object Ids of all stubs registered to this interface - Map> mapNewIntMethods = mapInt2NewInts.get(intface); - for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { - String newIntface = intMeth.getKey(); - int newObjectId = mapNewIntfaceObjId.get(newIntface); - println("const static int object" + newObjectId + "Id = " + newObjectId + ";"); - println("const static set set" + newObjectId + "Allowed;"); - } + writePropertiesCplusPermission(intface); println("\n"); } -- 2.34.1