1 package iotpolicy.tree;
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.HashSet;
10 /** Class InterfaceDecl is a data structure for interface
11 * declaration section in the policy file.
13 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
17 public class InterfaceDecl extends Declaration {
20 * A "interface" statement:
21 * public interface Camera {
22 * public void MethodA(int A, int B);
23 * public int MethodB(int C, string D);
24 * public string MethodC(string E, int F);
25 * public float MethodD(int G, float H);
26 * public boolean MethodE(Camera I, boolean J);
27 * public void MethodF();
29 * In this data structure we will record its interface name, i.e. Camera
30 * its method names and the parameters for each method.
36 private List<String> listMethods; // Method signature (no spaces), e.g. MethodA(intA,SpeakerB)
37 private List<String> listMethodIds; // Method identifiers, e.g. MethodA
38 private List<String> listMethodTypes; // Method types, e.g. void
39 private List<List<String>> listMethodParams; // Method parameter names, e.g. A, B
40 private List<List<String>> listMethodParamTypes; // Method parameter types, e.g. int, int
45 public InterfaceDecl() {
48 listMethods = new ArrayList<String>();
49 listMethodIds = new ArrayList<String>();
50 listMethodTypes = new ArrayList<String>();
51 listMethodParams = new ArrayList<List<String>>();
52 listMethodParamTypes = new ArrayList<List<String>>();
56 public InterfaceDecl(String _origInt) {
59 listMethods = new ArrayList<String>();
60 listMethodIds = new ArrayList<String>();
61 listMethodTypes = new ArrayList<String>();
62 listMethodParams = new ArrayList<List<String>>();
63 listMethodParamTypes = new ArrayList<List<String>>();
68 * addNewMethod() adds a new method name and type into the list
70 public void addNewMethod(String newMethod, String newMethodId, String newMethodType) {
72 listMethods.add(newMethod);
73 listMethodIds.add(newMethodId);
74 listMethodTypes.add(newMethodType);
75 listMethodParams.add(new ArrayList<String>());
76 listMethodParamTypes.add(new ArrayList<String>());
81 * addMethodParam() adds the name and type of a parameter
83 public void addMethodParam(String method, String paramName, String paramType) {
85 int index = listMethods.indexOf(method);
86 List<String> listMethodParam = listMethodParams.get(index);
87 listMethodParam.add(paramName);
88 List<String> listMethodParamType = listMethodParamTypes.get(index);
89 listMethodParamType.add(paramType);
94 * getMethods() gets list of methods
96 public List<String> getMethods() {
103 * getMethodNumId() gets Id number for a method
105 public int getMethodNumId(String method) {
107 return listMethods.indexOf(method);
112 * getMethodIds() gets method identifiers
114 public List<String> getMethodIds() {
116 return listMethodIds;
121 * getMethodTypes() gets method types
123 public List<String> getMethodTypes() {
125 return listMethodTypes;
130 * getMethodId() gets a method identifier
132 public String getMethodId(String method) {
134 int index = listMethods.indexOf(method);
135 // If index=-1, it means that it's not found.
136 // There is perhaps a discrepancy in the policy file
137 // between the method signatures in the interface
138 // and capability sections
140 throw new Error("InterfaceDecl: Discrepancies in method signature for " +
141 method + "! Please check your policy file...");
142 return listMethodIds.get(index);
147 * getMethodType() gets a method type
149 public String getMethodType(String method) {
151 int index = listMethods.indexOf(method);
152 // If index=-1, it means that it's not found.
153 // There is perhaps a discrepancy in the policy file
154 // between the method signatures in the interface
155 // and capability sections
157 throw new Error("InterfaceDecl: Discrepancies in method signature for " +
158 method + "! Please check your policy file...");
159 return listMethodTypes.get(index);
164 * getMethodParams() gets list of method parameters for a method
166 public List<String> getMethodParams(String method) {
168 int index = listMethods.indexOf(method);
169 // If index=-1, it means that it's not found.
170 // There is perhaps a discrepancy in the policy file
171 // between the method signatures in the interface
172 // and capability sections
174 throw new Error("InterfaceDecl: Discrepancies in method signature for " +
175 method + "! Please check your policy file...");
176 return listMethodParams.get(index);
181 * getMethodParams() gets list of method parameter types for a method
183 public List<String> getMethodParamTypes(String method) {
185 int index = listMethods.indexOf(method);
186 // If index=-1, it means that it's not found.
187 // There is perhaps a discrepancy in the policy file
188 // between the method signatures in the interface
189 // and capability sections
191 throw new Error("InterfaceDecl: Discrepancies in method signature for " +
192 method + "! Please check your policy file...");
193 return listMethodParamTypes.get(index);