Refactoring policy writing
authorrtrimana <rtrimana@uci.edu>
Thu, 17 Nov 2016 22:59:08 +0000 (14:59 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 17 Nov 2016 22:59:08 +0000 (14:59 -0800)
iotjava/iotpolicy/IoTCompiler.java

index a43be1d16a4ff875f3f44255a5f327f92e15034a..3fb425ff84d24c94303980a7e3e0ef545b35bb91 100644 (file)
@@ -355,6 +355,35 @@ public class IoTCompiler {
        }
 
 
+       /**
+        * HELPER: writePropertiesJavaPermission() writes the permission in properties
+        */
+       private void writePropertiesJavaPermission(String intface, InterfaceDecl intDecl) {
+
+               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("private final static int object" + newObjectId + "Id = " + 
+                               newObjectId + ";\t//" + newIntface);
+                       Set<String> 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<Integer> 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<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(callbackType);
-                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
-                               String newCallbackIntface = intMeth.getKey();
-                               int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface);
-                               println("private final static int object" + newObjectId + "Id = " + 
-                                       newObjectId + ";\t//" + newCallbackIntface);
-                               Set<String> 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<Integer> 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<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(callbackType);
-                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
-                               String newCallbackIntface = intMeth.getKey();
-                               int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface);
-                               println("private final static int object" + newObjectId + "Id = " + 
-                                       newObjectId + ";\t//" + newCallbackIntface);
-                               Set<String> 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<Integer> 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<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("private final static int object" + newObjectId + "Id = " + 
-                               newObjectId + ";\t//" + newIntface);
-                       Set<String> 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<Integer> 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<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("const static int object" + newObjectId + "Id = " + newObjectId + ";");
+                       println("const static set<int> 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<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(callbackType);
-                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
-                               String newCallbackIntface = intMeth.getKey();
-                               int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface);
-                               println("const static int object" + newObjectId + "Id = " + newObjectId + ";");
-                               println("const static set<int> 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<int> ports;\n");
-                       Map<String,Set<String>> mapNewIntMethods = mapInt2NewInts.get(callbackType);
-                       for (Map.Entry<String,Set<String>> intMeth : mapNewIntMethods.entrySet()) {
-                               String newCallbackIntface = intMeth.getKey();
-                               int newObjectId = mapNewIntfaceObjId.get(newCallbackIntface);
-                               println("const static int object" + newObjectId + "Id = " + newObjectId + ";");
-                               println("const static set<int> 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<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("const static int object" + newObjectId + "Id = " + newObjectId + ";");
-                       println("const static set<int> set" + newObjectId + "Allowed;");
-               }
+               writePropertiesCplusPermission(intface);
                println("\n");
        }