From 18c3d9d884aa82b77b839b6cbf3de0f206653715 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Fri, 30 Sep 2016 15:43:02 -0700 Subject: [PATCH] Cleaning up; Adding new files --- iotjava/iotpolicy/IoTCompiler.java | 15 ---- iotjava/iotpolicy/tree/CapabilityDecl.java | 24 ------ iotjava/iotpolicy/tree/Declaration.java | 31 ++++++++ .../iotpolicy/tree/DeclarationHandler.java | 73 +++++++++++++++++++ iotjava/iotpolicy/tree/InterfaceDecl.java | 21 ------ iotjava/iotpolicy/tree/RequiresDecl.java | 20 ----- 6 files changed, 104 insertions(+), 80 deletions(-) create mode 100644 iotjava/iotpolicy/tree/Declaration.java create mode 100644 iotjava/iotpolicy/tree/DeclarationHandler.java diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index acd0a62..79202c4 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -245,21 +245,6 @@ public class IoTCompiler { } // Map the map of interface-methods to the original interface mapInt2NewInts.put(origInt, mapNewIntMethods); - -/* for (String origint : mapInt2NewInts.keySet()) { - - System.out.println("Original Interface: " + origint); - Map> mapNewInt = mapInt2NewInts.get(origint); - for (String intf : mapNewInt.keySet()) { - - System.out.println("\tNew Interface: " + intf); - Set methods = mapNewInt.get(intf); - for (String meth : methods) { - - System.out.println("\t\tMethod: " + meth); - } - } - }*/ } diff --git a/iotjava/iotpolicy/tree/CapabilityDecl.java b/iotjava/iotpolicy/tree/CapabilityDecl.java index a55f30a..7b2f923 100644 --- a/iotjava/iotpolicy/tree/CapabilityDecl.java +++ b/iotjava/iotpolicy/tree/CapabilityDecl.java @@ -112,28 +112,4 @@ public class CapabilityDecl extends Declaration { int index = listCapabs.indexOf(cap); return listMethods.get(index); } - - - public static void main(String[] args) { - - CapabilityDecl cd = new CapabilityDecl("Camera"); - cd.addNewCapability("ImageCapture"); - cd.addNewDescription("ImageCapture", "The quick brown fox jumps over the smart dog"); - cd.addNewDescription("ImageCapture", "ImageCapture capability"); - cd.addNewMethod("ImageCapture", "MethodA"); - cd.addNewMethod("ImageCapture", "MethodC"); - cd.addNewMethod("ImageCapture", "MethodD"); - - cd.addNewCapability("VideoRecording"); - cd.addNewDescription("VideoRecording", "The quick brown fox jumps over the smart dog"); - cd.addNewDescription("VideoRecording", "VideoRecording "); - cd.addNewMethod("VideoRecording", "MethodE"); - cd.addNewMethod("VideoRecording", "MethodF"); - - System.out.println("Set of capabilities: " + cd.getCapabilities().toString()); - System.out.println("Set of descriptions: " + cd.getDescriptions("VideoRecording").toString()); - System.out.println("Set of methods: " + cd.getMethods("VideoRecording").toString()); - System.out.println("Set of descriptions: " + cd.getDescriptions("ImageCapture").toString()); - System.out.println("Set of methods: " + cd.getMethods("ImageCapture").toString()); - } } diff --git a/iotjava/iotpolicy/tree/Declaration.java b/iotjava/iotpolicy/tree/Declaration.java new file mode 100644 index 0000000..ee2d9c8 --- /dev/null +++ b/iotjava/iotpolicy/tree/Declaration.java @@ -0,0 +1,31 @@ +package iotpolicy.tree; + +/** Abstract class Declaration is a parent class of InterfaceDecl, + * CapabilityDecl, and RequiresDecl + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-09-30 + */ +public abstract class Declaration { + + /** + * Class properties + */ + private String origInt; + + /** + * Class constructors + */ + public Declaration() { + + origInt = null; + } + + + public Declaration(String _origInt) { + + origInt = _origInt; + } +} + diff --git a/iotjava/iotpolicy/tree/DeclarationHandler.java b/iotjava/iotpolicy/tree/DeclarationHandler.java new file mode 100644 index 0000000..0b8089f --- /dev/null +++ b/iotjava/iotpolicy/tree/DeclarationHandler.java @@ -0,0 +1,73 @@ +package iotpolicy.tree; + +import java.util.HashMap; +import java.util.Map; + +/** Abstract class Declaration is a parent class of InterfaceDecl, + * CapabilityDecl, and RequiresDecl + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-09-30 + */ +public class DeclarationHandler { + + /** + * Class properties + */ + private Map mapInt2IntfaceDecl; + private Map mapInt2CapabDecl; + private Map mapInt2ReqDecl; + + /** + * Class constructors + */ + public DeclarationHandler() { + + mapInt2IntfaceDecl = new HashMap(); + mapInt2CapabDecl = new HashMap(); + mapInt2ReqDecl = new HashMap(); + } + + + /** + * Setters/adders + */ + public void addInterfaceDecl(String origInt, Declaration intDecl) { + + mapInt2IntfaceDecl.put(origInt, intDecl); + } + + + public void addCapabilityDecl(String origInt, Declaration capDecl) { + + mapInt2CapabDecl.put(origInt, capDecl); + } + + + public void addRequiresDecl(String origInt, Declaration reqDecl) { + + mapInt2ReqDecl.put(origInt, reqDecl); + } + + + /** + * Getters + */ + public Declaration getInterfaceDecl(String origInt) { + + return mapInt2IntfaceDecl.get(origInt); + } + + + public Declaration getCapabilityDecl(String origInt) { + + return mapInt2CapabDecl.get(origInt); + } + + + public Declaration getRequiresDecl(String origInt) { + + return mapInt2ReqDecl.get(origInt); + } +} diff --git a/iotjava/iotpolicy/tree/InterfaceDecl.java b/iotjava/iotpolicy/tree/InterfaceDecl.java index 15893e3..2cd1d54 100644 --- a/iotjava/iotpolicy/tree/InterfaceDecl.java +++ b/iotjava/iotpolicy/tree/InterfaceDecl.java @@ -183,25 +183,4 @@ public class InterfaceDecl extends Declaration { method + "! Please check your policy file..."); return listMethodParamTypes.get(index); } - - - public static void main(String[] args) { - - InterfaceDecl id = new InterfaceDecl("Camera"); - id.addNewMethod("MethodA(intA,SpeakerB)", "MethodA", "void"); - id.addMethodParam("MethodA", "A", "int"); - id.addMethodParam("MethodA", "B", "int"); - id.addMethodParam("MethodB", "C", "int"); - id.addMethodParam("MethodB", "D", "string"); - id.addMethodParam("MethodC", "E", "string"); - id.addMethodParam("MethodC", "F", "int"); - - System.out.println("Set of methods: " + id.getMethods().toString()); - System.out.println("Set of params: " + id.getMethodParams("MethodA").toString()); - System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodA").toString()); - System.out.println("Set of params: " + id.getMethodParams("MethodB").toString()); - System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodB").toString()); - System.out.println("Set of params: " + id.getMethodParams("MethodC").toString()); - System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodC").toString()); - } } diff --git a/iotjava/iotpolicy/tree/RequiresDecl.java b/iotjava/iotpolicy/tree/RequiresDecl.java index 4170155..b058716 100644 --- a/iotjava/iotpolicy/tree/RequiresDecl.java +++ b/iotjava/iotpolicy/tree/RequiresDecl.java @@ -82,24 +82,4 @@ public class RequiresDecl extends Declaration { return mapRequires.get(intFace); } - - - public static void main(String[] args) { - - RequiresDecl rd = new RequiresDecl("Camera"); - rd.addNewIntface("CameraWithCaptureAndData"); - rd.addNewCapability("CameraWithCaptureAndData", "ImageCapture"); - rd.addNewCapability("CameraWithCaptureAndData", "VideoRecording"); - - System.out.println("Set of interfaces: " + rd.getInterfaces().toString()); - System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString()); - - rd.addNewIntface("CameraWithCaptureAndRecording"); - rd.addNewCapability("CameraWithCaptureAndRecording", "ImageCapture"); - rd.addNewCapability("CameraWithCaptureAndRecording", "BackupData"); - - System.out.println("Set of interfaces: " + rd.getInterfaces().toString()); - System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString()); - System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString()); - } } -- 2.34.1