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