89df91f1bc707c2e662c5f172706eef05c7bcd2c
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / 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.serviceprovider.manager;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.Iterator;
23 import java.util.LinkedList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27 import java.util.Vector;
28
29 import oic.simulator.serviceprovider.Activator;
30 import oic.simulator.serviceprovider.model.AttributeElement;
31 import oic.simulator.serviceprovider.model.MetaProperty;
32 import oic.simulator.serviceprovider.model.Resource;
33 import oic.simulator.serviceprovider.model.ResourceType;
34 import oic.simulator.serviceprovider.model.SingleResource;
35 import oic.simulator.serviceprovider.utils.Constants;
36 import oic.simulator.serviceprovider.utils.Utility;
37
38 import org.eclipse.swt.widgets.Display;
39 import org.oic.simulator.AttributeProperty;
40 import org.oic.simulator.AttributeProperty.Type;
41 import org.oic.simulator.AttributeValue;
42 import org.oic.simulator.AttributeValue.TypeInfo;
43 import org.oic.simulator.AttributeValue.ValueType;
44 import org.oic.simulator.DeviceInfo;
45 import org.oic.simulator.DeviceListener;
46 import org.oic.simulator.ILogger.Level;
47 import org.oic.simulator.PlatformInfo;
48 import org.oic.simulator.SimulatorException;
49 import org.oic.simulator.SimulatorManager;
50 import org.oic.simulator.SimulatorResourceAttribute;
51 import org.oic.simulator.SimulatorResourceModel;
52 import org.oic.simulator.server.Observer;
53 import org.oic.simulator.server.SimulatorResource;
54 import org.oic.simulator.server.SimulatorResource.AutoUpdateListener;
55 import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
56 import org.oic.simulator.server.SimulatorResource.ObserverListener;
57 import org.oic.simulator.server.SimulatorResource.ResourceModelChangeListener;
58 import org.oic.simulator.server.SimulatorSingleResource;
59
60 /**
61  * This class acts as an interface between the simulator java SDK and the
62  * various UI modules. It maintains all the details of resources and provides
63  * other UI modules with the information required. It also handles model change,
64  * automation, and observer related events from native layer and propagates
65  * those events to the registered UI listeners.
66  */
67 public class ResourceManager {
68
69     private Data                           data;
70
71     private Resource                       currentResourceInSelection;
72
73     private ResourceModelChangeListener    resourceModelChangeListener;
74
75     private AutoUpdateListener             automationListener;
76
77     private ObserverListener               observer;
78
79     private DeviceListener                 deviceListener;
80
81     private NotificationSynchronizerThread synchronizerThread;
82
83     private Thread                         threadHandle;
84
85     private DeviceInfo                     deviceInfo;
86     private PlatformInfo                   platformInfo;
87
88     private String                         deviceName;
89
90     public ResourceManager() {
91         data = new Data();
92
93         // Set the default device and platform information
94         deviceName = "IoTivity Simulator";
95         try {
96             SimulatorManager.setDeviceInfo(deviceName);
97         } catch (SimulatorException e) {
98             Activator
99                     .getDefault()
100                     .getLogManager()
101                     .log(Level.ERROR.ordinal(),
102                             new Date(),
103                             "Error while registering the device info.\n"
104                                     + Utility.getSimulatorErrorString(e, null));
105         }
106
107         platformInfo = new PlatformInfo();
108         platformInfo.setPlatformID("Samsung Platform Identifier");
109         platformInfo.setManufacturerName("Samsung");
110         platformInfo.setManufacturerUrl("www.samsung.com");
111         platformInfo.setModelNumber("Samsung Model Num01");
112         platformInfo.setDateOfManufacture("2015-09-10T11:10:30Z");
113         platformInfo.setPlatformVersion("PlatformVersion01");
114         platformInfo.setOperationSystemVersion("OSVersion01");
115         platformInfo.setHardwareVersion("HardwareVersion01");
116         platformInfo.setFirmwareVersion("FirwareVersion01");
117         platformInfo.setSupportUrl("http://www.samsung.com/support");
118         platformInfo.setSystemTime("2015-09-10T11:10:30Z");
119         try {
120             SimulatorManager.setPlatformInfo(platformInfo);
121         } catch (SimulatorException e) {
122             Activator
123                     .getDefault()
124                     .getLogManager()
125                     .log(Level.ERROR.ordinal(),
126                             new Date(),
127                             "Error while registering the platform info.\n"
128                                     + Utility.getSimulatorErrorString(e, null));
129         }
130
131         deviceListener = new DeviceListener() {
132
133             @Override
134             public void onDeviceFound(final String host,
135                     final DeviceInfo deviceInfo) {
136                 if (null != ResourceManager.this.deviceInfo
137                         || null == deviceInfo || null == host) {
138                     return;
139                 }
140                 synchronizerThread.addToQueue(new Runnable() {
141                     @Override
142                     public void run() {
143                         String rcvdDeviceName = deviceInfo.getName();
144                         if (null == rcvdDeviceName) {
145                             return;
146                         }
147                         if (deviceName.equalsIgnoreCase(rcvdDeviceName)) {
148                             ResourceManager.this.deviceInfo = deviceInfo;
149
150                             // Notify the UI Listeners
151                             UiListenerHandler.getInstance()
152                                     .deviceInfoReceivedNotification();
153                         }
154                     }
155                 });
156             }
157         };
158
159         // Get the device information to show other details of the device in UI.
160         try {
161             SimulatorManager.findDevices("", deviceListener);
162         } catch (SimulatorException e) {
163             Activator
164                     .getDefault()
165                     .getLogManager()
166                     .log(Level.ERROR.ordinal(),
167                             new Date(),
168                             "Failed to get the local device information.\n"
169                                     + Utility.getSimulatorErrorString(e, null));
170         }
171
172         resourceModelChangeListener = new ResourceModelChangeListener() {
173
174             @Override
175             public void onResourceModelChanged(final String resourceURI,
176                     final SimulatorResourceModel resourceModelN) {
177                 synchronizerThread.addToQueue(new Runnable() {
178
179                     @Override
180                     public void run() {
181                         if (null == resourceURI || null == resourceModelN) {
182                             return;
183                         }
184
185                         Display.getDefault().asyncExec(new Runnable() {
186                             @Override
187                             public void run() {
188                                 Resource resource = data
189                                         .getResourceByURI(resourceURI);
190                                 if (null != resource) {
191                                     try {
192                                         resource.setResourceRepresentation(resourceModelN);
193                                     } catch (NumberFormatException e) {
194                                         Activator
195                                                 .getDefault()
196                                                 .getLogManager()
197                                                 .log(Level.ERROR.ordinal(),
198                                                         new Date(),
199                                                         "Error while trying to update the attributes.\n"
200                                                                 + Utility
201                                                                         .getSimulatorErrorString(
202                                                                                 e,
203                                                                                 null));
204                                     }
205                                 }
206                             }
207                         });
208                     }
209                 });
210             }
211         };
212
213         automationListener = new AutoUpdateListener() {
214
215             @Override
216             public void onUpdateComplete(final String resourceURI,
217                     final int automationId) {
218                 synchronizerThread.addToQueue(new Runnable() {
219
220                     @Override
221                     public void run() {
222                         SingleResource resource = data
223                                 .getSingleResourceByURI(resourceURI);
224                         if (null == resource) {
225                             return;
226                         }
227                         // Checking whether this notification is for an
228                         // attribute or a resource
229                         if (resource.isResourceAutomationInProgress()) {
230                             changeResourceLevelAutomationStatus(resource, false);
231                             // Notify the UI listeners
232                             UiListenerHandler.getInstance()
233                                     .automationCompleteUINotification(resource,
234                                             null);
235                         } else if (resource.isAttributeAutomationInProgress()) {
236                             // Find the attribute with the given automation id
237                             final AttributeElement attribute = getAttributeWithGivenAutomationId(
238                                     resource, automationId);
239                             if (null != attribute) {
240                                 attribute.setAutoUpdateState(false);
241                                 resource.setAttributeAutomationInProgress(isAnyAttributeInAutomation(resource));
242                             } else {
243                                 // Setting the attribute automation status to
244                                 // false.
245                                 resource.setAttributeAutomationInProgress(false);
246                             }
247                         }
248                     }
249                 });
250             }
251         };
252
253         observer = new ObserverListener() {
254
255             public void onObserverChanged(final String resourceURI,
256                     final int status, final Observer observer) {
257                 new Thread() {
258                     @Override
259                     public void run() {
260                         if (null == resourceURI || null == observer) {
261                             return;
262                         }
263                         Resource resource = data.getResourceByURI(resourceURI);
264                         if (null == resource) {
265                             return;
266                         }
267                         // Update the observers information
268                         if (status == 0) {
269                             resource.addObserverInfo(observer);
270                         } else {
271                             resource.removeObserverInfo(observer);
272                         }
273                         // Notify the UI listeners
274                         UiListenerHandler.getInstance()
275                                 .observerListChangedUINotification(resource);
276                     }
277                 }.start();
278             }
279
280             @Override
281             public void onObserverAdded(String resourceURI, Observer observer) {
282                 onObserverChanged(resourceURI, 0, observer);
283             }
284
285             @Override
286             public void onObserverRemoved(String resourceURI, Observer observer) {
287                 onObserverChanged(resourceURI, 1, observer);
288             }
289         };
290
291         synchronizerThread = new NotificationSynchronizerThread();
292         threadHandle = new Thread(synchronizerThread);
293         threadHandle.setName("Simulator service provider event queue");
294         threadHandle.start();
295     }
296
297     private static class NotificationSynchronizerThread implements Runnable {
298
299         LinkedList<Runnable> notificationQueue = new LinkedList<Runnable>();
300
301         @Override
302         public void run() {
303             while (!Thread.interrupted()) {
304                 synchronized (this) {
305                     try {
306                         while (notificationQueue.isEmpty()) {
307                             this.wait();
308                             break;
309                         }
310                     } catch (InterruptedException e) {
311                         return;
312                     }
313                 }
314
315                 Runnable thread;
316                 synchronized (this) {
317                     thread = notificationQueue.pop();
318                 }
319                 try {
320                     thread.run();
321                 } catch (Exception e) {
322                     if (e instanceof InterruptedException) {
323                         return;
324                     }
325                     e.printStackTrace();
326                 }
327             }
328         }
329
330         public void addToQueue(Runnable event) {
331             synchronized (this) {
332                 notificationQueue.add(event);
333                 this.notify();
334             }
335         }
336     }
337
338     public void setDeviceInfo(List<MetaProperty> metaProperties) {
339         if (null == metaProperties || metaProperties.size() < 1) {
340             return;
341         }
342         Iterator<MetaProperty> itr = metaProperties.iterator();
343         MetaProperty prop;
344         String propName;
345         String propValue;
346         boolean found = false;
347         while (itr.hasNext()) {
348             prop = itr.next();
349             propName = prop.getPropName();
350             propValue = prop.getPropValue();
351             if (propName.equals(Constants.DEVICE_NAME)) {
352                 this.deviceName = propValue;
353                 found = true;
354                 break;
355             }
356         }
357
358         if (!found) {
359             return;
360         }
361
362         try {
363             SimulatorManager.setDeviceInfo(deviceName);
364         } catch (SimulatorException e) {
365             Activator
366                     .getDefault()
367                     .getLogManager()
368                     .log(Level.ERROR.ordinal(),
369                             new Date(),
370                             "Error while registering the device info.\n"
371                                     + Utility.getSimulatorErrorString(e, null));
372         }
373     }
374
375     public boolean isDeviceInfoValid(List<MetaProperty> metaProperties) {
376         if (null == metaProperties || metaProperties.size() < 1) {
377             return false;
378         }
379
380         Iterator<MetaProperty> itr = metaProperties.iterator();
381         MetaProperty prop;
382         String propName;
383         String propValue;
384         while (itr.hasNext()) {
385             prop = itr.next();
386             propName = prop.getPropName();
387             propValue = prop.getPropValue();
388             if (propName.equals(Constants.DEVICE_NAME)) {
389                 if (null == propValue || propValue.length() < 1) {
390                     return false;
391                 }
392                 break;
393             }
394         }
395         return true;
396     }
397
398     public List<MetaProperty> getDeviceInfo() {
399         List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
400         metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, deviceName));
401         if (null != deviceInfo) {
402             metaProperties.add(new MetaProperty(Constants.DEVICE_ID, deviceInfo
403                     .getID()));
404             metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
405                     deviceInfo.getSpecVersion()));
406             metaProperties.add(new MetaProperty(Constants.DEVICE_DMV,
407                     deviceInfo.getDataModelVersion()));
408         }
409         return metaProperties;
410     }
411
412     public List<MetaProperty> getPlatformInfo() {
413         List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
414         metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platformInfo
415                 .getPlatformID()));
416         metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME,
417                 platformInfo.getManufacturerName()));
418         metaProperties.add(new MetaProperty(Constants.PLATFORM_MANUFAC_URL,
419                 platformInfo.getManufacturerUrl()));
420         metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
421                 platformInfo.getModelNumber()));
422         metaProperties.add(new MetaProperty(Constants.PLATFORM_DATE_OF_MANUFAC,
423                 platformInfo.getDateOfManufacture()));
424         metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION,
425                 platformInfo.getPlatformVersion()));
426         metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
427                 platformInfo.getOperationSystemVersion()));
428         metaProperties.add(new MetaProperty(
429                 Constants.PLATFORM_HARDWARE_VERSION, platformInfo
430                         .getHardwareVersion()));
431         metaProperties.add(new MetaProperty(
432                 Constants.PLATFORM_FIRMWARE_VERSION, platformInfo
433                         .getFirmwareVersion()));
434         metaProperties.add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
435                 platformInfo.getSupportUrl()));
436         metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME,
437                 platformInfo.getSystemTime()));
438         return metaProperties;
439     }
440
441     public void setPlatformInfo(List<MetaProperty> metaProperties) {
442         if (null == metaProperties || metaProperties.size() < 1) {
443             return;
444         }
445         Iterator<MetaProperty> itr = metaProperties.iterator();
446         MetaProperty prop;
447         String propName;
448         String propValue;
449         while (itr.hasNext()) {
450             prop = itr.next();
451             propName = prop.getPropName();
452             propValue = prop.getPropValue();
453             if (propName.equals(Constants.PLATFORM_ID)) {
454                 platformInfo.setPlatformID(propValue);
455             } else if (propName.equals(Constants.PLATFORM_MANUFAC_NAME)) {
456                 platformInfo.setManufacturerName(propValue);
457             } else if (propName.equals(Constants.PLATFORM_MANUFAC_URL)) {
458                 platformInfo.setManufacturerUrl(propValue);
459             } else if (propName.equals(Constants.PLATFORM_MODEL_NO)) {
460                 platformInfo.setModelNumber(propValue);
461             } else if (propName.equals(Constants.PLATFORM_DATE_OF_MANUFAC)) {
462                 platformInfo.setDateOfManufacture(propValue);
463             } else if (propName.equals(Constants.PLATFORM_VERSION)) {
464                 platformInfo.setPlatformVersion(propValue);
465             } else if (propName.equals(Constants.PLATFORM_OS_VERSION)) {
466                 platformInfo.setOperationSystemVersion(propValue);
467             } else if (propName.equals(Constants.PLATFORM_HARDWARE_VERSION)) {
468                 platformInfo.setHardwareVersion(propValue);
469             } else if (propName.equals(Constants.PLATFORM_FIRMWARE_VERSION)) {
470                 platformInfo.setFirmwareVersion(propValue);
471             } else if (propName.equals(Constants.PLATFORM_SUPPORT_URL)) {
472                 platformInfo.setSupportUrl(propValue);
473             } else if (propName.equals(Constants.PLATFORM_SYSTEM_TIME)) {
474                 platformInfo.setSystemTime(propValue);
475             }
476         }
477         try {
478             SimulatorManager.setPlatformInfo(platformInfo);
479         } catch (SimulatorException e) {
480             Activator
481                     .getDefault()
482                     .getLogManager()
483                     .log(Level.ERROR.ordinal(),
484                             new Date(),
485                             "Error while registering the platform info.\n"
486                                     + Utility.getSimulatorErrorString(e, null));
487         }
488     }
489
490     public boolean isPlatformInfoValid(List<MetaProperty> metaProperties) {
491         if (null == metaProperties || metaProperties.size() < 1) {
492             return false;
493         }
494         Iterator<MetaProperty> itr = metaProperties.iterator();
495         MetaProperty prop;
496         String propValue;
497         while (itr.hasNext()) {
498             prop = itr.next();
499             propValue = prop.getPropValue();
500             if (null == propValue || propValue.length() < 1) {
501                 return false;
502             }
503         }
504         return true;
505     }
506
507     public synchronized Resource getCurrentResourceInSelection() {
508         return currentResourceInSelection;
509     }
510
511     public synchronized void setCurrentResourceInSelection(Resource resource) {
512         this.currentResourceInSelection = resource;
513     }
514
515     public boolean isResourceExist(String resourceURI) {
516         return data.isResourceExist(resourceURI);
517     }
518
519     public boolean isAnyResourceExist() {
520         return data.isAnyResourceExist();
521     }
522
523     public boolean createSingleResource(SingleResource resource,
524             Map<String, SimulatorResourceAttribute> attributes)
525             throws SimulatorException {
526         if (null == resource) {
527             return false;
528         }
529
530         try {
531             // Create the resource.
532             SimulatorResource jSimulatorResource = SimulatorManager
533                     .createResource(SimulatorResource.Type.SINGLE,
534                             resource.getResourceName(),
535                             resource.getResourceURI(),
536                             resource.getResourceType());
537             if (null == jSimulatorResource
538                     || !(jSimulatorResource instanceof SimulatorSingleResource)) {
539                 return false;
540             }
541             SimulatorSingleResource jSimulatorSingleResource = (SimulatorSingleResource) jSimulatorResource;
542             resource.setSimulatorResource(jSimulatorSingleResource);
543
544             // Cancel observable property if requested by user.
545             if (!resource.isObservable()) {
546                 jSimulatorSingleResource.setObservable(false);
547             }
548
549             // Set the model change listener.
550             jSimulatorSingleResource
551                     .setResourceModelChangeListener(resourceModelChangeListener);
552
553             // Set the observer listener if the resource is observable.
554             if (resource.isObservable()) {
555                 jSimulatorSingleResource.setObserverListener(observer);
556             }
557
558             // Add attributes.
559             if (null != attributes && !attributes.isEmpty()) {
560                 SimulatorResourceAttribute value;
561                 for (Map.Entry<String, SimulatorResourceAttribute> entry : attributes
562                         .entrySet()) {
563                     value = entry.getValue();
564                     if (null != value)
565                         jSimulatorSingleResource.addAttribute(value);
566                 }
567
568                 // Get the resource model java object reference.
569                 resource.setResourceModel(jSimulatorSingleResource
570                         .getResourceModel());
571
572                 resource.setResourceRepresentation(resource.getResourceModel());
573             }
574
575             // Register the resource with the platform.
576             jSimulatorSingleResource.start();
577             resource.setStarted(true);
578
579             // Get the resource interfaces
580             resource.setResourceInterfaces(Utility
581                     .convertVectorToSet(jSimulatorSingleResource.getInterface()));
582         } catch (SimulatorException e) {
583             Activator
584                     .getDefault()
585                     .getLogManager()
586                     .log(Level.ERROR.ordinal(), new Date(),
587                             Utility.getSimulatorErrorString(e, null));
588             throw e;
589         }
590
591         // Add to local cache.
592         data.addResource(resource);
593
594         // Update UI listeners
595         UiListenerHandler.getInstance().resourceCreatedUINotification(
596                 ResourceType.SINGLE);
597
598         return true;
599     }
600
601     public Resource createResourceByRAML(String configFilePath)
602             throws SimulatorException {
603         Resource resource = null;
604         try {
605             // Create the resource
606             SimulatorResource jSimulatorResource = SimulatorManager
607                     .createResource(configFilePath);
608             if (null == jSimulatorResource) {
609                 return null;
610             }
611             if (jSimulatorResource instanceof SimulatorSingleResource) {
612                 resource = new SingleResource();
613             } else {
614                 return null;
615             }
616             resource.setSimulatorResource(jSimulatorResource);
617
618             // Fetch and locally store the resource name and uri.
619             String uri = jSimulatorResource.getURI();
620             if (null == uri || uri.trim().isEmpty()) {
621                 return null;
622             }
623             resource.setResourceURI(uri.trim());
624
625             String name = jSimulatorResource.getName();
626             if (null == name || name.trim().isEmpty()) {
627                 return null;
628             }
629             resource.setResourceName(name.trim());
630         } catch (SimulatorException e) {
631             Activator
632                     .getDefault()
633                     .getLogManager()
634                     .log(Level.ERROR.ordinal(), new Date(),
635                             Utility.getSimulatorErrorString(e, null));
636             throw e;
637         }
638         return resource;
639     }
640
641     /**
642      * This method can set/change the resource uri and name of an already
643      * created resource which is not yet registered with the platform. This
644      * method registers the model change and observer listeners, registers the
645      * resource, fetches the resource attributes, updates the local cache and
646      * notifies the UI listeners.
647      */
648     public boolean completeSingleResourceCreationByRAML(Resource resource,
649             String uri, String name, boolean multiInstance)
650             throws SimulatorException {
651         if (null == resource || !(resource instanceof SingleResource)) {
652             return false;
653         }
654         try {
655             SingleResource singleRes = (SingleResource) resource;
656
657             SimulatorSingleResource jSimulatorSingleResource = (SimulatorSingleResource) resource
658                     .getSimulatorResource();
659             if (null == jSimulatorSingleResource) {
660                 return false;
661             }
662
663             // Update resource URI and Name if they are changed.
664             String newUri = uri.trim();
665             String newName = name.trim();
666
667             if (multiInstance) {
668                 singleRes.setResourceURI(newUri);
669                 singleRes.setResourceName(newName);
670             } else {
671                 if (!singleRes.getResourceURI().equals(newUri)) {
672                     jSimulatorSingleResource.setURI(newUri);
673                     singleRes.setResourceURI(newUri);
674                 }
675                 if (!singleRes.getResourceName().equals(newName)) {
676                     jSimulatorSingleResource.setName(newName);
677                     singleRes.setResourceName(newName);
678                 }
679             }
680
681             // Set the model change listener.
682             jSimulatorSingleResource
683                     .setResourceModelChangeListener(resourceModelChangeListener);
684
685             // Set the observer listener if the resource is observable.
686             if (jSimulatorSingleResource.isObservable()) {
687                 jSimulatorSingleResource.setObserverListener(observer);
688                 singleRes.setObservable(true);
689             }
690
691             // Fetch the resource model.
692             SimulatorResourceModel jResModel = jSimulatorSingleResource
693                     .getResourceModel();
694             if (null == jResModel) {
695                 return false;
696             }
697             singleRes.setResourceModel(jResModel);
698
699             // Fetch the basic details of the resource.
700             singleRes.setResourceType(jSimulatorSingleResource
701                     .getResourceType());
702             singleRes
703                     .setResourceInterfaces(Utility
704                             .convertVectorToSet(jSimulatorSingleResource
705                                     .getInterface()));
706
707             // Fetch the resource attributes.
708             singleRes.setResourceRepresentation(jResModel);
709
710             // Register the resource with the platform.
711             jSimulatorSingleResource.start();
712             singleRes.setStarted(true);
713
714             // Add to local cache.
715             data.addResource(singleRes);
716
717             // Update UI listeners for single instance creation
718             if (!multiInstance)
719                 UiListenerHandler.getInstance().resourceCreatedUINotification(
720                         ResourceType.SINGLE);
721         } catch (Exception e) {
722             Activator
723                     .getDefault()
724                     .getLogManager()
725                     .log(Level.ERROR.ordinal(), new Date(),
726                             Utility.getSimulatorErrorString(e, null));
727             throw e;
728         }
729         return true;
730     }
731
732     public int createSingleResourceMultiInstances(String configFile, int count)
733             throws SimulatorException {
734         int createCount = 0;
735         try {
736             Vector<SimulatorResource> jSimulatorResources = SimulatorManager
737                     .createResource(configFile, count);
738             if (null == jSimulatorResources || jSimulatorResources.size() < 1) {
739                 return 0;
740             }
741             SimulatorSingleResource jResource;
742             SingleResource resource;
743             boolean result;
744             for (SimulatorResource jSimulatorResource : jSimulatorResources) {
745                 jResource = (SimulatorSingleResource) jSimulatorResource;
746                 resource = new SingleResource();
747                 resource.setSimulatorResource(jResource);
748                 try {
749                     result = completeSingleResourceCreationByRAML(resource,
750                             jResource.getURI(), jResource.getName(), true);
751                     if (result) {
752                         createCount++;
753                     }
754                 } catch (SimulatorException eInner) {
755                     Activator
756                             .getDefault()
757                             .getLogManager()
758                             .log(Level.ERROR.ordinal(),
759                                     new Date(),
760                                     Utility.getSimulatorErrorString(eInner,
761                                             null));
762                 }
763             }
764             if (createCount > 0) {
765                 UiListenerHandler.getInstance().resourceCreatedUINotification(
766                         ResourceType.SINGLE);
767             }
768         } catch (SimulatorException eOuter) {
769             Activator
770                     .getDefault()
771                     .getLogManager()
772                     .log(Level.ERROR.ordinal(), new Date(),
773                             Utility.getSimulatorErrorString(eOuter, null));
774             throw eOuter;
775         }
776         return createCount;
777     }
778
779     public List<Resource> getResourceList() {
780         List<Resource> resourceList = data.getResources();
781         if (null == resourceList) {
782             return null;
783         }
784         // Sort the list
785         Collections.sort(resourceList, Utility.resourceComparator);
786
787         return resourceList;
788     }
789
790     public List<SingleResource> getSingleResourceList() {
791         List<SingleResource> resourceList = data.getSingleResources();
792         if (null == resourceList) {
793             return null;
794         }
795         // Sort the list
796         Collections.sort(resourceList, Utility.singleResourceComparator);
797
798         return resourceList;
799     }
800
801     public void removeSingleResources(Set<SingleResource> resources)
802             throws SimulatorException {
803         if (null == resources) {
804             return;
805         }
806         Iterator<SingleResource> itr = resources.iterator();
807         while (itr.hasNext()) {
808             removeResource(itr.next());
809         }
810     }
811
812     public void removeResource(Resource res) throws SimulatorException {
813         // Unregister the resource from the platform.
814         SimulatorResource simRes = res.getSimulatorResource();
815         try {
816             simRes.stop();
817         } catch (SimulatorException e) {
818             Activator
819                     .getDefault()
820                     .getLogManager()
821                     .log(Level.ERROR.ordinal(), new Date(),
822                             Utility.getSimulatorErrorString(e, null));
823             throw e;
824         }
825
826         // Delete this resource
827         data.deleteResource(res);
828     }
829
830     public boolean isUriUnique(List<MetaProperty> properties) {
831         if (null == properties) {
832             return false;
833         }
834         MetaProperty prop;
835         Iterator<MetaProperty> itr = properties.iterator();
836         while (itr.hasNext()) {
837             prop = itr.next();
838             if (prop.getPropName().equals(Constants.RESOURCE_URI)) {
839                 String uri = prop.getPropValue();
840                 return !data.isResourceExist(uri);
841             }
842         }
843         return false;
844     }
845
846     public void resourceSelectionChanged(final Resource selectedResource) {
847         new Thread() {
848             @Override
849             public void run() {
850                 if (null != selectedResource) {
851                     setCurrentResourceInSelection(selectedResource);
852                 } else {
853                     setCurrentResourceInSelection(null);
854                 }
855                 // Notify all observers for resource selection change event
856                 UiListenerHandler.getInstance()
857                         .resourceSelectionChangedUINotification(
858                                 selectedResource);
859             }
860         }.start();
861     }
862
863     public List<MetaProperty> getMetaProperties(Resource resource) {
864         if (null != resource) {
865             String propName;
866             String propValue;
867
868             List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
869
870             for (int index = 0; index < Constants.META_PROPERTY_COUNT; index++) {
871                 propName = Constants.META_PROPERTIES[index];
872                 if (propName.equals(Constants.RESOURCE_NAME)) {
873                     propValue = resource.getResourceName();
874                 } else if (propName.equals(Constants.RESOURCE_URI)) {
875                     propValue = resource.getResourceURI();
876                 } else if (propName.equals(Constants.RESOURCE_TYPE)) {
877                     propValue = resource.getResourceType();
878                 } else {
879                     propValue = null;
880                 }
881                 if (null != propValue) {
882                     metaPropertyList.add(new MetaProperty(propName, propValue));
883                 }
884             }
885             return metaPropertyList;
886         }
887         return null;
888     }
889
890     public boolean startResource(Resource resource) throws SimulatorException {
891         if (null == resource) {
892             return false;
893         }
894         SimulatorResource server = resource.getSimulatorResource();
895         if (null == server) {
896             return false;
897         }
898         try {
899             server.start();
900             resource.setStarted(true);
901         } catch (SimulatorException e) {
902             Activator
903                     .getDefault()
904                     .getLogManager()
905                     .log(Level.ERROR.ordinal(),
906                             new Date(),
907                             "There is an error while starting the resource.\n"
908                                     + Utility.getSimulatorErrorString(e, null));
909             throw e;
910         }
911         return true;
912     }
913
914     public boolean stopResource(Resource resource) throws SimulatorException {
915         if (null == resource) {
916             return false;
917         }
918         SimulatorResource server = resource.getSimulatorResource();
919         if (null == server) {
920             return false;
921         }
922         try {
923             server.stop();
924             resource.setStarted(false);
925         } catch (SimulatorException e) {
926             Activator
927                     .getDefault()
928                     .getLogManager()
929                     .log(Level.ERROR.ordinal(),
930                             new Date(),
931                             "There is an error while stopping the resource.\n"
932                                     + Utility.getSimulatorErrorString(e, null));
933             throw e;
934         }
935         return true;
936     }
937
938     public boolean changeResourceName(Resource resource, String newName)
939             throws SimulatorException {
940         if (null == resource || null == newName) {
941             return false;
942         }
943
944         if (!stopResource(resource)) {
945             return false;
946         }
947
948         SimulatorResource server = resource.getSimulatorResource();
949         try {
950             server.setName(newName);
951             resource.setResourceName(newName);
952         } catch (SimulatorException e) {
953             Activator
954                     .getDefault()
955                     .getLogManager()
956                     .log(Level.ERROR.ordinal(),
957                             new Date(),
958                             "There is an error while changing the resource name.\n"
959                                     + Utility.getSimulatorErrorString(e, null));
960             throw e;
961         }
962
963         if (!startResource(resource)) {
964             return false;
965         }
966
967         return true;
968     }
969
970     public boolean changeResourceURI(Resource resource, String newURI)
971             throws SimulatorException {
972         if (null == resource || null == newURI) {
973             return false;
974         }
975
976         if (!stopResource(resource)) {
977             return false;
978         }
979
980         String curURI = resource.getResourceURI();
981         setResourceURI(resource, newURI);
982
983         try {
984             if (!startResource(resource)) {
985                 return false;
986             }
987         } catch (SimulatorException e) {
988             setResourceURI(resource, curURI);
989         }
990
991         return true;
992     }
993
994     public void setResourceURI(Resource resource, String newURI)
995             throws SimulatorException {
996         String curURI = resource.getResourceURI();
997         SimulatorResource server = resource.getSimulatorResource();
998         try {
999             server.setURI(newURI);
1000             data.changeResourceURI(resource, curURI, newURI);
1001         } catch (SimulatorException e) {
1002             Activator
1003                     .getDefault()
1004                     .getLogManager()
1005                     .log(Level.ERROR.ordinal(),
1006                             new Date(),
1007                             "There is an error while changing the resource URI.\n"
1008                                     + Utility.getSimulatorErrorString(e, null));
1009             throw e;
1010         }
1011     }
1012
1013     public boolean updateResourceProperties(Resource resource,
1014             List<MetaProperty> properties, boolean uriChanged,
1015             boolean nameChanged) throws SimulatorException {
1016         if (null == resource || null == properties) {
1017             return false;
1018         }
1019
1020         // Updating the properties
1021         Iterator<MetaProperty> itr = properties.iterator();
1022         MetaProperty property;
1023         String propName;
1024         String propValue;
1025         String resName = null;
1026         String resURI = null;
1027         while (itr.hasNext()) {
1028             property = itr.next();
1029             if (null == property) {
1030                 continue;
1031             }
1032             propName = property.getPropName();
1033             propValue = property.getPropValue();
1034             if (propName.equals(Constants.RESOURCE_NAME)) {
1035                 resName = propValue;
1036             } else if (propName.equals(Constants.RESOURCE_URI)) {
1037                 resURI = propValue;
1038             }
1039         }
1040
1041         if (nameChanged) {
1042             if (!changeResourceName(resource, resName)) {
1043                 return false;
1044             }
1045
1046             // Notify UI Listeners
1047             UiListenerHandler.getInstance().propertiesChangedUINotification(
1048                     Resource.class);
1049         }
1050
1051         if (uriChanged) {
1052             if (!changeResourceURI(resource, resURI)) {
1053                 return false;
1054             }
1055         }
1056
1057         return true;
1058     }
1059
1060     public boolean attributeValueUpdated(SingleResource resource,
1061             String attributeName, AttributeValue value) {
1062         if (null != resource && null != attributeName && null != value) {
1063             SimulatorSingleResource simRes = (SimulatorSingleResource) resource
1064                     .getSimulatorResource();
1065             if (null != simRes) {
1066                 try {
1067                     simRes.updateAttribute(attributeName, value);
1068                     return true;
1069                 } catch (SimulatorException e) {
1070                     Activator
1071                             .getDefault()
1072                             .getLogManager()
1073                             .log(Level.ERROR.ordinal(), new Date(),
1074                                     Utility.getSimulatorErrorString(e, null));
1075                 }
1076             }
1077         }
1078         return false;
1079     }
1080
1081     public boolean isResourceStarted(Resource resource) {
1082         if (null == resource) {
1083             return false;
1084         }
1085         return resource.isStarted();
1086     }
1087
1088     public boolean isPropertyValueInvalid(Resource resource,
1089             List<MetaProperty> properties, String propName) {
1090         if (null == resource || null == properties || null == propName) {
1091             return false;
1092         }
1093         boolean invalid = false;
1094         MetaProperty prop;
1095         Iterator<MetaProperty> itr = properties.iterator();
1096         while (itr.hasNext()) {
1097             prop = itr.next();
1098             if (prop.getPropName().equals(propName)) {
1099                 String value = prop.getPropValue();
1100                 if (propName.equals(Constants.RESOURCE_URI)) {
1101                     if (!Utility.isUriValid(value)) {
1102                         invalid = true;
1103                     }
1104                 } else {
1105                     if (null == value || value.trim().isEmpty()) {
1106                         invalid = true;
1107                     }
1108                 }
1109             }
1110         }
1111         return invalid;
1112     }
1113
1114     public boolean isPropValueChanged(Resource resource,
1115             List<MetaProperty> properties, String propName) {
1116         if (null == resource || null == properties || null == propName) {
1117             return false;
1118         }
1119         boolean changed = false;
1120         MetaProperty prop;
1121         String oldValue;
1122         Iterator<MetaProperty> itr = properties.iterator();
1123         while (itr.hasNext()) {
1124             prop = itr.next();
1125             if (prop.getPropName().equals(propName)) {
1126                 oldValue = getPropertyValueFromResource(resource, propName);
1127                 if (null != oldValue && !prop.getPropValue().equals(oldValue)) {
1128                     changed = true;
1129                 }
1130                 break;
1131             }
1132         }
1133         return changed;
1134     }
1135
1136     private String getPropertyValueFromResource(Resource resource,
1137             String propName) {
1138         if (null == resource || null == propName) {
1139             return null;
1140         }
1141         if (propName.equals(Constants.RESOURCE_URI)) {
1142             return resource.getResourceURI();
1143         } else if (propName.equals(Constants.RESOURCE_NAME)) {
1144             return resource.getResourceName();
1145         } else if (propName.equals(Constants.RESOURCE_TYPE)) {
1146             return resource.getResourceType();
1147         } else {
1148             return null;
1149         }
1150     }
1151
1152     public boolean isAttHasRangeOrAllowedValues(SimulatorResourceAttribute att) {
1153         if (null == att) {
1154             return false;
1155         }
1156         AttributeProperty prop = att.property();
1157         if (null == prop) {
1158             return false;
1159         }
1160         Type attProp = prop.type();
1161         if (attProp == Type.UNKNOWN) {
1162             return false;
1163         }
1164         return true;
1165     }
1166
1167     public int startAutomation(SingleResource resource,
1168             AttributeElement attribute, AutoUpdateType autoType,
1169             int autoUpdateInterval) {
1170         int autoId = -1;
1171         if (null != resource && null != attribute) {
1172             SimulatorSingleResource server = (SimulatorSingleResource) resource
1173                     .getSimulatorResource();
1174             if (null != server) {
1175                 String attrName = attribute.getSimulatorResourceAttribute()
1176                         .name();
1177                 try {
1178                     autoId = server.startAttributeUpdation(attrName, autoType,
1179                             autoUpdateInterval, automationListener);
1180                 } catch (SimulatorException e) {
1181                     Activator
1182                             .getDefault()
1183                             .getLogManager()
1184                             .log(Level.ERROR.ordinal(),
1185                                     new Date(),
1186                                     "[" + e.getClass().getSimpleName() + "]"
1187                                             + e.code().toString() + "-"
1188                                             + e.message());
1189                     return -1;
1190                 }
1191                 if (-1 != autoId) {
1192                     attribute.setAutoUpdateId(autoId);
1193                     attribute.setAutoUpdateType(autoType);
1194                     attribute.setAutoUpdateInterval(autoUpdateInterval);
1195                     attribute.setAutoUpdateState(true);
1196                     resource.setAttributeAutomationInProgress(true);
1197                 }
1198             }
1199         }
1200         return autoId;
1201     }
1202
1203     public void stopAutomation(SingleResource resource, AttributeElement att,
1204             int autoId) {
1205         if (null != resource) {
1206             SimulatorSingleResource server = (SimulatorSingleResource) resource
1207                     .getSimulatorResource();
1208             if (null != server) {
1209                 try {
1210                     server.stopUpdation(autoId);
1211                 } catch (SimulatorException e) {
1212                     Activator
1213                             .getDefault()
1214                             .getLogManager()
1215                             .log(Level.ERROR.ordinal(),
1216                                     new Date(),
1217                                     "[" + e.getClass().getSimpleName() + "]"
1218                                             + e.code().toString() + "-"
1219                                             + e.message());
1220                     return;
1221                 }
1222                 // Change the automation status
1223                 att.setAutoUpdateState(false);
1224                 resource.setAttributeAutomationInProgress(isAnyAttributeInAutomation(resource));
1225             }
1226         }
1227     }
1228
1229     public boolean startResourceAutomationUIRequest(AutoUpdateType autoType,
1230             int autoUpdateInterval, final SingleResource resource) {
1231         if (null == resource) {
1232             return false;
1233         }
1234         boolean status = false;
1235         changeResourceLevelAutomationStatus(resource, true);
1236         // Invoke the native automation method
1237         SimulatorSingleResource resourceServer = (SimulatorSingleResource) resource
1238                 .getSimulatorResource();
1239         if (null != resourceServer) {
1240             int autoId = -1;
1241             try {
1242                 autoId = resourceServer.startResourceUpdation(autoType,
1243                         autoUpdateInterval, automationListener);
1244             } catch (SimulatorException e) {
1245                 Activator
1246                         .getDefault()
1247                         .getLogManager()
1248                         .log(Level.ERROR.ordinal(), new Date(),
1249                                 Utility.getSimulatorErrorString(e, null));
1250                 autoId = -1;
1251             }
1252             if (-1 == autoId) {
1253                 // Automation request failed and hence status is being
1254                 // rolled back
1255                 changeResourceLevelAutomationStatus(resource, false);
1256             } else {
1257                 // Automation request accepted.
1258                 resource.setAutomationId(autoId);
1259
1260                 // Notify the UI listeners in a different thread.
1261                 Thread notifyThread = new Thread() {
1262                     public void run() {
1263                         UiListenerHandler.getInstance()
1264                                 .resourceAutomationStartedUINotification(
1265                                         resource);
1266                     };
1267                 };
1268                 notifyThread.setPriority(Thread.MAX_PRIORITY);
1269                 notifyThread.start();
1270
1271                 status = true;
1272             }
1273         }
1274         return status;
1275     }
1276
1277     public boolean stopResourceAutomationUIRequest(final SingleResource resource) {
1278         if (null == resource) {
1279             return false;
1280         }
1281         final int autoId = resource.getAutomationId();
1282         if (-1 == autoId) {
1283             return false;
1284         }
1285         SimulatorSingleResource resourceServer = (SimulatorSingleResource) resource
1286                 .getSimulatorResource();
1287         if (null == resourceServer) {
1288             return false;
1289         }
1290         // Call native method
1291         try {
1292             resourceServer.stopUpdation(autoId);
1293         } catch (SimulatorException e) {
1294             Activator
1295                     .getDefault()
1296                     .getLogManager()
1297                     .log(Level.ERROR.ordinal(), new Date(),
1298                             Utility.getSimulatorErrorString(e, null));
1299             return false;
1300         }
1301
1302         // Notify the UI Listeners. Invoke the automation complete callback.
1303         Thread stopThread = new Thread() {
1304             public void run() {
1305                 automationListener.onUpdateComplete(resource.getResourceURI(),
1306                         autoId);
1307             }
1308         };
1309         stopThread.start();
1310         return true;
1311     }
1312
1313     private boolean isAnyAttributeInAutomation(SingleResource resource) {
1314         if (null == resource || null == resource.getResourceRepresentation()) {
1315             return false;
1316         }
1317
1318         Map<String, AttributeElement> attributes = resource
1319                 .getResourceRepresentation().getAttributes();
1320         if (null == attributes || 0 == attributes.size())
1321             return false;
1322
1323         for (Map.Entry<String, AttributeElement> entry : attributes.entrySet()) {
1324             if (entry.getValue().isAutoUpdateInProgress())
1325                 return true;
1326         }
1327
1328         return false;
1329     }
1330
1331     // Changes the automation state of the resource and its attributes
1332     private void changeResourceLevelAutomationStatus(SingleResource resource,
1333             boolean status) {
1334
1335         if (null == resource || null == resource.getResourceRepresentation()) {
1336             return;
1337         }
1338
1339         Map<String, AttributeElement> attributes = resource
1340                 .getResourceRepresentation().getAttributes();
1341         if (null == attributes || 0 == attributes.size())
1342             return;
1343
1344         for (Map.Entry<String, AttributeElement> entry : attributes.entrySet()) {
1345             entry.getValue().setAutoUpdateState(status);
1346         }
1347
1348         resource.setResourceAutomationInProgress(status);
1349     }
1350
1351     private AttributeElement getAttributeWithGivenAutomationId(
1352             SingleResource resource, int automationId) {
1353         if (null == resource || null == resource.getResourceRepresentation()) {
1354             return null;
1355         }
1356
1357         Map<String, AttributeElement> attributes = resource
1358                 .getResourceRepresentation().getAttributes();
1359         if (null == attributes || 0 == attributes.size())
1360             return null;
1361
1362         for (Map.Entry<String, AttributeElement> entry : attributes.entrySet()) {
1363             if (automationId == entry.getValue().getAutoUpdateId())
1364                 return entry.getValue();
1365         }
1366
1367         return null;
1368     }
1369
1370     public boolean isResourceAutomationStarted(SingleResource resource) {
1371         boolean status = false;
1372         if (null != resource) {
1373             status = resource.isResourceAutomationInProgress();
1374         }
1375         return status;
1376     }
1377
1378     public boolean isAttributeAutomationStarted(SingleResource resource) {
1379         if (null == resource) {
1380             return false;
1381         }
1382         return resource.isAttributeAutomationInProgress();
1383     }
1384
1385     public void notifyObserverRequest(Resource resource, int observerId) {
1386         if (null == resource) {
1387             return;
1388         }
1389         SimulatorResource simulatorResource = resource.getSimulatorResource();
1390         if (null == simulatorResource) {
1391             return;
1392         }
1393         try {
1394             simulatorResource.notifyObserver(observerId);
1395         } catch (SimulatorException e) {
1396             Activator
1397                     .getDefault()
1398                     .getLogManager()
1399                     .log(Level.ERROR.ordinal(), new Date(),
1400                             Utility.getSimulatorErrorString(e, null));
1401         }
1402     }
1403
1404     public List<String> getAllValuesOfAttribute(SimulatorResourceAttribute att) {
1405         if (null == att) {
1406             return null;
1407         }
1408
1409         AttributeValue val = att.value();
1410         if (null == val) {
1411             return null;
1412         }
1413
1414         TypeInfo type = val.typeInfo();
1415
1416         AttributeProperty prop = att.property();
1417         if (null == prop) {
1418             return null;
1419         }
1420
1421         List<String> values = new ArrayList<String>();
1422
1423         Type valuesType = prop.type();
1424
1425         if (valuesType == Type.UNKNOWN) {
1426             // Adding the default value
1427             values.add(Utility.getAttributeValueAsString(val));
1428             return values;
1429         }
1430
1431         if (type.mType != ValueType.RESOURCEMODEL) {
1432             if (type.mType == ValueType.ARRAY) {
1433                 if (type.mDepth == 1) {
1434                     AttributeProperty childProp = prop.getChildProperty();
1435                     if (null != childProp) {
1436                         valuesType = childProp.type();
1437                         if (valuesType == Type.RANGE) {
1438                             List<String> list = getRangeForPrimitiveNonArrayAttributes(
1439                                     childProp, type.mBaseType);
1440                             if (null != list) {
1441                                 values.addAll(list);
1442                             }
1443                         } else if (valuesType == Type.VALUESET) {
1444                             List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
1445                                     childProp.valueSet(), type.mBaseType);
1446                             if (null != list) {
1447                                 values.addAll(list);
1448                             }
1449                         }
1450                     }
1451                 }
1452             } else {
1453                 if (valuesType == Type.RANGE) {
1454                     List<String> list = getRangeForPrimitiveNonArrayAttributes(
1455                             prop, type.mType);
1456                     if (null != list) {
1457                         values.addAll(list);
1458                     }
1459                 } else if (valuesType == Type.VALUESET) {
1460                     List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
1461                             prop.valueSet(), type.mType);
1462                     if (null != list) {
1463                         values.addAll(list);
1464                     }
1465                 }
1466             }
1467         }
1468
1469         return values;
1470     }
1471
1472     public List<String> getRangeForPrimitiveNonArrayAttributes(
1473             AttributeProperty prop, ValueType type) {
1474         if (null == prop) {
1475             return null;
1476         }
1477
1478         if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
1479             return null;
1480         }
1481
1482         List<String> values = new ArrayList<String>();
1483         switch (type) {
1484             case INTEGER:
1485                 int min = (int) prop.min();
1486                 int max = (int) prop.max();
1487                 for (int iVal = min; iVal <= max; iVal++) {
1488                     values.add(String.valueOf(iVal));
1489                 }
1490                 break;
1491             case DOUBLE:
1492                 double minD = (double) prop.min();
1493                 double maxD = (double) prop.max();
1494                 for (double iVal = minD; iVal <= maxD; iVal = iVal + 1.0) {
1495                     values.add(String.valueOf(iVal));
1496                 }
1497                 break;
1498             default:
1499         }
1500         return values;
1501     }
1502
1503     public List<String> getAllowedValuesForPrimitiveNonArrayAttributes(
1504             AttributeValue[] attValues, ValueType type) {
1505         if (null == attValues || attValues.length < 1) {
1506             return null;
1507         }
1508
1509         if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
1510             return null;
1511         }
1512
1513         Object obj;
1514         List<String> values = new ArrayList<String>();
1515         for (AttributeValue val : attValues) {
1516             if (null == val) {
1517                 continue;
1518             }
1519             obj = val.get();
1520             if (null == obj) {
1521                 continue;
1522             }
1523             values.add(String.valueOf(obj));
1524         }
1525         return values;
1526     }
1527
1528     public int getResourceCount() {
1529         return data.getResourceCount();
1530     }
1531
1532     public void shutdown() {
1533         threadHandle.interrupt();
1534     }
1535 }