import java.util.Set;
import java.util.Vector;
-import oic.simulator.clientcontroller.Activator;
-import oic.simulator.clientcontroller.listener.IConfigurationUpload;
-import oic.simulator.clientcontroller.listener.IDevicePlatformInfoUIListener;
-import oic.simulator.clientcontroller.listener.IFindResourceUIListener;
-import oic.simulator.clientcontroller.listener.IGetUIListener;
-import oic.simulator.clientcontroller.listener.IObserveUIListener;
-import oic.simulator.clientcontroller.listener.IPostUIListener;
-import oic.simulator.clientcontroller.listener.IPutUIListener;
-import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
-import oic.simulator.clientcontroller.listener.IVerificationUIListener;
-import oic.simulator.clientcontroller.remoteresource.DeviceAndPlatformInfo;
-import oic.simulator.clientcontroller.remoteresource.MetaProperty;
-import oic.simulator.clientcontroller.remoteresource.RemoteResource;
-import oic.simulator.clientcontroller.utils.Constants;
-import oic.simulator.clientcontroller.utils.Utility;
-
+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.PlatformListener;
import org.oic.simulator.SimulatorException;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
import org.oic.simulator.SimulatorResult;
+import org.oic.simulator.StringProperty;
import org.oic.simulator.client.FindResourceListener;
import org.oic.simulator.client.SimulatorRemoteResource;
import org.oic.simulator.client.SimulatorRemoteResource.GetResponseListener;
import org.oic.simulator.client.SimulatorRemoteResource.VerificationListener;
import org.oic.simulator.client.SimulatorRemoteResource.VerificationType;
+import oic.simulator.clientcontroller.Activator;
+import oic.simulator.clientcontroller.remoteresource.DeviceAndPlatformInfo;
+import oic.simulator.clientcontroller.remoteresource.MetaProperty;
+import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
+import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.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
*/
public class ResourceManager {
- private Set<String> lastKnownSearchTypes;
-
- private RemoteResource currentResourceInSelection;
+ private Set<String> lastKnownSearchTypes;
- private FindResourceListener findResourceListener;
- private GetResponseListener getListener;
- private PutResponseListener putListener;
- private PostResponseListener postListener;
- private ObserveNotificationListener observeListener;
- private VerificationListener verifyListener;
- private DeviceListener deviceListener;
- private PlatformListener platformListener;
+ private RemoteResource currentResourceInSelection;
- private ResponseSynchronizerThread synchronizerThread;
+ private FindResourceListener findResourceListener;
+ private GetResponseListener getListener;
+ private PutResponseListener putListener;
+ private PostResponseListener postListener;
+ private ObserveNotificationListener observeListener;
+ private VerificationListener verifyListener;
+ private DeviceListener deviceListener;
+ private PlatformListener platformListener;
- private Thread threadHandle;
+ private ResponseSynchronizerThread synchronizerThread;
- private List<IFindResourceUIListener> findResourceUIListeners;
- private List<IResourceSelectionChangedUIListener> resourceSelectionChangedUIListeners;
- private List<IGetUIListener> getUIListeners;
- private List<IPutUIListener> putUIListeners;
- private List<IPostUIListener> postUIListeners;
- private List<IObserveUIListener> observeUIListeners;
- private List<IVerificationUIListener> verificationUIListeners;
- private List<IConfigurationUpload> configUploadUIListeners;
- private List<IDevicePlatformInfoUIListener> devicePlatformInfoUIListeners;
+ private Thread threadHandle;
// Map with Server ID as key and the complete object as the value
- private Map<String, RemoteResource> resourceMap;
- private List<RemoteResource> favoriteResources;
+ private Map<String, RemoteResource> resourceMap;
+ private List<RemoteResource> favoriteResources;
// Maintaining a list of resource URIs for favorite resources feature.
- private List<String> favoriteURIList;
+ private List<String> favoriteURIList;
// Maintaining a list of observed resource URIs.
- private List<String> observedResourceURIList;
+ private List<String> observedResourceURIList;
- private Map<String, DeviceAndPlatformInfo> hostDeviceAndPlatformMap;
+ private Map<String, DeviceAndPlatformInfo> hostDeviceAndPlatformMap;
public ResourceManager() {
resourceMap = new HashMap<String, RemoteResource>();
observedResourceURIList = new ArrayList<String>();
hostDeviceAndPlatformMap = new HashMap<String, DeviceAndPlatformInfo>();
- findResourceUIListeners = new ArrayList<IFindResourceUIListener>();
- resourceSelectionChangedUIListeners = new ArrayList<IResourceSelectionChangedUIListener>();
- getUIListeners = new ArrayList<IGetUIListener>();
- putUIListeners = new ArrayList<IPutUIListener>();
- postUIListeners = new ArrayList<IPostUIListener>();
- observeUIListeners = new ArrayList<IObserveUIListener>();
- verificationUIListeners = new ArrayList<IVerificationUIListener>();
- configUploadUIListeners = new ArrayList<IConfigurationUpload>();
- devicePlatformInfoUIListeners = new ArrayList<IDevicePlatformInfoUIListener>();
-
findResourceListener = new FindResourceListener() {
@Override
return;
}
+ // Ignore the response if the resource is a device or
+ // platform.
+ Vector<String> resTypes = resourceN.getResourceTypes();
+ if (null != resTypes && resTypes.contains("oic.wk.d")
+ || resTypes.contains("oic.wk.p")) {
+ return;
+ }
+
// If id is not available, then it cannot be added to
// the local map as null value should not be allowed as
// key.
return;
}
- // Fetch the resource data
- // RemoteResource resource =
- // fetchResourceDetails(resourceN);
RemoteResource resource = new RemoteResource();
resource.setRemoteResourceRef(resourceN);
addResourceDetails(resource);
// Notify the UI listener
- newResourceFoundNotification(resource);
+ UiListenerHandler.getInstance()
+ .newResourceFoundNotification(resource);
Activator
.getDefault()
+ "].");
// Send an initial GET request to get the resource
- // attributes
+ // attributes on an interface supported by the resource.
try {
- resourceN.get(null, getListener);
+ String ifType = null;
+ Vector<String> resInterfaces = resourceN
+ .getResourceInterfaces();
+ if (null != resInterfaces) {
+ ifType = resInterfaces.get(0);
+ }
+ resourceN.get(formQueryParameters(ifType, null),
+ getListener);
} catch (SimulatorException e) {
Activator
.getDefault()
}
};
- // TODO: Listeners for device and platform information.
+ // Listeners for device and platform information.
deviceListener = new DeviceListener() {
@Override
}
// Notify UI listeners
- deviceInfoReceivedNotification();
+ UiListenerHandler.getInstance()
+ .deviceInfoReceivedNotification();
}
});
}
}
// Notify UI listeners
- platformInfoReceivedNotification();
+ UiListenerHandler.getInstance()
+ .platformInfoReceivedNotification();
}
});
}
public void onGetResponse(final String uid,
final SimulatorResult result,
final SimulatorResourceModel resourceModelN) {
- System.out.println(result);
if (result != SimulatorResult.SIMULATOR_OK) {
Activator
.getDefault()
resourceModelN);
if (null != resource) {
// Notify the UI listeners
- getCompleteNotification(resource);
+ UiListenerHandler.getInstance()
+ .getCompleteNotification(resource);
}
}
});
resourceModelN);
if (null != resource) {
// Notify the UI listeners
- putCompleteNotification(resource);
+ UiListenerHandler.getInstance()
+ .putCompleteNotification(resource);
}
}
});
resourceModelN);
if (null != resource) {
// Notify the UI listeners
- postCompleteNotification(resource);
+ UiListenerHandler.getInstance()
+ .postCompleteNotification(resource);
}
}
});
resourceModelN);
if (null != resource) {
// Notify the UI listeners
- observeCompleteNotification(resource);
+ UiListenerHandler.getInstance()
+ .observeCompleteNotification(resource);
}
}
});
int autoType = resource.getAutomationtype(autoId);
// Notify the listeners.
- verificationStartedNotification(resource, autoType);
+ UiListenerHandler.getInstance()
+ .verificationStartedNotification(resource,
+ autoType);
}
});
}
int autoType = resource.getAutomationtype(autoId);
// Notify the listeners.
- verificationCompletedNotification(resource, autoType);
+ UiListenerHandler.getInstance()
+ .verificationCompletedNotification(resource,
+ autoType);
}
});
}
int autoType = resource.getAutomationtype(autoId);
// Notify the listeners.
- verificationAbortedNotification(resource, autoType);
+ UiListenerHandler.getInstance()
+ .verificationAbortedNotification(resource,
+ autoType);
}
});
}
return null;
}
- // if(!resource.isConfigUploaded() || null ==
- // resource.getResourceModelRef())
- SimulatorResourceModel resourceModel = resource.getResourceModelRef();
- if (null == resourceModel) {
- resource.setResourceModelRef(resourceModelN);
- } else {
- resourceModel.update(resourceModelN);
- }
-
+ resource.setResourceModelRef(resourceModelN);
resource.setResourceRepresentation(resourceModelN, false);
return resource;
}
}
- public void addResourceSelectionChangedUIListener(
- IResourceSelectionChangedUIListener resourceSelectionChangedUIListener) {
- synchronized (resourceSelectionChangedUIListeners) {
- resourceSelectionChangedUIListeners
- .add(resourceSelectionChangedUIListener);
- }
- }
-
- public void addGetUIListener(IGetUIListener getUIListener) {
- synchronized (getUIListeners) {
- getUIListeners.add(getUIListener);
- }
- }
-
- public void addPutUIListener(IPutUIListener putUIListener) {
- synchronized (putUIListeners) {
- putUIListeners.add(putUIListener);
- }
- }
-
- public void addPostUIListener(IPostUIListener postUIListener) {
- synchronized (postUIListeners) {
- postUIListeners.add(postUIListener);
- }
- }
-
- public void addObserveUIListener(IObserveUIListener observeUIListener) {
- synchronized (observeUIListeners) {
- observeUIListeners.add(observeUIListener);
- }
- }
-
- public void addVerificationUIListener(
- IVerificationUIListener verificationUIListener) {
- synchronized (verificationUIListeners) {
- verificationUIListeners.add(verificationUIListener);
- }
- }
-
- public void addConfigUploadUIListener(IConfigurationUpload configListener) {
- synchronized (configUploadUIListeners) {
- configUploadUIListeners.add(configListener);
- }
- }
-
- public void addDevicePlatformInfoUIListener(
- IDevicePlatformInfoUIListener deviceUIListener) {
- synchronized (devicePlatformInfoUIListeners) {
- devicePlatformInfoUIListeners.add(deviceUIListener);
- }
- }
-
- public void removeDevicePlatformInfoUIListener(
- IDevicePlatformInfoUIListener platformUIListener) {
- synchronized (devicePlatformInfoUIListeners) {
- devicePlatformInfoUIListeners.remove(platformUIListener);
- }
- }
-
- public void removeResourceSelectionChangedUIListener(
- IResourceSelectionChangedUIListener listener) {
- synchronized (resourceSelectionChangedUIListeners) {
- if (null != listener
- && resourceSelectionChangedUIListeners.size() > 0) {
- resourceSelectionChangedUIListeners.remove(listener);
- }
- }
- }
-
- public void removeGetUIListener(IGetUIListener getUIListener) {
- synchronized (getUIListeners) {
- getUIListeners.remove(getUIListener);
- }
- }
-
- public void removePutUIListener(IPutUIListener putUIListener) {
- synchronized (putUIListeners) {
- putUIListeners.remove(putUIListener);
- }
- }
-
- public void removePostUIListener(IPostUIListener postUIListener) {
- synchronized (postUIListeners) {
- postUIListeners.remove(postUIListener);
- }
- }
-
- public void removeObserveUIListener(IObserveUIListener observeUIListener) {
- synchronized (observeUIListeners) {
- observeUIListeners.remove(observeUIListener);
- }
- }
-
- public void removeVerificationUIListener(
- IVerificationUIListener verificationUIListener) {
- synchronized (verificationUIListeners) {
- verificationUIListeners.remove(verificationUIListener);
- }
- }
-
- public void removeConfigUploadUIListener(IConfigurationUpload configListener) {
- synchronized (configUploadUIListeners) {
- configUploadUIListeners.remove(configListener);
- }
- }
-
public void addResourcetoFavorites(RemoteResource resource) {
if (null == resource) {
return;
}
}
- public void addFindresourceUIListener(IFindResourceUIListener listener) {
- if (null == listener) {
- return;
- }
- synchronized (findResourceUIListeners) {
- findResourceUIListeners.add(listener);
- }
- }
-
- public void removeFindresourceUIListener(IFindResourceUIListener listener) {
- if (null == listener) {
- return;
- }
- synchronized (findResourceUIListeners) {
- findResourceUIListeners.remove(listener);
- }
- }
-
private boolean isUidExist(String uid) {
boolean exist;
synchronized (resourceMap) {
return resource;
}
- private void newResourceFoundNotification(RemoteResource resource) {
- synchronized (findResourceUIListeners) {
- if (findResourceUIListeners.size() > 0) {
- IFindResourceUIListener listener;
- Iterator<IFindResourceUIListener> listenerItr = findResourceUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onNewResourceFound(resource);
- }
- }
- }
- }
- }
-
- private void resourceSelectionChangedUINotification(RemoteResource resource) {
- synchronized (resourceSelectionChangedUIListeners) {
- if (resourceSelectionChangedUIListeners.size() > 0) {
- IResourceSelectionChangedUIListener listener;
- Iterator<IResourceSelectionChangedUIListener> listenerItr = resourceSelectionChangedUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onResourceSelectionChange(resource);
- }
- }
- }
- }
- }
-
- private void getCompleteNotification(RemoteResource resource) {
- synchronized (getUIListeners) {
- if (getUIListeners.size() > 0) {
- IGetUIListener listener;
- Iterator<IGetUIListener> listenerItr = getUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onGetCompleted(resource);
- }
- }
- }
- }
- }
-
- private void putCompleteNotification(RemoteResource resource) {
- synchronized (putUIListeners) {
- if (putUIListeners.size() > 0) {
- IPutUIListener listener;
- Iterator<IPutUIListener> listenerItr = putUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onPutCompleted(resource);
- }
- }
- }
- }
- }
-
- private void postCompleteNotification(RemoteResource resource) {
- synchronized (postUIListeners) {
- if (postUIListeners.size() > 0) {
- IPostUIListener listener;
- Iterator<IPostUIListener> listenerItr = postUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onPostCompleted(resource);
- }
- }
- }
- }
- }
-
- private void observeCompleteNotification(RemoteResource resource) {
- synchronized (observeUIListeners) {
- if (observeUIListeners.size() > 0) {
- IObserveUIListener listener;
- Iterator<IObserveUIListener> listenerItr = observeUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onObserveCompleted(resource);
- }
- }
- }
- }
- }
-
- private void verificationStartedNotification(RemoteResource resource,
- int autoType) {
- synchronized (verificationUIListeners) {
- if (verificationUIListeners.size() > 0) {
- IVerificationUIListener listener;
- Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onVerificationStarted(resource, autoType);
- }
- }
- }
- }
- }
-
- private void verificationAbortedNotification(RemoteResource resource,
- int autoType) {
- synchronized (verificationUIListeners) {
- if (verificationUIListeners.size() > 0) {
- IVerificationUIListener listener;
- Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onVerificationAborted(resource, autoType);
- }
- }
- }
- }
- }
-
- private void verificationCompletedNotification(RemoteResource resource,
- int autoType) {
- synchronized (verificationUIListeners) {
- if (verificationUIListeners.size() > 0) {
- IVerificationUIListener listener;
- Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onVerificationCompleted(resource, autoType);
- }
- }
- }
- }
- }
-
- private void configUploadedNotification(RemoteResource resource) {
- synchronized (configUploadUIListeners) {
- if (configUploadUIListeners.size() > 0) {
- IConfigurationUpload listener;
- Iterator<IConfigurationUpload> listenerItr = configUploadUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onConfigurationUploaded(resource);
- }
- }
- }
- }
- }
-
- private void deviceInfoReceivedNotification() {
- synchronized (devicePlatformInfoUIListeners) {
- if (devicePlatformInfoUIListeners.size() > 0) {
- IDevicePlatformInfoUIListener listener;
- Iterator<IDevicePlatformInfoUIListener> listenerItr = devicePlatformInfoUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onDeviceInfoFound();
- }
- }
- }
- }
- }
-
- private void platformInfoReceivedNotification() {
- synchronized (devicePlatformInfoUIListeners) {
- if (devicePlatformInfoUIListeners.size() > 0) {
- IDevicePlatformInfoUIListener listener;
- Iterator<IDevicePlatformInfoUIListener> listenerItr = devicePlatformInfoUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onPlatformInfoFound();
- }
- }
- }
- }
- }
-
public synchronized Set<String> getLastKnownSearchTypes() {
return lastKnownSearchTypes;
}
}
// Change the current resource in selection
setCurrentResourceInSelection(null);
- resourceSelectionChangedUINotification(null);
+ UiListenerHandler.getInstance()
+ .resourceSelectionChangedUINotification(null);
} else {
Iterator<String> typeItr = searchTypes.iterator();
String resType;
type = itr.next();
if (searchTypes.contains(type)) {
setCurrentResourceInSelection(null);
- resourceSelectionChangedUINotification(null);
+ UiListenerHandler.getInstance()
+ .resourceSelectionChangedUINotification(null);
break;
}
}
public void run() {
setCurrentResourceInSelection(resource);
// Notify all observers for resource selection change event
- resourceSelectionChangedUINotification(resource);
+ UiListenerHandler.getInstance()
+ .resourceSelectionChangedUINotification(resource);
}
}.start();
}
devInfo.getDataModelVersion()));
}
- /*
- * metaProperties.add(new MetaProperty(Constants.DEVICE_ID, ""));
- * metaProperties.add(new MetaProperty(Constants.DEVICE_NAME, ""));
- * metaProperties.add(new MetaProperty(Constants.DEVICE_SPEC_VERSION,
- * "")); metaProperties.add(new
- * MetaProperty(Constants.DEVICE_DMV_VERSION, ""));
- */
return metaProperties;
}
metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME,
platInfo.getSystemTime()));
}
- /*
- * metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, ""));
- * metaProperties .add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME,
- * "")); metaProperties .add(new
- * MetaProperty(Constants.PLATFORM_MANUFAC_URL, ""));
- * metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
- * "")); metaProperties.add(new
- * MetaProperty(Constants.PLATFORM_DATE_OF_MANUFAC, ""));
- * metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION, ""));
- * metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
- * "")); metaProperties.add(new MetaProperty(
- * Constants.PLATFORM_HARDWARE_VERSION, "")); metaProperties.add(new
- * MetaProperty( Constants.PLATFORM_FIRMWARE_VERSION, ""));
- * metaProperties .add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
- * "")); metaProperties .add(new
- * MetaProperty(Constants.PLATFORM_SYSTEM_TIME, ""));
- */
return metaProperties;
}
}
AttributeValue val = att.value();
- if (null == val) {
+ if (null == val || null == val.get()) {
return null;
}
- List<String> values = new ArrayList<String>();
-
TypeInfo type = val.typeInfo();
+ if (type.mType == ValueType.RESOURCEMODEL
+ || type.mBaseType == ValueType.RESOURCEMODEL) {
+ return null;
+ }
+
+ List<String> values = new ArrayList<String>();
+
AttributeProperty prop = att.property();
- if (null == prop || prop.type().ordinal() == Type.UNKNOWN.ordinal()) {
- values.add(Utility.getAttributeValueAsString(val));
+ if (null == prop) {
+ values.add(new AttributeValueStringConverter(val).toString());
return values;
}
- Type valuesType = prop.type();
-
- 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.ordinal() == Type.RANGE.ordinal()) {
- List<String> list = getRangeForPrimitiveNonArrayAttributes(
- childProp, type.mBaseType);
- if (null != list) {
- values.addAll(list);
+ if (type.mType == ValueType.ARRAY) {
+ if (type.mDepth == 1) {
+ 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));
}
- } else if (valuesType.ordinal() == Type.VALUESET
- .ordinal()) {
- List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
- childProp.valueSet(), type.mBaseType);
- if (null != list) {
- values.addAll(list);
+ 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.ordinal() == Type.RANGE.ordinal()) {
- List<String> list = getRangeForPrimitiveNonArrayAttributes(
- prop, type.mType);
- if (null != list) {
- values.addAll(list);
+ }
+ } else {
+ switch (prop.getType()) {
+ case INTEGER:
+ IntegerProperty intProperty = prop.asInteger();
+ if (null != intProperty) {
+ values.addAll(getAllValues(intProperty, Type.INTEGER));
}
- } else if (valuesType.ordinal() == Type.VALUESET.ordinal()) {
- List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
- prop.valueSet(), type.mType);
- if (null != list) {
- values.addAll(list);
+ 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;
}
}
- if (values.isEmpty()) {
- values.add(Utility.getAttributeValueAsString(val));
- }
-
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 String getAttributeValue(RemoteResource res, String attName) { if
- * (null == res || null == attName) { return null; } return
- * res.getAttributeValue(attName); }
- */
- public void sendGetRequest(RemoteResource resource) {
+ public void sendGetRequest(String ifType, String query,
+ RemoteResource resource) {
if (null == resource) {
return;
}
if (null == resourceN) {
return;
}
+
+ Map<String, String> queryParams = formQueryParameters(ifType, query);
try {
- resourceN.get(null, getListener);
+ resourceN.get(queryParams, getListener);
} catch (SimulatorException e) {
Activator
.getDefault()
}
}
- public void sendPutRequest(RemoteResource resource,
+ public void sendPutRequest(String ifType, RemoteResource resource,
SimulatorResourceModel model) {
if (null == resource || null == model) {
return;
if (null == resourceN) {
return;
}
+ Map<String, String> queryParams = formQueryParameters(ifType, null);
try {
- resourceN.put(null, model, putListener);
+ resourceN.put(queryParams, model, putListener);
} catch (Exception e) {
String addlInfo;
addlInfo = "Invalid Attribute Value. Cannot send PUT request.";
}
}
- public void sendPostRequest(RemoteResource resource,
+ public void sendPostRequest(String ifType, RemoteResource resource,
SimulatorResourceModel model) {
if (null == resource || null == model) {
return;
if (null == resourceN) {
return;
}
+ Map<String, String> queryParams = formQueryParameters(ifType, null);
try {
- resourceN.post(null, model, postListener);
+ resourceN.post(queryParams, model, postListener);
} catch (Exception e) {
String addlInfo;
addlInfo = "Invalid Attribute Value. Cannot send POST request.";
return false;
}
try {
- resourceN.startObserve(null, observeListener);
+ resourceN.observe(observeListener);
resource.setObserved(true);
// Add observed resource URI to show the proper status after every
// find/refresh operations.
return true;
}
+ private Map<String, String> formQueryParameters(String ifType, String query) {
+ Map<String, String> queryParams = new HashMap<String, String>();
+
+ // Including the interface type, if given,
+ if (null != ifType) {
+ ifType = ifType.trim();
+ if (ifType.length() > 0)
+ queryParams.put("if", ifType);
+ }
+
+ // Including other queries, if given.
+ if (null != query) {
+ query = query.trim();
+ if (query.length() > 0) {
+ // Parse the query parameters and fill the map.
+ String queries[] = query.split(";");
+ if (queries.length > 0) {
+ for (String pair : queries) {
+ String tok[] = pair.split("=");
+ if (null != tok && tok.length == 2) {
+ queryParams.put(tok[0].trim(), tok[1].trim());
+ }
+ }
+ }
+ }
+ }
+ return queryParams;
+ }
+
public boolean sendCancelObserveRequest(RemoteResource resource,
boolean removeEntry) {
if (null == resource || !resource.isObserved()) {
autoId = resourceN.startVerification(reqType, verifyListener);
if (autoId != -1) {
if (reqType == VerificationType.GET) {
- // resource.setGetAutomtnInProgress(true);
resource.setGetAutomtnId(autoId);
} else if (reqType == VerificationType.PUT) {
- // resource.setPutAutomtnInProgress(true);
resource.setPutAutomtnId(autoId);
- } else {// if(reqType == Constants.POST_AUTOMATION_INDEX) {
- // resource.setPostAutomtnInProgress(true);
+ } else {
resource.setPostAutomtnId(autoId);
}
}
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.INFO.ordinal(),
+ new Date(),
+ "[" + reqType.toString()
+ + "] Verification Started for \""
+ + resourceN.getURI() + "\".");
} catch (SimulatorException e) {
Activator
.getDefault()
} else if (reqType == VerificationType.PUT) {
resource.setPutAutomtnInProgress(false);
autoId = resource.getPutAutomtnId();
- } else {// if(reqType == Constants.POST_AUTOMATION_INDEX) {
+ } else {
resource.setPostAutomtnInProgress(false);
autoId = resource.getPostAutomtnId();
}
}
// Store the resource model in the local cache
- SimulatorResourceModel resourceModel = resource
- .getResourceModelRef();
- if (null != resourceModel) {
- configuredResourceModel.update(resourceModel);
- }
- resource.setResourceModelRef(configuredResourceModel);
+ /*
+ * SimulatorResourceModel resourceModel = resource
+ * .getResourceModelRef(); if (null != resourceModel) {
+ * configuredResourceModel.update(resourceModel); }
+ * resource.setResourceModelRef(configuredResourceModel);
+ */
} catch (SimulatorException e) {
Activator
.getDefault()
resource.setConfigUploaded(true);
// Notify the UI listeners
- configUploadedNotification(resource);
+ UiListenerHandler.getInstance().configUploadedNotification(resource);
return true;
}