0b6b3a36c68215fccde672fe9feabf8f92c8bbf4
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / manager / ResourceManager.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package oic.simulator.clientcontroller.manager;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.Comparator;
22 import java.util.Date;
23 import java.util.HashMap;
24 import java.util.Iterator;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29 import java.util.Vector;
30
31 import oic.simulator.clientcontroller.Activator;
32 import oic.simulator.clientcontroller.remoteresource.DeviceAndPlatformInfo;
33 import oic.simulator.clientcontroller.remoteresource.MetaProperty;
34 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
35 import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
36 import oic.simulator.clientcontroller.utils.Constants;
37 import oic.simulator.clientcontroller.utils.Utility;
38
39 import org.oic.simulator.ArrayProperty;
40 import org.oic.simulator.AttributeProperty;
41 import org.oic.simulator.AttributeProperty.Type;
42 import org.oic.simulator.AttributeValue;
43 import org.oic.simulator.AttributeValue.TypeInfo;
44 import org.oic.simulator.AttributeValue.ValueType;
45 import org.oic.simulator.BooleanProperty;
46 import org.oic.simulator.DeviceInfo;
47 import org.oic.simulator.DeviceListener;
48 import org.oic.simulator.DoubleProperty;
49 import org.oic.simulator.ILogger.Level;
50 import org.oic.simulator.IntegerProperty;
51 import org.oic.simulator.PlatformInfo;
52 import org.oic.simulator.PlatformListener;
53 import org.oic.simulator.SimulatorException;
54 import org.oic.simulator.SimulatorManager;
55 import org.oic.simulator.SimulatorResourceAttribute;
56 import org.oic.simulator.SimulatorResourceModel;
57 import org.oic.simulator.SimulatorResult;
58 import org.oic.simulator.StringProperty;
59 import org.oic.simulator.client.FindResourceListener;
60 import org.oic.simulator.client.SimulatorRemoteResource;
61 import org.oic.simulator.client.SimulatorRemoteResource.GetResponseListener;
62 import org.oic.simulator.client.SimulatorRemoteResource.ObserveNotificationListener;
63 import org.oic.simulator.client.SimulatorRemoteResource.PostResponseListener;
64 import org.oic.simulator.client.SimulatorRemoteResource.PutResponseListener;
65 import org.oic.simulator.client.SimulatorRemoteResource.VerificationListener;
66 import org.oic.simulator.client.SimulatorRemoteResource.VerificationType;
67
68 /**
69  * This class acts as an interface between the simulator java SDK and the
70  * various UI modules. It maintains all the details of resources and provides
71  * other UI modules with the information required. It also handles responses for
72  * find, GET, PUT, POST, Observe and automatic verification operations from
73  * native layer and propagates those events to the registered UI listeners.
74  */
75 public class ResourceManager {
76
77     private Set<String>                        lastKnownSearchTypes;
78
79     private RemoteResource                     currentResourceInSelection;
80
81     private FindResourceListener               findResourceListener;
82     private GetResponseListener                getListener;
83     private PutResponseListener                putListener;
84     private PostResponseListener               postListener;
85     private ObserveNotificationListener        observeListener;
86     private VerificationListener               verifyListener;
87     private DeviceListener                     deviceListener;
88     private PlatformListener                   platformListener;
89
90     private ResponseSynchronizerThread         synchronizerThread;
91
92     private Thread                             threadHandle;
93
94     // Map with Server ID as key and the complete object as the value
95     private Map<String, RemoteResource>        resourceMap;
96     private List<RemoteResource>               favoriteResources;
97     // Maintaining a list of resource URIs for favorite resources feature.
98     private List<String>                       favoriteURIList;
99
100     // Maintaining a list of observed resource URIs.
101     private List<String>                       observedResourceURIList;
102
103     private Map<String, DeviceAndPlatformInfo> hostDeviceAndPlatformMap;
104
105     public ResourceManager() {
106         resourceMap = new HashMap<String, RemoteResource>();
107         favoriteResources = new ArrayList<RemoteResource>();
108         favoriteURIList = new ArrayList<String>();
109         observedResourceURIList = new ArrayList<String>();
110         hostDeviceAndPlatformMap = new HashMap<String, DeviceAndPlatformInfo>();
111
112         findResourceListener = new FindResourceListener() {
113
114             @Override
115             public void onResourceFound(final SimulatorRemoteResource resourceN) {
116                 synchronizerThread.addToQueue(new Runnable() {
117                     @Override
118                     public void run() {
119                         if (null == resourceN) {
120                             return;
121                         }
122
123                         // Ignore the response if the resource is a device or
124                         // platform.
125                         Vector<String> resTypes = resourceN.getResourceTypes();
126                         if (null != resTypes && resTypes.contains("oic.wk.d")
127                                 || resTypes.contains("oic.wk.p")) {
128                             return;
129                         }
130
131                         // If id is not available, then it cannot be added to
132                         // the local map as null value should not be allowed as
133                         // key.
134                         String uid = resourceN.getId();
135                         if (null == uid) {
136                             return;
137                         }
138
139                         // If resource already exist, then ignore it.
140                         boolean exist = isUidExist(uid);
141                         if (exist) {
142                             return;
143                         }
144
145                         RemoteResource resource = new RemoteResource();
146                         resource.setRemoteResourceRef(resourceN);
147
148                         String uri = resourceN.getURI();
149                         if (null != uri && uri.trim().length() > 0) {
150                             // Add resource to favorite list if it was in
151                             // favorites list during find/refresh operation.
152                             if (favoriteURIList.contains(uri)) {
153                                 addResourcetoFavorites(resource);
154                             }
155                             // Add resource to observed resources list if it was
156                             // in observe list during find/refresh operation.
157                             if (observedResourceURIList.contains(uri)) {
158                                 sendObserveRequest(resource);
159                             }
160                         } else {
161                             Activator
162                                     .getDefault()
163                                     .getLogManager()
164                                     .log(Level.INFO.ordinal(), new Date(),
165                                             "Found a resource without URI. Ignoring it.");
166                             return;
167                         }
168
169                         // Add the resource in local data structure
170                         addResourceDetails(resource);
171
172                         // Notify the UI listener
173                         UiListenerHandler.getInstance()
174                                 .newResourceFoundNotification(resource);
175
176                         Activator
177                                 .getDefault()
178                                 .getLogManager()
179                                 .log(Level.INFO.ordinal(),
180                                         new Date(),
181                                         "Resource Found [" + resourceN.getURI()
182                                                 + "].");
183
184                         // Send an initial GET request to get the resource
185                         // attributes on an interface supported by the resource.
186                         try {
187                             String ifType = null;
188                             Vector<String> resInterfaces = resourceN
189                                     .getResourceInterfaces();
190                             if (null != resInterfaces) {
191                                 ifType = resInterfaces.get(0);
192                             }
193                             resourceN.get(formQueryParameters(ifType, null),
194                                     getListener);
195                         } catch (SimulatorException e) {
196                             Activator
197                                     .getDefault()
198                                     .getLogManager()
199                                     .log(Level.ERROR.ordinal(),
200                                             new Date(),
201                                             Utility.getSimulatorErrorString(e,
202                                                     null));
203                         }
204
205                         // Get the device information
206                         if (!isDeviceInfoExist(resourceN.getHost())) {
207                             try {
208                                 SimulatorManager.findDevices(resource
209                                         .getRemoteResourceRef().getHost(),
210                                         deviceListener);
211                             } catch (SimulatorException e) {
212                                 Activator
213                                         .getDefault()
214                                         .getLogManager()
215                                         .log(Level.ERROR.ordinal(),
216                                                 new Date(),
217                                                 Utility.getSimulatorErrorString(
218                                                         e, null));
219                             }
220                         }
221
222                         // Get the platform information
223                         if (!isPlatformInfoExist(resourceN.getHost())) {
224                             try {
225                                 SimulatorManager.getPlatformInformation(
226                                         resource.getRemoteResourceRef()
227                                                 .getHost(), platformListener);
228                             } catch (SimulatorException e) {
229                                 Activator
230                                         .getDefault()
231                                         .getLogManager()
232                                         .log(Level.ERROR.ordinal(),
233                                                 new Date(),
234                                                 Utility.getSimulatorErrorString(
235                                                         e, null));
236                             }
237                         }
238                     }
239                 });
240             }
241         };
242
243         // Listeners for device and platform information.
244         deviceListener = new DeviceListener() {
245
246             @Override
247             public void onDeviceFound(final String host,
248                     final DeviceInfo deviceInfo) {
249                 if (null == deviceInfo || null == host) {
250                     return;
251                 }
252                 synchronizerThread.addToQueue(new Runnable() {
253                     @Override
254                     public void run() {
255                         synchronized (hostDeviceAndPlatformMap) {
256                             DeviceAndPlatformInfo info = hostDeviceAndPlatformMap
257                                     .get(host);
258                             if (null == info) {
259                                 info = new DeviceAndPlatformInfo();
260                                 info.setHost(host);
261                                 hostDeviceAndPlatformMap.put(host, info);
262                             }
263                             info.setDeviceInfo(deviceInfo);
264                         }
265
266                         // Notify UI listeners
267                         UiListenerHandler.getInstance()
268                                 .deviceInfoReceivedNotification();
269                     }
270                 });
271             }
272         };
273
274         platformListener = new PlatformListener() {
275
276             @Override
277             public void onPlatformFound(final String host,
278                     final PlatformInfo platformInfo) {
279                 if (null == platformInfo || null == host) {
280                     return;
281                 }
282                 synchronizerThread.addToQueue(new Runnable() {
283                     @Override
284                     public void run() {
285                         synchronized (hostDeviceAndPlatformMap) {
286                             DeviceAndPlatformInfo info = hostDeviceAndPlatformMap
287                                     .get(host);
288                             if (null == info) {
289                                 info = new DeviceAndPlatformInfo();
290                                 info.setHost(host);
291                                 hostDeviceAndPlatformMap.put(host, info);
292                             }
293                             info.setPlatformInfo(platformInfo);
294                         }
295
296                         // Notify UI listeners
297                         UiListenerHandler.getInstance()
298                                 .platformInfoReceivedNotification();
299                     }
300                 });
301             }
302         };
303
304         getListener = new GetResponseListener() {
305             @Override
306             public void onGetResponse(final String uid,
307                     final SimulatorResult result,
308                     final SimulatorResourceModel resourceModelN) {
309                 if (result != SimulatorResult.SIMULATOR_OK) {
310                     Activator
311                             .getDefault()
312                             .getLogManager()
313                             .log(Level.ERROR.ordinal(),
314                                     new Date(),
315                                     "["
316                                             + result.toString()
317                                             + "] Received error response for GET request.");
318                     return;
319                 }
320                 synchronizerThread.addToQueue(new Runnable() {
321                     @Override
322                     public void run() {
323                         // Handling the response which includes retrieving the
324                         // attributes and updating the local model.
325                         RemoteResource resource = handleResponse(uid,
326                                 resourceModelN);
327                         if (null != resource) {
328                             // Notify the UI listeners
329                             UiListenerHandler.getInstance()
330                                     .getCompleteNotification(resource);
331                         }
332                     }
333                 });
334             }
335         };
336
337         putListener = new PutResponseListener() {
338
339             @Override
340             public void onPutResponse(final String uid,
341                     final SimulatorResult result,
342                     final SimulatorResourceModel resourceModelN) {
343                 if (result != SimulatorResult.SIMULATOR_OK) {
344                     Activator
345                             .getDefault()
346                             .getLogManager()
347                             .log(Level.ERROR.ordinal(),
348                                     new Date(),
349                                     "["
350                                             + result.toString()
351                                             + "] Received error response for PUT request.");
352                     return;
353                 }
354                 synchronizerThread.addToQueue(new Thread() {
355                     @Override
356                     public void run() {
357                         // Handling the response which includes retrieving the
358                         // attributes and updating the local model.
359                         RemoteResource resource = handleResponse(uid,
360                                 resourceModelN);
361                         if (null != resource) {
362                             // Notify the UI listeners
363                             UiListenerHandler.getInstance()
364                                     .putCompleteNotification(resource);
365                         }
366                     }
367                 });
368             }
369         };
370
371         postListener = new PostResponseListener() {
372             @Override
373             public void onPostResponse(final String uid,
374                     final SimulatorResult result,
375                     final SimulatorResourceModel resourceModelN) {
376                 if (result != SimulatorResult.SIMULATOR_OK) {
377                     Activator
378                             .getDefault()
379                             .getLogManager()
380                             .log(Level.ERROR.ordinal(),
381                                     new Date(),
382                                     "["
383                                             + result.toString()
384                                             + "] Received error response for POST request.");
385                     return;
386                 }
387                 synchronizerThread.addToQueue(new Runnable() {
388                     @Override
389                     public void run() {
390                         // Handling the response which includes retrieving the
391                         // attributes and updating the local model.
392                         RemoteResource resource = handleResponse(uid,
393                                 resourceModelN);
394                         if (null != resource) {
395                             // Notify the UI listeners
396                             UiListenerHandler.getInstance()
397                                     .postCompleteNotification(resource);
398                         }
399                     }
400                 });
401             }
402         };
403
404         observeListener = new ObserveNotificationListener() {
405
406             @Override
407             public void onObserveNotification(final String uid,
408                     final SimulatorResourceModel resourceModelN, final int seq) {
409                 synchronizerThread.addToQueue(new Runnable() {
410                     @Override
411                     public void run() {
412                         // Handling the response which includes retrieving the
413                         // attributes and updating the local model.
414                         RemoteResource resource = handleResponse(uid,
415                                 resourceModelN);
416                         if (null != resource) {
417                             // Notify the UI listeners
418                             UiListenerHandler.getInstance()
419                                     .observeCompleteNotification(resource);
420                         }
421                     }
422                 });
423             }
424         };
425
426         verifyListener = new VerificationListener() {
427
428             @Override
429             public void onVerificationStarted(final String uid, final int autoId) {
430                 synchronizerThread.addToQueue(new Runnable() {
431                     @Override
432                     public void run() {
433                         RemoteResource resource = getResource(uid);
434                         if (null == resource) {
435                             return;
436                         }
437                         // Update the automation status.
438                         resource.updateAutomationStatus(autoId, true);
439
440                         int autoType = resource.getAutomationtype(autoId);
441
442                         // Notify the listeners.
443                         UiListenerHandler.getInstance()
444                                 .verificationStartedNotification(resource,
445                                         autoType);
446                     }
447                 });
448             }
449
450             @Override
451             public void onVerificationCompleted(final String uid,
452                     final int autoId) {
453                 synchronizerThread.addToQueue(new Runnable() {
454                     @Override
455                     public void run() {
456                         RemoteResource resource = getResource(uid);
457                         if (null == resource) {
458                             return;
459                         }
460                         // Update the automation status.
461                         resource.updateAutomationStatus(autoId, false);
462
463                         int autoType = resource.getAutomationtype(autoId);
464
465                         // Notify the listeners.
466                         UiListenerHandler.getInstance()
467                                 .verificationCompletedNotification(resource,
468                                         autoType);
469                     }
470                 });
471             }
472
473             @Override
474             public void onVerificationAborted(final String uid, final int autoId) {
475                 synchronizerThread.addToQueue(new Runnable() {
476                     @Override
477                     public void run() {
478                         RemoteResource resource = getResource(uid);
479                         if (null == resource) {
480                             return;
481                         }
482                         // Update the automation status.
483                         resource.updateAutomationStatus(autoId, false);
484
485                         int autoType = resource.getAutomationtype(autoId);
486
487                         // Notify the listeners.
488                         UiListenerHandler.getInstance()
489                                 .verificationAbortedNotification(resource,
490                                         autoType);
491                     }
492                 });
493             }
494         };
495
496         synchronizerThread = new ResponseSynchronizerThread();
497         threadHandle = new Thread(synchronizerThread);
498         threadHandle.setName("Simulator Client Controller Event Queue");
499         threadHandle.start();
500     }
501
502     private RemoteResource handleResponse(String uid,
503             SimulatorResourceModel resourceModelN) {
504         if (null == uid || null == resourceModelN) {
505             return null;
506         }
507
508         // Update the local model
509         RemoteResource resource;
510         resource = getResource(uid);
511         if (null == resource) {
512             return null;
513         }
514
515         resource.setResourceModelRef(resourceModelN);
516         resource.setResourceRepresentation(resourceModelN, false);
517
518         return resource;
519     }
520
521     public synchronized boolean isDeviceInfoExist(String host) {
522         DeviceAndPlatformInfo info = hostDeviceAndPlatformMap.get(host);
523         if (null == info) {
524             return false;
525         }
526         if (null == info.getDeviceInfo()) {
527             return false;
528         }
529         return true;
530     }
531
532     public synchronized boolean isPlatformInfoExist(String host) {
533         DeviceAndPlatformInfo info = hostDeviceAndPlatformMap.get(host);
534         if (null == info) {
535             return false;
536         }
537         if (null == info.getPlatformInfo()) {
538             return false;
539         }
540         return true;
541     }
542
543     private static class ResponseSynchronizerThread implements Runnable {
544
545         LinkedList<Runnable> responseQueue = new LinkedList<Runnable>();
546
547         @Override
548         public void run() {
549             while (!Thread.interrupted()) {
550                 synchronized (this) {
551                     try {
552                         while (responseQueue.isEmpty()) {
553                             this.wait();
554                             break;
555                         }
556                     } catch (InterruptedException e) {
557                         return;
558                     }
559                 }
560
561                 Runnable thread;
562                 synchronized (this) {
563                     thread = responseQueue.pop();
564                 }
565                 try {
566                     thread.run();
567                 } catch (Exception e) {
568                     if (e instanceof InterruptedException) {
569                         return;
570                     }
571                     e.printStackTrace();
572                 }
573             }
574         }
575
576         public void addToQueue(Runnable event) {
577             synchronized (this) {
578                 responseQueue.add(event);
579                 this.notify();
580             }
581         }
582     }
583
584     public void addResourcetoFavorites(RemoteResource resource) {
585         if (null == resource) {
586             return;
587         }
588         resource.setFavorite(true);
589         synchronized (favoriteResources) {
590             favoriteResources.add(resource);
591         }
592     }
593
594     public void removeResourceFromFavorites(RemoteResource resource) {
595         if (null == resource) {
596             return;
597         }
598         resource.setFavorite(false);
599         synchronized (favoriteResources) {
600             favoriteResources.remove(resource);
601         }
602     }
603
604     public void addResourceURItoFavorites(RemoteResource resource) {
605         if (null == resource) {
606             return;
607         }
608         synchronized (favoriteURIList) {
609             favoriteURIList.add(resource.getRemoteResourceRef().getURI());
610         }
611     }
612
613     public void removeResourceURIFromFavorites(RemoteResource resource) {
614         if (null == resource) {
615             return;
616         }
617         synchronized (favoriteURIList) {
618             favoriteURIList.remove(resource.getRemoteResourceRef().getURI());
619         }
620     }
621
622     public void addObservedResourceURI(String resourceURI) {
623         synchronized (observedResourceURIList) {
624             if (!observedResourceURIList.contains(resourceURI))
625                 observedResourceURIList.add(resourceURI);
626         }
627     }
628
629     public void removeObservedResourceURI(String resourceURI) {
630         synchronized (observedResourceURIList) {
631             observedResourceURIList.remove(resourceURI);
632         }
633     }
634
635     public boolean isResourceObserved(String resourceURI) {
636         boolean observed = false;
637         synchronized (observedResourceURIList) {
638             observed = observedResourceURIList.contains(resourceURI);
639         }
640         return observed;
641     }
642
643     public synchronized RemoteResource getCurrentResourceInSelection() {
644         return currentResourceInSelection;
645     }
646
647     public synchronized void setCurrentResourceInSelection(
648             RemoteResource resource) {
649         this.currentResourceInSelection = resource;
650     }
651
652     private void addResourceDetails(RemoteResource remoteResource) {
653         if (null != remoteResource) {
654             synchronized (resourceMap) {
655                 resourceMap.put(remoteResource.getRemoteResourceRef().getId(),
656                         remoteResource);
657             }
658         }
659     }
660
661     private boolean isUidExist(String uid) {
662         boolean exist;
663         synchronized (resourceMap) {
664             exist = resourceMap.containsKey(uid);
665         }
666         return exist;
667     }
668
669     private RemoteResource getResource(String uid) {
670         if (null == uid) {
671             return null;
672         }
673         RemoteResource resource;
674         synchronized (resourceMap) {
675             resource = resourceMap.get(uid);
676         }
677         return resource;
678     }
679
680     public synchronized Set<String> getLastKnownSearchTypes() {
681         return lastKnownSearchTypes;
682     }
683
684     public synchronized void setLastKnownSearchTypes(
685             Set<String> lastKnownSearchTypes) {
686         this.lastKnownSearchTypes = lastKnownSearchTypes;
687     }
688
689     public boolean findResourceRequest(Set<String> searchTypes) {
690         boolean result = false;
691         if (null == searchTypes || searchTypes.size() < 1) {
692             try {
693                 SimulatorManager.findResource(findResourceListener);
694                 result = true;
695             } catch (SimulatorException e) {
696                 Activator
697                         .getDefault()
698                         .getLogManager()
699                         .log(Level.ERROR.ordinal(), new Date(),
700                                 Utility.getSimulatorErrorString(e, null));
701             }
702         } else {
703             Iterator<String> searchItr = searchTypes.iterator();
704             String rType;
705             while (searchItr.hasNext()) {
706                 rType = searchItr.next();
707                 try {
708                     SimulatorManager.findResource(rType, findResourceListener);
709                     result = true;
710                 } catch (SimulatorException e) {
711                     Activator
712                             .getDefault()
713                             .getLogManager()
714                             .log(Level.ERROR.ordinal(), new Date(),
715                                     Utility.getSimulatorErrorString(e, null));
716                 }
717             }
718         }
719         return result;
720     }
721
722     public void deleteResources(final Set<String> searchTypes) {
723         synchronized (resourceMap) {
724             if (null == resourceMap && resourceMap.isEmpty()) {
725                 return;
726             }
727         }
728         new Thread() {
729             public void run() {
730                 if (null == searchTypes || searchTypes.size() < 1) {
731                     synchronized (resourceMap) {
732                         // Stop observing all the resources
733                         Iterator<String> itr = resourceMap.keySet().iterator();
734                         while (itr.hasNext()) {
735                             sendCancelObserveRequest(
736                                     resourceMap.get(itr.next()), false);
737                         }
738                         // Delete all cached details of resources
739                         resourceMap.clear();
740                         favoriteResources.clear();
741
742                         // Clearing the device and platform information
743                         hostDeviceAndPlatformMap.clear();
744                     }
745                     // Change the current resource in selection
746                     setCurrentResourceInSelection(null);
747                     UiListenerHandler.getInstance()
748                             .resourceSelectionChangedUINotification(null);
749                 } else {
750                     Iterator<String> typeItr = searchTypes.iterator();
751                     String resType;
752                     while (typeItr.hasNext()) {
753                         resType = typeItr.next();
754                         deleteResourcesByType(resType);
755
756                         // Change the current resource in selection
757                         updateCurrentResourceInSelection(searchTypes);
758                     }
759                 }
760             }
761         }.start();
762     }
763
764     private void updateCurrentResourceInSelection(Set<String> searchTypes) {
765         if (null == searchTypes || searchTypes.size() < 1) {
766             return;
767         }
768         RemoteResource resourceInSelection = getCurrentResourceInSelection();
769         if (null == resourceInSelection) {
770             return;
771         }
772         List<String> typesOfSelection = resourceInSelection
773                 .getRemoteResourceRef().getResourceTypes();
774         if (null == typesOfSelection || typesOfSelection.size() < 1) {
775             return;
776         }
777         Iterator<String> itr = typesOfSelection.iterator();
778         String type;
779         while (itr.hasNext()) {
780             type = itr.next();
781             if (searchTypes.contains(type)) {
782                 setCurrentResourceInSelection(null);
783                 UiListenerHandler.getInstance()
784                         .resourceSelectionChangedUINotification(null);
785                 break;
786             }
787         }
788     }
789
790     private void deleteResourcesByType(String resourceType) {
791         if (null == resourceType) {
792             return;
793         }
794         synchronized (resourceMap) {
795             Set<String> keySet = resourceMap.keySet();
796             if (null == keySet) {
797                 return;
798             }
799             Iterator<String> keyItr = keySet.iterator();
800             String uId;
801             RemoteResource resource;
802             boolean exist;
803             List<String> types;
804             while (keyItr.hasNext()) {
805                 uId = keyItr.next();
806                 resource = resourceMap.get(uId);
807                 if (null == resource) {
808                     continue;
809                 }
810                 types = resource.getRemoteResourceRef().getResourceTypes();
811                 if (null != types) {
812                     exist = types.contains(resourceType);
813                     if (exist) {
814                         // Cancel observing the resource.
815                         sendCancelObserveRequest(resource, false);
816                         // Remove the resource from favorites list.
817                         removeResourceFromFavorites(resource);
818                         // Remove the resource
819                         keyItr.remove();
820                         // Remove the device and platform information
821                         synchronized (hostDeviceAndPlatformMap) {
822                             hostDeviceAndPlatformMap.remove(resource
823                                     .getRemoteResourceRef().getHost());
824                         }
825                     }
826                 }
827             }
828         }
829     }
830
831     public void resourceSelectionChanged(final RemoteResource resource) {
832         new Thread() {
833             @Override
834             public void run() {
835                 setCurrentResourceInSelection(resource);
836                 // Notify all observers for resource selection change event
837                 UiListenerHandler.getInstance()
838                         .resourceSelectionChangedUINotification(resource);
839             }
840         }.start();
841     }
842
843     public List<MetaProperty> getDefaultProperties(RemoteResource resource) {
844         if (null != resource) {
845             String propName;
846             String propValue;
847
848             List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
849
850             for (int index = 0; index < Constants.META_PROPERTY_COUNT; index++) {
851                 propName = Constants.META_PROPERTIES[index];
852                 if (propName.equals(Constants.RESOURCE_URI)) {
853                     propValue = resource.getRemoteResourceRef().getURI();
854                 } else if (propName.equals(Constants.CONNECTIVITY_TYPE)) {
855                     propValue = resource.getRemoteResourceRef()
856                             .getConnectivityType().toString();
857                 } else if (propName.equals(Constants.ADDRESS)) {
858                     propValue = resource.getRemoteResourceRef().getHost();
859                 } else if (propName.equals(Constants.OBSERVABLE)) {
860                     propValue = Utility.getObservableInString(resource
861                             .getRemoteResourceRef().isObservable());
862                 } else if (propName.equals(Constants.RESOURCE_TYPES)) {
863                     Vector<String> resTypes = resource.getRemoteResourceRef()
864                             .getResourceTypes();
865                     if (null != resTypes && !resTypes.isEmpty()) {
866                         propValue = "";
867                         Iterator<String> itr = resTypes.iterator();
868                         while (itr.hasNext()) {
869                             propValue += itr.next();
870                             if (itr.hasNext()) {
871                                 propValue += ", ";
872                             }
873                         }
874                     } else {
875                         propValue = Constants.NOT_AVAILABLE;
876                     }
877                 } else if (propName.equals(Constants.RESOURCE_INTERFACES)) {
878                     Vector<String> interfaces = resource.getRemoteResourceRef()
879                             .getResourceInterfaces();
880                     if (null != interfaces && !interfaces.isEmpty()) {
881                         propValue = "";
882                         Iterator<String> itr = interfaces.iterator();
883                         while (itr.hasNext()) {
884                             propValue += itr.next();
885                             if (itr.hasNext()) {
886                                 propValue += ", ";
887                             }
888                         }
889                     } else {
890                         propValue = Constants.NOT_AVAILABLE;
891                     }
892                 } else {
893                     propValue = null;
894                 }
895                 if (null != propValue) {
896                     metaPropertyList.add(new MetaProperty(propName, propValue));
897                 }
898             }
899
900             return metaPropertyList;
901         }
902         return null;
903     }
904
905     public List<MetaProperty> getDeviceProperties() {
906         if (null == currentResourceInSelection) {
907             return null;
908         }
909
910         SimulatorRemoteResource remoteResource = currentResourceInSelection
911                 .getRemoteResourceRef();
912         if (null == remoteResource) {
913             return null;
914         }
915
916         String host = remoteResource.getHost();
917         if (null == host) {
918             return null;
919         }
920
921         if (!isDeviceInfoExist(host)) {
922             // Device Information
923             try {
924                 SimulatorManager.findDevices(host, deviceListener);
925             } catch (SimulatorException e) {
926                 Activator
927                         .getDefault()
928                         .getLogManager()
929                         .log(Level.ERROR.ordinal(), new Date(),
930                                 Utility.getSimulatorErrorString(e, null));
931             }
932             return null;
933         }
934
935         List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
936         synchronized (hostDeviceAndPlatformMap) {
937             DeviceInfo devInfo = hostDeviceAndPlatformMap.get(host)
938                     .getDeviceInfo();
939             metaProperties.add(new MetaProperty(Constants.DEVICE_ID, devInfo
940                     .getID()));
941             metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, devInfo
942                     .getName()));
943             metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
944                     devInfo.getSpecVersion()));
945             metaProperties.add(new MetaProperty(Constants.DEVICE_DMV_VERSION,
946                     devInfo.getDataModelVersion()));
947         }
948
949         return metaProperties;
950     }
951
952     public List<MetaProperty> getPlatformProperties() {
953         if (null == currentResourceInSelection) {
954             return null;
955         }
956
957         SimulatorRemoteResource remoteResource = currentResourceInSelection
958                 .getRemoteResourceRef();
959         if (null == remoteResource) {
960             return null;
961         }
962
963         String host = remoteResource.getHost();
964         if (null == host) {
965             return null;
966         }
967
968         if (!isPlatformInfoExist(host)) {
969             // Platform Information
970             try {
971                 SimulatorManager.getPlatformInformation(host, platformListener);
972             } catch (SimulatorException e) {
973                 Activator
974                         .getDefault()
975                         .getLogManager()
976                         .log(Level.ERROR.ordinal(), new Date(),
977                                 Utility.getSimulatorErrorString(e, null));
978             }
979             return null;
980         }
981
982         List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
983         synchronized (hostDeviceAndPlatformMap) {
984             PlatformInfo platInfo = hostDeviceAndPlatformMap.get(host)
985                     .getPlatformInfo();
986             metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platInfo
987                     .getPlatformID()));
988             metaProperties.add(new MetaProperty(
989                     Constants.PLATFORM_MANUFAC_NAME, platInfo
990                             .getManufacturerName()));
991             metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_URL,
992                     platInfo.getManufacturerUrl()));
993             metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
994                     platInfo.getModelNumber()));
995             metaProperties.add(new MetaProperty(
996                     Constants.PLATFORM_DATE_OF_MANUFAC, platInfo
997                             .getDateOfManufacture()));
998             metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION,
999                     platInfo.getPlatformVersion()));
1000             metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
1001                     platInfo.getOperationSystemVersion()));
1002             metaProperties.add(new MetaProperty(
1003                     Constants.PLATFORM_HARDWARE_VERSION, platInfo
1004                             .getHardwareVersion()));
1005             metaProperties.add(new MetaProperty(
1006                     Constants.PLATFORM_FIRMWARE_VERSION, platInfo
1007                             .getFirmwareVersion()));
1008             metaProperties.add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
1009                     platInfo.getSupportUrl()));
1010             metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME,
1011                     platInfo.getSystemTime()));
1012         }
1013         return metaProperties;
1014     }
1015
1016     public Map<String, Boolean> getAutomationStatus(RemoteResource resource) {
1017         if (null == resource) {
1018             return null;
1019         }
1020         Map<String, Boolean> autoStatus = new HashMap<String, Boolean>();
1021         autoStatus.put(Constants.GET, resource.isGetAutomtnInProgress());
1022         autoStatus.put(Constants.PUT, resource.isPutAutomtnInProgress());
1023         autoStatus.put(Constants.POST, resource.isPostAutomtnInProgress());
1024         return autoStatus;
1025     }
1026
1027     public List<RemoteResource> getResourceList() {
1028         List<RemoteResource> resourceList = new ArrayList<RemoteResource>();
1029         synchronized (resourceMap) {
1030             Set<String> idSet = resourceMap.keySet();
1031             Iterator<String> idItr = idSet.iterator();
1032             RemoteResource resource;
1033             while (idItr.hasNext()) {
1034                 resource = resourceMap.get(idItr.next());
1035                 if (null != resource) {
1036                     resourceList.add(resource);
1037                 }
1038             }
1039         }
1040         // Sort the list
1041         Collections.sort(resourceList, new Comparator<RemoteResource>() {
1042             public int compare(RemoteResource res1, RemoteResource res2) {
1043                 String s1 = res1.getRemoteResourceRef().getURI();
1044                 String s2 = res2.getRemoteResourceRef().getURI();
1045
1046                 String s1Part = s1.replaceAll("\\d", "");
1047                 String s2Part = s2.replaceAll("\\d", "");
1048
1049                 if (s1Part.equalsIgnoreCase(s2Part)) {
1050                     return extractInt(s1) - extractInt(s2);
1051                 }
1052                 return s1.compareTo(s2);
1053             }
1054
1055             int extractInt(String s) {
1056                 String num = s.replaceAll("\\D", "");
1057                 // return 0 if no digits found
1058                 return num.isEmpty() ? 0 : Integer.parseInt(num);
1059             }
1060         });
1061
1062         return resourceList;
1063     }
1064
1065     public List<RemoteResource> getFavResourceList() {
1066         List<RemoteResource> resourceList;
1067         synchronized (favoriteResources) {
1068             resourceList = new ArrayList<RemoteResource>(favoriteResources);
1069         }
1070         return resourceList;
1071     }
1072
1073     public List<String> getAllValuesOfAttribute(SimulatorResourceAttribute att) {
1074         if (null == att) {
1075             return null;
1076         }
1077
1078         AttributeValue val = att.value();
1079         if (null == val || null == val.get()) {
1080             return null;
1081         }
1082
1083         TypeInfo type = val.typeInfo();
1084
1085         if (type.mType == ValueType.RESOURCEMODEL
1086                 || type.mBaseType == ValueType.RESOURCEMODEL) {
1087             return null;
1088         }
1089
1090         List<String> values = new ArrayList<String>();
1091
1092         AttributeProperty prop = att.property();
1093         if (null == prop) {
1094             values.add(new AttributeValueStringConverter(val).toString());
1095             return values;
1096         }
1097
1098         if (type.mType == ValueType.ARRAY) {
1099             if (type.mDepth == 1) {
1100                 ArrayProperty arrayProperty = prop.asArray();
1101                 if (null != arrayProperty) {
1102                     AttributeProperty childProp = arrayProperty
1103                             .getElementProperty();
1104                     switch (childProp.getType()) {
1105                         case INTEGER:
1106                             IntegerProperty intProperty = childProp.asInteger();
1107                             if (null != intProperty) {
1108                                 values.addAll(getAllValues(intProperty,
1109                                         Type.INTEGER));
1110                             }
1111                             break;
1112                         case DOUBLE:
1113                             DoubleProperty dblProperty = childProp.asDouble();
1114                             if (null != dblProperty) {
1115                                 values.addAll(getAllValues(dblProperty,
1116                                         Type.DOUBLE));
1117                             }
1118                             break;
1119                         case BOOLEAN:
1120                             BooleanProperty boolProperty = childProp
1121                                     .asBoolean();
1122                             if (null != boolProperty) {
1123                                 values.addAll(getAllValues(boolProperty,
1124                                         Type.BOOLEAN));
1125                             }
1126                             break;
1127                         case STRING:
1128                             StringProperty stringProperty = childProp
1129                                     .asString();
1130                             if (null != stringProperty) {
1131                                 values.addAll(getAllValues(stringProperty,
1132                                         Type.STRING));
1133                             }
1134                             break;
1135                         default:
1136                             break;
1137                     }
1138                 }
1139             }
1140         } else {
1141             switch (prop.getType()) {
1142                 case INTEGER:
1143                     IntegerProperty intProperty = prop.asInteger();
1144                     if (null != intProperty) {
1145                         values.addAll(getAllValues(intProperty, Type.INTEGER));
1146                     }
1147                     break;
1148                 case DOUBLE:
1149                     DoubleProperty dblProperty = prop.asDouble();
1150                     if (null != dblProperty) {
1151                         values.addAll(getAllValues(dblProperty, Type.DOUBLE));
1152                     }
1153                     break;
1154                 case BOOLEAN:
1155                     BooleanProperty boolProperty = prop.asBoolean();
1156                     if (null != boolProperty) {
1157                         values.addAll(getAllValues(boolProperty, Type.BOOLEAN));
1158                     }
1159                     break;
1160                 case STRING:
1161                     StringProperty stringProperty = prop.asString();
1162                     if (null != stringProperty) {
1163                         values.addAll(getAllValues(stringProperty, Type.STRING));
1164                     }
1165                     break;
1166                 default:
1167                     break;
1168             }
1169         }
1170
1171         return values;
1172     }
1173
1174     public List<String> getAllValues(IntegerProperty intProperty,
1175             AttributeProperty.Type type) {
1176         List<String> values = new ArrayList<String>();
1177
1178         if (intProperty.hasRange()) {
1179             int min = (int) intProperty.min();
1180             int max = (int) intProperty.max();
1181             for (int iVal = min; iVal <= max; iVal++) {
1182                 values.add(String.valueOf(iVal));
1183             }
1184         } else if (intProperty.hasValues()) {
1185             for (Integer val : intProperty.getValues()) {
1186                 values.add(String.valueOf(val));
1187             }
1188         } else {
1189             // Adding the default value.
1190             values.add(String.valueOf(intProperty.getDefaultValue()));
1191         }
1192         return values;
1193     }
1194
1195     public List<String> getAllValues(DoubleProperty dblProperty,
1196             AttributeProperty.Type type) {
1197         List<String> values = new ArrayList<String>();
1198
1199         if (dblProperty.hasRange()) {
1200             double min = (double) dblProperty.min();
1201             double max = (double) dblProperty.max();
1202             for (double iVal = min; iVal <= max; iVal = iVal + 1) {
1203                 values.add(String.valueOf(iVal));
1204             }
1205         } else if (dblProperty.hasValues()) {
1206             for (Double val : dblProperty.getValues()) {
1207                 values.add(String.valueOf(val));
1208             }
1209         } else {
1210             // Adding the default value.
1211             values.add(String.valueOf(dblProperty.getDefaultValue()));
1212         }
1213         return values;
1214     }
1215
1216     public List<String> getAllValues(BooleanProperty boolProperty,
1217             AttributeProperty.Type type) {
1218         List<String> values = new ArrayList<String>();
1219         values.add("true");
1220         values.add("false");
1221         return values;
1222     }
1223
1224     public List<String> getAllValues(StringProperty stringProperty,
1225             AttributeProperty.Type type) {
1226         List<String> values = new ArrayList<String>();
1227
1228         if (stringProperty.hasValues()) {
1229             for (String val : stringProperty.getValues()) {
1230                 values.add(String.valueOf(val));
1231             }
1232         } else {
1233             // Adding the default value.
1234             values.add(String.valueOf(stringProperty.getDefaultValue()));
1235         }
1236         return values;
1237     }
1238
1239     public void sendGetRequest(String ifType, String query,
1240             RemoteResource resource) {
1241         if (null == resource) {
1242             return;
1243         }
1244         SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
1245         if (null == resourceN) {
1246             return;
1247         }
1248
1249         Map<String, String> queryParams = formQueryParameters(ifType, query);
1250         try {
1251             resourceN.get(queryParams, getListener);
1252         } catch (SimulatorException e) {
1253             Activator
1254                     .getDefault()
1255                     .getLogManager()
1256                     .log(Level.ERROR.ordinal(), new Date(),
1257                             Utility.getSimulatorErrorString(e, null));
1258         }
1259     }
1260
1261     public void sendPutRequest(String ifType, RemoteResource resource,
1262             SimulatorResourceModel model) {
1263         if (null == resource || null == model) {
1264             return;
1265         }
1266         SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
1267         if (null == resourceN) {
1268             return;
1269         }
1270         Map<String, String> queryParams = formQueryParameters(ifType, null);
1271         try {
1272             resourceN.put(queryParams, model, putListener);
1273         } catch (Exception e) {
1274             String addlInfo;
1275             addlInfo = "Invalid Attribute Value. Cannot send PUT request.";
1276             Activator
1277                     .getDefault()
1278                     .getLogManager()
1279                     .log(Level.ERROR.ordinal(), new Date(),
1280                             Utility.getSimulatorErrorString(e, addlInfo));
1281         }
1282     }
1283
1284     public void sendPostRequest(String ifType, RemoteResource resource,
1285             SimulatorResourceModel model) {
1286         if (null == resource || null == model) {
1287             return;
1288         }
1289         SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
1290         if (null == resourceN) {
1291             return;
1292         }
1293         Map<String, String> queryParams = formQueryParameters(ifType, null);
1294         try {
1295             resourceN.post(queryParams, model, postListener);
1296         } catch (Exception e) {
1297             String addlInfo;
1298             addlInfo = "Invalid Attribute Value. Cannot send POST request.";
1299             Activator
1300                     .getDefault()
1301                     .getLogManager()
1302                     .log(Level.ERROR.ordinal(), new Date(),
1303                             Utility.getSimulatorErrorString(e, addlInfo));
1304         }
1305     }
1306
1307     public boolean sendObserveRequest(RemoteResource resource) {
1308         if (null == resource) {
1309             return false;
1310         }
1311         SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
1312         if (null == resourceN) {
1313             return false;
1314         }
1315         try {
1316             resourceN.observe(observeListener);
1317             resource.setObserved(true);
1318             // Add observed resource URI to show the proper status after every
1319             // find/refresh operations.
1320             addObservedResourceURI(resource.getRemoteResourceRef().getURI());
1321         } catch (SimulatorException e) {
1322             Activator
1323                     .getDefault()
1324                     .getLogManager()
1325                     .log(Level.ERROR.ordinal(), new Date(),
1326                             Utility.getSimulatorErrorString(e, null));
1327             return false;
1328         }
1329         return true;
1330     }
1331
1332     private Map<String, String> formQueryParameters(String ifType, String query) {
1333         Map<String, String> queryParams = new HashMap<String, String>();
1334
1335         // Including the interface type, if given,
1336         if (null != ifType) {
1337             ifType = ifType.trim();
1338             if (ifType.length() > 0)
1339                 queryParams.put("if", ifType);
1340         }
1341
1342         // Including other queries, if given.
1343         if (null != query) {
1344             query = query.trim();
1345             if (query.length() > 0) {
1346                 // Parse the query parameters and fill the map.
1347                 String queries[] = query.split(";");
1348                 if (queries.length > 0) {
1349                     for (String pair : queries) {
1350                         String tok[] = pair.split("=");
1351                         if (null != tok && tok.length == 2) {
1352                             queryParams.put(tok[0].trim(), tok[1].trim());
1353                         }
1354                     }
1355                 }
1356             }
1357         }
1358         return queryParams;
1359     }
1360
1361     public boolean sendCancelObserveRequest(RemoteResource resource,
1362             boolean removeEntry) {
1363         if (null == resource || !resource.isObserved()) {
1364             return false;
1365         }
1366         SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
1367         if (null == resourceN) {
1368             return false;
1369         }
1370         try {
1371             resourceN.stopObserve();
1372             resource.setObserved(false);
1373             // Remove observed resource URI to show the proper status after
1374             // every find/refresh operations.
1375             if (removeEntry)
1376                 removeObservedResourceURI(resource.getRemoteResourceRef()
1377                         .getURI());
1378         } catch (SimulatorException e) {
1379             Activator
1380                     .getDefault()
1381                     .getLogManager()
1382                     .log(Level.ERROR.ordinal(), new Date(),
1383                             Utility.getSimulatorErrorString(e, null));
1384             return false;
1385         }
1386         return true;
1387     }
1388
1389     public void startAutomationRequest(VerificationType reqType,
1390             RemoteResource resource) {
1391         if (null == resource) {
1392             return;
1393         }
1394         SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
1395         if (null == resourceN) {
1396             return;
1397         }
1398         if (null == reqType) {
1399             return;
1400         }
1401         int autoId;
1402         try {
1403             autoId = resourceN.startVerification(reqType, verifyListener);
1404             if (autoId != -1) {
1405                 if (reqType == VerificationType.GET) {
1406                     resource.setGetAutomtnId(autoId);
1407                 } else if (reqType == VerificationType.PUT) {
1408                     resource.setPutAutomtnId(autoId);
1409                 } else {
1410                     resource.setPostAutomtnId(autoId);
1411                 }
1412             }
1413             Activator
1414                     .getDefault()
1415                     .getLogManager()
1416                     .log(Level.INFO.ordinal(),
1417                             new Date(),
1418                             "[" + reqType.toString()
1419                                     + "] Verification Started for \""
1420                                     + resourceN.getURI() + "\".");
1421         } catch (SimulatorException e) {
1422             Activator
1423                     .getDefault()
1424                     .getLogManager()
1425                     .log(Level.ERROR.ordinal(), new Date(),
1426                             Utility.getSimulatorErrorString(e, null));
1427         }
1428     }
1429
1430     public void stopAutomationRequest(VerificationType reqType,
1431             RemoteResource resource) {
1432         if (null == resource) {
1433             return;
1434         }
1435         SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
1436         if (null == resourceN) {
1437             return;
1438         }
1439         int autoId;
1440         if (reqType == VerificationType.GET) {
1441             resource.setGetAutomtnInProgress(false);
1442             autoId = resource.getGetAutomtnId();
1443         } else if (reqType == VerificationType.PUT) {
1444             resource.setPutAutomtnInProgress(false);
1445             autoId = resource.getPutAutomtnId();
1446         } else {
1447             resource.setPostAutomtnInProgress(false);
1448             autoId = resource.getPostAutomtnId();
1449         }
1450         try {
1451             resourceN.stopVerification(autoId);
1452         } catch (SimulatorException e) {
1453             Activator
1454                     .getDefault()
1455                     .getLogManager()
1456                     .log(Level.ERROR.ordinal(), new Date(),
1457                             Utility.getSimulatorErrorString(e, null));
1458         }
1459     }
1460
1461     public boolean setConfigFilePath(RemoteResource resource,
1462             String configFilePath) throws SimulatorException {
1463         if (null == resource) {
1464             return false;
1465         }
1466         SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
1467         if (null == resourceN) {
1468             return false;
1469         }
1470         try {
1471             SimulatorResourceModel configuredResourceModel;
1472             configuredResourceModel = resourceN.setConfigInfo(configFilePath);
1473             if (null == configuredResourceModel) {
1474                 return false;
1475             }
1476
1477             // Store the resource model in the local cache
1478             /*
1479              * SimulatorResourceModel resourceModel = resource
1480              * .getResourceModelRef(); if (null != resourceModel) {
1481              * configuredResourceModel.update(resourceModel); }
1482              * resource.setResourceModelRef(configuredResourceModel);
1483              */
1484         } catch (SimulatorException e) {
1485             Activator
1486                     .getDefault()
1487                     .getLogManager()
1488                     .log(Level.ERROR.ordinal(), new Date(),
1489                             Utility.getSimulatorErrorString(e, null));
1490             throw e;
1491         }
1492         // Update the status
1493         resource.setConfigUploaded(true);
1494
1495         // Notify the UI listeners
1496         UiListenerHandler.getInstance().configUploadedNotification(resource);
1497
1498         return true;
1499     }
1500
1501     public void shutdown() {
1502     }
1503 }