import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
-import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.Vector;
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.model.AttributeElement;
+import oic.simulator.serviceprovider.model.MetaProperty;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.ResourceType;
+import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
+
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.widgets.Display;
+import org.oic.simulator.ArrayProperty;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeProperty.Type;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.BooleanProperty;
+import org.oic.simulator.DeviceInfo;
+import org.oic.simulator.DeviceListener;
+import org.oic.simulator.DoubleProperty;
import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.IntegerProperty;
import org.oic.simulator.PlatformInfo;
import org.oic.simulator.SimulatorException;
import org.oic.simulator.SimulatorManager;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.StringProperty;
import org.oic.simulator.server.Observer;
-import org.oic.simulator.server.SimulatorCollectionResource;
import org.oic.simulator.server.SimulatorResource;
import org.oic.simulator.server.SimulatorResource.AutoUpdateListener;
import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
import org.oic.simulator.server.SimulatorResource.ResourceModelChangeListener;
import org.oic.simulator.server.SimulatorSingleResource;
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.AttributeElement;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Device;
-import oic.simulator.serviceprovider.model.LocalResourceAttribute;
-import oic.simulator.serviceprovider.model.MetaProperty;
-import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.ResourceType;
-import oic.simulator.serviceprovider.model.SRMItem;
-import oic.simulator.serviceprovider.model.SingleResource;
-import oic.simulator.serviceprovider.utils.Constants;
-import oic.simulator.serviceprovider.utils.Utility;
-
/**
* This class acts as an interface between the simulator java SDK and the
* various UI modules. It maintains all the details of resources and provides
private Resource currentResourceInSelection;
- private Device currentDeviceInSelection;
-
private ResourceModelChangeListener resourceModelChangeListener;
private AutoUpdateListener automationListener;
private ObserverListener observer;
+ private DeviceListener deviceListener;
+
private NotificationSynchronizerThread synchronizerThread;
private Thread threadHandle;
- private String deviceName;
+ private DeviceInfo deviceInfo;
private PlatformInfo platformInfo;
+ private String deviceName;
+
public ResourceManager() {
data = new Data();
- // Set the default device and platform information
- deviceName = "IoTivity Simulator";
- try {
- SimulatorManager.setDeviceInfo(deviceName);
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "Error while registering the device info.\n"
- + Utility.getSimulatorErrorString(e, null));
- }
+ deviceListener = new DeviceListener() {
- platformInfo = new PlatformInfo();
- platformInfo.setPlatformID("Samsung Platform Identifier");
- platformInfo.setManufacturerName("Samsung");
- platformInfo.setManufacturerUrl("www.samsung.com");
- platformInfo.setModelNumber("Samsung Model Num01");
- platformInfo.setDateOfManufacture("2015-09-10T11:10:30Z");
- platformInfo.setPlatformVersion("PlatformVersion01");
- platformInfo.setOperationSystemVersion("OSVersion01");
- platformInfo.setHardwareVersion("HardwareVersion01");
- platformInfo.setFirmwareVersion("FirwareVersion01");
- platformInfo.setSupportUrl("http://www.samsung.com/support");
- platformInfo.setSystemTime("2015-09-10T11:10:30Z");
- try {
- SimulatorManager.setPlatformInfo(platformInfo);
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "Error while registering the platform info.\n"
- + Utility.getSimulatorErrorString(e, null));
- }
+ @Override
+ public void onDeviceFound(final String host,
+ final DeviceInfo deviceInfo) {
+ if (null != ResourceManager.this.deviceInfo
+ || null == deviceInfo || null == host) {
+ return;
+ }
+ synchronizerThread.addToQueue(new Runnable() {
+ @Override
+ public void run() {
+ String rcvdDeviceName = deviceInfo.getName();
+ if (null == rcvdDeviceName) {
+ return;
+ }
+ if (deviceName.equalsIgnoreCase(rcvdDeviceName)) {
+ ResourceManager.this.deviceInfo = deviceInfo;
+
+ // Notify the UI Listeners
+ UiListenerHandler.getInstance()
+ .deviceInfoReceivedNotification();
+ }
+ }
+ });
+ }
+ };
resourceModelChangeListener = new ResourceModelChangeListener() {
Resource resource = data
.getResourceByURI(resourceURI);
if (null != resource) {
- resource.setResourceRepresentation(resourceModelN);
+ try {
+ resource.updateResourceRepresentation(resourceModelN);
+ } catch (NumberFormatException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "Error while trying to update the attributes.\n"
+ + Utility
+ .getSimulatorErrorString(
+ e,
+ null));
+ }
}
}
});
final AttributeElement attribute = getAttributeWithGivenAutomationId(
resource, automationId);
if (null != attribute) {
- // Display.getDefault().asyncExec(new Runnable()
- // {
- // @Override
- // public void run() {
attribute.setAutoUpdateState(false);
- // }
- // });
resource.setAttributeAutomationInProgress(isAnyAttributeInAutomation(resource));
- // Notify the UI listeners
- /*
- * UiListenerHandler .getInstance()
- * .automationCompleteUINotification( resource,
- * attribute
- * .getSimulatorResourceAttribute().name());
- */
} else {
- // TODO: Temporarily reset the attribute
- // automation status to false for making
- // resource-level automation work after
- // attribute-level automations.
+ // Setting the attribute automation status to
+ // false.
resource.setAttributeAutomationInProgress(false);
}
}
threadHandle = new Thread(synchronizerThread);
threadHandle.setName("Simulator service provider event queue");
threadHandle.start();
+
+ // Set the default device name.
+ deviceName = "IoTivity Simulator";
+ try {
+ SimulatorManager.setDeviceInfo(deviceName);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "Error while registering the device info.\n"
+ + Utility.getSimulatorErrorString(e, null));
+ }
+
+ // Set the default platform information.
+ platformInfo = new PlatformInfo();
+ platformInfo.setPlatformID("Samsung Platform Identifier");
+ platformInfo.setManufacturerName("Samsung");
+ platformInfo.setManufacturerUrl("www.samsung.com");
+ platformInfo.setModelNumber("Samsung Model Num01");
+ platformInfo.setDateOfManufacture("2015-09-10T11:10:30Z");
+ platformInfo.setPlatformVersion("PlatformVersion01");
+ platformInfo.setOperationSystemVersion("OSVersion01");
+ platformInfo.setHardwareVersion("HardwareVersion01");
+ platformInfo.setFirmwareVersion("FirwareVersion01");
+ platformInfo.setSupportUrl("http://www.samsung.com/support");
+ platformInfo.setSystemTime("2015-09-10T11:10:30Z");
+ try {
+ SimulatorManager.setPlatformInfo(platformInfo);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "Error while registering the platform info.\n"
+ + Utility.getSimulatorErrorString(e, null));
+ }
+
+ // Get the device information to show other details of the device in UI.
+ try {
+ SimulatorManager.findDevices("", deviceListener);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "Failed to get the local device information.\n"
+ + Utility.getSimulatorErrorString(e, null));
+ }
}
private static class NotificationSynchronizerThread implements Runnable {
}
}
- public String getDeviceName() {
- return deviceName;
- }
+ public void setDeviceInfo(List<MetaProperty> metaProperties) {
+ if (null == metaProperties || metaProperties.size() < 1) {
+ return;
+ }
+ Iterator<MetaProperty> itr = metaProperties.iterator();
+ MetaProperty prop;
+ String propName;
+ String propValue;
+ boolean found = false;
+ while (itr.hasNext()) {
+ prop = itr.next();
+ propName = prop.getPropName();
+ propValue = prop.getPropValue();
+ if (propName.equals(Constants.DEVICE_NAME)) {
+ this.deviceName = propValue;
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ return;
+ }
- public void setDeviceName(String deviceName) {
- this.deviceName = deviceName;
try {
SimulatorManager.setDeviceInfo(deviceName);
} catch (SimulatorException e) {
}
}
+ public boolean isDeviceInfoValid(List<MetaProperty> metaProperties) {
+ if (null == metaProperties || metaProperties.size() < 1) {
+ return false;
+ }
+
+ Iterator<MetaProperty> itr = metaProperties.iterator();
+ MetaProperty prop;
+ String propName;
+ String propValue;
+ while (itr.hasNext()) {
+ prop = itr.next();
+ propName = prop.getPropName();
+ propValue = prop.getPropValue();
+ if (propName.equals(Constants.DEVICE_NAME)) {
+ if (null == propValue || propValue.length() < 1) {
+ return false;
+ }
+ break;
+ }
+ }
+ return true;
+ }
+
+ public List<MetaProperty> getDeviceInfo() {
+ List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
+ metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, deviceName));
+ if (null != deviceInfo) {
+ metaProperties.add(new MetaProperty(Constants.DEVICE_ID, deviceInfo
+ .getID()));
+ metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
+ deviceInfo.getSpecVersion()));
+ metaProperties.add(new MetaProperty(Constants.DEVICE_DMV,
+ deviceInfo.getDataModelVersion()));
+ }
+ return metaProperties;
+ }
+
public List<MetaProperty> getPlatformInfo() {
List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();
metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, platformInfo
}
}
+ public boolean isPlatformInfoValid(List<MetaProperty> metaProperties) {
+ if (null == metaProperties || metaProperties.size() < 1) {
+ return false;
+ }
+ Iterator<MetaProperty> itr = metaProperties.iterator();
+ MetaProperty prop;
+ String propValue;
+ while (itr.hasNext()) {
+ prop = itr.next();
+ propValue = prop.getPropValue();
+ if (null == propValue || propValue.length() < 1) {
+ return false;
+ }
+ }
+ return true;
+ }
+
public synchronized Resource getCurrentResourceInSelection() {
return currentResourceInSelection;
}
this.currentResourceInSelection = resource;
}
- public synchronized Device getCurrentDeviceInSelection() {
- return currentDeviceInSelection;
- }
-
- public synchronized void setCurrentDeviceInSelection(Device dev) {
- this.currentDeviceInSelection = dev;
- }
-
public boolean isResourceExist(String resourceURI) {
return data.isResourceExist(resourceURI);
}
return data.isAnyResourceExist();
}
- public boolean createSingleResource(SingleResource resource)
+ public boolean createSingleResource(SingleResource resource,
+ Map<String, SimulatorResourceAttribute> attributes)
throws SimulatorException {
if (null == resource) {
return false;
}
- String resType = (String) resource.getResourceTypes().toArray()[0];
+
try {
- // 1. Create the resource.
+ // Create the resource.
SimulatorResource jSimulatorResource = SimulatorManager
.createResource(SimulatorResource.Type.SINGLE,
resource.getResourceName(),
- resource.getResourceURI(), resType);
+ resource.getResourceURI(),
+ resource.getResourceType());
if (null == jSimulatorResource
|| !(jSimulatorResource instanceof SimulatorSingleResource)) {
return false;
SimulatorSingleResource jSimulatorSingleResource = (SimulatorSingleResource) jSimulatorResource;
resource.setSimulatorResource(jSimulatorSingleResource);
- // 2. Cancel observable property if requested by user.
+ // Cancel discoverable property if requested by user.
+ if (!resource.isDiscoverable()) {
+ jSimulatorSingleResource.setDiscoverable(false);
+ }
+
+ // Cancel observable property if requested by user.
if (!resource.isObservable()) {
jSimulatorSingleResource.setObservable(false);
}
- // 3. Set the model change listener.
+ // Set the model change listener.
jSimulatorSingleResource
.setResourceModelChangeListener(resourceModelChangeListener);
- // 4. Set the observer listener if the resource is observable.
+ // Set the observer listener if the resource is observable.
if (resource.isObservable()) {
jSimulatorSingleResource.setObserverListener(observer);
}
- // 5. Add attributes.
- Map<String, LocalResourceAttribute> attributes = resource
- .getResourceAttributes();
+ // Add attributes.
if (null != attributes && !attributes.isEmpty()) {
- Set<String> keySet = attributes.keySet();
- Iterator<String> itr = keySet.iterator();
-
- String attName;
- LocalResourceAttribute localAtt;
- SimulatorResourceAttribute simResAtt;
-
- while (itr.hasNext()) {
- attName = itr.next();
- localAtt = attributes.get(attName);
- if (null == localAtt) {
- continue;
- }
- simResAtt = localAtt.getResourceAttributeRef();
- if (null == simResAtt) {
- continue;
- }
- jSimulatorSingleResource.addAttribute(simResAtt);
+ SimulatorResourceAttribute value;
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : attributes
+ .entrySet()) {
+ value = entry.getValue();
+ if (null != value)
+ jSimulatorSingleResource.addAttribute(value);
}
- // 6. Get the resource model java object reference.
+ // Get the resource model java object reference.
resource.setResourceModel(jSimulatorSingleResource
.getResourceModel());
- resource.setResourceRepresentation(resource.getResourceModel());
+ resource.createResourceRepresentation(jSimulatorSingleResource
+ .getAttributes());
}
- // 7. Register the resource with the platform.
+ // Set the resource interfaces.
+ jSimulatorSingleResource
+ .setInterface(Utility.convertSetToVectorString(resource
+ .getResourceInterfaces()));
+
+ // Register the resource with the platform.
jSimulatorSingleResource.start();
resource.setStarted(true);
} catch (SimulatorException e) {
throw e;
}
- // 8. Add to local cache.
+ // Add to local cache.
data.addResource(resource);
- // 9. Update UI listeners
+ // Update UI listeners
UiListenerHandler.getInstance().resourceCreatedUINotification(
ResourceType.SINGLE);
return true;
}
- public boolean createCollectionResource(CollectionResource resource)
- throws SimulatorException {
- if (null == resource) {
- return false;
- }
- String resType = (String) resource.getResourceTypes().toArray()[0];
- try {
- // 1. Create the resource.
- SimulatorResource jSimulatorResource = SimulatorManager
- .createResource(SimulatorResource.Type.COLLECTION,
- resource.getResourceName(),
- resource.getResourceURI(), resType);
- if (null == jSimulatorResource
- || !(jSimulatorResource instanceof SimulatorCollectionResource)) {
- return false;
- }
- SimulatorCollectionResource jSimulatorCollectionResource = (SimulatorCollectionResource) jSimulatorResource;
- resource.setSimulatorResource(jSimulatorCollectionResource);
-
- // 2. Cancel observable property if requested by user.
- if (!resource.isObservable()) {
- jSimulatorCollectionResource.setObservable(false);
- }
-
- // 3. Set the observer listener if the resource is observable.
- if (resource.isObservable()) {
- jSimulatorCollectionResource.setObserverListener(observer);
- }
-
- // 4. Set the model change listener.
- jSimulatorCollectionResource
- .setResourceModelChangeListener(resourceModelChangeListener);
-
- // set resource model
- resource.setResourceRepresentation(jSimulatorCollectionResource
- .getResourceModel());;
-
- // 5. Register the resource with the platform.
- jSimulatorCollectionResource.start();
- resource.setStarted(true);
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- throw e;
- }
-
- // 6. Add to local cache.
- data.addResource(resource);
-
- // 7. Update UI listeners
- UiListenerHandler.getInstance().resourceCreatedUINotification(
- ResourceType.COLLECTION);
-
- return true;
- }
-
public Resource createResourceByRAML(String configFilePath)
throws SimulatorException {
Resource resource = null;
try {
- // 1. Create the resource
+ // Create the resource
SimulatorResource jSimulatorResource = SimulatorManager
.createResource(configFilePath);
if (null == jSimulatorResource) {
if (jSimulatorResource instanceof SimulatorSingleResource) {
resource = new SingleResource();
} else {
- resource = new CollectionResource();
+ return null;
}
resource.setSimulatorResource(jSimulatorResource);
- // 2. Fetch and locally store the resource name and uri.
+ // Fetch and locally store the resource name and uri.
String uri = jSimulatorResource.getURI();
if (null == uri || uri.trim().isEmpty()) {
return null;
return false;
}
- // 1. Update resource URI and Name if they are changed.
+ // Update resource URI and Name if they are changed.
String newUri = uri.trim();
String newName = name.trim();
}
}
- // 2. Set the model change listener.
+ // Set the model change listener.
jSimulatorSingleResource
.setResourceModelChangeListener(resourceModelChangeListener);
- // 3. Set the observer listener if the resource is observable.
+ // Set the observer listener if the resource is observable.
if (jSimulatorSingleResource.isObservable()) {
jSimulatorSingleResource.setObserverListener(observer);
singleRes.setObservable(true);
}
- // 4. Fetch the resource model.
+ // Fetch the resource model.
SimulatorResourceModel jResModel = jSimulatorSingleResource
.getResourceModel();
if (null == jResModel) {
}
singleRes.setResourceModel(jResModel);
- // 5. Fetch the basic details of the resource.
- singleRes.addResourceType(jSimulatorSingleResource
+ // Fetch the basic details of the resource.
+ singleRes.setResourceType(jSimulatorSingleResource
.getResourceType());
singleRes
.setResourceInterfaces(Utility
.convertVectorToSet(jSimulatorSingleResource
.getInterface()));
- // 6. Register the resource with the platform.
+ // Fetch the resource attributes.
+ singleRes.createResourceRepresentation(jSimulatorSingleResource
+ .getAttributes());
+
+ // Register the resource with the platform.
jSimulatorSingleResource.start();
singleRes.setStarted(true);
- singleRes.setResourceRepresentation(jResModel);
-
- // 7. Fetch the resource attributes.
- Map<String, LocalResourceAttribute> resourceAttributeMap;
- resourceAttributeMap = fetchResourceAttributesFromModel(jResModel);
- if (null != resourceAttributeMap) {
- singleRes.setResourceAttributes(resourceAttributeMap);
- }
-
- // 8. Add to local cache.
+ // Add to local cache.
data.addResource(singleRes);
- // 9. Update UI listeners for single instance creation
+ // Update UI listeners for single instance creation
if (!multiInstance)
UiListenerHandler.getInstance().resourceCreatedUINotification(
ResourceType.SINGLE);
- } catch (SimulatorException e) {
+ } catch (Exception e) {
Activator
.getDefault()
.getLogManager()
return true;
}
- /**
- * This method can set/change the resource uri and name of an already
- * created resource which is not yet registered with the platform. This
- * method registers the model change and observer listeners, registers the
- * resource, fetches the resource attributes, updates the local cache and
- * notifies the UI listeners.
- */
- public boolean completeCollectionResourceCreationByRAML(Resource resource,
- String uri, String name) throws SimulatorException {
- if (null == resource || !(resource instanceof CollectionResource)) {
- return false;
- }
+ public Set<SingleResource> createSingleResourceMultiInstances(
+ String configFile, int count, IProgressMonitor progressMonitor)
+ throws SimulatorException {
+ Set<SingleResource> resultSet;
try {
- CollectionResource collectionRes = (CollectionResource) resource;
-
- SimulatorCollectionResource jSimulatorCollectionResource = (SimulatorCollectionResource) resource
- .getSimulatorResource();
- if (null == jSimulatorCollectionResource) {
- return false;
- }
-
- // 1. Update resource URI and Name if they are changed.
- String newUri = uri.trim();
- String newName = name.trim();
-
- if (!collectionRes.getResourceURI().equals(newUri)) {
- jSimulatorCollectionResource.setURI(newUri);
- collectionRes.setResourceURI(newUri);
- }
- if (!collectionRes.getResourceName().equals(newName)) {
- jSimulatorCollectionResource.setName(newName);
- collectionRes.setResourceName(newName);
- }
-
- // 2. Set the model change listener.
- jSimulatorCollectionResource
- .setResourceModelChangeListener(resourceModelChangeListener);
-
- // 3. Fetch the resource model.
- SimulatorResourceModel jResModel = jSimulatorCollectionResource
- .getResourceModel();
- if (null == jResModel) {
- return false;
- }
- collectionRes.setResourceModel(jResModel);
-
- // 4. Fetch the basic details of the resource.
- collectionRes.addResourceType(jSimulatorCollectionResource
- .getResourceType());
- collectionRes.setResourceInterfaces(Utility
- .convertVectorToSet(jSimulatorCollectionResource
- .getInterface()));
-
- // 5. Set the observer listener if the resource is observable.
- if (jSimulatorCollectionResource.isObservable()) {
- jSimulatorCollectionResource.setObserverListener(observer);
- collectionRes.setObservable(true);
- }
-
- // 6. Register the resource with the platform.
- jSimulatorCollectionResource.start();
- collectionRes.setStarted(true);
-
- collectionRes.setResourceRepresentation(jResModel);
-
- // 7. Fetch the resource attributes.
- Map<String, LocalResourceAttribute> resourceAttributeMap;
- resourceAttributeMap = fetchResourceAttributesFromModel(jResModel);
- if (null != resourceAttributeMap) {
- collectionRes.setResourceAttributes(resourceAttributeMap);
- }
-
- // 6. Add to local cache.
- data.addResource(collectionRes);
-
- // 7. Update UI listeners for single instance creation
- UiListenerHandler.getInstance().resourceCreatedUINotification(
- ResourceType.COLLECTION);
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- throw e;
- }
- return true;
- }
-
- public int createSingleResourceMultiInstances(String configFile, int count)
- throws SimulatorException {
- int createCount = 0;
- try {
- Vector<SimulatorResource> jSimulatorResources = SimulatorManager
- .createResource(configFile, count);
- if (null == jSimulatorResources || jSimulatorResources.size() < 1) {
- return 0;
+ resultSet = new HashSet<SingleResource>();
+ Vector<SimulatorResource> jSimulatorResources = SimulatorManager
+ .createResource(configFile, count);
+ if (null == jSimulatorResources || jSimulatorResources.size() < 1) {
+ return null;
}
SimulatorSingleResource jResource;
SingleResource resource;
boolean result;
for (SimulatorResource jSimulatorResource : jSimulatorResources) {
+ // If the resource creation progress is canceled, then stop the
+ // creation and stop/delete
+ // the resources created already.
+ if (progressMonitor.isCanceled()) {
+ removeSingleResources(resultSet);
+ return null;
+ }
jResource = (SimulatorSingleResource) jSimulatorResource;
resource = new SingleResource();
resource.setSimulatorResource(jResource);
result = completeSingleResourceCreationByRAML(resource,
jResource.getURI(), jResource.getName(), true);
if (result) {
- createCount++;
+ resultSet.add(resource);
}
} catch (SimulatorException eInner) {
Activator
Utility.getSimulatorErrorString(eInner,
null));
}
- }
- if (createCount > 0) {
- UiListenerHandler.getInstance().resourceCreatedUINotification(
- ResourceType.SINGLE);
+ progressMonitor.worked(1);
}
} catch (SimulatorException eOuter) {
Activator
Utility.getSimulatorErrorString(eOuter, null));
throw eOuter;
}
- return createCount;
- }
-
- public void createDevice(String deviceName, Set<Resource> childs) {
- // 1. Create device
- Device dev = new Device();
- dev.setDeviceName(deviceName);
- data.addDevice(dev);
-
- // 2. Add children to device
- if (null != childs && !childs.isEmpty())
- addResourceToDevice(dev, childs);
-
- // 3. Update ui listeners
- UiListenerHandler.getInstance().resourceListUpdateUINotification(
- ResourceType.DEVICE);
- }
-
- private Map<String, LocalResourceAttribute> fetchResourceAttributesFromModel(
- SimulatorResourceModel jResModel) throws SimulatorException {
- Map<String, LocalResourceAttribute> resourceAttributeMap = null;
- if (null != jResModel) {
- Map<String, SimulatorResourceAttribute> jAttributeMap;
- jAttributeMap = jResModel.getAttributes();
- if (null != jAttributeMap) {
- resourceAttributeMap = new HashMap<String, LocalResourceAttribute>();
- Iterator<String> itr = jAttributeMap.keySet().iterator();
- String attName;
- SimulatorResourceAttribute jResAtt;
- LocalResourceAttribute localAtt;
- while (itr.hasNext()) {
- attName = itr.next();
- if (null != attName) {
- jResAtt = jAttributeMap.get(attName);
- if (null != jResAtt) {
- localAtt = new LocalResourceAttribute();
-
- localAtt.setResourceAttributeRef(jResAtt);
-
- // Initially disabling the automation
- localAtt.setAutomationInProgress(false);
-
- // Assigning the default automation interval
- localAtt.setAutomationUpdateInterval(Constants.DEFAULT_AUTOMATION_INTERVAL);
-
- // Setting the default automation type
- localAtt.setAutomationType(Constants.DEFAULT_AUTOMATION_TYPE);
-
- resourceAttributeMap.put(attName, localAtt);
- }
- }
- }
- }
- }
- return resourceAttributeMap;
-
- }
-
- // This method gives all known possible values of the attribute in string
- // format. It takes allowed values or range of values whichever is available
- private List<String> getValueList(SimulatorResourceAttribute attributeN) {
- AttributeProperty attProp = attributeN.property();
- if (null == attProp) {
- return null;
- }
- List<String> valueList = new ArrayList<String>();
- Type valuesType = attProp.type();
- if (valuesType == Type.VALUESET) {
- Object[] allowedValues = attProp.valueSet();
- if (null != allowedValues && allowedValues.length > 0) {
- for (Object value : allowedValues) {
- if (null != value) {
- valueList.add(String.valueOf(((AttributeValue) value)
- .get()));
- }
- }
- }
- } else if (valuesType == Type.RANGE) {
- double minD = attProp.min();
- double maxD = attProp.max();
- for (double value = minD; value <= maxD; value++) {
- valueList.add(String.valueOf(value));
- }
- }
- Object attValue = attributeN.value().get();
- if (valueList.size() < 1 && null != attValue) {
- valueList.add(String.valueOf(attValue));
- }
- return valueList;
+ return resultSet;
}
public List<Resource> getResourceList() {
return resourceList;
}
- public List<CollectionResource> getCollectionResourceList() {
- List<CollectionResource> resourceList = data.getCollectionResources();
- if (null == resourceList) {
- return null;
- }
- // Sort the list
- Collections.sort(resourceList, Utility.collectionResourceComparator);
-
- return resourceList;
- }
-
- public List<Device> getDeviceList() {
- List<Device> deviceList = data.getDevices();
- if (null == deviceList) {
- return null;
- }
- // Sort the list
- Collections.sort(deviceList, Utility.deviceComparator);
- return deviceList;
- }
-
- // Returns the number of resources which are added properly to the
- // collection.
- public int addResourceToCollection(CollectionResource collectionParent,
- Set<Resource> childs) {
- if (null == collectionParent || null == childs || childs.isEmpty()) {
- return -1;
- }
- Iterator<Resource> itr = childs.iterator();
- Resource res;
- int count = childs.size();
- while (itr.hasNext()) {
- res = itr.next();
- try {
- addResourceToCollection(collectionParent, res);
- } catch (SimulatorException e) {
- count--;
- }
- }
- return count;
- }
-
- public void addResourceToCollection(CollectionResource collectionParent,
- Resource child) throws SimulatorException {
- if (null == collectionParent || null == child) {
- return;
- }
- try {
- // 1. Add child to collection
- collectionParent.addChildResource(child);
-
- // 2. Add a reference to the collection in the child
- if (child instanceof SingleResource) {
- ((SingleResource) child)
- .addCollectionMembership(collectionParent);
- } else {
- ((CollectionResource) child).addMembership(collectionParent);
- }
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- throw e;
- }
- }
-
- public int addResourceToCollection(Set<CollectionResource> collections,
- Resource child) {
- if (null == collections || collections.isEmpty() || null == child) {
- return -1;
- }
- Iterator<CollectionResource> itr = collections.iterator();
- CollectionResource res;
- int count = collections.size();
- while (itr.hasNext()) {
- res = itr.next();
- try {
- addResourceToCollection(res, child);
- } catch (SimulatorException e) {
- count--;
- }
- }
- return count;
- }
-
- public void addResourceToDevice(Device dev, Set<Resource> childs) {
- // 1. Add children to the device.
- dev.addChildResource(childs);
-
- // 2. Add a reference to the device in all children.
- Iterator<Resource> itr = childs.iterator();
- Resource res;
- while (itr.hasNext()) {
- res = itr.next();
- if (res instanceof SingleResource) {
- ((SingleResource) res).addDeviceMembership(dev);
- } else {
- ((CollectionResource) res).addDeviceMembership(dev);
- }
- }
- }
-
- public void addResourceToDevice(Device dev, Resource child) {
- // 1. Add child to the device.
- dev.addChildResource(child);
-
- // 2. Add a reference to the device in the child.
- if (child instanceof SingleResource) {
- ((SingleResource) child).addDeviceMembership(dev);
- } else {
- ((CollectionResource) child).addDeviceMembership(dev);
- }
- }
-
- public void addResourceToDevice(Set<Device> devices, Resource child) {
- // 1. Add device reference in child.
- if (child instanceof SingleResource)
- ((SingleResource) child).addDeviceMembership(devices);
- else
- ((CollectionResource) child).addDeviceMembership(devices);
-
- // 2. Add a reference to the child in all devices.
- Iterator<Device> itr = devices.iterator();
- Device dev;
- while (itr.hasNext()) {
- dev = itr.next();
- dev.addChildResource(child);
- }
- }
-
- public int removeResourceFromCollection(
- Set<CollectionResource> collections, Resource resource) {
- // 1. Remove the reference of resource from all the collections.
- Iterator<CollectionResource> itr = collections.iterator();
- CollectionResource colRes;
- int count = collections.size();
- while (itr.hasNext()) {
- colRes = itr.next();
- try {
- removeResourceFromCollection(colRes, resource);
- } catch (SimulatorException e) {
- count--;
- }
- }
- return count;
-
- }
-
- public void removeResourceFromDevice(Set<Device> devices, Resource resource) {
- // 1. Remove the reference of resource from all the devices.
- Iterator<Device> itr = devices.iterator();
- Device dev;
- while (itr.hasNext()) {
- dev = itr.next();
- dev.removeChildResource(resource);
- }
-
- // 2. Remove the reference of devices from the resource.
- resource.removeDeviceMembership(devices);
- }
-
- // Returns the count of resources removed from the collection
- public int removeResourcesFromCollection(CollectionResource colRes,
- Set<Resource> resources) {
- Iterator<Resource> itr = resources.iterator();
- Resource res;
- int count = resources.size();
- while (itr.hasNext()) {
- res = itr.next();
- try {
- removeResourceFromCollection(colRes, res);
- } catch (SimulatorException e) {
- count--;
- }
- }
- return count;
- }
-
- public void removeResourcesFromDevice(Device dev, Set<Resource> resources) {
- Iterator<Resource> itr = resources.iterator();
- Resource res;
- while (itr.hasNext()) {
- res = itr.next();
- res.removeDeviceMembership(dev);
- }
- dev.removeChildResource(resources);
- }
-
- public void removeResourceFromCollection(CollectionResource parent,
- Resource child) throws SimulatorException {
- try {
- // 1. Remove the child from the parent
- parent.removeChildResource(child);
-
- // 2. Remove the reference to parent from child
- if (child instanceof SingleResource) {
- ((SingleResource) child).removeCollectionMembership(parent);
- } else {
- ((CollectionResource) child).removeMembership(parent);
- }
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- throw e;
- }
- }
-
- public void removeResourceFromDevice(Device parent, Resource child) {
- // 1. Remove the reference to parent from child
- child.removeDeviceMembership(parent);
-
- // 2. Remove the child from the parent
- parent.removeChildResource(child);
- }
-
public void removeSingleResources(Set<SingleResource> resources)
throws SimulatorException {
if (null == resources) {
}
}
- public void removeCollectionResources(Set<CollectionResource> resources)
- throws SimulatorException {
- if (null == resources) {
- return;
- }
- Iterator<CollectionResource> itr = resources.iterator();
- while (itr.hasNext()) {
- removeResource(itr.next());
- }
- }
-
public void removeResource(Resource res) throws SimulatorException {
- // 1. Unregister the resource from the platform.
+ // Unregister the resource from the platform.
SimulatorResource simRes = res.getSimulatorResource();
try {
simRes.stop();
throw e;
}
- Set<CollectionResource> collectionMembership;
- Set<Device> deviceMembership;
-
- if (res instanceof SingleResource) {
- collectionMembership = ((SingleResource) res)
- .getCollectionMembership();
- deviceMembership = ((SingleResource) res).getDeviceMembership();
- } else {
- collectionMembership = ((CollectionResource) res).getMembership();
- deviceMembership = ((CollectionResource) res).getDeviceMembership();
- }
-
- // 2. Delete from the collections to which this resource is a member.
- if (null != collectionMembership && !collectionMembership.isEmpty()) {
- removeResourceFromCollection(collectionMembership, res);
- }
-
- // 3. Delete from the devices to which this resource is a member.
- if (null != deviceMembership && !deviceMembership.isEmpty()) {
- removeResourceFromDevice(deviceMembership, res);
- }
-
- // 4. Delete this resource
+ // Delete this resource
data.deleteResource(res);
}
- public void removeDevice(Device dev) {
- Set<Resource> childs = dev.getChildResources();
- if (null != childs && !childs.isEmpty()) {
- // 1. Remove the reference from all the children.
- Iterator<Resource> itr = childs.iterator();
- Resource res;
- while (itr.hasNext()) {
- res = itr.next();
- res.removeDeviceMembership(dev);
- }
- }
- // 2. Delete the device.
- data.deleteDevice(dev);
- }
-
public boolean isUriUnique(List<MetaProperty> properties) {
if (null == properties) {
return false;
String uri = prop.getPropValue();
return !data.isResourceExist(uri);
}
- }
- return false;
- }
-
- public List<CollectionResource> getCollectionsForAddingToSingleResource(
- SingleResource resource) {
- List<CollectionResource> collectionResources = data
- .getCollectionResources();
- if (null == collectionResources || collectionResources.isEmpty()) {
- return null;
- }
-
- Set<CollectionResource> collectionMembership;
- collectionMembership = resource.getCollectionMembership();
- if (null == collectionMembership || collectionMembership.isEmpty()) {
- return collectionResources;
- }
-
- if (collectionMembership.size() == collectionResources.size()) {
- return null;
- }
-
- collectionResources.removeAll(collectionMembership);
-
- // Sort the list
- Collections.sort(collectionResources,
- Utility.collectionResourceComparator);
-
- return collectionResources;
- }
-
- public List<SingleResource> getSingleTypeResourcesForAddingToCollectionResource(
- CollectionResource colRes) {
- List<SingleResource> singleResources = data.getSingleResources();
- if (null == singleResources || singleResources.isEmpty()) {
- return null;
- }
-
- Set<SingleResource> childs;
- childs = colRes.getSingleTypeChildResources();
- if (null == childs || childs.isEmpty()) {
- return singleResources;
- }
-
- if (childs.size() == singleResources.size()) {
- return null;
- }
-
- singleResources.removeAll(childs);
-
- // Sort the list
- Collections.sort(singleResources, Utility.singleResourceComparator);
-
- return singleResources;
- }
-
- public List<SingleResource> getSingleTypeResourcesForAddingToDevice(
- Device dev) {
- List<SingleResource> singleResources = data.getSingleResources();
- if (null == singleResources || singleResources.isEmpty()) {
- return null;
- }
-
- Set<SingleResource> childs;
- childs = dev.getSingleTypeChildResources();
- if (null == childs || childs.isEmpty()) {
- return singleResources;
- }
-
- if (childs.size() == singleResources.size()) {
- return null;
- }
-
- singleResources.removeAll(childs);
-
- // Sort the list
- Collections.sort(singleResources, Utility.singleResourceComparator);
-
- return singleResources;
- }
-
- public List<CollectionResource> getCollectionTypeResourcesForAddingToCollectionResource(
- CollectionResource colRes) {
- List<CollectionResource> collectionResources = data
- .getCollectionResources();
- if (null == collectionResources || collectionResources.isEmpty()) {
- return null;
- }
-
- // Remove the colRes from the list
- collectionResources.remove(colRes);
-
- Set<CollectionResource> childs;
- childs = colRes.getCollectionTypeChildResources();
- if (null == childs || childs.isEmpty()) {
- return collectionResources;
- }
-
- if (childs.size() == collectionResources.size()) {
- return null;
- }
-
- collectionResources.removeAll(childs);
-
- // Sort the list
- Collections.sort(collectionResources,
- Utility.collectionResourceComparator);
-
- return collectionResources;
- }
-
- public List<CollectionResource> getCollectionTypeResourcesForAddingToDevice(
- Device dev) {
- List<CollectionResource> collectionResources = data
- .getCollectionResources();
- if (null == collectionResources || collectionResources.isEmpty()) {
- return null;
- }
-
- Set<CollectionResource> childs;
- childs = dev.getCollectionTypeChildResources();
- if (null == childs || childs.isEmpty()) {
- return collectionResources;
- }
-
- if (childs.size() == collectionResources.size()) {
- return null;
- }
-
- collectionResources.removeAll(childs);
-
- // Sort the list
- Collections.sort(collectionResources,
- Utility.collectionResourceComparator);
-
- return collectionResources;
- }
-
- public List<Device> getDevicesForAddingToResource(Resource resource) {
- List<Device> devices = data.getDevices();
- if (null == devices || devices.isEmpty()) {
- return null;
- }
-
- Set<Device> deviceMembership;
- if (resource instanceof SingleResource) {
- deviceMembership = ((SingleResource) resource)
- .getDeviceMembership();
- } else {
- deviceMembership = ((CollectionResource) resource)
- .getDeviceMembership();
- }
- if (null == deviceMembership || deviceMembership.isEmpty()) {
- return devices;
- }
-
- if (devices.size() == deviceMembership.size()) {
- return null;
- }
-
- devices.removeAll(deviceMembership);
-
- // Sort the list
- Collections.sort(devices, Utility.deviceComparator);
-
- return devices;
- }
-
- public List<CollectionResource> getResourceReferences(
- SingleResource resource) {
- List<CollectionResource> resources = Utility
- .getCollectionResourceListFromSet(resource
- .getCollectionMembership());
- if (null == resources || resources.isEmpty()) {
- return null;
- }
-
- Collections.sort(resources, Utility.collectionResourceComparator);
-
- return resources;
- }
-
- public List<Device> getDeviceReferences(Resource resource) {
- Set<Device> deviceMembership;
- if (resource instanceof SingleResource) {
- deviceMembership = ((SingleResource) resource)
- .getDeviceMembership();
- } else {
- deviceMembership = ((CollectionResource) resource)
- .getDeviceMembership();
- }
-
- List<Device> devices = Utility.getDeviceListFromSet(deviceMembership);
- if (null == devices || devices.isEmpty()) {
- return null;
- }
-
- Collections.sort(devices, Utility.deviceComparator);
-
- return devices;
- }
-
- public List<SingleResource> getSingleTypeChilds(CollectionResource colRes) {
- Set<SingleResource> childs = colRes.getSingleTypeChildResources();
- return Utility.getSingleResourceListFromSet(childs);
- }
-
- public List<SingleResource> getSingleTypeChilds(Device dev) {
- Set<SingleResource> childs = dev.getSingleTypeChildResources();
- return Utility.getSingleResourceListFromSet(childs);
- }
-
- public List<CollectionResource> getCollectionTypeChilds(
- CollectionResource colRes) {
- Set<CollectionResource> childs = colRes
- .getCollectionTypeChildResources();
- return Utility.getCollectionResourceListFromSet(childs);
- }
-
- public List<CollectionResource> getCollectionTypeChilds(Device dev) {
- Set<CollectionResource> childs = dev.getCollectionTypeChildResources();
- return Utility.getCollectionResourceListFromSet(childs);
+ }
+ return false;
}
public void resourceSelectionChanged(final Resource selectedResource) {
new Thread() {
@Override
public void run() {
-
- setCurrentDeviceInSelection(null);
-
if (null != selectedResource) {
setCurrentResourceInSelection(selectedResource);
} else {
}.start();
}
- public void deviceSelectionChanged(final Device selectedDevice) {
- new Thread() {
- @Override
- public void run() {
-
- setCurrentResourceInSelection(null);
-
- if (null != selectedDevice) {
- setCurrentDeviceInSelection(selectedDevice);
- } else {
- setCurrentDeviceInSelection(null);
- }
- // Notify all observers for resource selection change event
- UiListenerHandler.getInstance()
- .deviceSelectionChangedUINotification(selectedDevice);
- }
- }.start();
- }
-
public List<MetaProperty> getMetaProperties(Resource resource) {
if (null != resource) {
String propName;
} else if (propName.equals(Constants.RESOURCE_URI)) {
propValue = resource.getResourceURI();
} else if (propName.equals(Constants.RESOURCE_TYPE)) {
- propValue = resource.getResourceTypes().toString();
+ propValue = resource.getResourceType();
+ } else if (propName.equals(Constants.INTERFACE_TYPES)) {
+ Set<String> ifTypes = resource.getResourceInterfaces();
+ if (null != ifTypes && !ifTypes.isEmpty()) {
+ propValue = "";
+ Iterator<String> itr = ifTypes.iterator();
+ while (itr.hasNext()) {
+ propValue += itr.next();
+ if (itr.hasNext()) {
+ propValue += ", ";
+ }
+ }
+ } else {
+ propValue = null;
+ }
} else {
propValue = null;
}
return null;
}
- public List<MetaProperty> getMetaProperties(Device dev) {
- if (null != dev) {
- List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
- metaPropertyList.add(new MetaProperty(Constants.DEVICE_NAME, dev
- .getDeviceName()));
- return metaPropertyList;
- }
- return null;
- }
-
public boolean startResource(Resource resource) throws SimulatorException {
if (null == resource) {
return false;
return true;
}
- public boolean changeDeviceName(Device dev, String newName) {
- if (null == dev || null == newName) {
- return false;
- }
- data.changeDeviceName(dev, dev.getDeviceName(), newName);
- return true;
- }
-
public boolean changeResourceURI(Resource resource, String newURI)
throws SimulatorException {
if (null == resource || null == newURI) {
}
String curURI = resource.getResourceURI();
+ setResourceURI(resource, newURI);
+
+ try {
+ if (!startResource(resource)) {
+ return false;
+ }
+ } catch (SimulatorException e) {
+ setResourceURI(resource, curURI);
+ }
+
+ return true;
+ }
+
+ public void setResourceURI(Resource resource, String newURI)
+ throws SimulatorException {
+ String curURI = resource.getResourceURI();
SimulatorResource server = resource.getSimulatorResource();
try {
server.setURI(newURI);
+ Utility.getSimulatorErrorString(e, null));
throw e;
}
-
- if (!startResource(resource)) {
- return false;
- }
- return true;
}
public boolean updateResourceProperties(Resource resource,
return true;
}
- public boolean updateDeviceProperties(Device dev,
- List<MetaProperty> properties) {
- if (null == dev || null == properties) {
+ public boolean updateResourceInterfaces(Resource resource,
+ Set<String> newIfSet) throws SimulatorException {
+ if (null == resource || null == newIfSet || newIfSet.isEmpty()) {
return false;
}
-
- // Updating the properties
- Iterator<MetaProperty> itr = properties.iterator();
- MetaProperty property;
- String propName;
- String propValue;
- String devName = null;
- while (itr.hasNext()) {
- property = itr.next();
- if (null == property) {
- continue;
- }
- propName = property.getPropName();
- propValue = property.getPropValue();
- if (propName.equals(Constants.DEVICE_NAME)) {
- devName = propValue;
- }
- }
-
- if (!changeDeviceName(dev, devName)) {
+ SimulatorResource jResource = resource.getSimulatorResource();
+ if (null == jResource) {
return false;
}
-
- // Notify UI Listeners
- UiListenerHandler.getInstance().propertiesChangedUINotification(
- Device.class);
-
- return true;
- }
-
- public List<LocalResourceAttribute> getAttributes(Resource resource) {
- List<LocalResourceAttribute> attList = null;
- if (null != resource) {
- Map<String, LocalResourceAttribute> attMap = resource
- .getResourceAttributes();
- if (null != attMap && attMap.size() > 0) {
- attList = new ArrayList<LocalResourceAttribute>();
- Set<String> attNameSet = attMap.keySet();
- String attName;
- LocalResourceAttribute attribute;
- Iterator<String> attNameItr = attNameSet.iterator();
- while (attNameItr.hasNext()) {
- attName = attNameItr.next();
- attribute = attMap.get(attName);
- if (null != attribute) {
- attList.add(attribute);
- }
- }
+ Set<String> curIfSet = resource.getResourceInterfaces();
+ Iterator<String> itr = curIfSet.iterator();
+ String interfaceType;
+ boolean resourceRestartRequired = false;
+ while (itr.hasNext()) {
+ interfaceType = itr.next();
+ if (!newIfSet.contains(interfaceType)) {
+ resourceRestartRequired = true;
+ break;
}
}
- return attList;
- }
- public List<SimulatorResourceAttribute> getAttributes(
- SimulatorResourceModel model) {
- List<SimulatorResourceAttribute> attList = null;
- if (null != model) {
- Map<String, SimulatorResourceAttribute> attMap = model
- .getAttributes();
- if (null != attMap && attMap.size() > 0) {
- attList = new ArrayList<SimulatorResourceAttribute>();
- Set<String> attNameSet = attMap.keySet();
- String attName;
- SimulatorResourceAttribute attribute;
- Iterator<String> attNameItr = attNameSet.iterator();
- while (attNameItr.hasNext()) {
- attName = attNameItr.next();
- attribute = attMap.get(attName);
- if (null != attribute) {
- attList.add(attribute);
+ try {
+ // As there is no support from native layer for interface removal,
+ // supporting it from the simulator requires restarting the resource
+ // if any existing interfaces are removed.
+
+ if (resourceRestartRequired) {
+ stopResource(resource);
+ jResource.setInterface(Utility
+ .convertSetToVectorString(newIfSet));
+ startResource(resource);
+ } else {
+ // Existing interfaces are not removed.
+ itr = newIfSet.iterator();
+ while (itr.hasNext()) {
+ interfaceType = itr.next();
+ if (!curIfSet.contains(interfaceType)) {
+ jResource.addInterface(interfaceType);
}
}
}
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while changing the interface types."
+ + Utility.getSimulatorErrorString(e, null));
+ throw e;
}
- return attList;
- }
- public List<SRMItem> getIndexedAttributes(SimulatorResourceModel[] model) {
- List<SRMItem> indexedAttList = null;
- if (null != model && model.length > 0) {
- indexedAttList = new ArrayList<SRMItem>();
- int i = 0;
- for (SimulatorResourceModel m : model) {
- indexedAttList.add(new SRMItem(i++, m));
- }
- }
- return indexedAttList;
+ // Set the resource interfaces.
+ resource.setResourceInterfaces(newIfSet);
+
+ return true;
}
- public void attributeValueUpdated(SingleResource resource,
+ public boolean attributeValueUpdated(SingleResource resource,
String attributeName, AttributeValue value) {
if (null != resource && null != attributeName && null != value) {
SimulatorSingleResource simRes = (SimulatorSingleResource) resource
if (null != simRes) {
try {
simRes.updateAttribute(attributeName, value);
+ return true;
} catch (SimulatorException e) {
Activator
.getDefault()
}
}
}
+ return false;
}
- // TODO: This method should get the status from the native layer.
public boolean isResourceStarted(Resource resource) {
if (null == resource) {
return false;
prop = itr.next();
if (prop.getPropName().equals(propName)) {
String value = prop.getPropValue();
- if (null == value || value.trim().isEmpty()) {
- invalid = true;
- }
- }
- }
- return invalid;
- }
-
- public boolean isPropertyValueInvalid(Device dev,
- List<MetaProperty> properties, String propName) {
- if (null == dev || null == properties || null == propName) {
- return false;
- }
- boolean invalid = false;
- MetaProperty prop;
- Iterator<MetaProperty> itr = properties.iterator();
- while (itr.hasNext()) {
- prop = itr.next();
- if (prop.getPropName().equals(propName)) {
- String value = prop.getPropValue();
- if (null == value || value.trim().isEmpty()) {
- invalid = true;
+ if (propName.equals(Constants.RESOURCE_URI)) {
+ if (!Utility.isUriValid(value)) {
+ invalid = true;
+ }
+ } else {
+ if (null == value || value.trim().isEmpty()) {
+ invalid = true;
+ }
}
}
}
return changed;
}
- public boolean isPropValueChanged(Device dev,
- List<MetaProperty> properties, String propName) {
- if (null == dev || null == properties || null == propName) {
- return false;
- }
- boolean changed = false;
- MetaProperty prop;
- String oldValue;
- Iterator<MetaProperty> itr = properties.iterator();
- while (itr.hasNext()) {
- prop = itr.next();
- if (prop.getPropName().equals(propName)) {
- oldValue = dev.getDeviceName();
- if (null != oldValue && !prop.getPropValue().equals(oldValue)) {
- changed = true;
- }
- break;
- }
- }
- return changed;
- }
-
private String getPropertyValueFromResource(Resource resource,
String propName) {
if (null == resource || null == propName) {
} else if (propName.equals(Constants.RESOURCE_NAME)) {
return resource.getResourceName();
} else if (propName.equals(Constants.RESOURCE_TYPE)) {
- return resource.getResourceTypes().toString();
+ return resource.getResourceType();
} else {
return null;
}
}
- public boolean isURIChanged(Resource resource, List<MetaProperty> properties) {
- if (null == resource || null == properties) {
- return false;
- }
- boolean changed = false;
- MetaProperty prop;
- Iterator<MetaProperty> itr = properties.iterator();
- while (itr.hasNext()) {
- prop = itr.next();
- if (prop.getPropName().equals(Constants.RESOURCE_URI)) {
- if (!prop.getPropValue().equals(resource.getResourceURI())) {
- changed = true;
- }
- break;
- }
- }
- return changed;
- }
-
- public boolean startResource(SingleResource resource) {
- if (null == resource || resource.isStarted()) {
- return false;
- }
- boolean result;
- SimulatorResource server = resource.getSimulatorResource();
- if (null == server) {
- result = false;
- } else {
- try {
- server.start();
- resource.setStarted(true);
- result = true;
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- result = false;
- }
- }
- return result;
- }
-
- public boolean stopResource(SingleResource resource) {
- if (null == resource || !resource.isStarted()) {
- return false;
- }
- boolean result;
- SimulatorResource server = resource.getSimulatorResource();
- if (null == server) {
- result = false;
- } else {
- try {
- server.stop();
- resource.setStarted(false);
- result = true;
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- result = false;
- }
- }
- return result;
- }
-
public boolean isAttHasRangeOrAllowedValues(SimulatorResourceAttribute att) {
if (null == att) {
return false;
if (null == prop) {
return false;
}
- Type attProp = prop.type();
- if (attProp == Type.UNKNOWN) {
- return false;
+
+ if (prop.getType() == Type.INTEGER) {
+ IntegerProperty intProperty = prop.asInteger();
+ if (null != intProperty) {
+ return (intProperty.hasRange() || intProperty.hasValues());
+ } else {
+ return false;
+ }
+ } else if (prop.getType() == Type.DOUBLE) {
+ DoubleProperty dblProperty = prop.asDouble();
+ if (null != dblProperty) {
+ return (dblProperty.hasRange() || dblProperty.hasValues());
+ } else {
+ return false;
+ }
+ } else if (prop.getType() == Type.STRING) {
+ StringProperty stringProperty = prop.asString();
+ if (null != stringProperty) {
+ return stringProperty.hasValues();
+ } else {
+ return false;
+ }
}
+
return true;
}
return false;
}
boolean status = false;
- changeResourceLevelAutomationStatus(resource, true);
// Invoke the native automation method
SimulatorSingleResource resourceServer = (SimulatorSingleResource) resource
.getSimulatorResource();
Utility.getSimulatorErrorString(e, null));
autoId = -1;
}
- if (-1 == autoId) {
- // Automation request failed and hence status is being
- // rolled back
- changeResourceLevelAutomationStatus(resource, false);
- } else {
+ if (-1 != autoId) {
// Automation request accepted.
+ changeResourceLevelAutomationStatus(resource, true);
+
resource.setAutomationId(autoId);
// Notify the UI listeners in a different thread.
return resource.isAttributeAutomationInProgress();
}
- public LocalResourceAttribute getAttributeByResourceURI(
- SingleResource resource, String attName) {
- if (null == resource || null == attName) {
- return null;
- }
- Map<String, LocalResourceAttribute> attMap = resource
- .getResourceAttributes();
- if (null == attMap) {
- return null;
- }
- return attMap.get(attName);
- }
-
public void notifyObserverRequest(Resource resource, int observerId) {
if (null == resource) {
return;
}
}
- public void shutdown() {
- threadHandle.interrupt();
- }
-
public List<String> getAllValuesOfAttribute(SimulatorResourceAttribute att) {
if (null == att) {
return null;
List<String> values = new ArrayList<String>();
- Type valuesType = prop.type();
-
- if (valuesType == Type.UNKNOWN) {
- // Adding the default value
- values.add(Utility.getAttributeValueAsString(val));
- return values;
- }
-
if (type.mType != ValueType.RESOURCEMODEL) {
if (type.mType == ValueType.ARRAY) {
if (type.mDepth == 1) {
- AttributeProperty childProp = prop.getChildProperty();
- if (null != childProp) {
- valuesType = childProp.type();
- if (valuesType == Type.RANGE) {
- List<String> list = getRangeForPrimitiveNonArrayAttributes(
- childProp, type.mBaseType);
- if (null != list) {
- values.addAll(list);
- }
- } else if (valuesType == Type.VALUESET) {
- List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
- childProp.valueSet(), type.mBaseType);
- if (null != list) {
- values.addAll(list);
- }
+ ArrayProperty arrayProperty = prop.asArray();
+ if (null != arrayProperty) {
+ AttributeProperty childProp = arrayProperty
+ .getElementProperty();
+ switch (childProp.getType()) {
+ case INTEGER:
+ IntegerProperty intProperty = childProp
+ .asInteger();
+ if (null != intProperty) {
+ values.addAll(getAllValues(intProperty,
+ Type.INTEGER));
+ }
+ break;
+ case DOUBLE:
+ DoubleProperty dblProperty = childProp
+ .asDouble();
+ if (null != dblProperty) {
+ values.addAll(getAllValues(dblProperty,
+ Type.DOUBLE));
+ }
+ break;
+ case BOOLEAN:
+ BooleanProperty boolProperty = childProp
+ .asBoolean();
+ if (null != boolProperty) {
+ values.addAll(getAllValues(boolProperty,
+ Type.BOOLEAN));
+ }
+ break;
+ case STRING:
+ StringProperty stringProperty = childProp
+ .asString();
+ if (null != stringProperty) {
+ values.addAll(getAllValues(stringProperty,
+ Type.STRING));
+ }
+ break;
+ default:
+ break;
}
}
}
} else {
- if (valuesType == Type.RANGE) {
- List<String> list = getRangeForPrimitiveNonArrayAttributes(
- prop, type.mType);
- if (null != list) {
- values.addAll(list);
- }
- } else if (valuesType == Type.VALUESET) {
- List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
- prop.valueSet(), type.mType);
- if (null != list) {
- values.addAll(list);
- }
+ switch (prop.getType()) {
+ case INTEGER:
+ IntegerProperty intProperty = prop.asInteger();
+ if (null != intProperty) {
+ values.addAll(getAllValues(intProperty,
+ Type.INTEGER));
+ }
+ break;
+ case DOUBLE:
+ DoubleProperty dblProperty = prop.asDouble();
+ if (null != dblProperty) {
+ values.addAll(getAllValues(dblProperty, Type.DOUBLE));
+ }
+ break;
+ case BOOLEAN:
+ BooleanProperty boolProperty = prop.asBoolean();
+ if (null != boolProperty) {
+ values.addAll(getAllValues(boolProperty,
+ Type.BOOLEAN));
+ }
+ break;
+ case STRING:
+ StringProperty stringProperty = prop.asString();
+ if (null != stringProperty) {
+ values.addAll(getAllValues(stringProperty,
+ Type.STRING));
+ }
+ break;
+ default:
+ break;
}
}
}
return values;
}
- public List<String> getRangeForPrimitiveNonArrayAttributes(
- AttributeProperty prop, ValueType type) {
- if (null == prop) {
- return null;
- }
+ public List<String> getAllValues(IntegerProperty intProperty,
+ AttributeProperty.Type type) {
+ List<String> values = new ArrayList<String>();
- if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
- return null;
+ if (intProperty.hasRange()) {
+ int min = (int) intProperty.min();
+ int max = (int) intProperty.max();
+ for (int iVal = min; iVal <= max; iVal++) {
+ values.add(String.valueOf(iVal));
+ }
+ } else if (intProperty.hasValues()) {
+ for (Integer val : intProperty.getValues()) {
+ values.add(String.valueOf(val));
+ }
+ } else {
+ // Adding the default value.
+ values.add(String.valueOf(intProperty.getDefaultValue()));
}
+ return values;
+ }
+ public List<String> getAllValues(DoubleProperty dblProperty,
+ AttributeProperty.Type type) {
List<String> values = new ArrayList<String>();
- switch (type) {
- case INTEGER:
- int min = (int) prop.min();
- int max = (int) prop.max();
- for (int iVal = min; iVal <= max; iVal++) {
- values.add(String.valueOf(iVal));
- }
- break;
- case DOUBLE:
- double minD = (double) prop.min();
- double maxD = (double) prop.max();
- for (double iVal = minD; iVal <= maxD; iVal = iVal + 1.0) {
- values.add(String.valueOf(iVal));
- }
- break;
- default:
+
+ if (dblProperty.hasRange()) {
+ double min = (double) dblProperty.min();
+ double max = (double) dblProperty.max();
+ for (double iVal = min; iVal <= max; iVal = iVal + 1) {
+ values.add(String.valueOf(iVal));
+ }
+ } else if (dblProperty.hasValues()) {
+ for (Double val : dblProperty.getValues()) {
+ values.add(String.valueOf(val));
+ }
+ } else {
+ // Adding the default value.
+ values.add(String.valueOf(dblProperty.getDefaultValue()));
}
return values;
}
- public List<String> getAllowedValuesForPrimitiveNonArrayAttributes(
- AttributeValue[] attValues, ValueType type) {
- if (null == attValues || attValues.length < 1) {
- return null;
- }
-
- if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
- return null;
- }
+ public List<String> getAllValues(BooleanProperty boolProperty,
+ AttributeProperty.Type type) {
+ List<String> values = new ArrayList<String>();
+ values.add("true");
+ values.add("false");
+ return values;
+ }
- Object obj;
+ public List<String> getAllValues(StringProperty stringProperty,
+ AttributeProperty.Type type) {
List<String> values = new ArrayList<String>();
- for (AttributeValue val : attValues) {
- if (null == val) {
- continue;
- }
- obj = val.get();
- if (null == obj) {
- continue;
+
+ if (stringProperty.hasValues()) {
+ for (String val : stringProperty.getValues()) {
+ values.add(String.valueOf(val));
}
- values.add(String.valueOf(obj));
+ } else {
+ // Adding the default value.
+ values.add(String.valueOf(stringProperty.getDefaultValue()));
}
return values;
}
+
+ public int getResourceCount() {
+ return data.getResourceCount();
+ }
+
+ public void shutdown() {
+ threadHandle.interrupt();
+ }
}
\ No newline at end of file