Perfecting parser, lexer, and parse-tree handling for policy files; Generating skelet...
[iot2.git] / iotjava / iotpolicy / tree / RequiresDecl.java
1 package iotpolicy.tree;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7 import java.util.Set;
8
9 /** Class RequiresDecl is a data structure for "requires"
10  *  declaration section in the policy file.
11  *  This section declares the needed interfaces based on
12  *  different combinations of capabilities.
13  *
14  * @author      Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
15  * @version     1.0
16  * @since       2016-09-20
17  */
18 public final class RequiresDecl {
19
20         /**
21          * Class properties
22          */
23         private String origInt;
24
25         /**
26          * A "requires" statement:
27          *              requires Camera with VideoRecording, ImageCapture as interface CameraWithCaptureAndData;
28          *
29          * In this data structure we will record its new interface name, i.e. CameraWithCaptureAndData
30          *              and its required capabilities, i.e. VideoRecording and ImageCapture.
31          */
32         private Map<String,List<String>> mapRequires;
33
34         /**
35          * Class constructors
36          */
37         public RequiresDecl() {
38
39                 origInt = null;
40                 mapRequires = new HashMap<String,List<String>>();
41         }
42
43
44         public RequiresDecl(String _origInt) {
45
46                 origInt = _origInt;
47                 mapRequires = new HashMap<String,List<String>>();
48         }
49
50
51         /**
52          * addNewInterface() adds a new interface name into the map
53          */
54         public void addNewIntface(String newInt) {
55
56                 mapRequires.put(newInt, new ArrayList<String>());
57         }
58
59
60         /**
61          * addNewCapability() adds a new capability name into the map
62          */
63         public void addNewCapability(String intFace, String newCapab) {
64
65                 List<String> listCapab = mapRequires.get(intFace);
66                 listCapab.add(newCapab);
67         }
68
69
70         /**
71          * getInterfaces() gets set of interfaces
72          */
73         public Set<String> getInterfaces() {
74
75                 return mapRequires.keySet();
76         }
77
78
79         /**
80          * getCapabList() gets list of capabilities
81          */
82         public List<String> getCapabList(String intFace) {
83
84                 return mapRequires.get(intFace);
85         }
86
87
88         public static void main(String[] args) {
89
90                 RequiresDecl rd = new RequiresDecl("Camera");
91                 rd.addNewIntface("CameraWithCaptureAndData");
92                 rd.addNewCapability("CameraWithCaptureAndData", "ImageCapture");
93                 rd.addNewCapability("CameraWithCaptureAndData", "VideoRecording");
94
95                 System.out.println("Set of interfaces: " + rd.getInterfaces().toString());
96                 System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
97
98                 rd.addNewIntface("CameraWithCaptureAndRecording");
99                 rd.addNewCapability("CameraWithCaptureAndRecording", "ImageCapture");
100                 rd.addNewCapability("CameraWithCaptureAndRecording", "BackupData");
101
102                 System.out.println("Set of interfaces: " + rd.getInterfaces().toString());
103                 System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
104                 System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
105         }
106 }