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