More refactoring for permission writing in Java constructor
[iot2.git] / iotjava / iotpolicy / IoTCompiler.java
index 3fb425ff84d24c94303980a7e3e0ef545b35bb91..8c84a4cbbf0ec8f39fa3302690749443ca721e14 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");
        }