Perfecting parser, lexer, and parse-tree handling for policy files; Generating skelet...
[iot2.git] / iotjava / iotpolicy / tree / RequiresDecl.java
diff --git a/iotjava/iotpolicy/tree/RequiresDecl.java b/iotjava/iotpolicy/tree/RequiresDecl.java
new file mode 100644 (file)
index 0000000..73239e1
--- /dev/null
@@ -0,0 +1,106 @@
+package iotpolicy.tree;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/** Class RequiresDecl is a data structure for "requires"
+ *  declaration section in the policy file.
+ *  This section declares the needed interfaces based on
+ *  different combinations of capabilities.
+ *
+ * @author      Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
+ * @version     1.0
+ * @since       2016-09-20
+ */
+public final class RequiresDecl {
+
+       /**
+        * Class properties
+        */
+       private String origInt;
+
+       /**
+        * A "requires" statement:
+        *              requires Camera with VideoRecording, ImageCapture as interface CameraWithCaptureAndData;
+        *
+        * In this data structure we will record its new interface name, i.e. CameraWithCaptureAndData
+        *              and its required capabilities, i.e. VideoRecording and ImageCapture.
+        */
+       private Map<String,List<String>> mapRequires;
+
+       /**
+        * Class constructors
+        */
+       public RequiresDecl() {
+
+               origInt = null;
+               mapRequires = new HashMap<String,List<String>>();
+       }
+
+
+       public RequiresDecl(String _origInt) {
+
+               origInt = _origInt;
+               mapRequires = new HashMap<String,List<String>>();
+       }
+
+
+       /**
+        * addNewInterface() adds a new interface name into the map
+        */
+       public void addNewIntface(String newInt) {
+
+               mapRequires.put(newInt, new ArrayList<String>());
+       }
+
+
+       /**
+        * addNewCapability() adds a new capability name into the map
+        */
+       public void addNewCapability(String intFace, String newCapab) {
+
+               List<String> listCapab = mapRequires.get(intFace);
+               listCapab.add(newCapab);
+       }
+
+
+       /**
+        * getInterfaces() gets set of interfaces
+        */
+       public Set<String> getInterfaces() {
+
+               return mapRequires.keySet();
+       }
+
+
+       /**
+        * getCapabList() gets list of capabilities
+        */
+       public List<String> getCapabList(String intFace) {
+
+               return mapRequires.get(intFace);
+       }
+
+
+       public static void main(String[] args) {
+
+               RequiresDecl rd = new RequiresDecl("Camera");
+               rd.addNewIntface("CameraWithCaptureAndData");
+               rd.addNewCapability("CameraWithCaptureAndData", "ImageCapture");
+               rd.addNewCapability("CameraWithCaptureAndData", "VideoRecording");
+
+               System.out.println("Set of interfaces: " + rd.getInterfaces().toString());
+               System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
+
+               rd.addNewIntface("CameraWithCaptureAndRecording");
+               rd.addNewCapability("CameraWithCaptureAndRecording", "ImageCapture");
+               rd.addNewCapability("CameraWithCaptureAndRecording", "BackupData");
+
+               System.out.println("Set of interfaces: " + rd.getInterfaces().toString());
+               System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
+               System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
+       }
+}