Separating policy file into main policy and generated interfaces; fixing lexer, parse...
[iot2.git] / iotjava / iotpolicy / tree / InterfaceDecl.java
index 27e932615d7c40776e560dd5167e675811b20902..a646e629fe639932ed613f03dfbded6882d46e0f 100644 (file)
@@ -1,7 +1,11 @@
 package iotpolicy.tree;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /** Class InterfaceDecl is a data structure for interface
  *  declaration section in the policy file.
@@ -10,7 +14,7 @@ import java.util.List;
  * @version     1.0
  * @since       2016-09-20
  */
-public final class InterfaceDecl {
+public class InterfaceDecl {
 
        /**
         * Class properties
@@ -30,7 +34,8 @@ public final class InterfaceDecl {
         * In this data structure we will record its interface name, i.e. Camera
         *              its method names and the parameters for each method.
         */
-       private List<String> listMethods;                                       // Method names, e.g. MethodA
+       private List<String> listMethods;                                       // Method signature (no spaces), e.g. MethodA(intA,SpeakerB)
+       private List<String> listMethodIds;                                     // Method identifiers, e.g. MethodA
        private List<String> listMethodTypes;                           // Method types, e.g. void
        private List<List<String>> listMethodParams;            // Method parameter names, e.g. A, B
        private List<List<String>> listMethodParamTypes;        // Method parameter types, e.g. int, int
@@ -42,6 +47,7 @@ public final class InterfaceDecl {
 
                origInt = null;
                listMethods = new ArrayList<String>();
+               listMethodIds = new ArrayList<String>();
                listMethodTypes = new ArrayList<String>();
                listMethodParams = new ArrayList<List<String>>();
                listMethodParamTypes = new ArrayList<List<String>>();
@@ -52,6 +58,7 @@ public final class InterfaceDecl {
 
                origInt = _origInt;
                listMethods = new ArrayList<String>();
+               listMethodIds = new ArrayList<String>();
                listMethodTypes = new ArrayList<String>();
                listMethodParams = new ArrayList<List<String>>();
                listMethodParamTypes = new ArrayList<List<String>>();
@@ -61,9 +68,10 @@ public final class InterfaceDecl {
        /**
         * addNewMethod() adds a new method name and type into the list
         */
-       public void addNewMethod(String newMethod, String newMethodType) {
+       public void addNewMethod(String newMethod, String newMethodId, String newMethodType) {
 
                listMethods.add(newMethod);
+               listMethodIds.add(newMethodId);
                listMethodTypes.add(newMethodType);
                listMethodParams.add(new ArrayList<String>());
                listMethodParamTypes.add(new ArrayList<String>());
@@ -90,8 +98,17 @@ public final class InterfaceDecl {
 
                return listMethods;
        }
-       
-       
+
+
+       /**
+        * getMethodIds() gets method identifiers
+        */
+       public List<String> getMethodIds() {
+
+               return listMethodIds;
+       }
+
+
        /**
         * getMethodTypes() gets method types
         */
@@ -101,6 +118,16 @@ public final class InterfaceDecl {
        }
 
 
+       /**
+        * getMethodId() gets a method identifier
+        */
+       public String getMethodId(String method) {
+
+               int index = listMethods.indexOf(method);
+               return listMethodIds.get(index);
+       }
+
+
        /**
         * getMethodType() gets a method type
         */
@@ -134,9 +161,7 @@ public final class InterfaceDecl {
        public static void main(String[] args) {
 
                InterfaceDecl id = new InterfaceDecl("Camera");
-               id.addNewMethod("MethodA", "void");
-               id.addNewMethod("MethodB", "int");
-               id.addNewMethod("MethodC", "String");
+               id.addNewMethod("MethodA(intA,SpeakerB)", "MethodA", "void");
                id.addMethodParam("MethodA", "A", "int");
                id.addMethodParam("MethodA", "B", "int");
                id.addMethodParam("MethodB", "C", "int");
@@ -144,8 +169,6 @@ public final class InterfaceDecl {
                id.addMethodParam("MethodC", "E", "string");
                id.addMethodParam("MethodC", "F", "int");
 
-
-
                System.out.println("Set of methods: " + id.getMethods().toString());
                System.out.println("Set of params: " + id.getMethodParams("MethodA").toString());
                System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodA").toString());