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