7 Skip = ["(", "\"", ":", ",", "{", "}", ")", '\n', '\t', ' ', "/"]
17 if (c == "{" or c == "}"):
25 if (c == "{" or c == "}"):
36 outGlobal = open("Extractor/outGlobal.groovy", "w+")
42 def ExtractorFunc(F, outApp, outConstructorApp, Temp):
48 while (Temp != "EOF"):
49 #Extract the global objects for input
53 Temp = GetToken(F) #name or "name"
54 #input name: "name", type: "type",...
56 Temp = GetToken(F) #"name"
59 Temp = GetToken(F) #"type"
61 #input "name", "type",...
64 Temp = GetToken(F) #"type"
70 while (Temp != "input" and Temp != "}"):
74 elif (Temp == "required"):
77 elif (Temp == "multiple"):
81 if (Type == "capability.lock"):
83 print(Object+", "+Title)
84 if (Multiple != "" and Multiple == "true" and lockIsSet != 1):
86 g = raw_input("Enter the number of locks to control: (1, 2, or 3)\n")
87 outGlobal.write("//Global Object for class lock!\n")
88 outGlobal.write("@Field def lockObject = new Locking(sendEvent, ")
89 outGlobal.write("%s)\n" % g)
90 elif ((Multiple == "" or Multiple == "false") and lockIsSet != 1):
92 outGlobal.write("//Global Object for class lock!\n")
93 outGlobal.write("@Field def lockObject = new Locking(sendEvent, 1)\n")
94 outApp.write("//Object for class lock!\n")
95 outApp.write("def %s\n" % Object)
96 outConstructorApp.write("%s = obj.lockObject\n" % Object)
97 #elif (Type == "capability.alarm"):
99 #elif (Type == "capability.battery"):
101 #elif (Type == "capability.beacon"):
103 #elif (Type == "capability.carbonMonoxideDetector"):
105 #elif (Type == "capability.colorControl"):
107 elif (Type == "capability.contactSensor"):
109 print(Object+", "+Title)
110 if (Multiple != "" and Multiple == "true" and ContactIsSet != 1):
112 g = raw_input("Enter the number of contact sensors to control: (1, 2, or 3)\n")
113 outGlobal.write("//Global Object for class contactSensor!\n")
114 outGlobal.write("@Field def contactObject = new Contacting(sendEvent, ")
115 outGlobal.write("%s)\n" % g)
116 elif ((Multiple == "" or Multiple == "false") and ContactIsSet != 1):
118 outGlobal.write("//Global Object for class contactSensor!\n")
119 outGlobal.write("@Field def contactObject = new Contacting(sendEvent, 1)\n")
120 outApp.write("//Object for class contactSensor!\n")
121 outApp.write("def %s\n" % Object)
122 outConstructorApp.write("%s = obj.contactObject\n" % Object)
123 #elif (Type == "capability.doorControl"):
125 #elif (Type == "capability.energyMeter"):
127 #elif (Type == "capability.illuminanceMeasurement"):
129 #elif (Type == "capability.accelerationSensor"):
131 #elif (Type == "capability.motionSensor"):
133 #elif (Type == "capability.musicPlayer"):
135 #elif (Type == "capability.powerMeter"):
137 #elif (Type == "capability.presenceSensor"):
139 #elif (Type == "capability.relativeHumidityMeasurement"):
141 #elif (Type == "capability.relaySwitch"):
143 #elif (Type == "capability.sleepSensor"):
145 #elif (Type == "capability.smokeDetector"):
147 #elif (Type == "capability.stepSensor"):
149 elif (Type == "capability.switch"):
151 print(Object+", "+Title)
152 if (Multiple != "" and Multiple == "true" and SwitchIsSet != 1):
154 g = raw_input("Enter the number of switches to control: (1, 2, or 3)\n")
155 outGlobal.write("//Global Object for class Switch!\n")
156 outGlobal.write("@Field def switchObject = new Switching(sendEvent, ")
157 outGlobal.write("%s)\n" % g)
158 elif ((Multiple == "" or Multiple == "false") and SwitchIsSet != 1):
160 outGlobal.write("//Global Object for class Switch!\n")
161 outGlobal.write("@Field def switchObject = new Switching(sendEvent, 1)\n")
162 outApp.write("//Object for class Switch!\n")
163 outApp.write("def %s\n" % Object)
164 outConstructorApp.write("%s = obj.switchObject\n" % Object)
165 #elif (Type == "capability.switchLevel"):
167 #elif (Type == "capability.temperatureMeasurement"):
169 #elif (Type == "capability.thermostat"):
171 #elif (Type == "capability.valve"):
173 #elif (Type == "capability.waterSensor"):
175 #elif (Type == "capability.touchSensor"):
177 #elif (Type == "capability.imageCapture"):
179 #elif (Type == "device.mobilePresence"):
181 #elif (Type == "device.aeonKeyFob"):
183 elif (Type == "mode"):
185 print(Object+", "+Title)
186 g = raw_input("Enter the mode: ")
187 outApp.write("//Global variable for mode!\n")
188 outApp.write("def %s = " % Object)
189 outApp.write("\"%s\"\n" % g)
190 #elif (Type == "decimal"):
192 #elif (Type == "text"):
194 elif (Type == "number"):
196 print(Object+", "+Title)
197 g = raw_input("Enter the number: ")
198 outApp.write("//Global variable for number!\n")
199 outApp.write("def %s = " % Object)
200 outApp.write("%s\n" % g)
201 #elif (Type == "time"):
203 #elif (Type == "enum"):
205 #elif (Type == "bool"):
207 elif (Type == "phone"):
209 print(Object+", "+Title)
210 g = raw_input("Enter the number to send notification to:\n")
211 outApp.write("//Global variable for phone number!\n")
212 outApp.write("def %s = " % Object)
213 outApp.write("%s\n" % g)
214 elif (Type == "contact"):
216 print(Object+", "+Title)
217 g = raw_input("Enter the name of the recipients:\n")
218 outApp.write("//Global variable for recipients!\n")
220 outApp.write("def %s = " % Object)
221 outApp.write("%s\n" % g)
222 #Extract the global object for functions
223 elif (Temp == "def"):
226 if (GetToken(F) != "="): #We have a function to create object for
227 outApp.write("//Global Object for functions in subscribe method!\n")
228 outApp.write("def %s = this.&" % NameofFunc)
229 outApp.write("%s\n" % NameofFunc)
230 if (Temp != "input"):
235 outConstructorApp.close()
238 F = open("Extractor/App1.groovy", "r")
239 outApp = open("Extractor/extractedObjectsApp1.groovy", "w+")
240 outConstructorApp = open("Extractor/extractedObjectsConstructorApp1.groovy", "w+")
243 ExtractorFunc(F, outApp, outConstructorApp, Temp)
246 F = open("Extractor/App2.groovy", "r")
247 outApp = open("Extractor/extractedObjectsApp2.groovy", "w+")
248 outConstructorApp = open("Extractor/extractedObjectsConstructorApp2.groovy", "w+")
251 ExtractorFunc(F, outApp, outConstructorApp, Temp)