+
+ /**
+ * A method to extract device/entity information from the user
+ * <p>
+ * 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<iFields; i++) {
+ tpDeviceSpecific[i] = new TableProperty();
+
+ // Looping over the fields
+ strScan = scanFile.next();
+ tpDeviceSpecific[i].setField(strScan);
+ strScan = scanFile.next();
+ tpDeviceSpecific[i].setType(strScan);
+ strScan = scanFile.next();
+ tpDeviceSpecific[i].setLength(strScan);
+ }
+ } else if (strScan.equals("Data")) {
+
+ // Get the device information
+ strFields = new String[2];
+ strFields[0] = strID;
+ strFields[1] = strTypeSpecific;
+
+ if ((tpDeviceSpecific.length == 1) &&
+ (tpDeviceSpecific[0].getField().equals("EMPTY"))) {
+
+ // Get the fields for specific device
+ strFieldsSpecific = null;
+ System.out.println("IoTInstaller: Empty constructor for: " + strTypeSpecific);
+
+ } else {
+
+ // Get the fields for specific device
+ strFieldsSpecific = new String[iFields];
+ for (int i=0; i<iFields; i++) {
+ strScan = scanFile.next();
+ strFieldsSpecific[i] = strScan;
+ }
+ }
+ }
+ }
+
+ installNewEntity(strType, strTypeSpecific, strID, tpDevice,
+ tpDeviceSpecific, strFields, strFieldsSpecific);
+ System.out.println("IoTInstaller: Installing a new entity/device into the system");
+ }