Fixing program structure; now accepting multiple policy files; cross-checking referen...
[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 class RequiresDecl extends Declaration {
19
20         /**
21          * A "requires" statement:
22          *              requires Camera with VideoRecording, ImageCapture as interface CameraWithCaptureAndData;
23          *
24          * In this data structure we will record its new interface name, i.e. CameraWithCaptureAndData
25          *              and its required capabilities, i.e. VideoRecording and ImageCapture.
26          */
27
28         /**
29          * Class properties
30          */
31         private Map<String,List<String>> mapRequires;
32
33         /**
34          * Class constructors
35          */
36         public RequiresDecl() {
37
38                 super();
39                 mapRequires = new HashMap<String,List<String>>();
40         }
41
42
43         public RequiresDecl(String _origInt) {
44
45                 super(_origInt);
46                 mapRequires = new HashMap<String,List<String>>();
47         }
48
49
50         /**
51          * addNewInterface() adds a new interface name into the map
52          */
53         public void addNewIntface(String newInt) {
54
55                 mapRequires.put(newInt, new ArrayList<String>());
56         }
57
58
59         /**
60          * addNewCapability() adds a new capability name into the map
61          */
62         public void addNewCapability(String intFace, String newCapab) {
63
64                 List<String> listCapab = mapRequires.get(intFace);
65                 listCapab.add(newCapab);
66         }
67
68
69         /**
70          * getInterfaces() gets set of interfaces
71          */
72         public Set<String> getInterfaces() {
73
74                 return mapRequires.keySet();
75         }
76
77
78         /**
79          * getCapabList() gets list of capabilities
80          */
81         public List<String> getCapabList(String intFace) {
82
83                 return mapRequires.get(intFace);
84         }
85
86
87         public static void main(String[] args) {
88
89                 RequiresDecl rd = new RequiresDecl("Camera");
90                 rd.addNewIntface("CameraWithCaptureAndData");
91                 rd.addNewCapability("CameraWithCaptureAndData", "ImageCapture");
92                 rd.addNewCapability("CameraWithCaptureAndData", "VideoRecording");
93
94                 System.out.println("Set of interfaces: " + rd.getInterfaces().toString());
95                 System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
96
97                 rd.addNewIntface("CameraWithCaptureAndRecording");
98                 rd.addNewCapability("CameraWithCaptureAndRecording", "ImageCapture");
99                 rd.addNewCapability("CameraWithCaptureAndRecording", "BackupData");
100
101                 System.out.println("Set of interfaces: " + rd.getInterfaces().toString());
102                 System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
103                 System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
104         }
105 }