Imported Upstream version 1.0.1
[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.net.URL;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.Comparator;
23 import java.util.Date;
24 import java.util.HashMap;
25 import java.util.Iterator;
26 import java.util.LinkedList;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
30
31 import oic.simulator.clientcontroller.Activator;
32 import oic.simulator.clientcontroller.listener.IConfigurationUpload;
33 import oic.simulator.clientcontroller.listener.IFindResourceUIListener;
34 import oic.simulator.clientcontroller.listener.IGetUIListener;
35 import oic.simulator.clientcontroller.listener.IObserveUIListener;
36 import oic.simulator.clientcontroller.listener.IPostUIListener;
37 import oic.simulator.clientcontroller.listener.IPutUIListener;
38 import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
39 import oic.simulator.clientcontroller.listener.IVerificationUIListener;
40 import oic.simulator.clientcontroller.remoteresource.MetaProperty;
41 import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
42 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
43 import oic.simulator.clientcontroller.remoteresource.RemoteResourceAttribute;
44 import oic.simulator.clientcontroller.utils.Constants;
45 import oic.simulator.clientcontroller.utils.Utility;
46
47 import org.eclipse.jface.resource.ImageDescriptor;
48 import org.eclipse.swt.graphics.Image;
49 import org.oic.simulator.ILogger.Level;
50 import org.oic.simulator.ResourceAttribute;
51 import org.oic.simulator.ResourceAttribute.Range;
52 import org.oic.simulator.ResourceAttribute.Type;
53 import org.oic.simulator.SimulatorException;
54 import org.oic.simulator.SimulatorManager;
55 import org.oic.simulator.SimulatorResourceModel;
56 import org.oic.simulator.clientcontroller.IFindResourceListener;
57 import org.oic.simulator.clientcontroller.IGetListener;
58 import org.oic.simulator.clientcontroller.IObserveListener;
59 import org.oic.simulator.clientcontroller.IPostListener;
60 import org.oic.simulator.clientcontroller.IPutListener;
61 import org.oic.simulator.clientcontroller.IVerificationListener;
62 import org.oic.simulator.clientcontroller.SimulatorObserveType;
63 import org.oic.simulator.clientcontroller.SimulatorRemoteResource;
64 import org.oic.simulator.clientcontroller.SimulatorVerificationType;
65
66 /**
67  * This class acts as an interface between the simulator java SDK and the
68  * various UI modules. It maintains all the details of resources and provides
69  * other UI modules with the information required. It also handles responses for
70  * find, GET, PUT, POST, Observe and automatic verification operations from
71  * native layer and propagates those events to the registered UI listeners.
72  */
73 public class ResourceManager {
74
75     private Set<String>                               lastKnownSearchTypes;
76
77     private RemoteResource                            currentResourceInSelection;
78
79     private IFindResourceListener                     findResourceListener;
80     private IGetListener                              getListener;
81     private IPutListener                              putListener;
82     private IPostListener                             postListener;
83     private IObserveListener                          observeListener;
84     private IVerificationListener                     verifyListener;
85
86     private ResponseSynchronizerThread                synchronizerThread;
87
88     private Thread                                    threadHandle;
89
90     private List<IFindResourceUIListener>             findResourceUIListeners;
91     private List<IResourceSelectionChangedUIListener> resourceSelectionChangedUIListeners;
92     private List<IGetUIListener>                      getUIListeners;
93     private List<IPutUIListener>                      putUIListeners;
94     private List<IPostUIListener>                     postUIListeners;
95     private List<IObserveUIListener>                  observeUIListeners;
96     private List<IVerificationUIListener>             verificationUIListeners;
97     private List<IConfigurationUpload>                configUploadUIListeners;
98
99     // Map with Server ID as key and the complete object as the value
100     private Map<String, RemoteResource>               resourceMap;
101     private List<RemoteResource>                      favoriteResources;
102     // Maintaining a list of resource URIs for favorite resources feature.
103     private List<String>                              favoriteURIList;
104
105     // Maintaining a list of observed resource URIs.
106     private List<String>                              observedResourceURIList;
107
108     public ResourceManager() {
109         resourceMap = new HashMap<String, RemoteResource>();
110         favoriteResources = new ArrayList<RemoteResource>();
111         favoriteURIList = new ArrayList<String>();
112         observedResourceURIList = new ArrayList<String>();
113         findResourceUIListeners = new ArrayList<IFindResourceUIListener>();
114         resourceSelectionChangedUIListeners = new ArrayList<IResourceSelectionChangedUIListener>();
115         getUIListeners = new ArrayList<IGetUIListener>();
116         putUIListeners = new ArrayList<IPutUIListener>();
117         postUIListeners = new ArrayList<IPostUIListener>();
118         observeUIListeners = new ArrayList<IObserveUIListener>();
119         verificationUIListeners = new ArrayList<IVerificationUIListener>();
120         configUploadUIListeners = new ArrayList<IConfigurationUpload>();
121
122         findResourceListener = new IFindResourceListener() {
123
124             @Override
125             public void onResourceCallback(
126                     final SimulatorRemoteResource resourceN) {
127                 synchronizerThread.addToQueue(new Runnable() {
128                     @Override
129                     public void run() {
130                         System.out.println("onResourceCallback() entry");
131                         if (null == resourceN) {
132                             return;
133                         }
134                         // If resource already exist, then ignore it.
135                         String uid = resourceN.getId();
136                         if (null == uid) {
137                             return;
138                         }
139                         boolean exist = isUidExist(uid);
140                         if (exist) {
141                             System.out.println("Duplicate resource found: ["
142                                     + uid + "]");
143                             return;
144                         }
145
146                         // Fetch the resource data
147                         RemoteResource resource = fetchResourceDetails(resourceN);
148                         if (null == resource) {
149                             return;
150                         }
151
152                         resource.setResource(resourceN);
153
154                         String uri = resource.getResourceURI();
155                         if (null != uri) {
156                             // Add resource to favorite list if it was in
157                             // favorites list during find/refresh operation.
158                             if (favoriteURIList.contains(uri)) {
159                                 addResourcetoFavorites(resource);
160                             }
161                             // Add resource to observed resources list if it was
162                             // in observe list during find/refresh operation.
163                             if (observedResourceURIList.contains(uri)) {
164                                 resource.setObserved(true);
165                             }
166                         }
167
168                         // Add the resource in local data structure
169                         addResourceDetails(resource);
170
171                         // Notify the UI listener
172                         newResourceFoundNotification(resource);
173
174                         // Send an initial GET request to get the resource
175                         // attributes
176                         try {
177                             resourceN.get(null, getListener);
178                         } catch (SimulatorException e) {
179                             Activator
180                                     .getDefault()
181                                     .getLogManager()
182                                     .log(Level.ERROR.ordinal(),
183                                             new Date(),
184                                             "[" + e.getClass().getSimpleName()
185                                                     + "]" + e.code().toString()
186                                                     + "-" + e.message());
187                         }
188                     }
189                 });
190             }
191         };
192
193         getListener = new IGetListener() {
194             @Override
195             public void onGetCompleted(final String uid,
196                     final SimulatorResourceModel resourceModelN) {
197                 synchronizerThread.addToQueue(new Runnable() {
198                     @Override
199                     public void run() {
200                         // Handling the response which includes retrieving the
201                         // attributes and updating the local model.
202                         RemoteResource resource = handleResponse(uid,
203                                 resourceModelN);
204                         if (null != resource) {
205                             // Notify the UI listeners
206                             getCompleteNotification(resource);
207                         }
208                     }
209                 });
210             }
211
212             @Override
213             public void onGetFailed(Throwable th) {
214                 synchronizerThread.addToQueue(new Runnable() {
215                     @Override
216                     public void run() {
217                     }
218                 });
219             }
220         };
221
222         putListener = new IPutListener() {
223
224             @Override
225             public void onPutCompleted(final String uid,
226                     final SimulatorResourceModel resourceModelN) {
227                 synchronizerThread.addToQueue(new Thread() {
228                     @Override
229                     public void run() {
230                         // Handling the response which includes retrieving the
231                         // attributes and updating the local model.
232                         RemoteResource resource = handleResponse(uid,
233                                 resourceModelN);
234                         if (null != resource) {
235                             // Notify the UI listeners
236                             putCompleteNotification(resource);
237                         }
238                     }
239                 });
240             }
241
242             @Override
243             public void onPutFailed(Throwable th) {
244                 synchronizerThread.addToQueue(new Runnable() {
245                     @Override
246                     public void run() {
247                     }
248                 });
249             }
250         };
251
252         postListener = new IPostListener() {
253             @Override
254             public void onPostCompleted(final String uid,
255                     final SimulatorResourceModel resourceModelN) {
256                 synchronizerThread.addToQueue(new Runnable() {
257                     @Override
258                     public void run() {
259                         // Handling the response which includes retrieving the
260                         // attributes and updating the local model.
261                         RemoteResource resource = handleResponse(uid,
262                                 resourceModelN);
263                         if (null != resource) {
264                             // Notify the UI listeners
265                             postCompleteNotification(resource);
266                         }
267                     }
268                 });
269             }
270
271             @Override
272             public void onPostFailed(Throwable th) {
273                 synchronizerThread.addToQueue(new Runnable() {
274                     @Override
275                     public void run() {
276                     }
277                 });
278             }
279         };
280
281         observeListener = new IObserveListener() {
282
283             @Override
284             public void onObserveCompleted(final String uid,
285                     final SimulatorResourceModel resourceModelN, final int seq) {
286                 System.out.println("ResourceManager: onObserveCallback()");
287                 synchronizerThread.addToQueue(new Runnable() {
288                     @Override
289                     public void run() {
290                         // Handling the response which includes retrieving the
291                         // attributes and updating the local model.
292                         RemoteResource resource = handleResponse(uid,
293                                 resourceModelN);
294                         if (null != resource) {
295                             // Notify the UI listeners
296                             observeCompleteNotification(resource);
297                         }
298                     }
299                 });
300             }
301
302             @Override
303             public void onObserveFailed(Throwable th) {
304                 // TODO Auto-generated method stub
305             }
306         };
307
308         verifyListener = new IVerificationListener() {
309
310             @Override
311             public void onVerificationStarted(final String uid, final int autoId) {
312                 System.out.println("onVefificationStarted: " + autoId);
313                 synchronizerThread.addToQueue(new Runnable() {
314                     @Override
315                     public void run() {
316                         RemoteResource resource = getResource(uid);
317                         if (null == resource) {
318                             return;
319                         }
320                         // Update the automation status.
321                         resource.updateAutomationStatus(autoId, true);
322
323                         int autoType = resource.getAutomationtype(autoId);
324
325                         // Notify the listeners.
326                         verificationStartedNotification(resource, autoType);
327                     }
328                 });
329             }
330
331             @Override
332             public void onVerificationCompleted(final String uid,
333                     final int autoId) {
334                 System.out.println("onVefificationCompleted: " + autoId);
335                 synchronizerThread.addToQueue(new Runnable() {
336                     @Override
337                     public void run() {
338                         RemoteResource resource = getResource(uid);
339                         if (null == resource) {
340                             return;
341                         }
342                         // Update the automation status.
343                         resource.updateAutomationStatus(autoId, false);
344
345                         int autoType = resource.getAutomationtype(autoId);
346
347                         // Notify the listeners.
348                         verificationCompletedNotification(resource, autoType);
349                     }
350                 });
351             }
352
353             @Override
354             public void onVerificationAborted(final String uid, final int autoId) {
355                 System.out.println("onVefificationAborted: " + autoId);
356                 synchronizerThread.addToQueue(new Runnable() {
357                     @Override
358                     public void run() {
359                         RemoteResource resource = getResource(uid);
360                         if (null == resource) {
361                             return;
362                         }
363                         // Update the automation status.
364                         resource.updateAutomationStatus(autoId, false);
365
366                         int autoType = resource.getAutomationtype(autoId);
367
368                         // Notify the listeners.
369                         verificationAbortedNotification(resource, autoType);
370                     }
371                 });
372             }
373         };
374
375         synchronizerThread = new ResponseSynchronizerThread();
376         threadHandle = new Thread(synchronizerThread);
377         threadHandle.setName("Simulator Client Controller Event Queue");
378         threadHandle.start();
379     }
380
381     private RemoteResource handleResponse(String uid,
382             SimulatorResourceModel resourceModelN) {
383         if (null == uid || null == resourceModelN) {
384             return null;
385         }
386
387         // Update the local model
388         RemoteResource resource;
389         resource = getResource(uid);
390         if (null == resource) {
391             return null;
392         }
393
394         resource.setResourceModel(resourceModelN);
395         Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModelN);
396
397         // TODO: For debugging
398         if (null != attributeMap) {
399             RemoteResourceAttribute.printAttributes(attributeMap);
400             System.out.println("Attributes found: " + (null != attributeMap));
401             System.out.println("No of attributes: " + attributeMap.size());
402
403             resource.setResourceAttributesMap(attributeMap);
404         }
405         return resource;
406     }
407
408     private static class ResponseSynchronizerThread implements Runnable {
409
410         LinkedList<Runnable> responseQueue = new LinkedList<Runnable>();
411
412         @Override
413         public void run() {
414             while (!Thread.interrupted()) {
415                 synchronized (this) {
416                     try {
417                         while (responseQueue.isEmpty()) {
418                             this.wait();
419                             break;
420                         }
421                     } catch (InterruptedException e) {
422                         return;
423                     }
424                 }
425
426                 Runnable thread;
427                 synchronized (this) {
428                     thread = responseQueue.pop();
429                 }
430                 try {
431                     thread.run();
432                 } catch (Exception e) {
433                     if (e instanceof InterruptedException) {
434                         return;
435                     }
436                     e.printStackTrace();
437                 }
438             }
439         }
440
441         public void addToQueue(Runnable event) {
442             synchronized (this) {
443                 responseQueue.add(event);
444                 this.notify();
445             }
446         }
447     }
448
449     public void addResourceSelectionChangedUIListener(
450             IResourceSelectionChangedUIListener resourceSelectionChangedUIListener) {
451         synchronized (resourceSelectionChangedUIListeners) {
452             resourceSelectionChangedUIListeners
453                     .add(resourceSelectionChangedUIListener);
454         }
455     }
456
457     public void addGetUIListener(IGetUIListener getUIListener) {
458         synchronized (getUIListeners) {
459             getUIListeners.add(getUIListener);
460         }
461     }
462
463     public void addPutUIListener(IPutUIListener putUIListener) {
464         synchronized (putUIListeners) {
465             putUIListeners.add(putUIListener);
466         }
467     }
468
469     public void addPostUIListener(IPostUIListener postUIListener) {
470         synchronized (postUIListeners) {
471             postUIListeners.add(postUIListener);
472         }
473     }
474
475     public void addObserveUIListener(IObserveUIListener observeUIListener) {
476         synchronized (observeUIListeners) {
477             observeUIListeners.add(observeUIListener);
478         }
479     }
480
481     public void addVerificationUIListener(
482             IVerificationUIListener verificationUIListener) {
483         synchronized (verificationUIListeners) {
484             verificationUIListeners.add(verificationUIListener);
485         }
486     }
487
488     public void addConfigUploadUIListener(IConfigurationUpload configListener) {
489         synchronized (configUploadUIListeners) {
490             configUploadUIListeners.add(configListener);
491         }
492     }
493
494     public void removeResourceSelectionChangedUIListener(
495             IResourceSelectionChangedUIListener listener) {
496         synchronized (resourceSelectionChangedUIListeners) {
497             if (null != listener
498                     && resourceSelectionChangedUIListeners.size() > 0) {
499                 resourceSelectionChangedUIListeners.remove(listener);
500             }
501         }
502     }
503
504     public void removeGetUIListener(IGetUIListener getUIListener) {
505         synchronized (getUIListeners) {
506             getUIListeners.remove(getUIListener);
507         }
508     }
509
510     public void removePutUIListener(IPutUIListener putUIListener) {
511         synchronized (putUIListeners) {
512             putUIListeners.remove(putUIListener);
513         }
514     }
515
516     public void removePostUIListener(IPostUIListener postUIListener) {
517         synchronized (postUIListeners) {
518             postUIListeners.remove(postUIListener);
519         }
520     }
521
522     public void removeObserveUIListener(IObserveUIListener observeUIListener) {
523         synchronized (observeUIListeners) {
524             observeUIListeners.remove(observeUIListener);
525         }
526     }
527
528     public void removeVerificationUIListener(
529             IVerificationUIListener verificationUIListener) {
530         synchronized (verificationUIListeners) {
531             verificationUIListeners.remove(verificationUIListener);
532         }
533     }
534
535     public void removeConfigUploadUIListener(IConfigurationUpload configListener) {
536         synchronized (configUploadUIListeners) {
537             configUploadUIListeners.remove(configListener);
538         }
539     }
540
541     public void addResourcetoFavorites(RemoteResource resource) {
542         if (null == resource) {
543             return;
544         }
545         resource.setFavorite(true);
546         synchronized (favoriteResources) {
547             favoriteResources.add(resource);
548             favoriteURIList.add(resource.getResourceURI());
549         }
550     }
551
552     public void removeResourceFromFavorites(RemoteResource resource) {
553         if (null == resource) {
554             return;
555         }
556         resource.setFavorite(false);
557         synchronized (favoriteResources) {
558             favoriteResources.remove(resource);
559         }
560     }
561
562     public void removeResourceURIFromFavorites(RemoteResource resource) {
563         if (null == resource) {
564             return;
565         }
566         synchronized (favoriteURIList) {
567             favoriteURIList.remove(resource.getResourceURI());
568         }
569     }
570
571     public void addObservedResourceURI(String resourceURI) {
572         synchronized (observedResourceURIList) {
573             observedResourceURIList.add(resourceURI);
574         }
575     }
576
577     public void removeObservedResourceURI(String resourceURI) {
578         synchronized (observedResourceURIList) {
579             observedResourceURIList.remove(resourceURI);
580         }
581     }
582
583     public boolean isResourceObserved(String resourceURI) {
584         boolean observed = false;
585         synchronized (observedResourceURIList) {
586             observed = observedResourceURIList.contains(resourceURI);
587         }
588         return observed;
589     }
590
591     public synchronized RemoteResource getCurrentResourceInSelection() {
592         return currentResourceInSelection;
593     }
594
595     public synchronized void setCurrentResourceInSelection(
596             RemoteResource resource) {
597         this.currentResourceInSelection = resource;
598     }
599
600     private void addResourceDetails(RemoteResource remoteResource) {
601         if (null != remoteResource) {
602             synchronized (resourceMap) {
603                 resourceMap.put(remoteResource.getuId(), remoteResource);
604             }
605         }
606     }
607
608     public void addFindresourceUIListener(IFindResourceUIListener listener) {
609         if (null == listener) {
610             return;
611         }
612         synchronized (findResourceUIListeners) {
613             findResourceUIListeners.add(listener);
614         }
615     }
616
617     public void removeFindresourceUIListener(IFindResourceUIListener listener) {
618         if (null == listener) {
619             return;
620         }
621         synchronized (findResourceUIListeners) {
622             findResourceUIListeners.remove(listener);
623         }
624     }
625
626     private RemoteResource fetchResourceDetails(
627             SimulatorRemoteResource remoteResourceN) {
628         if (null == remoteResourceN) {
629             return null;
630         }
631         RemoteResource remoteResource = new RemoteResource();
632         remoteResource.setuId(remoteResourceN.getId());
633         remoteResource.setResourceURI(remoteResourceN.getUri());
634         remoteResource.setHost(remoteResourceN.getHost());
635         remoteResource.setResourceTypes(remoteResourceN.getResourceTypes());
636         remoteResource.setResourceInterfaces(remoteResourceN
637                 .getResourceInterfaces());
638         remoteResource.setConnectivityType(remoteResourceN
639                 .getConnectivityType());
640         remoteResource.setObservable(remoteResourceN.getIsObservable());
641         return remoteResource;
642     }
643
644     private boolean isUidExist(String uid) {
645         boolean exist;
646         synchronized (resourceMap) {
647             exist = resourceMap.containsKey(uid);
648         }
649         return exist;
650     }
651
652     private RemoteResource getResource(String uid) {
653         if (null == uid) {
654             return null;
655         }
656         RemoteResource resource;
657         synchronized (resourceMap) {
658             resource = resourceMap.get(uid);
659         }
660         return resource;
661     }
662
663     private Map<String, RemoteResourceAttribute> fetchResourceAttributesFromModel(
664             SimulatorResourceModel resourceModelN) {
665         Map<String, RemoteResourceAttribute> resourceAttributeMap = null;
666         if (null != resourceModelN) {
667             Map<String, ResourceAttribute> attributeMapN;
668             try {
669                 attributeMapN = resourceModelN.getAttributes();
670             } catch (SimulatorException e) {
671                 Activator
672                         .getDefault()
673                         .getLogManager()
674                         .log(Level.ERROR.ordinal(),
675                                 new Date(),
676                                 "[" + e.getClass().getSimpleName() + "]"
677                                         + e.code().toString() + "-"
678                                         + e.message());
679                 return null;
680             }
681             if (null != attributeMapN) {
682                 resourceAttributeMap = new HashMap<String, RemoteResourceAttribute>();
683
684                 Set<String> attNameSet = attributeMapN.keySet();
685                 String attName;
686                 Object attValueObj;
687                 ResourceAttribute attributeN;
688                 RemoteResourceAttribute attribute;
689                 Iterator<String> attNameItr = attNameSet.iterator();
690                 while (attNameItr.hasNext()) {
691                     attName = attNameItr.next();
692                     attributeN = attributeMapN.get(attName);
693                     if (null != attributeN) {
694                         attribute = new RemoteResourceAttribute();
695                         attribute.setResourceAttribute(attributeN);
696                         attribute.setAttributeName(attName);
697
698                         attValueObj = attributeN.getValue();
699                         if (null != attValueObj) {
700                             attribute.setAttributeValue(attValueObj);
701                         }
702
703                         // Set the attribute type
704                         attribute.setAttValBaseType(attributeN.getBaseType());
705                         attribute.setAttValType(attributeN.getType());
706
707                         // Set the range and allowed values
708                         Range range = attributeN.getRange();
709                         if (null != range) {
710                             attribute.setMinValue(range.getMin());
711                             attribute.setMaxValue(range.getMax());
712                         } else {
713                             Object[] values = attributeN.getAllowedValues();
714                             if (null != values && values.length > 0) {
715                                 List<Object> valueList = new ArrayList<Object>();
716                                 for (Object obj : values) {
717                                     valueList.add(obj);
718                                 }
719                                 attribute.setAllowedValues(valueList);
720                             }
721                             /*
722                              * Type baseType = attribute.getAttValBaseType();
723                              *
724                              * if(baseType == Type.INT) { //int[] values =
725                              * attributeN.getAllowedValues();
726                              * attribute.setAllowedValues
727                              * (attributeN.getAllowedValues()); } else
728                              * if(baseType == Type.DOUBLE) { double[] values =
729                              * attributeN.getAllowedValues();
730                              * attribute.setAllowedValues
731                              * (Utility.converArrayToList(values)); } else
732                              * if(baseType == Type.BOOL) { //boolean[] values =
733                              * attributeN.getAllowedValues(); List<Object> obj =
734                              * new ArrayList<Object>(); obj.add(true);
735                              * obj.add(false); attribute.setAllowedValues(obj);
736                              * } else if(baseType == Type.STRING) { String[]
737                              * values = attributeN.getAllowedValues();
738                              * attribute.
739                              * setAllowedValues(Utility.converArrayToList
740                              * (values)); }
741                              */
742                         }
743                         resourceAttributeMap.put(attName, attribute);
744                     }
745                 }
746             }
747         }
748         return resourceAttributeMap;
749     }
750
751     private void newResourceFoundNotification(RemoteResource resource) {
752         synchronized (findResourceUIListeners) {
753             if (findResourceUIListeners.size() > 0) {
754                 IFindResourceUIListener listener;
755                 Iterator<IFindResourceUIListener> listenerItr = findResourceUIListeners
756                         .iterator();
757                 while (listenerItr.hasNext()) {
758                     listener = listenerItr.next();
759                     if (null != listener) {
760                         listener.onNewResourceFound(resource);
761                     }
762                 }
763             }
764         }
765     }
766
767     private void resourceSelectionChangedUINotification(RemoteResource resource) {
768         synchronized (resourceSelectionChangedUIListeners) {
769             if (resourceSelectionChangedUIListeners.size() > 0) {
770                 IResourceSelectionChangedUIListener listener;
771                 Iterator<IResourceSelectionChangedUIListener> listenerItr = resourceSelectionChangedUIListeners
772                         .iterator();
773                 while (listenerItr.hasNext()) {
774                     listener = listenerItr.next();
775                     if (null != listener) {
776                         listener.onResourceSelectionChange(resource);
777                     }
778                 }
779             }
780         }
781     }
782
783     private void getCompleteNotification(RemoteResource resource) {
784         synchronized (getUIListeners) {
785             if (getUIListeners.size() > 0) {
786                 IGetUIListener listener;
787                 Iterator<IGetUIListener> listenerItr = getUIListeners
788                         .iterator();
789                 while (listenerItr.hasNext()) {
790                     listener = listenerItr.next();
791                     if (null != listener) {
792                         listener.onGetCompleted(resource);
793                     }
794                 }
795             }
796         }
797     }
798
799     private void putCompleteNotification(RemoteResource resource) {
800         synchronized (putUIListeners) {
801             if (putUIListeners.size() > 0) {
802                 IPutUIListener listener;
803                 Iterator<IPutUIListener> listenerItr = putUIListeners
804                         .iterator();
805                 while (listenerItr.hasNext()) {
806                     listener = listenerItr.next();
807                     if (null != listener) {
808                         listener.onPutCompleted(resource);
809                     }
810                 }
811             }
812         }
813     }
814
815     private void postCompleteNotification(RemoteResource resource) {
816         synchronized (postUIListeners) {
817             if (postUIListeners.size() > 0) {
818                 IPostUIListener listener;
819                 Iterator<IPostUIListener> listenerItr = postUIListeners
820                         .iterator();
821                 while (listenerItr.hasNext()) {
822                     listener = listenerItr.next();
823                     if (null != listener) {
824                         listener.onPostCompleted(resource);
825                     }
826                 }
827             }
828         }
829     }
830
831     private void observeCompleteNotification(RemoteResource resource) {
832         synchronized (observeUIListeners) {
833             if (observeUIListeners.size() > 0) {
834                 IObserveUIListener listener;
835                 Iterator<IObserveUIListener> listenerItr = observeUIListeners
836                         .iterator();
837                 while (listenerItr.hasNext()) {
838                     listener = listenerItr.next();
839                     if (null != listener) {
840                         listener.onObserveCompleted(resource);
841                     }
842                 }
843             }
844         }
845     }
846
847     private void verificationStartedNotification(RemoteResource resource,
848             int autoType) {
849         synchronized (verificationUIListeners) {
850             if (verificationUIListeners.size() > 0) {
851                 IVerificationUIListener listener;
852                 Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
853                         .iterator();
854                 while (listenerItr.hasNext()) {
855                     listener = listenerItr.next();
856                     if (null != listener) {
857                         listener.onVerificationStarted(resource, autoType);
858                     }
859                 }
860             }
861         }
862     }
863
864     private void verificationAbortedNotification(RemoteResource resource,
865             int autoType) {
866         synchronized (verificationUIListeners) {
867             if (verificationUIListeners.size() > 0) {
868                 IVerificationUIListener listener;
869                 Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
870                         .iterator();
871                 while (listenerItr.hasNext()) {
872                     listener = listenerItr.next();
873                     if (null != listener) {
874                         listener.onVerificationAborted(resource, autoType);
875                     }
876                 }
877             }
878         }
879     }
880
881     private void verificationCompletedNotification(RemoteResource resource,
882             int autoType) {
883         synchronized (verificationUIListeners) {
884             if (verificationUIListeners.size() > 0) {
885                 IVerificationUIListener listener;
886                 Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
887                         .iterator();
888                 while (listenerItr.hasNext()) {
889                     listener = listenerItr.next();
890                     if (null != listener) {
891                         listener.onVerificationCompleted(resource, autoType);
892                     }
893                 }
894             }
895         }
896     }
897
898     private void configUploadedNotification(RemoteResource resource) {
899         synchronized (configUploadUIListeners) {
900             if (configUploadUIListeners.size() > 0) {
901                 IConfigurationUpload listener;
902                 Iterator<IConfigurationUpload> listenerItr = configUploadUIListeners
903                         .iterator();
904                 while (listenerItr.hasNext()) {
905                     listener = listenerItr.next();
906                     if (null != listener) {
907                         listener.onConfigurationUploaded(resource);
908                     }
909                 }
910             }
911         }
912     }
913
914     // TODO: Temporarily used to display the resource in the UI
915     public List<String> getURIList() {
916         List<String> list = new ArrayList<String>();
917         synchronized (resourceMap) {
918             /*
919              * Set<String> idSet = resourceMap.keySet(); Iterator<String> idItr
920              * = idSet.iterator(); String sId; RemoteResource resource;
921              * while(idItr.hasNext()) { sId = idItr.next(); resource =
922              * resourceMap.get(sId); if(null == resource) { continue; }
923              * list.add(resource.getResourceURI()); }
924              */
925             Set<String> uriSet = resourceMap.keySet();
926             Iterator<String> uriItr = uriSet.iterator();
927             String uri;
928             while (uriItr.hasNext()) {
929                 uri = uriItr.next();
930                 if (null != uri) {
931                     list.add(uri);
932                 }
933             }
934
935             // Sort the types
936             Collections.sort(list);
937         }
938         return list;
939     }
940
941     public synchronized Set<String> getLastKnownSearchTypes() {
942         return lastKnownSearchTypes;
943     }
944
945     public synchronized void setLastKnownSearchTypes(
946             Set<String> lastKnownSearchTypes) {
947         this.lastKnownSearchTypes = lastKnownSearchTypes;
948     }
949
950     public boolean findResourceRequest(Set<String> searchTypes) {
951         if (null == searchTypes || searchTypes.size() < 1) {
952             return false;
953         }
954         boolean result = false;
955         Iterator<String> searchItr = searchTypes.iterator();
956         String rType;
957         while (searchItr.hasNext()) {
958             rType = searchItr.next();
959             try {
960                 SimulatorManager.findResource(rType, findResourceListener);
961                 result = true;
962             } catch (SimulatorException e) {
963                 Activator
964                         .getDefault()
965                         .getLogManager()
966                         .log(Level.ERROR.ordinal(),
967                                 new Date(),
968                                 "[" + e.getClass().getSimpleName() + "]"
969                                         + e.code().toString() + "-"
970                                         + e.message());
971             }
972         }
973         return result;
974     }
975
976     public void deleteResources(final Set<String> searchTypes) {
977         if (null == searchTypes || searchTypes.size() < 1) {
978             return;
979         }
980         new Thread() {
981             public void run() {
982                 Iterator<String> typeItr = searchTypes.iterator();
983                 String resType;
984                 while (typeItr.hasNext()) {
985                     resType = typeItr.next();
986                     deleteResourcesByType(resType);
987
988                     // Change the current resource in selection
989                     updateCurrentResourceInSelection(searchTypes);
990                 }
991             }
992         }.start();
993     }
994
995     private void updateCurrentResourceInSelection(Set<String> searchTypes) {
996         if (null == searchTypes || searchTypes.size() < 1) {
997             return;
998         }
999         RemoteResource resourceInSelection = getCurrentResourceInSelection();
1000         if (null == resourceInSelection) {
1001             return;
1002         }
1003         List<String> typesOfSelection = resourceInSelection.getResourceTypes();
1004         if (null == typesOfSelection || typesOfSelection.size() < 1) {
1005             return;
1006         }
1007         Iterator<String> itr = typesOfSelection.iterator();
1008         String type;
1009         while (itr.hasNext()) {
1010             type = itr.next();
1011             if (searchTypes.contains(type)) {
1012                 setCurrentResourceInSelection(null);
1013                 resourceSelectionChangedUINotification(null);
1014                 break;
1015             }
1016         }
1017     }
1018
1019     private void deleteResourcesByType(String resourceType) {
1020         if (null == resourceType) {
1021             return;
1022         }
1023         synchronized (resourceMap) {
1024             Set<String> keySet = resourceMap.keySet();
1025             if (null == keySet) {
1026                 return;
1027             }
1028             Iterator<String> keyItr = keySet.iterator();
1029             String uId;
1030             RemoteResource resource;
1031             boolean exist;
1032             List<String> types;
1033             while (keyItr.hasNext()) {
1034                 uId = keyItr.next();
1035                 resource = resourceMap.get(uId);
1036                 if (null == resource) {
1037                     continue;
1038                 }
1039                 types = resource.getResourceTypes();
1040                 if (null != types) {
1041                     exist = types.contains(resourceType);
1042                     if (exist) {
1043                         // Remove the resource
1044                         keyItr.remove();
1045                         // Remove the resource from favorites list.
1046                         removeResourceFromFavorites(resource);
1047                     }
1048                 }
1049             }
1050         }
1051     }
1052
1053     public void resourceSelectionChanged(final RemoteResource resource) {
1054         new Thread() {
1055             @Override
1056             public void run() {
1057                 setCurrentResourceInSelection(resource);
1058                 // Notify all observers for resource selection change event
1059                 resourceSelectionChangedUINotification(resource);
1060             }
1061         }.start();
1062     }
1063
1064     public List<MetaProperty> getMetaProperties(RemoteResource resource) {
1065         if (null != resource) {
1066             String propName;
1067             String propValue;
1068
1069             List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
1070
1071             for (int index = 0; index < Constants.META_PROPERTY_COUNT; index++) {
1072                 propName = Constants.META_PROPERTIES[index];
1073                 if (propName.equals(Constants.RESOURCE_URI)) {
1074                     propValue = resource.getResourceURI();
1075                 } else if (propName.equals(Constants.CONNECTIVITY_TYPE)) {
1076                     propValue = resource.getConnectivityType().toString();
1077                 } else if (propName.equals(Constants.OBSERVABLE)) {
1078                     propValue = Utility.getObservableInString(resource
1079                             .isObservable());
1080                     // see in UI
1081                 } else if (propName.equals(Constants.RESOURCE_TYPES)) {
1082                     List<String> types = resource.getResourceTypes();
1083                     if (null != types) {
1084                         propValue = types.toString();
1085                     } else {
1086                         propValue = Constants.NOT_AVAILABLE;
1087                     }
1088                 } else if (propName.equals(Constants.RESOURCE_INTERFACES)) {
1089                     List<String> interfaces = resource.getResourceInterfaces();
1090                     if (null != interfaces) {
1091                         propValue = interfaces.toString();
1092                     } else {
1093                         propValue = Constants.NOT_AVAILABLE;
1094                     }
1095                 } else {
1096                     propValue = null;
1097                 }
1098                 if (null != propValue) {
1099                     metaPropertyList.add(new MetaProperty(propName, propValue));
1100                 }
1101             }
1102
1103             return metaPropertyList;
1104         }
1105         return null;
1106     }
1107
1108     public Map<String, Boolean> getAutomationStatus(RemoteResource resource) {
1109         if (null == resource) {
1110             return null;
1111         }
1112         Map<String, Boolean> autoStatus = new HashMap<String, Boolean>();
1113         autoStatus.put(Constants.GET, resource.isGetAutomtnInProgress());
1114         autoStatus.put(Constants.PUT, resource.isPutAutomtnInProgress());
1115         autoStatus.put(Constants.POST, resource.isPostAutomtnInProgress());
1116         return autoStatus;
1117     }
1118
1119     public Map<String, String> getDummyAttributes() {
1120         Map<String, String> attributes = new HashMap<String, String>();
1121         attributes.put("intensity", "1");
1122         attributes.put("power", "off");
1123         return attributes;
1124     }
1125
1126     public List<RemoteResource> getResourceList() {
1127         List<RemoteResource> resourceList = new ArrayList<RemoteResource>();
1128         synchronized (resourceMap) {
1129             Set<String> idSet = resourceMap.keySet();
1130             Iterator<String> idItr = idSet.iterator();
1131             RemoteResource resource;
1132             while (idItr.hasNext()) {
1133                 resource = resourceMap.get(idItr.next());
1134                 if (null != resource) {
1135                     resourceList.add(resource);
1136                 }
1137             }
1138         }
1139         // Sort the list
1140         Collections.sort(resourceList, new Comparator<RemoteResource>() {
1141             public int compare(RemoteResource res1, RemoteResource res2) {
1142                 String s1 = res1.getResourceURI();
1143                 String s2 = res2.getResourceURI();
1144
1145                 String s1Part = s1.replaceAll("\\d", "");
1146                 String s2Part = s2.replaceAll("\\d", "");
1147
1148                 if (s1Part.equalsIgnoreCase(s2Part)) {
1149                     return extractInt(s1) - extractInt(s2);
1150                 }
1151                 return s1.compareTo(s2);
1152             }
1153
1154             int extractInt(String s) {
1155                 String num = s.replaceAll("\\D", "");
1156                 // return 0 if no digits found
1157                 return num.isEmpty() ? 0 : Integer.parseInt(num);
1158             }
1159         });
1160
1161         return resourceList;
1162     }
1163
1164     public List<RemoteResource> getFavResourceList() {
1165         List<RemoteResource> resourceList;
1166         synchronized (favoriteResources) {
1167             resourceList = new ArrayList<RemoteResource>(favoriteResources);
1168         }
1169         return resourceList;
1170     }
1171
1172     public String getAttributeValue(RemoteResource res, String attName) {
1173         if (null == res || null == attName) {
1174             return null;
1175         }
1176         return res.getAttributeValue(attName);
1177     }
1178
1179     public void sendGetRequest(RemoteResource resource) {
1180         if (null == resource) {
1181             return;
1182         }
1183         SimulatorRemoteResource resourceN = resource.getResource();
1184         if (null == resourceN) {
1185             return;
1186         }
1187         try {
1188             resourceN.get(null, getListener);
1189         } catch (SimulatorException e) {
1190             Activator
1191                     .getDefault()
1192                     .getLogManager()
1193                     .log(Level.ERROR.ordinal(),
1194                             new Date(),
1195                             "[" + e.getClass().getSimpleName() + "]"
1196                                     + e.code().toString() + "-" + e.message());
1197         }
1198     }
1199
1200     public void sendPutRequest(RemoteResource resource,
1201             List<PutPostAttributeModel> putPostModelList) {
1202         System.out.println(putPostModelList);
1203         System.out.println("ResourceManager: sendPutRequest");
1204         if (null == resource) {
1205             return;
1206         }
1207         System.out.println("ResourceManager: resource not null");
1208         SimulatorRemoteResource resourceN = resource.getResource();
1209         if (null == resourceN) {
1210             return;
1211         }
1212         System.out.println("ResourceManager: Native resource not null");
1213         Map<String, RemoteResourceAttribute> attMap = resource
1214                 .getResourceAttributesMap();
1215         if (null == attMap || attMap.size() < 1) {
1216             return;
1217         }
1218         System.out.println("ResourceManager: attrubutes obtained");
1219         SimulatorResourceModel resourceModel = getUpdatedResourceModel(attMap,
1220                 putPostModelList);
1221         System.out.println("ResourceModel exist?:" + (resourceModel != null));
1222         try {
1223             resourceN.put(resourceModel, null, putListener);
1224         } catch (SimulatorException e) {
1225             Activator
1226                     .getDefault()
1227                     .getLogManager()
1228                     .log(Level.ERROR.ordinal(),
1229                             new Date(),
1230                             "[" + e.getClass().getSimpleName() + "]"
1231                                     + e.code().toString() + "-" + e.message());
1232         }
1233         System.out.println("ResourceManager: called native put");
1234     }
1235
1236     public void sendPostRequest(RemoteResource resource,
1237             List<PutPostAttributeModel> putPostModelList) {
1238         System.out.println(putPostModelList);
1239         if (null == resource) {
1240             return;
1241         }
1242         SimulatorRemoteResource resourceN = resource.getResource();
1243         if (null == resourceN) {
1244             return;
1245         }
1246         Map<String, RemoteResourceAttribute> attMap = resource
1247                 .getResourceAttributesMap();
1248         if (null == attMap || attMap.size() < 1) {
1249             return;
1250         }
1251         // Filter out the attributes whose modification status is true.
1252         Iterator<PutPostAttributeModel> itr = putPostModelList.iterator();
1253         PutPostAttributeModel model;
1254         while (itr.hasNext()) {
1255             model = itr.next();
1256             if (!model.isModified()) {
1257                 itr.remove();
1258             }
1259         }
1260         SimulatorResourceModel resourceModel = getUpdatedResourceModel(attMap,
1261                 putPostModelList);
1262         try {
1263             resourceN.post(resourceModel, null, postListener);
1264         } catch (SimulatorException e) {
1265             Activator
1266                     .getDefault()
1267                     .getLogManager()
1268                     .log(Level.ERROR.ordinal(),
1269                             new Date(),
1270                             "[" + e.getClass().getSimpleName() + "]"
1271                                     + e.code().toString() + "-" + e.message());
1272         }
1273     }
1274
1275     private SimulatorResourceModel getUpdatedResourceModel(
1276             Map<String, RemoteResourceAttribute> attMap,
1277             List<PutPostAttributeModel> putPostModelList) {
1278         String attName;
1279         SimulatorResourceModel resourceModel = new SimulatorResourceModel();
1280         PutPostAttributeModel model;
1281         RemoteResourceAttribute attribute;
1282         Type attType;
1283         Iterator<PutPostAttributeModel> itr = putPostModelList.iterator();
1284         while (itr.hasNext()) {
1285             model = itr.next();
1286             attName = model.getAttName();
1287             attribute = attMap.get(attName);
1288             if (null == attribute) {
1289                 continue;
1290             }
1291             attType = attribute.getAttValBaseType();
1292             if (attType == Type.INT) {
1293                 int attValue;
1294                 try {
1295                     attValue = Integer.parseInt(model.getAttValue());
1296                     resourceModel.addAttributeInt(attName, attValue);
1297                 } catch (NumberFormatException e) {
1298                     Activator
1299                             .getDefault()
1300                             .getLogManager()
1301                             .log(Level.ERROR.ordinal(), new Date(),
1302                                     e.getMessage());
1303                 } catch (SimulatorException e) {
1304                     Activator
1305                             .getDefault()
1306                             .getLogManager()
1307                             .log(Level.ERROR.ordinal(),
1308                                     new Date(),
1309                                     "[" + e.getClass().getSimpleName() + "]"
1310                                             + e.code().toString() + "-"
1311                                             + e.message());
1312                 }
1313             } else if (attType == Type.DOUBLE) {
1314                 double attValue;
1315                 try {
1316                     attValue = Double.parseDouble(model.getAttValue());
1317                     resourceModel.addAttributeDouble(attName, attValue);
1318                 } catch (NumberFormatException e) {
1319                     Activator
1320                             .getDefault()
1321                             .getLogManager()
1322                             .log(Level.ERROR.ordinal(), new Date(),
1323                                     e.getMessage());
1324                 } catch (SimulatorException e) {
1325                     Activator
1326                             .getDefault()
1327                             .getLogManager()
1328                             .log(Level.ERROR.ordinal(),
1329                                     new Date(),
1330                                     "[" + e.getClass().getSimpleName() + "]"
1331                                             + e.code().toString() + "-"
1332                                             + e.message());
1333                 }
1334             } else if (attType == Type.BOOL) {
1335                 boolean attValue;
1336                 attValue = Boolean.parseBoolean(model.getAttValue());
1337                 try {
1338                     resourceModel.addAttributeBoolean(attName, attValue);
1339                 } catch (SimulatorException e) {
1340                     Activator
1341                             .getDefault()
1342                             .getLogManager()
1343                             .log(Level.ERROR.ordinal(),
1344                                     new Date(),
1345                                     "[" + e.getClass().getSimpleName() + "]"
1346                                             + e.code().toString() + "-"
1347                                             + e.message());
1348                 }
1349             } else if (attType == Type.STRING) {
1350                 String attValue;
1351                 attValue = model.getAttValue();
1352                 try {
1353                     resourceModel.addAttributeString(attName, attValue);
1354                 } catch (SimulatorException e) {
1355                     Activator
1356                             .getDefault()
1357                             .getLogManager()
1358                             .log(Level.ERROR.ordinal(),
1359                                     new Date(),
1360                                     "[" + e.getClass().getSimpleName() + "]"
1361                                             + e.code().toString() + "-"
1362                                             + e.message());
1363                 }
1364             }
1365         }
1366         return resourceModel;
1367     }
1368
1369     public void sendObserveRequest(RemoteResource resource) {
1370         System.out.println("sendObserverRequest() entry");
1371         if (null == resource) {
1372             return;
1373         }
1374         System.out.println("Resource is null:" + (resource == null));
1375         resource.setObserved(true);
1376         SimulatorRemoteResource resourceN = resource.getResource();
1377         if (null == resourceN) {
1378             return;
1379         }
1380         try {
1381             resourceN.startObserve(SimulatorObserveType.OBSERVE, null,
1382                     observeListener);
1383             // Add observed resource URI to show the proper status after every
1384             // find/refresh operations.
1385             addObservedResourceURI(resource.getResourceURI());
1386         } catch (SimulatorException e) {
1387             Activator
1388                     .getDefault()
1389                     .getLogManager()
1390                     .log(Level.ERROR.ordinal(),
1391                             new Date(),
1392                             "[" + e.getClass().getSimpleName() + "]"
1393                                     + e.code().toString() + "-" + e.message());
1394         }
1395         System.out.println("Observer called.");
1396     }
1397
1398     public void sendCancelObserveRequest(RemoteResource resource) {
1399         if (null == resource) {
1400             return;
1401         }
1402         resource.setObserved(false);
1403         SimulatorRemoteResource resourceN = resource.getResource();
1404         if (null == resourceN) {
1405             return;
1406         }
1407         try {
1408             resourceN.stopObserve();
1409             // Remove observed resource URI to show the proper status after
1410             // every find/refresh operations.
1411             removeObservedResourceURI(resource.getResourceURI());
1412         } catch (SimulatorException e) {
1413             Activator
1414                     .getDefault()
1415                     .getLogManager()
1416                     .log(Level.ERROR.ordinal(),
1417                             new Date(),
1418                             "[" + e.getClass().getSimpleName() + "]"
1419                                     + e.code().toString() + "-" + e.message());
1420         }
1421     }
1422
1423     public void startAutomationRequest(int reqType, RemoteResource resource) {
1424         if (null == resource) {
1425             return;
1426         }
1427         SimulatorRemoteResource resourceN = resource.getResource();
1428         if (null == resourceN) {
1429             return;
1430         }
1431         SimulatorVerificationType type = SimulatorVerificationType
1432                 .getVerificationType(reqType);
1433         if (null == type) {
1434             return;
1435         }
1436         System.out.println("Before calling startVerification: " + reqType);
1437         int autoId;
1438         try {
1439             autoId = resourceN.startVerification(type, verifyListener);
1440             System.out.println("After calling startVerification: " + autoId);
1441             if (autoId != -1) {
1442                 if (reqType == Constants.GET_AUTOMATION_INDEX) {
1443                     // resource.setGetAutomtnInProgress(true);
1444                     resource.setGetAutomtnId(autoId);
1445                 } else if (reqType == Constants.PUT_AUTOMATION_INDEX) {
1446                     // resource.setPutAutomtnInProgress(true);
1447                     resource.setPutAutomtnId(autoId);
1448                 } else {// if(reqType == Constants.POST_AUTOMATION_INDEX) {
1449                         // resource.setPostAutomtnInProgress(true);
1450                     resource.setPostAutomtnId(autoId);
1451                 }
1452             }
1453         } catch (SimulatorException e) {
1454             Activator
1455                     .getDefault()
1456                     .getLogManager()
1457                     .log(Level.ERROR.ordinal(),
1458                             new Date(),
1459                             "[" + e.getClass().getSimpleName() + "]"
1460                                     + e.code().toString() + "-" + e.message());
1461         }
1462     }
1463
1464     public void stopAutomationRequest(int reqType, RemoteResource resource) {
1465         if (null == resource) {
1466             return;
1467         }
1468         SimulatorRemoteResource resourceN = resource.getResource();
1469         if (null == resourceN) {
1470             return;
1471         }
1472         int autoId;
1473         if (reqType == Constants.GET_AUTOMATION_INDEX) {
1474             resource.setGetAutomtnInProgress(false);
1475             autoId = resource.getGetAutomtnId();
1476         } else if (reqType == Constants.PUT_AUTOMATION_INDEX) {
1477             resource.setPutAutomtnInProgress(false);
1478             autoId = resource.getPutAutomtnId();
1479         } else {// if(reqType == Constants.POST_AUTOMATION_INDEX) {
1480             resource.setPostAutomtnInProgress(false);
1481             autoId = resource.getPostAutomtnId();
1482         }
1483         try {
1484             resourceN.stopVerification(autoId);
1485         } catch (SimulatorException e) {
1486             Activator
1487                     .getDefault()
1488                     .getLogManager()
1489                     .log(Level.ERROR.ordinal(),
1490                             new Date(),
1491                             "[" + e.getClass().getSimpleName() + "]"
1492                                     + e.code().toString() + "-" + e.message());
1493         }
1494     }
1495
1496     public void setConfigFilePath(RemoteResource resource, String configFilePath) {
1497         if (null == resource) {
1498             return;
1499         }
1500         SimulatorRemoteResource resourceN = resource.getResource();
1501         if (null == resourceN) {
1502             return;
1503         }
1504         try {
1505             resourceN.setConfigInfo(configFilePath);
1506         } catch (SimulatorException e) {
1507             Activator
1508                     .getDefault()
1509                     .getLogManager()
1510                     .log(Level.ERROR.ordinal(),
1511                             new Date(),
1512                             "[" + e.getClass().getSimpleName() + "]"
1513                                     + e.code().toString() + "-" + e.message());
1514             return;
1515         }
1516         // Update the status
1517         resource.setConfigUploaded(true);
1518
1519         // Notify the UI listeners
1520         configUploadedNotification(resource);
1521     }
1522
1523     public Image getImage(String resourceURI) {
1524         if (null == resourceURI) {
1525             return null;
1526         }
1527         URL url = Activator.getDefault().getBundle()
1528                 .getEntry(getImageURL(resourceURI));
1529         if (null == url) {
1530             return null;
1531         }
1532         return ImageDescriptor.createFromURL(url).createImage();
1533     }
1534
1535     private String getImageURL(String resourceURI) {
1536         // TODO: Hard-coding the image file name temporarily.
1537         // It will be included in a separate class which manages all image
1538         // resources
1539         return "/icons/light_16x16.png";
1540     }
1541
1542     public void shutdown() {
1543         // TODO: To be implemented for clean-up activities.
1544     }
1545 }