From: rtrimana Date: Thu, 17 Nov 2016 23:02:33 +0000 (-0800) Subject: More refactoring for permission writing in Java constructor X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=109357614cd72cfa5b9b1280bfbe31c18bba1092;p=iot2.git More refactoring for permission writing in Java constructor --- diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index 3fb425f..8c84a4c 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -414,6 +414,20 @@ public class IoTCompiler { } + /** + * HELPER: writeConstructorJavaPermission() writes the permission in constructor + */ + private void writeConstructorJavaPermission(String intface) { + + Map> mapNewIntMethods = mapInt2NewInts.get(intface); + for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { + String newIntface = intMeth.getKey(); + int newObjectId = mapNewIntfaceObjId.get(newIntface); + println("set" + newObjectId + "Allowed = Arrays.asList(object" + newObjectId +"Permission);"); + } + } + + /** * HELPER: writeConstructorJavaStub() writes the constructor of the stub class */ @@ -426,12 +440,7 @@ public class IoTCompiler { if (callbackExist) { Iterator it = callbackClasses.iterator(); String callbackType = (String) it.next(); - Map> mapNewIntMethods = mapInt2NewInts.get(intface); - for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { - String newIntface = intMeth.getKey(); - int newObjectId = mapNewIntfaceObjId.get(newIntface); - println("set" + newObjectId + "Allowed = Arrays.asList(object" + newObjectId +"Permission);"); - } + writeConstructorJavaPermission(intface); println("listCallbackObj = new ArrayList<" + callbackType + ">();"); println("___initCallBack();"); } @@ -772,12 +781,7 @@ public class IoTCompiler { if (callbackExist) { Iterator it = callbackClasses.iterator(); String callbackType = (String) it.next(); - Map> mapNewIntMethods = mapInt2NewInts.get(intface); - for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { - String newIntface = intMeth.getKey(); - int newObjectId = mapNewIntfaceObjId.get(newIntface); - println("set" + newObjectId + "Allowed = Arrays.asList(object" + newObjectId +"Permission);"); - } + writeConstructorJavaPermission(intface); println("listCallbackObj = new ArrayList<" + callbackType + ">();"); println("___initCallBack();"); println("// TODO: Add address and port initialization here if we want callback in callback!"); @@ -862,12 +866,7 @@ public class IoTCompiler { println("mainObj = _mainObj;"); println("rmiObj = new IoTRMIObject(_port);"); // Generate permission control initialization - Map> mapNewIntMethods = mapInt2NewInts.get(intface); - for (Map.Entry> intMeth : mapNewIntMethods.entrySet()) { - String newIntface = intMeth.getKey(); - int newObjectId = mapNewIntfaceObjId.get(newIntface); - println("set" + newObjectId + "Allowed = Arrays.asList(object" + newObjectId +"Permission);"); - } + writeConstructorJavaPermission(intface); println("___waitRequestInvokeMethod();"); println("}\n"); }