More refactoring for permission writing in Java constructor
authorrtrimana <rtrimana@uci.edu>
Thu, 17 Nov 2016 23:02:33 +0000 (15:02 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 17 Nov 2016 23:02:33 +0000 (15:02 -0800)
iotjava/iotpolicy/IoTCompiler.java

index 3fb425f..8c84a4c 100644 (file)
@@ -414,6 +414,20 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: writeConstructorJavaPermission() writes the permission in constructor
+        */
+       private void writeConstructorJavaPermission(String intface) {
+
+               Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
+               for (Map.Entry<String,Set<String>> 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<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
-                       for (Map.Entry<String,Set<String>> 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<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
-                       for (Map.Entry<String,Set<String>> 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<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(intface);
-               for (Map.Entry<String,Set<String>> 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");
        }