X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=iotjava%2Fiotinstaller%2FIoTInstaller.java;h=e281c9e9ec111a7d2f517708840923e2e56a0570;hb=7e8c0cabb7057ad561adbb8b6cc2a0fd5c41bbf4;hp=4d3dcb6c409f910dc214b115cf5a32d802cd1e33;hpb=7a27eab091d560ca1222d3a2652da56c97456980;p=iot2.git diff --git a/iotjava/iotinstaller/IoTInstaller.java b/iotjava/iotinstaller/IoTInstaller.java index 4d3dcb6..e281c9e 100644 --- a/iotjava/iotinstaller/IoTInstaller.java +++ b/iotjava/iotinstaller/IoTInstaller.java @@ -15,7 +15,7 @@ import java.util.Properties; * @version 1.0 * @since 2015-12-01 */ -public class IoTInstaller { +public final class IoTInstaller { /** * IoTInstaller class properties @@ -41,6 +41,7 @@ public class IoTInstaller { private static final String STR_INSTALL_DEV_ADDRESS_CMD = "-install_dev_add"; private static final String STR_INSTALL_ZB_ADDRESS_CMD = "-install_zb_add"; private static final String STR_INSTALL_HOST_CMD = "-install_host"; + private static final String STR_DELETE_COMMUNICATION_CMD = "-delete_comm"; private static final String STR_DELETE_ENTITY_CMD = "-delete_ent"; private static final String STR_DELETE_ADDRESS_CMD = "-delete_add"; private static final String STR_DELETE_DEV_ADD_CMD = "-delete_dev_add"; @@ -83,6 +84,126 @@ public class IoTInstaller { tbl.insertEntry(strFlds); System.out.println("IoTInstaller: Inserting a new entry into main table"); } + + /** + * A method to extract device/entity information from the user + *
+ * Users are supposed to supply the information needed for installation
+ * This is the core of the operation after getting the Scanner object.
+ *
+ * @param scanFile Scanner object of source
+ * @return void
+ */
+ public void extractTableAndInstallCore(Scanner scanFile) {
+
+ // Parse configuration file
+ // Assumption here is that .config file is written with the correct syntax (need typechecking)
+ // Initialize String for ID and TYPE
+ String strID = "";
+ String strType = "";
+ String strTypeSpecific = "";
+
+ // Initialize TableProperty for devices and specific devices
+ // We have 2 tables,
+ // e.g. ProximitySensor - table of many ProximitySensor devices
+ // ProximitySensorBrandA - table that contains the constructor
+ // information for a specific device
+ TableProperty[] tpDevice = new TableProperty[1];
+ TableProperty[] tpDeviceSpecific = new TableProperty[1];
+
+ // Initialize array of string
+ String[] strFields = new String[1];
+ String[] strFieldsSpecific = new String[1];
+
+ // String for scanning the file
+ String strScan = "";
+
+ // Store number of fields here
+ int iFields = 0;
+ while (scanFile.hasNext()) {
+
+ strScan = scanFile.next();
+ if (strScan.equals("IoTMain")) {
+
+ while (scanFile.hasNext()) {
+ strScan = scanFile.next();
+
+ // Get ID
+ if (strScan.equals("ID")) {
+ strID = scanFile.next();
+ }
+ // Get TYPE
+ else if (strScan.equals("TYPE")) {
+ strType = scanFile.next();
+ }
+ // Get TYPE
+ else if (strScan.equals("TYPESPECIFIC")) {
+ strTypeSpecific = scanFile.next();
+ } else if (strScan.equals("END")) {
+ // Break out of loop
+ break;
+ }
+ }
+ } else if (strScan.equals("Table")) {
+
+ // Get number of fields, e.g. Table 3
+ iFields = scanFile.nextInt();
+
+ // We have device ID and device specific names
+ // e.g. ID = PS1; TYPE
+ tpDevice = new TableProperty[2];
+ tpDevice[0] = new TableProperty();
+ tpDevice[0].setField("ID");
+ tpDevice[0].setType("VARCHAR");
+ tpDevice[0].setLength("5");
+ tpDevice[1] = new TableProperty();
+ tpDevice[1].setField("TYPE");
+ tpDevice[1].setType("VARCHAR");
+ tpDevice[1].setLength("30");
+
+ // Prepare properties for a specific device
+ tpDeviceSpecific = new TableProperty[iFields];
+ for (int i=0; i
@@ -328,77 +438,10 @@ public class IoTInstaller {
try {
// Parse configuration file
- Properties prop = new Properties();
File file = new File(strCfgFileName);
FileInputStream fis = new FileInputStream(file);
- try {
- prop.load(fis);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
System.out.println("IoTInstaller: Extracting information from config file: " + strCfgFileName);
- // Initialize string
- // We can only install one device address per one time with the following sequence
- String[] strFields = new String[2];
- String[] strFieldsAddress = null;
- // Check for wildcard feature
- if ((prop.getProperty("SOURCEWILDCARD", null) != null) &&
- (prop.getProperty("DESTWILDCARD", null) != null)) {
- strFieldsAddress = new String[5];
- strFieldsAddress[3] = prop.getProperty("SOURCEWILDCARD");
- strFieldsAddress[4] = prop.getProperty("DESTWILDCARD");
- } else {
- strFieldsAddress = new String[3];
- }
- strFields[0] = prop.getProperty("ID");
- strFields[1] = prop.getProperty("ADDRESSFOR");
- strFieldsAddress[0] = prop.getProperty("DEVICEADDRESS");
- strFieldsAddress[1] = prop.getProperty("PORTNUMBER");
- strFieldsAddress[2] = prop.getProperty("PROTOCOL");
-
- // Insert this entry into the main device address table
- tbl.setTableName(STR_DEV_ADD_TABLE_NAME);
- tbl.insertEntry(strFields);
-
- // Create a new table for a specific device address
- // e.g. AmcrestCameraAdd + CM1 = AmcrestCameraAddCM1
- tbl.setTableName(strFields[1] + strFields[0]);
-
- // Table does not exist yet
- // Set TableProperty for device address (MAC address)
- TableProperty[] tp = null;
- // Check for wildcard feature
- if (strFieldsAddress.length == 5) {
- tp = new TableProperty[5];
- tp[3] = new TableProperty();
- tp[3].setField("SOURCEWILDCARD");
- tp[3].setType("VARCHAR");
- tp[3].setLength("5");
- tp[4] = new TableProperty();
- tp[4].setField("DESTWILDCARD");
- tp[4].setType("VARCHAR");
- tp[4].setLength("5");
- } else {
- tp = new TableProperty[3];
- }
- tp[0] = new TableProperty();
- tp[0].setField("DEVICEADDRESS");
- tp[0].setType("VARCHAR");
- tp[0].setLength("20");
- tp[1] = new TableProperty();
- tp[1].setField("PORTNUMBER");
- tp[1].setType("INT");
- tp[1].setLength("11");
- tp[2] = new TableProperty();
- tp[2].setField("PROTOCOL");
- tp[2].setType("VARCHAR");
- tp[2].setLength("5");
- tbl.createTable(tp, "DEVICEADDRESS");
-
- // Insert new address entry
- tbl.insertEntry(strFieldsAddress);
-
- System.out.println("IoTInstaller: Installing a new device/entity address into the system");
+ installDeviceAddressCore(fis);
} catch (FileNotFoundException ex) {
@@ -457,7 +500,6 @@ public class IoTInstaller {
// Insert new address entry
tbl.insertEntry(strFieldsAddress);
-
System.out.println("IoTInstaller: Installing a new device/entity address into the system");
} catch (FileNotFoundException ex) {
@@ -468,7 +510,6 @@ public class IoTInstaller {
}
}
-
/**
* A method to extract simple addresses information, e.g. www.google.com
*
@@ -518,7 +559,6 @@ public class IoTInstaller {
// Insert new address entry
tbl.insertEntry(strFieldsAddress);
-
System.out.println("IoTInstaller: Installing a new device/entity address into the system");
} catch (FileNotFoundException ex) {
@@ -557,7 +597,6 @@ public class IoTInstaller {
// Create a new installer object
tbl.setTableName(STR_HOST_TABLE_NAME);
tbl.insertEntry(strFields);
-
System.out.println("IoTInstaller: Installing a new host into the system");
} catch (FileNotFoundException ex) {
@@ -579,7 +618,6 @@ public class IoTInstaller {
tbl.setTableName(STR_HOST_TABLE_NAME);
String strWhere = "HOSTADDRESS='" + strHostAddress + "';";
tbl.deleteEntry(strWhere);
-
System.out.println("IoTInstaller: Deleting a host from the system");
}
@@ -598,7 +636,6 @@ public class IoTInstaller {
String strWhere = "ID='" + strEntID + "';";
tbl.deleteEntry(strWhere);
System.out.println("IoTInstaller: Removing entity from table " + STR_MAIN_TABLE_NAME);
-
// Delete from table with type name, e.g. Camera
tbl.setTableName(strEntType);
strWhere = "ID='" + strEntID + "';";
@@ -638,7 +675,6 @@ public class IoTInstaller {
tbl.setTableName(strEntAddType + strEntID);
tbl.dropTable();
System.out.println("IoTInstaller: Dropping class constructor table...");
-
System.out.println("IoTInstaller: Deleting an entry from the system...");
}
@@ -666,7 +702,7 @@ public class IoTInstaller {
*
* @return void
*/
- private void helpMessages() {
+ public void helpMessages() {
System.out.println();
System.out.println("IoTInstaller: Command line options:");
System.out.println("IoTInstaller: 1) Install one device, e.g. java iotinstaller.IoTInstaller -install_ent