1 package iotpolicy.tree;
3 import java.util.ArrayList;
6 /** Class CapabilityDecl is a data structure for capability
7 * declaration section (list of capabilities) in the policy file.
9 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
13 public final class CapabilityDecl {
18 private String origInt;
21 * A "capability" statement:
22 * capability Camera.ImageCapture {
23 * description = "The quick brown fox jumps over the smart dog";
24 * description = "Another description";
28 * In this data structure we will record its capability name, i.e. ImageCapture
29 * and its descriptions and methods.
31 private List<String> listCapabs; // list of capabilities
32 private List<List<String>> listDescs; // list of descriptions
33 private List<List<String>> listMethods; // list of methods
38 public CapabilityDecl() {
41 listCapabs = new ArrayList<String>();
42 listDescs = new ArrayList<List<String>>();
43 listMethods = new ArrayList<List<String>>();
47 public CapabilityDecl(String _origInt) {
50 listCapabs = new ArrayList<String>();
51 listDescs = new ArrayList<List<String>>();
52 listMethods = new ArrayList<List<String>>();
57 * addNewCapability() adds a new capability into the list
59 public void addNewCapability(String newCap) {
61 listCapabs.add(newCap);
62 listDescs.add(new ArrayList<String>());
63 listMethods.add(new ArrayList<String>());
68 * addNewDescription() adds a new description into the list
70 public void addNewDescription(String cap, String newDesc) {
72 int index = listCapabs.indexOf(cap);
73 List<String> listDesc = listDescs.get(index);
74 listDesc.add(newDesc);
79 * addNewMethod() adds a new method into the list
81 public void addNewMethod(String cap, String newMethod) {
83 int index = listCapabs.indexOf(cap);
84 List<String> listMethod = listMethods.get(index);
85 listMethod.add(newMethod);
90 * getCapabilities() gets list of capabilities
92 public List<String> getCapabilities() {
99 * getDescriptions() gets list of descriptions
101 public List<String> getDescriptions(String cap) {
103 int index = listCapabs.indexOf(cap);
104 return listDescs.get(index);
109 * getMethods() gets list of methods
111 public List<String> getMethods(String cap) {
113 int index = listCapabs.indexOf(cap);
114 return listMethods.get(index);
118 public static void main(String[] args) {
120 CapabilityDecl cd = new CapabilityDecl("Camera");
121 cd.addNewCapability("ImageCapture");
122 cd.addNewDescription("ImageCapture", "The quick brown fox jumps over the smart dog");
123 cd.addNewDescription("ImageCapture", "ImageCapture capability");
124 cd.addNewMethod("ImageCapture", "MethodA");
125 cd.addNewMethod("ImageCapture", "MethodC");
126 cd.addNewMethod("ImageCapture", "MethodD");
128 cd.addNewCapability("VideoRecording");
129 cd.addNewDescription("VideoRecording", "The quick brown fox jumps over the smart dog");
130 cd.addNewDescription("VideoRecording", "VideoRecording ");
131 cd.addNewMethod("VideoRecording", "MethodE");
132 cd.addNewMethod("VideoRecording", "MethodF");
134 System.out.println("Set of capabilities: " + cd.getCapabilities().toString());
135 System.out.println("Set of descriptions: " + cd.getDescriptions("VideoRecording").toString());
136 System.out.println("Set of methods: " + cd.getMethods("VideoRecording").toString());
137 System.out.println("Set of descriptions: " + cd.getDescriptions("ImageCapture").toString());
138 System.out.println("Set of methods: " + cd.getMethods("ImageCapture").toString());