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 class CapabilityDecl extends Declaration {
16 * A "capability" statement:
17 * capability Camera.ImageCapture {
18 * description = "The quick brown fox jumps over the smart dog";
19 * description = "Another description";
23 * In this data structure we will record its capability name, i.e. ImageCapture
24 * and its descriptions and methods.
30 private List<String> listCapabs; // list of capabilities
31 private List<List<String>> listDescs; // list of descriptions
32 private List<List<String>> listMethods; // list of methods
37 public CapabilityDecl() {
40 listCapabs = new ArrayList<String>();
41 listDescs = new ArrayList<List<String>>();
42 listMethods = new ArrayList<List<String>>();
46 public CapabilityDecl(String _origInt) {
49 listCapabs = new ArrayList<String>();
50 listDescs = new ArrayList<List<String>>();
51 listMethods = new ArrayList<List<String>>();
56 * addNewCapability() adds a new capability into the list
58 public void addNewCapability(String newCap) {
60 listCapabs.add(newCap);
61 listDescs.add(new ArrayList<String>());
62 listMethods.add(new ArrayList<String>());
67 * addNewDescription() adds a new description into the list
69 public void addNewDescription(String cap, String newDesc) {
71 int index = listCapabs.indexOf(cap);
72 List<String> listDesc = listDescs.get(index);
73 listDesc.add(newDesc);
78 * addNewMethod() adds a new method into the list
80 public void addNewMethod(String cap, String newMethod) {
82 int index = listCapabs.indexOf(cap);
83 List<String> listMethod = listMethods.get(index);
84 listMethod.add(newMethod);
89 * getCapabilities() gets list of capabilities
91 public List<String> getCapabilities() {
98 * getDescriptions() gets list of descriptions
100 public List<String> getDescriptions(String cap) {
102 int index = listCapabs.indexOf(cap);
103 return listDescs.get(index);
108 * getMethods() gets list of methods
110 public List<String> getMethods(String cap) {
112 int index = listCapabs.indexOf(cap);
113 // If index=-1, it means that it's not found.
114 // There is perhaps a discrepancy in the policy file
115 // between the list of capabilities and requires
118 throw new Error("CapabilityDecl: Capability " + cap +
119 " does not exist in this interface! Please check your (requires) policy file...");
120 return listMethods.get(index);