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