Interleaving events.
[smartthings-infrastructure.git] / Extractor / Extractor.groovy
1 ////////////////////////////////////////
2 //import libraries
3 import groovy.transform.Field
4
5
6 //import classes
7 //Importing Classes
8 import ContactSensor.ContactSensor
9 import ContactSensor.ContactSensors
10 import DoorControl.DoorControl
11 import DoorControl.DoorControls
12 import Lock.Lock
13 import Lock.Locks
14 import Thermostat.Thermostat
15 import Thermostat.Thermostats
16 import Switch.Switch
17 import Switch.Switches
18 import PresenceSensor.PresenceSensor
19 import PresenceSensor.PresenceSensors
20 import Logger.Logger
21 import Location.LocationVar
22 import Location.Phrase
23 import appTouch.Touched
24 import NfcTouch.NfcTouch
25 import AeonKeyFob.AeonKeyFob
26 import AeonKeyFob.AeonKeyFobs
27 import MusicPlayer.MusicPlayer
28 import MusicPlayer.MusicPlayers
29 import MotionSensor.MotionSensor
30 import MotionSensor.MotionSensors
31 import ImageCapture.ImageCapture
32 import ImageCapture.ImageCaptures
33 import SmokeDetector.SmokeDetector
34 import SmokeDetector.SmokeDetectors
35 import Alarm.Alarm
36 import Alarm.Alarms
37 import SpeechSynthesis.SpeechSynthesis
38 import SpeechSynthesis.SpeechSynthesises
39 import AccelerationSensor.AccelerationSensor
40 import AccelerationSensor.AccelerationSensors
41 import Battery.Battery
42 import Battery.Batteries
43 import BeaconSensor.BeaconSensor
44 import BeaconSensor.BeaconSensors
45 import CarbonMonoxideDetector.CarbonMonoxideDetector
46 import CarbonMonoxideDetector.CarbonMonoxideDetectors
47 import ColorControl.ColorControl
48 import ColorControl.ColorControls
49 import EnergyMeter.EnergyMeter
50 import EnergyMeter.EnergyMeters
51 import IlluminanceMeasurement.IlluminanceMeasurement
52 import IlluminanceMeasurement.IlluminanceMeasurements
53 import PowerMeter.PowerMeter
54 import PowerMeter.PowerMeters
55 import RelativeHumidityMeasurement.RelativeHumidityMeasurement
56 import RelativeHumidityMeasurement.RelativeHumidityMeasurements
57 import RelaySwitch.RelaySwitch
58 import RelaySwitch.RelaySwitches
59 import SleepSensor.SleepSensor
60 import SleepSensor.SleepSensors
61 import StepSensor.StepSensor
62 import StepSensor.StepSensors
63 import SwitchLevel.SwitchLevel
64 import SwitchLevel.SwitchLevels
65 import TemperatureMeasurement.TemperatureMeasurement
66 import TemperatureMeasurement.TemperatureMeasurements
67 import WaterSensor.WaterSensor
68 import WaterSensor.WaterSensors
69 import Valve.Valve
70 import Valve.Valves
71 import MobilePresence.MobilePresence
72 import MobilePresence.MobilePresences
73 import Timer.SimulatedTimer
74
75 //GlobalVariables
76 @Field def location = new LocationVar()
77 //Settings variable defined to settings on purpose
78 @Field def settings = [app: "app"]
79 //Global variable for state[mode]
80 @Field def state = [home:[],away:[],night:[]]
81 //Create a global logger object for methods
82 @Field def log = new Logger()
83 //Create a global variable for optional property
84 @Field def optional = false //by default for now
85 //Global Object for class AtomicState!
86 @Field def atomicState = [history: "15:00"]
87
88
89 //Global variables for files
90 @Field File globalObjects = new File("Extractor/globalObjects.groovy")
91 @Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy")
92 @Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy")
93 @Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy")
94 @Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy")
95
96
97 //Empty the files
98 if (App == "App1") {
99         globalObjects.write("")
100         extractedObjectsApp1.write("")
101         extractedObjectsConstructorApp1.write("")
102 } else if (App == "App2") {
103         extractedObjectsApp2.write("")
104         extractedObjectsConstructorApp2.write("")
105 }
106
107
108
109 //Some of methods-May be needed even in install
110 /////////////////////////////////////////////////////////////////////
111 def timeToday(String time, Object timeZone) {
112         def timeOfDay = new Date()
113         def _inputTime = time.split(':')
114         def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60+1564191100415
115         timeOfDay.time = inputTime
116         return timeOfDay
117 }
118
119
120
121 //Global objects
122 //Global Object for class Touch Sensor!
123 @Field touchSensorObjects = 0
124 @Field def touchSensorObject0
125 @Field def touchSensorObject1
126 @Field def touchSensorObject2
127 //Global Object for class switch!
128 @Field switchObjects = 0
129 @Field def switchObject0
130 @Field def switchObject1
131 @Field def switchObject2
132 //Global Object for class lock!
133 @Field lockObjects = 0
134 @Field def lockObject0
135 @Field def lockObject1
136 @Field def lockObject2
137 //Global Object for class door control!
138 @Field doorControlObjects = 0
139 @Field def doorControlObject0
140 @Field def doorControlObject1
141 @Field def doorControlObject2
142 //Global Object for class contact sensor!
143 @Field contactObjects = 0
144 @Field def contactObject0
145 @Field def contactObject1
146 @Field def contactObject2
147 //Global Object for class presence sensor!
148 @Field presenceSensorObjects = 0
149 @Field def presenceSensorObject0
150 @Field def presenceSensorObject1
151 @Field def presenceSensorObject2
152 //Global Object for class thermostat!
153 @Field thermostatObjects = 0
154 @Field def thermostatObject0
155 @Field def thermostatObject1
156 @Field def thermostatObject2
157 //Global Object for class music player!
158 @Field musicPlayerObjects = 0
159 @Field def musicPlayerObject0
160 @Field def musicPlayerObject1
161 @Field def musicPlayerObject2
162 //Global Object for class aeon key fob!
163 @Field aeonKeyFobObjects = 0
164 @Field def aeonKeyFobObject0
165 @Field def aeonKeyFobObject1
166 @Field def aeonKeyFobObject2
167 //Global Object for class motion sensor!
168 @Field motionSensorObjects = 0
169 @Field def motionSensorObject0
170 @Field def motionSensorObject1
171 @Field def motionSensorObject2
172 //Global Object for class image capture!
173 @Field imageCaptureObjects = 0
174 @Field def imageCaptureObject0
175 @Field def imageCaptureObject1
176 @Field def imageCaptureObject2
177 //Global Object for class smoke detector!
178 @Field smokeDetectorObjects = 0
179 @Field def smokeDetectorObject0
180 @Field def smokeDetectorObject1
181 @Field def smokeDetectorObject2
182 //Global Object for class alarm!
183 @Field alarmObjects = 0
184 @Field def alarmObject0
185 @Field def alarmObject1
186 @Field def alarmObject2
187 //Global Object for class speech synthesis!
188 @Field speechSynthesisObjects = 0
189 @Field def speechSynthesisObject0
190 @Field def speechSynthesisObject1
191 @Field def speechSynthesisObject2
192 //Global Object for class acceleration sensor!
193 @Field accelerationSensorObjects = 0
194 @Field def accelerationSensorObject0
195 @Field def accelerationSensorObject1
196 @Field def accelerationSensorObject2
197 //Global Object for class battery!
198 @Field batteryObjects = 0
199 @Field def batteryObject0
200 @Field def batteryObject1
201 @Field def batteryObject2
202 //Global Object for class beacon sensor!
203 @Field beaconSensorObjects = 0
204 @Field def beaconSensorObject0
205 @Field def beaconSensorObject1
206 @Field def beaconSensorObject2
207 //Global Object for class carbon monoxide detector!
208 @Field carbonMonoxideDetectorObjects = 0
209 @Field def carbonMonoxideDetectorObject0
210 @Field def carbonMonoxideDetectorObject1
211 @Field def carbonMonoxideDetectorObject2
212 //Global Object for class color control!
213 @Field colorControlObjects = 0
214 @Field def colorControlObject0
215 @Field def colorControlObject1
216 @Field def colorControlObject2
217 //Global Object for class energy meter!
218 @Field energyMeterObjects = 0
219 @Field def energyMeterObject0
220 @Field def energyMeterObject1
221 @Field def energyMeterObject2
222 //Global Object for class energy meter!
223 @Field illuminanceMeasurementObjects = 0
224 @Field def illuminanceMeasurementObject0
225 @Field def illuminanceMeasurementObject1
226 @Field def illuminanceMeasurementObject2
227 //Global Object for class power meter!
228 @Field powerMeterObjects = 0
229 @Field def powerMeterObject0
230 @Field def powerMeterObject1
231 @Field def powerMeterObject2
232 //Global Object for class power meter!
233 @Field humidityMeasurementObjects = 0
234 @Field def humidityMeasurementObject0
235 @Field def humidityMeasurementObject1
236 @Field def humidityMeasurementObject2
237 //Global Object for class relay switch!
238 @Field relaySwitchObjects = 0
239 @Field def relaySwitchObject0
240 @Field def relaySwitchObject1
241 @Field def relaySwitchObject2
242 //Global Object for class sleep sensor!
243 @Field sleepSensorObjects = 0
244 @Field def sleepSensorObject0
245 @Field def sleepSensorObject1
246 @Field def sleepSensorObject2
247 //Global Object for class sleep sensor!
248 @Field stepSensorObjects = 0
249 @Field def stepSensorObject0
250 @Field def stepSensorObject1
251 @Field def stepSensorObject2
252 //Global Object for class switch level!
253 @Field switchLevelObjects = 0
254 @Field def switchLevelObject0
255 @Field def switchLevelObject1
256 @Field def switchLevelObject2
257 //Global Object for class temperature measurement!
258 @Field temperatureMeasurementObjects = 0
259 @Field def temperatureMeasurementObject0
260 @Field def temperatureMeasurementObject1
261 @Field def temperatureMeasurementObject2
262 //Global Object for class temperature measurement!
263 @Field waterSensorObjects = 0
264 @Field def waterSensorObject0
265 @Field def waterSensorObject1
266 @Field def waterSensorObject2
267 //Global Object for class valve!
268 @Field valveObjects = 0
269 @Field def valveObject0
270 @Field def valveObject1
271 @Field def valveObject2
272 //Global Object for class valve!
273 @Field mobilePresenceObjects = 0
274 @Field def mobilePresenceObject0
275 @Field def mobilePresenceObject1
276 @Field def mobilePresenceObject2
277
278
279
280 //Global variables
281 //For mode
282 @Field modeVariables = 0
283 @Field mode0
284 @Field mode1
285 @Field mode2
286 @Field mode3
287 @Field mode4
288 @Field mode5
289 //For number
290 @Field numberVariables = 0
291 @Field number0
292 @Field number1
293 @Field number2
294 @Field number3
295 @Field number4
296 @Field number5
297 //For decimal
298 @Field decimalVariables = 0
299 @Field decimal0
300 @Field decimal1
301 @Field decimal2
302 @Field decimal3
303 @Field decimal4
304 @Field decimal5
305 //For time
306 @Field timeVariables = 0
307 @Field time0
308 @Field time1
309 @Field time2
310 @Field time3
311 @Field time4
312 @Field time5
313 //For enum
314 @Field enumVariables = 0
315 @Field enum0
316 @Field enum1
317 @Field enum2
318 @Field enum3
319 @Field enum4
320 @Field enum5
321 //For phone
322 @Field phoneVariables = 0
323 @Field phone0
324 @Field phone1
325 @Field phone2
326 @Field phone3
327 @Field phone4
328 @Field phone5
329 //For contact
330 @Field contactVariables = 0
331 @Field contact0
332 @Field contact1
333 @Field contact2
334 @Field contact3
335 @Field contact4
336 @Field contact5
337 //For text
338 @Field textVariables = 0
339 @Field textVariable0
340 @Field textVariable1
341 @Field textVariable2
342 @Field textVariable3
343 @Field textVariable4
344 @Field textVariable5
345 //For boolean
346 @Field boolVariables = 0
347 @Field boolVariable0
348 @Field boolVariable1
349 @Field boolVariable2
350 @Field boolVariable3
351 @Field boolVariable4
352 @Field boolVariable5
353
354 /////Input Methods/////
355 //input "",""
356 def input(String name, String type) {
357         LinkedHashMap metaData = []
358         metaData.put('name',name)
359         metaData.put('type',type)
360         input(metaData)
361 }
362
363 //input "","",linkedHashMap
364 def input(LinkedHashMap metaData, String name, String type) {
365         metaData.put('name',name)
366         metaData.put('type',type)
367         input(metaData)
368 }
369
370 //input "", "", linkedHashMap, Closure
371 def input(LinkedHashMap metaData, String name, String type, Closure Input) {
372         metaData.put('name',name)
373         metaData.put('type',type)
374         input(metaData)
375         find(Input)
376 }
377
378 //input linkedHashMap
379 def input(LinkedHashMap metaData) {
380         if (metaData.containsKey('title')) {
381                 println metaData['title']
382         }
383         if (metaData.containsKey('options')) {
384                 println "Options: "+metaData['options']
385         }
386         def contains = 0
387         switch(metaData['type']) {
388                 case "capability.lock":
389                         globalObjects.eachLine { line ->
390                                 if(line.contains("lockObject")){
391                                         contains = 1
392                             }
393                         }
394
395                         if (contains == 0)
396                                 globalObjects.append("@Field def lockObject = new Locks(sendEvent, 1)\n")
397
398                         if (lockObjects == 0) {
399                                 lockObject0 = metaData['name']
400                                 this[lockObject0] = new Locks({}, 1)
401                         } else if (lockObjects == 1) {
402                                 lockObject1 = metaData['name']
403                                 this[lockObject1] = new Locks({}, 1)
404                         } else if (lockObjects == 2) {
405                                 lockObject2 = metaData['name']
406                                 this[lockObject2] = new Locks({}, 1)
407                         }
408
409                         lockObjects=lockObjects+1
410
411                         settings.put(metaData['name'], new Locks({}, 1)) 
412
413                         if (App == "App1") {
414                                 extractedObjectsApp1.append("//Object for class lock!\n")
415                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
416                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.lockObject\n")          
417                         } else {
418                                 extractedObjectsApp2.append("//Object for class lock!\n")
419                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
420                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.lockObject\n")
421                         }
422                         break
423                 case "capability.alarm":
424                         globalObjects.eachLine { line ->
425                                 if(line.contains("alarmObject")){
426                                         contains = 1
427                                 }
428                         }
429
430                         if (contains == 0)
431                                 globalObjects.append("@Field def alarmObject = new Alarms(sendEvent, 1)\n")
432
433                         if (alarmObjects == 0) {
434                                 alarmObject0 = metaData['name']
435                                 this[alarmObject0] = new Alarms({}, 1)
436                         } else if (alarmObjects == 1) {
437                                 alarmObject1 = metaData['name']
438                                 this[alarmObject1] = new Alarms({}, 1)
439                         } else if (alarmObjects == 2) {
440                                 alarmObject2 = metaData['name']
441                                 this[alarmObject2] = new Alarms({}, 1)
442                         }
443
444                         alarmObjects=alarmObjects+1
445
446                         settings.put(metaData['name'], new Alarms({}, 1)) 
447
448                         if (App == "App1") {
449                                 extractedObjectsApp1.append("//Object for class alarm!\n")
450                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
451                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.alarmObject\n")         
452                         } else {
453                                 extractedObjectsApp2.append("//Object for class alarm!\n")
454                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
455                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.alarmObject\n")
456                         }
457                         break
458                 case "capability.battery":
459                         globalObjects.eachLine { line ->
460                                 if(line.contains("batteryObject")){
461                                         contains = 1
462                                 }
463                         }
464
465                         if (contains == 0)
466                                 globalObjects.append("@Field def batteryObject = new Batteries(sendEvent, 1)\n")
467
468                         if (batteryObjects == 0) {
469                                 batteryObject0 = metaData['name']
470                                 this[batteryObject0] = new Batteries({}, 1)
471                         } else if (batteryObjects == 1) {
472                                 batteryObject1 = metaData['name']
473                                 this[batteryObject1] = new Batteries({}, 1)
474                         } else if (batteryObjects == 2) {
475                                 batteryObject2 = metaData['name']
476                                 this[batteryObject2] = new Batteries({}, 1)
477                         }
478
479                         batteryObjects=batteryObjects+1
480
481                         settings.put(metaData['name'], new Batteries({}, 1))
482
483                         if (App == "App1") {
484                                 extractedObjectsApp1.append("//Object for class Battery!\n")
485                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
486                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.batteryObject\n")               
487                         } else {
488                                 extractedObjectsApp2.append("//Object for class Battery!\n")
489                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
490                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.batteryObject\n")
491                         }
492                         break
493                 case "capability.beacon":
494                         globalObjects.eachLine { line ->
495                                 if(line.contains("beaconSensorObject")){
496                                         contains = 1
497                                 }
498                         }
499
500                         if (contains == 0)
501                                 globalObjects.append("@Field def beaconSensorObject = new BeaconSensors(sendEvent, 1)\n")
502
503                         if (beaconSensorObjects == 0) {
504                                 beaconSensorObject0 = metaData['name']
505                                 this[beaconSensorObject0] = new BeaconSensors({}, 1)
506                         } else if (beaconSensorObjects == 1) {
507                                 beaconSensorObject1 = metaData['name']
508                                 this[beaconSensorObject1] = new BeaconSensors({}, 1)
509                         } else if (beaconSensorObjects == 2) {
510                                 beaconSensorObject2 = metaData['name']
511                                 this[beaconSensorObject2] = new BeaconSensors({}, 1)
512                         }
513
514                         beaconSensorObjects=beaconSensorObjects+1
515
516                         settings.put(metaData['name'], new BeaconSensors({}, 1))
517
518                         if (App == "App1") {
519                                 extractedObjectsApp1.append("//Object for class beacon sensor!\n")
520                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
521                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.beaconSensorObject\n")          
522                         } else {
523                                 extractedObjectsApp2.append("//Object for class beacon sensor!\n")
524                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
525                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.beaconSensorObject\n")
526                         }
527                         break
528                 case "capability.carbonMonoxideDetector":
529                         globalObjects.eachLine { line ->
530                                 if(line.contains("carbonMonoxideDetectorObject")){
531                                         contains = 1
532                                 }
533                         }
534
535                         if (contains == 0)
536                                 globalObjects.append("@Field def carbonMonoxideDetectorObject = new CarbonMonoxideDetectors(sendEvent, 1)\n")
537
538                         if (carbonMonoxideDetectorObjects == 0) {
539                                 carbonMonoxideDetectorObject0 = metaData['name']
540                                 this[carbonMonoxideDetectorObject0] = new CarbonMonoxideDetectors({}, 1)
541                         } else if (carbonMonoxideDetectorObjects == 1) {
542                                 carbonMonoxideDetectorObject1 = metaData['name']
543                                 this[carbonMonoxideDetectorObject1] = new CarbonMonoxideDetectors({}, 1)
544                         } else if (carbonMonoxideDetectorObjects == 2) {
545                                 carbonMonoxideDetectorObject2 = metaData['name']
546                                 this[carbonMonoxideDetectorObject2] = new CarbonMonoxideDetectors({}, 1)
547                         }
548
549                         carbonMonoxideDetectorObjects=carbonMonoxideDetectorObjects+1
550                         
551                         settings.put(metaData['name'], new CarbonMonoxideDetectors({}, 1))
552
553                         if (App == "App1") {
554                                 extractedObjectsApp1.append("//Object for class carbon monoxide detector!\n")
555                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
556                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.carbonMonoxideDetectorObject\n")                
557                         } else {
558                                 extractedObjectsApp2.append("//Object for class carbon monoxide detector!\n")
559                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
560                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.carbonMonoxideDetectorObject\n")
561                         }
562                         break
563                 case "capability.colorControl":
564                         globalObjects.eachLine { line ->
565                                 if(line.contains("colorControlObject")){
566                                         contains = 1
567                                 }
568                         }
569
570                         if (contains == 0)
571                                 globalObjects.append("@Field def colorControlObject = new ColorControls(sendEvent, 1)\n")
572
573                         if (colorControlObjects == 0) {
574                                 colorControlObject0 = metaData['name']
575                                 this[colorControlObject0] = new ColorControls({}, 1)
576                         } else if (colorControlObjects == 1) {
577                                 colorControlObject1 = metaData['name']
578                                 this[colorControlObject1] = new ColorControls({}, 1)
579                         } else if (colorControlObjects == 2) {
580                                 colorControlObject2 = metaData['name']
581                                 this[colorControlObject2] = new ColorControls({}, 1)
582                         }
583
584                         colorControlObjects=colorControlObjects+1
585
586                         settings.put(metaData['name'], new ColorControls({}, 1))
587
588                         if (App == "App1") {
589                                 extractedObjectsApp1.append("//Object for class color control!\n")
590                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
591                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.colorControlObject\n")          
592                         } else {
593                                 extractedObjectsApp2.append("//Object for class color control!\n")
594                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
595                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.colorControlObject\n")
596                         }
597                         break
598                 case "capability.contactSensor":
599                         globalObjects.eachLine { line ->
600                                 if(line.contains("contactObject")){
601                                         contains = 1
602                                 }
603                         }
604
605                         if (contains == 0)
606                                 globalObjects.append("@Field def contactObject = new ContactSensors(sendEvent, 1)\n")
607
608                         if (contactObjects == 0) {
609                                 contactObject0 = metaData['name']
610                                 this[contactObject0] = new ContactSensors({}, 1)
611                         } else if (contactObjects == 1) {
612                                 contactObject1 = metaData['name']
613                                 this[contactObject1] = new ContactSensors({}, 1)
614                         } else if (contactObjects == 2) {
615                                 contactObject2 = metaData['name']
616                                 this[contactObject2] = new ContactSensors({}, 1)
617                         }
618
619                         contactObjects=contactObjects+1
620
621                         settings.put(metaData['name'], new ContactSensors({}, 1))
622
623                         if (App == "App1") {
624                                 extractedObjectsApp1.append("//Object for class contactSensor!\n")
625                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
626                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.contactObject\n")               
627                         } else {
628                                 extractedObjectsApp2.append("//Object for class contactSensor!\n")
629                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
630                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.contactObject\n")
631                         }
632                         break
633                 case "capability.doorControl":
634                         globalObjects.eachLine { line ->
635                                 if(line.contains("doorControlObject")){
636                                         contains = 1
637                                 }
638                         }
639
640                         if (contains == 0)
641                                 globalObjects.append("@Field def doorControlObject = new DoorControls(sendEvent, 1)\n")
642
643                         if (doorControlObjects == 0) {
644                                 doorControlObject0 = metaData['name']
645                                 this[doorControlObject0] = new DoorControls({}, 1)
646                         } else if (doorControlObjects == 1) {
647                                 doorControlObject1 = metaData['name']
648                                 this[doorControlObject1] = new DoorControls({}, 1)
649                         } else if (doorControlObjects == 2) {
650                                 doorControlObject2 = metaData['name']
651                                 this[doorControlObject2] = new DoorControls({}, 1)
652                         }
653
654                         doorControlObjects=doorControlObjects+1
655
656                         settings.put(metaData['name'], new DoorControls({}, 1))
657
658                         if (App == "App1") {
659                                 extractedObjectsApp1.append("//Object for class door control!\n")
660                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
661                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.doorControlObject\n")           
662                         } else {
663                                 extractedObjectsApp2.append("//Object for class door control!\n")
664                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
665                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.doorControlObject\n")
666                         }
667                         break
668                 case "capability.energyMeter":
669                         globalObjects.eachLine { line ->
670                                 if(line.contains("energyMeterObject")){
671                                         contains = 1
672                                 }
673                         }
674
675                         if (contains == 0)
676                                 globalObjects.append("@Field def energyMeterObject = new EnergyMeters(sendEvent, 1)\n")
677
678                         if (energyMeterObjects == 0) {
679                                 energyMeterObject0 = metaData['name']
680                                 this[energyMeterObject0] = new EnergyMeters({}, 1)
681                         } else if (energyMeterObjects == 1) {
682                                 energyMeterObject1 = metaData['name']
683                                 this[energyMeterObject1] = new EnergyMeters({}, 1)
684                         } else if (energyMeterObjects == 2) {
685                                 energyMeterObject2 = metaData['name']
686                                 this[energyMeterObject2] = new EnergyMeters({}, 1)
687                         }
688
689                         energyMeterObjects=energyMeterObjects+1
690
691                         settings.put(metaData['name'], new EnergyMeters({}, 1))
692
693                         if (App == "App1") {
694                                 extractedObjectsApp1.append("//Object for class energy meter!\n")
695                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
696                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.energyMeterObject\n")           
697                         } else {
698                                 extractedObjectsApp2.append("//Object for class energy meter!\n")
699                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
700                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.energyMeterObject\n")
701                         }
702                         break
703                 case "capability.illuminanceMeasurement":
704                         globalObjects.eachLine { line ->
705                                 if(line.contains("illuminanceMeasurementObject")){
706                                         contains = 1
707                                 }
708                         }
709
710                         if (contains == 0)
711                                 globalObjects.append("@Field def illuminanceMeasurementObject = new IlluminanceMeasurements(sendEvent, 1)\n")
712
713                         if (illuminanceMeasurementObjects == 0) {
714                                 illuminanceMeasurementObject0 = metaData['name']
715                                 this[illuminanceMeasurementObject0] = new IlluminanceMeasurements({}, 1)
716                         } else if (illuminanceMeasurementObjects == 1) {
717                                 illuminanceMeasurementObject1 = metaData['name']
718                                 this[illuminanceMeasurementObject1] = new IlluminanceMeasurements({}, 1)
719                         } else if (illuminanceMeasurementObjects == 2) {
720                                 illuminanceMeasurementObject2 = metaData['name']
721                                 this[illuminanceMeasurementObject2] = new IlluminanceMeasurements({}, 1)
722                         }
723
724                         illuminanceMeasurementObjects=illuminanceMeasurementObjects+1
725
726                         settings.put(metaData['name'], new IlluminanceMeasurements({}, 1))
727
728                         if (App == "App1") {
729                                 extractedObjectsApp1.append("//Object for class illuminance measurement!\n")
730                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
731                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.illuminanceMeasurementObject\n")                
732                         } else {
733                                 extractedObjectsApp2.append("//Object for class illuminance measurement!\n")
734                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
735                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.illuminanceMeasurementObject\n")
736                         }
737                         break
738                 case "capability.accelerationSensor":
739                         globalObjects.eachLine { line ->
740                                 if(line.contains("accelerationSensorObject")){
741                                         contains = 1
742                                 }
743                         }
744
745                         if (contains == 0)
746                                 globalObjects.append("@Field def accelerationSensorObject = new AccelerationSensors(sendEvent, 1)\n")
747
748                         if (accelerationSensorObjects == 0) {
749                                 accelerationSensorObject0 = metaData['name']
750                                 this[accelerationSensorObject0] = new AccelerationSensors({}, 1)
751                         } else if (accelerationSensorObjects == 1) {
752                                 accelerationSensorObject1 = metaData['name']
753                                 this[accelerationSensorObject1] = new AccelerationSensors({}, 1)
754                         } else if (accelerationSensorObjects == 2) {
755                                 accelerationSensorObject2 = metaData['name']
756                                 this[accelerationSensorObject2] = new AccelerationSensors({}, 1)
757                         }
758
759                         accelerationSensorObjects=accelerationSensorObjects+1
760
761                         settings.put(metaData['name'], new AccelerationSensors({}, 1))
762
763                         if (App == "App1") {
764                                 extractedObjectsApp1.append("//Object for class Acceleration Sensor!\n")
765                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
766                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.accelerationSensorObject\n")            
767                         } else {
768                                 extractedObjectsApp2.append("//Object for class Acceleration Sensor!\n")
769                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
770                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.accelerationSensorObject\n")
771                         }
772                         break
773                 case "capability.motionSensor":
774                         globalObjects.eachLine { line ->
775                                 if(line.contains("motionSensorObject")){
776                                         contains = 1
777                                 }
778                         }
779
780                         if (contains == 0)
781                                 globalObjects.append("@Field def motionSensorObject = new MotionSensors(sendEvent, 1)\n")
782
783                         if (motionSensorObjects == 0) {
784                                 motionSensorObject0 = metaData['name']
785                                 this[motionSensorObject0] = new MotionSensors({}, 1)
786                         } else if (motionSensorObjects == 1) {
787                                 motionSensorObject1 = metaData['name']
788                                 this[motionSensorObject1] = new MotionSensors({}, 1)
789                         } else if (motionSensorObjects == 2) {
790                                 motionSensorObject2 = metaData['name']
791                                 this[motionSensorObject2] = new MotionSensors({}, 1)
792                         }
793
794                         motionSensorObjects=motionSensorObjects+1
795
796                         settings.put(metaData['name'], new MotionSensors({}, 1))
797
798                         if (App == "App1") {
799                                 extractedObjectsApp1.append("//Object for class Motion Sensor!\n")
800                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
801                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.motionSensorObject\n")          
802                         } else {
803                                 extractedObjectsApp2.append("//Object for class Motion Sensor!\n")
804                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
805                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.motionSensorObject\n")
806                         }
807                         break
808                 case "capability.musicPlayer":
809                         globalObjects.eachLine { line ->
810                                 if(line.contains("musicPlayerObject")){
811                                         contains = 1
812                                 }
813                         }
814
815                         if (contains == 0)
816                                 globalObjects.append("@Field def musicPlayerObject = new MusicPlayers(sendEvent, 1)\n")
817
818                         if (musicPlayerObjects == 0) {
819                                 musicPlayerObject0 = metaData['name']
820                                 this[musicPlayerObject0] = new MusicPlayers({}, 1)
821                         } else if (musicPlayerObjects == 1) {
822                                 musicPlayerObject1 = metaData['name']
823                                 this[musicPlayerObject1] = new MusicPlayers({}, 1)
824                         } else if (musicPlayerObjects == 2) {
825                                 musicPlayerObject2 = metaData['name']
826                                 this[musicPlayerObject2] = new MusicPlayers({}, 1)
827                         }
828
829                         musicPlayerObjects=musicPlayerObjects+1
830
831                         settings.put(metaData['name'], new MusicPlayers({}, 1)) 
832
833                         if (App == "App1") {
834                                 extractedObjectsApp1.append("//Object for class music player!\n")
835                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
836                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.musicPlayerObject\n")           
837                         } else {
838                                 extractedObjectsApp2.append("//Object for class music player!\n")
839                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
840                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.musicPlayerObject\n")
841                         }
842                         break
843                 case "capability.powerMeter":
844                         globalObjects.eachLine { line ->
845                                 if(line.contains("powerMeterObject")){
846                                         contains = 1
847                                 }
848                         }
849
850                         if (contains == 0)
851                                 globalObjects.append("@Field def powerMeterObject = new PowerMeters(sendEvent, 1)\n")
852
853                         if (powerMeterObjects == 0) {
854                                 powerMeterObject0 = metaData['name']
855                                 this[powerMeterObject0] = new PowerMeters({}, 1)
856                         } else if (powerMeterObjects == 1) {
857                                 powerMeterObject1 = metaData['name']
858                                 this[powerMeterObject1] = new PowerMeters({}, 1)
859                         } else if (powerMeterObjects == 2) {
860                                 powerMeterObject2 = metaData['name']
861                                 this[powerMeterObject2] = new PowerMeters({}, 1)
862                         }
863
864                         powerMeterObjects=powerMeterObjects+1
865
866                         settings.put(metaData['name'], new PowerMeters({}, 1))
867
868                         if (App == "App1") {
869                                 extractedObjectsApp1.append("//Object for class power meter!\n")
870                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
871                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.powerMeterObject\n")            
872                         } else {
873                                 extractedObjectsApp2.append("//Object for class power meter!\n")
874                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
875                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.powerMeterObject\n")
876                         }
877                         break
878                 case "capability.presenceSensor":
879                         globalObjects.eachLine { line ->
880                                 if(line.contains("presenceSensorObject")){
881                                         contains = 1
882                                 }
883                         }
884
885                         if (contains == 0)
886                                 globalObjects.append("@Field def presenceSensorObject = new PresenceSensors(sendEvent, 1)\n")
887
888                         if (presenceSensorObjects == 0) {
889                                 presenceSensorObject0 = metaData['name']
890                                 this[presenceSensorObject0] = new PresenceSensors({}, 1)
891                         } else if (presenceSensorObjects == 1) {
892                                 presenceSensorObject1 = metaData['name']
893                                 this[presenceSensorObject1] = new PresenceSensors({}, 1)
894                         } else if (presenceSensorObjects == 2) {
895                                 presenceSensorObject2 = metaData['name']
896                                 this[presenceSensorObject2] = new PresenceSensors({}, 1)
897                         }
898
899                         presenceSensorObjects=presenceSensorObjects+1
900
901                         settings.put(metaData['name'], new PresenceSensors({}, 1))
902
903                         if (App == "App1") {
904                                 extractedObjectsApp1.append("//Object for class presence sensor!\n")
905                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
906                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.presenceSensorObject\n")                
907                         } else {
908                                 extractedObjectsApp2.append("//Object for class presence sensor!\n")
909                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
910                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.presenceSensorObject\n")
911                         }
912                         break
913                 case "capability.relativeHumidityMeasurement":
914                         globalObjects.eachLine { line ->
915                                 if(line.contains("humidityMeasurementObject")){
916                                         contains = 1
917                                 }
918                         }
919
920                         if (contains == 0)
921                                 globalObjects.append("@Field def humidityMeasurementObject = new RelativeHumidityMeasurements(sendEvent, 1)\n")
922
923                         if (humidityMeasurementObjects == 0) {
924                                 humidityMeasurementObject0 = metaData['name']
925                                 this[humidityMeasurementObject0] = new RelativeHumidityMeasurements({}, 1)
926                         } else if (humidityMeasurementObjects == 1) {
927                                 humidityMeasurementObject1 = metaData['name']
928                                 this[humidityMeasurementObject1] = new RelativeHumidityMeasurements({}, 1)
929                         } else if (humidityMeasurementObjects == 2) {
930                                 humidityMeasurementObject2 = metaData['name']
931                                 this[humidityMeasurementObject2] = new RelativeHumidityMeasurements({}, 1)
932                         }
933
934                         humidityMeasurementObjects=humidityMeasurementObjects+1
935
936                         settings.put(metaData['name'], new RelativeHumidityMeasurements({}, 1))
937
938                         if (App == "App1") {
939                                 extractedObjectsApp1.append("//Object for class humidity measurement!\n")
940                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
941                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.humidityMeasurementObject\n")           
942                         } else {
943                                 extractedObjectsApp2.append("//Object for class humidity measurement!\n")
944                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
945                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.humidityMeasurementObject\n")
946                         }
947                         break
948                 case "capability.relaySwitch":
949                         globalObjects.eachLine { line ->
950                                 if(line.contains("relaySwitchObject")){
951                                         contains = 1
952                                 }
953                         }
954
955                         if (contains == 0)
956                                 globalObjects.append("@Field def relaySwitchObject = new RelaySwitches(sendEvent, 1)\n")
957
958                         if (relaySwitchObjects == 0) {
959                                 relaySwitchObject0 = metaData['name']
960                                 this[relaySwitchObject0] = new RelaySwitches({}, 1)
961                         } else if (relaySwitchObjects == 1) {
962                                 relaySwitchObject1 = metaData['name']
963                                 this[relaySwitchObject1] = new RelaySwitches({}, 1)
964                         } else if (relaySwitchObjects == 2) {
965                                 relaySwitchObject2 = metaData['name']
966                                 this[relaySwitchObject2] = new RelaySwitches({}, 1)
967                         }
968
969                         relaySwitchObjects=relaySwitchObjects+1
970                         
971                         settings.put(metaData['name'], new RelaySwitches({}, 1))
972
973                         if (App == "App1") {
974                                 extractedObjectsApp1.append("//Object for class relay switch!\n")
975                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
976                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.relaySwitchObject\n")           
977                         } else {
978                                 extractedObjectsApp2.append("//Object for class relay switch!\n")
979                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
980                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.relaySwitchObject\n")
981                         }
982                         break
983                 case "capability.sleepSensor":
984                         globalObjects.eachLine { line ->
985                                 if(line.contains("sleepSensorObject")){
986                                         contains = 1
987                                 }
988                         }
989
990                         if (contains == 0)
991                                 globalObjects.append("@Field def sleepSensorObject = new SleepSensors(sendEvent, 1)\n")
992
993                         if (sleepSensorObjects == 0) {
994                                 sleepSensorObject0 = metaData['name']
995                                 this[sleepSensorObject0] = new SleepSensors({}, 1)
996                         } else if (sleepSensorObjects == 1) {
997                                 sleepSensorObject1 = metaData['name']
998                                 this[sleepSensorObject1] = new SleepSensors({}, 1)
999                         } else if (sleepSensorObjects == 2) {
1000                                 sleepSensorObject2 = metaData['name']
1001                                 this[sleepSensorObject2] = new SleepSensors({}, 1)
1002                         }
1003
1004                         sleepSensorObjects=sleepSensorObjects+1
1005                         
1006                         settings.put(metaData['name'], new SleepSensors({}, 1))
1007
1008                         if (App == "App1") {
1009                                 extractedObjectsApp1.append("//Object for class sleep sensor!\n")
1010                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1011                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.sleepSensorObject\n")           
1012                         } else {
1013                                 extractedObjectsApp2.append("//Object for class sleep sensor!\n")
1014                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1015                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.sleepSensorObject\n")
1016                         }
1017                         break
1018                 case "capability.smokeDetector":
1019                         globalObjects.eachLine { line ->
1020                                 if(line.contains("smokeDetectorObject")){
1021                                         contains = 1
1022                                 }
1023                         }
1024
1025                         if (contains == 0)
1026                                 globalObjects.append("@Field def smokeDetectorObject = new SmokeDetectors(sendEvent, 1)\n")
1027
1028                         if (smokeDetectorObjects == 0) {
1029                                 smokeDetectorObject0 = metaData['name']
1030                                 this[smokeDetectorObject0] = new SmokeDetectors({}, 1)
1031                         } else if (smokeDetectorObjects == 1) {
1032                                 smokeDetectorObject1 = metaData['name']
1033                                 this[smokeDetectorObject1] = new SmokeDetectors({}, 1)
1034                         } else if (smokeDetectorObjects == 2) {
1035                                 smokeDetectorObject2 = metaData['name']
1036                                 this[smokeDetectorObject2] = new SmokeDetectors({}, 1)
1037                         }
1038
1039                         smokeDetectorObjects=smokeDetectorObjects+1
1040                         
1041                         settings.put(metaData['name'], new SmokeDetectors({}, 1))
1042
1043                         if (App == "App1") {
1044                                 extractedObjectsApp1.append("//Object for class smoke detector!\n")
1045                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1046                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.smokeDetectorObject\n")         
1047                         } else {
1048                                 extractedObjectsApp2.append("//Object for class smoke detector!\n")
1049                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1050                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.smokeDetectorObject\n")
1051                         }
1052                         break
1053                 case "capability.stepSensor":
1054                         globalObjects.eachLine { line ->
1055                                 if(line.contains("stepSensorObject")){
1056                                         contains = 1
1057                                 }
1058                         }
1059
1060                         if (contains == 0)
1061                                 globalObjects.append("@Field def stepSensorObject = new StepSensors(sendEvent, 1)\n")
1062
1063                         if (stepSensorObjects == 0) {
1064                                 stepSensorObject0 = metaData['name']
1065                                 this[stepSensorObject0] = new StepSensors({}, 1)
1066                         } else if (stepSensorObjects == 1) {
1067                                 stepSensorObject1 = metaData['name']
1068                                 this[stepSensorObject1] = new StepSensors({}, 1)
1069                         } else if (stepSensorObjects == 2) {
1070                                 stepSensorObject2 = metaData['name']
1071                                 this[stepSensorObject2] = new StepSensors({}, 1)
1072                         }
1073
1074                         stepSensorObjects=stepSensorObjects+1
1075                         
1076                         settings.put(metaData['name'], new StepSensors({}, 1))
1077
1078                         if (App == "App1") {
1079                                 extractedObjectsApp1.append("//Object for class step sensor!\n")
1080                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1081                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.stepSensorObject\n")            
1082                         } else {
1083                                 extractedObjectsApp2.append("//Object for class step sensor!\n")
1084                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1085                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.stepSensorObject\n")
1086                         }
1087                         break
1088                 case "capability.switch":               
1089                         globalObjects.eachLine { line ->
1090                                 if(line.contains("switchObject")){
1091                                         contains = 1
1092                                 }
1093                         }
1094
1095                         if (contains == 0)
1096                                 globalObjects.append("@Field def switchObject = new Switches(sendEvent, 1)\n")
1097
1098                         if (switchObjects == 0) {
1099                                 switchObject0 = metaData['name']
1100                                 this[switchObject0] = new Switches({}, 1)
1101                         } else if (switchObjects == 1) {
1102                                 switchObject1 = metaData['name']
1103                                 this[switchObject1] = new Switches({}, 1)
1104                         } else if (switchObjects == 2) {
1105                                 switchObject2 = metaData['name']
1106                                 this[switchObject2] = new Switches({}, 1)
1107                         }
1108
1109                         switchObjects=switchObjects+1
1110                         
1111                         settings.put(metaData['name'], new Switches({}, 1))
1112
1113                         if (App == "App1") {
1114                                 extractedObjectsApp1.append("//Object for class switch!\n")
1115                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1116                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.switchObject\n")                
1117                         } else {
1118                                 extractedObjectsApp2.append("//Object for class switch!\n")
1119                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1120                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.switchObject\n")
1121                         }
1122                         break
1123                 case "capability.switchLevel":
1124                         globalObjects.eachLine { line ->
1125                                 if(line.contains("switchLevelObject")){
1126                                         contains = 1
1127                                 }
1128                         }
1129
1130                         if (contains == 0)
1131                                 globalObjects.append("@Field def switchLevelObject = new SwitchLevels(sendEvent, 1)\n")
1132
1133                         if (switchLevelObjects == 0) {
1134                                 switchLevelObject0 = metaData['name']
1135                                 this[switchLevelObject0] = new SwitchLevels({}, 1)
1136                         } else if (switchLevelObjects == 1) {
1137                                 switchLevelObject1 = metaData['name']
1138                                 this[switchLevelObject1] = new SwitchLevels({}, 1)
1139                         } else if (switchLevelObjects == 2) {
1140                                 switchLevelObject2 = metaData['name']
1141                                 this[switchLevelObject2] = new SwitchLevels({}, 1)
1142                         }
1143
1144                         switchLevelObjects=switchLevelObjects+1
1145
1146                         settings.put(metaData['name'], new SwitchLevels({}, 1))
1147
1148                         if (App == "App1") {
1149                                 extractedObjectsApp1.append("//Object for class switch level!\n")
1150                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1151                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.switchLevelObject\n")           
1152                         } else {
1153                                 extractedObjectsApp2.append("//Object for class switch level!\n")
1154                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1155                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.switchLevelObject\n")
1156                         }
1157                         break
1158                 case "capability.temperatureMeasurement":
1159                         globalObjects.eachLine { line ->
1160                                 if(line.contains("temperatureMeasurementObject")){
1161                                         contains = 1
1162                                 }
1163                         }
1164
1165                         if (contains == 0)
1166                                 globalObjects.append("@Field def temperatureMeasurementObject = new TemperatureMeasurements(sendEvent, 1)\n")
1167
1168                         if (temperatureMeasurementObjects == 0) {
1169                                 temperatureMeasurementObject0 = metaData['name']
1170                                 this[temperatureMeasurementObject0] = new TemperatureMeasurements({}, 1)
1171                         } else if (temperatureMeasurementObjects == 1) {
1172                                 temperatureMeasurementObject1 = metaData['name']
1173                                 this[temperatureMeasurementObject1] = new TemperatureMeasurements({}, 1)
1174                         } else if (temperatureMeasurementObjects == 2) {
1175                                 temperatureMeasurementObject2 = metaData['name']
1176                                 this[temperatureMeasurementObject2] = new TemperatureMeasurements({}, 1)
1177                         }
1178
1179                         temperatureMeasurementObjects=temperatureMeasurementObjects+1
1180
1181                         settings.put(metaData['name'], new TemperatureMeasurements({}, 1))
1182
1183                         if (App == "App1") {
1184                                 extractedObjectsApp1.append("//Object for class temperature measurement!\n")
1185                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1186                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.temperatureMeasurementObject\n")                
1187                         } else {
1188                                 extractedObjectsApp2.append("//Object for class temperature measurement!\n")
1189                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1190                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.temperatureMeasurementObject\n")
1191                         }
1192                         break
1193                 case "capability.thermostat":
1194                         globalObjects.eachLine { line ->
1195                                 if(line.contains("thermostatObject")){
1196                                         contains = 1
1197                                 }
1198                         }
1199
1200                         if (contains == 0)
1201                                 globalObjects.append("@Field def thermostatObject = new Thermostats(sendEvent, 1)\n")
1202                                 
1203                         if (thermostatObjects == 0) {
1204                                 thermostatObject0 = metaData['name']
1205                                 this[thermostatObject0] = new Thermostats({}, 1)
1206                         } else if (thermostatObjects == 1) {
1207                                 thermostatObject1 = metaData['name']
1208                                 this[thermostatObject1] = new Thermostats({}, 1)
1209                         } else if (thermostatObjects == 2) {
1210                                 thermostatObject2 = metaData['name']
1211                                 this[thermostatObject2] = new Thermostats({}, 1)
1212                         }
1213
1214                         thermostatObjects=thermostatObjects+1
1215
1216                         settings.put(metaData['name'], new Thermostats({}, 1))
1217
1218                         if (App == "App1") {
1219                                 extractedObjectsApp1.append("//Object for class thermostat!\n")
1220                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1221                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.thermostatObject\n")            
1222                         } else {
1223                                 extractedObjectsApp2.append("//Object for class thermostat!\n")
1224                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1225                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.thermostatObject\n")
1226                         }
1227                         break
1228                 case "capability.valve":
1229                         globalObjects.eachLine { line ->
1230                                 if(line.contains("valveObject")){
1231                                         contains = 1
1232                                 }
1233                         }
1234
1235                         if (contains == 0)
1236                                 globalObjects.append("@Field def valveObject = new Valves(sendEvent, 1)\n")
1237
1238                         if (valveObjects == 0) {
1239                                 valveObject0 = metaData['name']
1240                                 this[valveObject0] = new Valves({}, 1)
1241                         } else if (valveObjects == 1) {
1242                                 valveObject1 = metaData['name']
1243                                 this[valveObject1] = new Valves({}, 1)
1244                         } else if (valveObjects == 2) {
1245                                 valveObject2 = metaData['name']
1246                                 this[valveObject2] = new Valves({}, 1)
1247                         }
1248
1249                         valveObjects=valveObjects+1
1250
1251                         settings.put(metaData['name'], new Valves({}, 1))
1252
1253                         if (App == "App1") {
1254                                 extractedObjectsApp1.append("//Object for class valve!\n")
1255                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1256                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.valveObject\n")         
1257                         } else {
1258                                 extractedObjectsApp2.append("//Object for class valve!\n")
1259                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1260                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.valveObject\n")
1261                         }
1262                         break
1263                 case "capability.speechSynthesis":
1264                         globalObjects.eachLine { line ->
1265                                 if(line.contains("speechSynthesisObject")){
1266                                         contains = 1
1267                                 }
1268                         }
1269
1270                         if (contains == 0)
1271                                 globalObjects.append("@Field def speechSynthesisObject = new SpeechSynthesises(sendEvent, 1)\n")
1272
1273                         if (speechSynthesisObjects == 0) {
1274                                 speechSynthesisObject0 = metaData['name']
1275                                 this[speechSynthesisObject0] = new SpeechSynthesises({}, 1)
1276                         } else if (speechSynthesisObjects == 1) {
1277                                 speechSynthesisObject1 = metaData['name']
1278                                 this[speechSynthesisObject1] = new SpeechSynthesises({}, 1)
1279                         } else if (speechSynthesisObjects == 2) {
1280                                 speechSynthesisObject2 = metaData['name']
1281                                 this[speechSynthesisObject2] = new SpeechSynthesises({}, 1)
1282                         }
1283
1284                         speechSynthesisObjects=speechSynthesisObjects+1
1285
1286                         settings.put(metaData['name'], new SpeechSynthesises({}, 1))
1287
1288                         if (App == "App1") {
1289                                 extractedObjectsApp1.append("//Object for class speech synthesis!\n")
1290                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1291                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.speechSynthesisObject\n")               
1292                         } else {
1293                                 extractedObjectsApp2.append("//Object for class speech synthesis!\n")
1294                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1295                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.speechSynthesisObject\n")
1296                         }
1297                         break
1298                 case "capability.waterSensor":
1299                         globalObjects.eachLine { line ->
1300                                 if(line.contains("waterSensorObject")){
1301                                         contains = 1
1302                                 }
1303                         }
1304
1305                         if (contains == 0)
1306                                 globalObjects.append("@Field def waterSensorObject = new WaterSensors(sendEvent, 1)\n")
1307
1308                         if (waterSensorObjects == 0) {
1309                                 waterSensorObject0 = metaData['name']
1310                                 this[waterSensorObject0] = new WaterSensors({}, 1)
1311                         } else if (waterSensorObjects == 1) {
1312                                 waterSensorObject1 = metaData['name']
1313                                 this[waterSensorObject1] = new WaterSensors({}, 1)
1314                         } else if (waterSensorObjects == 2) {
1315                                 waterSensorObject2 = metaData['name']
1316                                 this[waterSensorObject2] = new WaterSensors({}, 1)
1317                         }
1318
1319                         waterSensorObjects=waterSensorObjects+1
1320
1321                         settings.put(metaData['name'], new WaterSensors({}, 1))
1322
1323                         if (App == "App1") {
1324                                 extractedObjectsApp1.append("//Object for class water sensor!\n")
1325                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1326                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.waterSensorObject\n")           
1327                         } else {
1328                                 extractedObjectsApp2.append("//Object for class water sensor!\n")
1329                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1330                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.waterSensorObject\n")
1331                         }
1332                         break
1333                 case "capability.touchSensor":
1334                         globalObjects.eachLine { line ->
1335                                 if(line.contains("touchSensorObject")){
1336                                         contains = 1
1337                                 }
1338                         }
1339
1340                         if (contains == 0)
1341                                 globalObjects.append("@Field def touchSensorObject = new NfcTouch(sendEvent, 1)\n")
1342
1343                         if (touchSensorObjects == 0) {
1344                                 touchSensorObject0 = metaData['name']
1345                                 this[touchSensorObject0] = new NfcTouch({}, 1)
1346                         } else if (touchSensorObjects == 1) {
1347                                 touchSensorObject1 = metaData['name']
1348                                 this[touchSensorObject1] = new NfcTouch({}, 1)
1349                         } else if (touchSensorObjects == 2) {
1350                                 touchSensorObject2 = metaData['name']
1351                                 this[touchSensorObject2] = new NfcTouch({}, 1)
1352                         }
1353
1354                         touchSensorObjects=touchSensorObjects+1
1355
1356                         settings.put(metaData['name'], new NfcTouch({}, 1))
1357
1358                         if (App == "App1") {
1359                                 extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
1360                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1361                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.touchSensorObject\n")           
1362                         } else {
1363                                 extractedObjectsApp2.append("//Object for class Touch Sensor!\n")
1364                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1365                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.touchSensorObject\n")
1366                         }
1367                         break
1368                 case "capability.imageCapture":
1369                         globalObjects.eachLine { line ->
1370                                 if(line.contains("imageCaptureObject")){
1371                                         contains = 1
1372                                 }
1373                         }
1374
1375                         if (contains == 0)
1376                                 globalObjects.append("@Field def imageCaptureObject = new ImageCaptures(sendEvent, 1)\n")
1377
1378                         if (imageCaptureObjects == 0) {
1379                                 imageCaptureObject0 = metaData['name']
1380                                 this[imageCaptureObject0] = new ImageCaptures({}, 1)
1381                         } else if (imageCaptureObjects == 1) {
1382                                 imageCaptureObject1 = metaData['name']
1383                                 this[imageCaptureObject1] = new ImageCaptures({}, 1)
1384                         } else if (imageCaptureObjects == 2) {
1385                                 imageCaptureObject2 = metaData['name']
1386                                 this[imageCaptureObject2] = new ImageCaptures({}, 1)
1387                         }
1388
1389                         imageCaptureObjects=imageCaptureObjects+1
1390
1391                         settings.put(metaData['name'], new ImageCaptures({}, 1))
1392
1393                         if (App == "App1") {
1394                                 extractedObjectsApp1.append("//Object for class Image Capture!\n")
1395                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1396                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.imageCaptureObject\n")          
1397                         } else {
1398                                 extractedObjectsApp2.append("//Object for class Image Capture!\n")
1399                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1400                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.imageCaptureObject\n")
1401                         }
1402                         break
1403                 case "device.mobilePresence":
1404                         globalObjects.eachLine { line ->
1405                                 if(line.contains("mobilePresenceObject")){
1406                                         contains = 1
1407                                 }
1408                         }
1409
1410                         if (contains == 0)
1411                                 globalObjects.append("@Field def mobilePresenceObject = new MobilePresences(sendEvent, 1)\n")
1412
1413                         if (mobilePresenceObjects == 0) {
1414                                 mobilePresenceObject0 = metaData['name']
1415                                 this[mobilePresenceObject0] = new MobilePresences({}, 1)
1416                         } else if (mobilePresenceObjects == 1) {
1417                                 mobilePresenceObject1 = metaData['name']
1418                                 this[mobilePresenceObject1] = new MobilePresences({}, 1)
1419                         } else if (mobilePresenceObjects == 2) {
1420                                 mobilePresenceObject2 = metaData['name']
1421                                 this[mobilePresenceObject2] = new MobilePresences({}, 1)
1422                         }
1423
1424                         mobilePresenceObjects=mobilePresenceObjects+1
1425
1426                         settings.put(metaData['name'], new MobilePresences({}, 1))
1427
1428                         if (App == "App1") {
1429                                 extractedObjectsApp1.append("//Object for class mobile presence!\n")
1430                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1431                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.mobilePresenceObject\n")                
1432                         } else {
1433                                 extractedObjectsApp2.append("//Object for class mobile presence!\n")
1434                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1435                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.mobilePresenceObject\n")
1436                         }
1437                         break
1438                 case "capability.button":
1439                 case "device.aeonKeyFob":
1440                         globalObjects.eachLine { line ->
1441                                 if(line.contains("aeonKeyFobObject")){
1442                                         contains = 1
1443                                 }
1444                         }
1445                         if (contains == 0)
1446                                 globalObjects.append("@Field def aeonKeyFobObject = new AeonKeyFobs(sendEvent, 1)\n")
1447
1448                         if (aeonKeyFobObjects == 0) {
1449                                 aeonKeyFobObject0 = metaData['name']
1450                                 this[aeonKeyFobObject0] = new AeonKeyFobs({}, 1)
1451                         } else if (aeonKeyFobObjects == 1) {
1452                                 aeonKeyFobObject1 = metaData['name']
1453                                 this[aeonKeyFobObject1] = new AeonKeyFobs({}, 1)
1454                         } else if (aeonKeyFobObjects == 2) {
1455                                 aeonKeyFobObject2 = metaData['name']
1456                                 this[aeonKeyFobObject2] = new AeonKeyFobs({}, 1)
1457                         }
1458
1459                         aeonKeyFobObjects=aeonKeyFobObjects+1
1460
1461                         settings.put(metaData['name'], new AeonKeyFobs({}, 1)) 
1462
1463                         if (App == "App1") {
1464                                 extractedObjectsApp1.append("//Object for class aeon key fob!\n")
1465                                 extractedObjectsApp1.append("def "+metaData['name']+"\n")
1466                                 extractedObjectsConstructorApp1.append(metaData['name']+" = obj.aeonKeyFobObject\n")            
1467                         } else {
1468                                 extractedObjectsApp2.append("//Object for class aeon key fob!\n")
1469                                 extractedObjectsApp2.append("def "+metaData['name']+"\n")
1470                                 extractedObjectsConstructorApp2.append(metaData['name']+" = obj.aeonKeyFobObject\n")
1471                         }
1472                         break
1473                 case "mode":
1474                         //def randomVariable = Math.abs(new Random().nextInt() % 3)
1475                         def modes = ["away", "home", "night"]
1476                         def userInput = modes[0]
1477
1478                         if (modeVariables == 0) {
1479                                 mode0 = metaData['name']
1480                                 this[mode0] = userInput
1481                         } else if (modeVariables == 1) {
1482                                 mode1 = metaData['name']
1483                                 this[mode1] = userInput
1484                         } else if (modeVariables == 2) {
1485                                 mode2 = metaData['name']
1486                                 this[mode2] = userInput
1487                         } else if (modeVariables == 3) {
1488                                 mode3 = metaData['name']
1489                                 this[mode3] = userInput
1490                         } else if (modeVariables == 4) {
1491                                 mode4 = metaData['name']
1492                                 this[mode4] = userInput
1493                         } else if (modeVariables == 5) {
1494                                 mode5 = metaData['name']
1495                                 this[mode5] = userInput
1496                         }
1497
1498                         if (modeVariables != 5)
1499                                 modeVariables=modeVariables+1
1500                         else
1501                                 modeVariables=0
1502
1503
1504                         settings.put(metaData['name'], metaData['name'])
1505
1506                         if (App == "App1") {                    
1507                                 extractedObjectsApp1.append("//Global variable for mode!\n")
1508                                 extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1509                         } else {
1510                                 extractedObjectsApp2.append("//Global variable for mode!\n")
1511                                 extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1512                         }
1513                         break
1514                 case "decimal":
1515                         //def userInput = Math.abs(new Random().nextInt() % 60) + 40
1516                         def userInput = 50
1517
1518                         if (decimalVariables == 0) {
1519                                 decimal0 = metaData['name']
1520                                 this[decimal0] = userInput
1521                         } else if (decimalVariables == 1) {
1522                                 decimal1 = metaData['name']
1523                                 this[decimal1] = userInput
1524                         } else if (decimalVariables == 2) {
1525                                 decimal2 = metaData['name']
1526                                 this[decimal2] = userInput
1527                         } else if (decimalVariables == 3) {
1528                                 decimal3 = metaData['name']
1529                                 this[decimal3] = userInput
1530                         } else if (decimalVariables == 4) {
1531                                 decimal4 = metaData['name']
1532                                 this[decimal4] = userInput
1533                         } else if (decimalVariables == 5) {
1534                                 decimal5 = metaData['name']
1535                                 this[decimal5] = userInput
1536                         }
1537
1538                         if (decimalVariables != 5)
1539                                 decimalVariables=decimalVariables+1
1540                         else
1541                                 decimalVariables=0
1542
1543                         settings.put(metaData['name'], metaData['name'])
1544
1545                         if (App == "App1") {                    
1546                                 extractedObjectsApp1.append("//Global variable for decimal number!\n")
1547                                 extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
1548                         } else {
1549                                 extractedObjectsApp2.append("//Global variable for decimal number!\n")
1550                                 extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
1551                         }
1552                         break
1553                 case "text":
1554                         def userInput = "This is just a text!"
1555                         
1556                         if (textVariables == 0) {
1557                                 text0 = metaData['name']
1558                                 this[text0] = userInput
1559                         } else if (textVariables == 1) {
1560                                 text1 = metaData['name']
1561                                 this[text1] = userInput
1562                         } else if (textVariables == 2) {
1563                                 text2 = metaData['name']
1564                                 this[text2] = userInput
1565                         } else if (textVariables == 3) {
1566                                 text3 = metaData['name']
1567                                 this[text3] = userInput
1568                         } else if (textVariables == 4) {
1569                                 text4 = metaData['name']
1570                                 this[text4] = userInput
1571                         } else if (textVariables == 5) {
1572                                 text5 = metaData['name']
1573                                 this[text5] = userInput
1574                         }
1575
1576                         if (textVariables != 5)
1577                                 textVariables=textVariables+1
1578                         else
1579                                 textVariables=0
1580
1581
1582                         settings.put(metaData['name'], metaData['name'])
1583
1584                         if (App == "App1") {                    
1585                                 extractedObjectsApp1.append("//Global variable for text!\n")
1586                                 extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1587                         } else {
1588                                 extractedObjectsApp2.append("//Global variable for text!\n")
1589                                 extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1590                         }
1591                         break
1592                 case "number":
1593                         //def userInput = Math.abs(new Random().nextInt() % 60) + 40
1594                         def userInput = 50
1595
1596                         if (numberVariables == 0) {
1597                                 number0 = metaData['name']
1598                                 this[number0] = userInput
1599                         } else if (numberVariables == 1) {
1600                                 number1 = metaData['name']
1601                                 this[number1] = userInput
1602                         } else if (numberVariables == 2) {
1603                                 number2 = metaData['name']
1604                                 this[number2] = userInput
1605                         } else if (numberVariables == 3) {
1606                                 number3 = metaData['name']
1607                                 this[number3] = userInput
1608                         } else if (numberVariables == 4) {
1609                                 number4 = metaData['name']
1610                                 this[number4] = userInput
1611                         } else if (numberVariables == 5) {
1612                                 number5 = metaData['name']
1613                                 this[number5] = userInput
1614                         }
1615
1616
1617                         if (numberVariables != 5)
1618                                 numberVariables=numberVariables+1
1619                         else
1620                                 numberVariables=0
1621                         
1622
1623                         settings.put(metaData['name'], metaData['name'])
1624
1625                         if (App == "App1") {                    
1626                                 extractedObjectsApp1.append("//Global variable for number!\n")
1627                                 extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
1628                         } else {
1629                                 extractedObjectsApp2.append("//Global variable for number!\n")
1630                                 extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
1631                         }
1632                         break
1633                 case "time":
1634                         def userInput = "15:00"
1635                         
1636                         if (timeVariables == 0) {
1637                                 time0 = metaData['name']
1638                                 this[time0] = userInput
1639                         } else if (timeVariables == 1) {
1640                                 time1 = metaData['name']
1641                                 this[time1] = userInput
1642                         } else if (timeVariables == 2) {
1643                                 time2 = metaData['name']
1644                                 this[time2] = userInput
1645                         } else if (timeVariables == 3) {
1646                                 time3 = metaData['name']
1647                                 this[time3] = userInput
1648                         } else if (timeVariables == 4) {
1649                                 time4 = metaData['name']
1650                                 this[time4] = userInput
1651                         } else if (timeVariables == 5) {
1652                                 time5 = metaData['name']
1653                                 this[time5] = userInput
1654                         }
1655
1656                         if (timeVariables != 5)
1657                                 timeVariables=timeVariables+1
1658                         else
1659                                 timeVariables=0
1660
1661                         settings.put(metaData['name'], metaData['name'])
1662
1663                         if (App == "App1") {                    
1664                                 extractedObjectsApp1.append("//Global variable for time!\n")
1665                                 extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1666                         } else {
1667                                 extractedObjectsApp2.append("//Global variable for time!\n")
1668                                 extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1669                         }
1670                         break
1671                 case "enum":
1672                         if (metaData['options'] != null)
1673                                 modes = metaData['options']
1674                         else if (metaData['metadata'] != null) { // If it is not named 'options' then it is captured as 'metadata'
1675                                 modes = metaData['metadata']
1676                                 modes = modes['values']
1677                         }
1678                         def userInput = modes[0]
1679         
1680                         if (enumVariables == 0) {
1681                                 enum0 = metaData['name']
1682                                 this[enum0] = userInput
1683                         } else if (enumVariables == 1) {
1684                                 enum1 = metaData['name']
1685                                 this[enum1] = userInput
1686                         } else if (enumVariables == 2) {
1687                                 enum2 = metaData['name']
1688                                 this[enum2] = userInput
1689                         } else if (enumVariables == 3) {
1690                                 enum3 = metaData['name']
1691                                 this[enum3] = userInput
1692                         } else if (enumVariables == 4) {
1693                                 enum4 = metaData['name']
1694                                 this[enum4] = userInput
1695                         } else if (enumVariables == 5) {
1696                                 enum5 = metaData['name']
1697                                 this[enum5] = userInput
1698                         }
1699
1700                         if (enumVariables != 5)
1701                                 enumVariables=enumVariables+1
1702                         else
1703                                 enumVariables=0                 
1704
1705
1706                         settings.put(metaData['name'], metaData['name'])
1707
1708                         if (App == "App1") {                    
1709                                 extractedObjectsApp1.append("//Global variable for enum!\n")
1710                                 extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1711                         } else {
1712                                 extractedObjectsApp2.append("//Global variable for enum!\n")
1713                                 extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1714                         }
1715                         break
1716                 case "bool":
1717                         //def userInput = Math.abs(new Random().nextInt() % 2)
1718                         def userInput = true
1719
1720                         if (boolVariables == 0) {
1721                                 bool0 = metaData['name']
1722                                 this[bool0] = userInput
1723                         } else if (boolVariables == 1) {
1724                                 bool1 = metaData['name']
1725                                 this[bool1] = userInput
1726                         } else if (boolVariables == 2) {
1727                                 bool2 = metaData['name']
1728                                 this[bool2] = userInput
1729                         } else if (boolVariables == 3) {
1730                                 bool3 = metaData['name']
1731                                 this[bool3] = userInput
1732                         } else if (boolVariables == 4) {
1733                                 bool4 = metaData['name']
1734                                 this[bool4] = userInput
1735                         } else if (boolVariables == 5) {
1736                                 bool5 = metaData['name']
1737                                 this[bool5] = userInput
1738                         }
1739
1740                         if (boolVariables != 5)
1741                                 boolVariables=boolVariables+1
1742                         else
1743                                 boolVariables=0
1744
1745
1746                         settings.put(metaData['name'], metaData['name'])
1747
1748                         if (App == "App1") {                    
1749                                 extractedObjectsApp1.append("//Global variable for boolean!\n")
1750                                 extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1751                         } else {
1752                                 extractedObjectsApp2.append("//Global variable for boolean!\n")
1753                                 extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1754                         }
1755                         break
1756                 case "phone":
1757                         def userInput = 9495379373
1758
1759                         if (phoneVariables == 0) {
1760                                 phone0 = metaData['name']
1761                                 this[phone0] = userInput
1762                         } else if (phoneVariables == 1) {
1763                                 phone1 = metaData['name']
1764                                 this[phone1] = userInput
1765                         } else if (phoneVariables == 2) {
1766                                 phone2 = metaData['name']
1767                                 this[phone2] = userInput
1768                         } else if (phoneVariables == 3) {
1769                                 phone3 = metaData['name']
1770                                 this[phone3] = userInput
1771                         } else if (phoneVariables == 4) {
1772                                 phone4 = metaData['name']
1773                                 this[phone4] = userInput
1774                         } else if (phoneVariables == 5) {
1775                                 phone5 = metaData['name']
1776                                 this[phone5] = userInput
1777                         }
1778
1779                         if (phoneVariables != 5)
1780                                 phoneVariables=phoneVariables+1
1781                         else
1782                                 phoneVariables=0
1783
1784                         settings.put(metaData['name'], metaData['name'])
1785
1786                         if (App == "App1") {                    
1787                                 extractedObjectsApp1.append("//Global variable for phone!\n")
1788                                 extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
1789                         } else {
1790                                 extractedObjectsApp2.append("//Global variable for phone!\n")
1791                                 extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
1792                         }
1793                         break
1794                 case "contact":
1795                         def userInput = "AJ"
1796         
1797                         if (contactVariables == 0) {
1798                                 contact0 = metaData['name']
1799                                 this[contact0] = userInput
1800                         } else if (contactVariables == 1) {
1801                                 contact1 = metaData['name']
1802                                 this[contact1] = userInput
1803                         } else if (contactVariables == 2) {
1804                                 contact2 = metaData['name']
1805                                 this[contact2] = userInput
1806                         } else if (contactVariables == 3) {
1807                                 contact3 = metaData['name']
1808                                 this[contact3] = userInput
1809                         } else if (contactVariables == 4) {
1810                                 contact4 = metaData['name']
1811                                 this[contact4] = userInput
1812                         } else if (contactVariables == 5) {
1813                                 contact5 = metaData['name']
1814                                 this[contact5] = userInput
1815                         }
1816
1817                         if (contactVariables != 5)
1818                                 contactVariables=contactVariables+1
1819                         else
1820                                 contactVariables=0
1821
1822                         settings.put(metaData['name'], metaData['name'])
1823
1824                         if (App == "App1") {                    
1825                                 extractedObjectsApp1.append("//Global variable for contact!\n")
1826                                 extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1827                         } else {
1828                                 extractedObjectsApp2.append("//Global variable for contact!\n")
1829                                 extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
1830                         }
1831                         break
1832                 default:
1833                         break
1834         }
1835 }
1836
1837 def label(LinkedHashMap metaData) {
1838         if (metaData.containsKey('title')) {
1839                 println metaData['title']
1840         }
1841         if (metaData.containsKey('options')) {
1842                 println "Options: "+metaData['options']
1843         }
1844
1845         println("//IGNORE--ForMobileUse//")
1846 }
1847
1848 def mode(LinkedHashMap metaData) {
1849         if (metaData.containsKey('title')) {
1850                 println metaData['title']
1851         }
1852         if (metaData.containsKey('options')) {
1853                 println "Options: "+metaData['options']
1854         }
1855
1856         println("//IGNORE--ForMobileUse//")
1857 }
1858
1859 def href(LinkedHashMap metaData) {
1860         println("//IGNORE--some data//")
1861 }
1862
1863 def href(LinkedHashMap metaData, String name) {
1864         println("//IGNORE--some data//")
1865 }
1866 /////Input Methods/////
1867
1868
1869 /////MethodsForExtraction/////
1870 def definition(LinkedHashMap metaData) {
1871         println("///Just some information///")
1872 }
1873
1874 def preferences(Closure inputData) {
1875         find(inputData) //Run the closure to extract pages/sections/inputMethods
1876         settings.put("END", "END")
1877         if (App == "App1") {            
1878                 extractedObjectsConstructorApp1.append("//Global variable for settings!\n")
1879                 extractedObjectsConstructorApp1.append("settings = [")
1880                 settings.each{
1881                         key, value ->
1882                         if (value != "END")
1883                                 extractedObjectsConstructorApp1.append("$key: $key, ")
1884                         else
1885                                 extractedObjectsConstructorApp1.append("END: \"END\"]\n")
1886                 }
1887         } else {
1888                 extractedObjectsConstructorApp2.append("//Global variable for settings!\n")
1889                 extractedObjectsConstructorApp2.append("settings = [")
1890                 settings.each{
1891                         key, value ->
1892                         if (value != "END")
1893                                 extractedObjectsConstructorApp2.append("$key: $key, ")
1894                         else
1895                                 extractedObjectsConstructorApp2.append("END: \"END\"]\n")
1896                 }
1897                 def line
1898                 File GlobalVariablesBothApps = new File("GlobalVariables/GlobalVariablesBothApps.groovy")
1899                 GlobalVariablesBothApps.write("")
1900                 GlobalVariablesBothApps.append("//Creating Global variables for both apps\n")
1901                 GlobalVariablesBothApps.append("@Field def sendEvent = {eventDataMap -> eventHandler(eventDataMap)}\n")
1902                 GlobalVariablesBothApps.append("@Field def locationObject = new LocationVar(sendEvent)\n")
1903                 GlobalVariablesBothApps.append("@Field def appObject = new Touched(sendEvent, 0)\n")
1904                 
1905                 globalObjects.withReader { reader ->
1906                         while ((line = reader.readLine()) != null) {
1907                                 GlobalVariablesBothApps.append(line)
1908                                 GlobalVariablesBothApps.append("\n")
1909                         }
1910                  }
1911         }
1912 }
1913
1914 def page(LinkedHashMap metaData, Closure inputData) {
1915         if (metaData.containsKey('name'))
1916                 println(metaData['name'])
1917         if (metaData.containsKey('title'))
1918                 println(metaData['title'])
1919
1920         find(inputData) //Run the closure to extract sections/inputMethods
1921 }
1922
1923 def page(LinkedHashMap metaData) {
1924         def nameOfFunction = metaData['name']
1925         "$nameOfFunction"() //Call the page     
1926 }
1927
1928 def dynamicPage(LinkedHashMap metaData, Closure inputData) {
1929         if (metaData.containsKey('name'))
1930                 println(metaData['name'])
1931         if (metaData.containsKey('title'))
1932                 println(metaData['title'])
1933
1934         find(inputData) //Run the closure to extract sections/inputMethods
1935 }
1936
1937 def paragraph(String paragraphText) {
1938         println(paragraphText)
1939 }
1940
1941 def section(String title, Closure inputData) {
1942         println(title)
1943         find(inputData) //Run the closure to extract inputMethods
1944 }
1945
1946 def section(Closure inputData) {
1947         find(inputData) //Run the closure to extract inputMethods
1948 }
1949
1950 def section(LinkedHashMap metaData, Closure inputData) {
1951         find(inputData) //Run the closure to extract inputMethods
1952 }
1953
1954 def section(LinkedHashMap metaData, String data, Closure inputData) {
1955         find(inputData)
1956 }
1957
1958 def mappings(Closure inputData) {
1959         println("//IGNORE--some data//")
1960 }
1961 /////MethodsForExtraction/////
1962