1. Tested model and array of model type attribute values.
2. Inclues bug fixing for single resource creation without RAML.
Change-Id: I3f0791dde17e4e0d7f6c2165eb59443465f4163d
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4267
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: RadhaBhavani <radha.p@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
int choice = -1;
std::cout << "Enter your choice: ";
std::cin >> choice;
- if (choice < 0 || choice > 12)
+ if (choice < 0 || choice > 14)
{
std::cout << "Invaild choice !" << std::endl; continue;
}
case 9: sendAllPUTRequests(); break;
case 10: sendAllPOSTRequests(); break;
case 11: configure(); break;
- case 12: printMenu(); break;
+ case 12: getDeviceInfo(); break;
+ case 13: getPlatformInfo(); break;
+ case 14: printMenu(); break;
case 0: cont = false;
}
}
std::cout << "9. Send All PUT requests" << std::endl;
std::cout << "10. Send All POST requests" << std::endl;
std::cout << "11. Configure (using RAML file)" << std::endl;
- std::cout << "12: Help" << std::endl;
+ std::cout << "12. Get Device Information" << std::endl;
+ std::cout << "13. Get Platform Information" << std::endl;
+ std::cout << "14: Help" << std::endl;
std::cout << "0. Exit" << std::endl;
std::cout << "###################################################" << std::endl;
}
}
}
+ void getDeviceInfo()
+ {
+ SimulatorRemoteResourceSP resource = selectResource();
+ if (!resource)
+ return;
+
+ try
+ {
+ SimulatorManager::getInstance()->getDeviceInfo(resource->getHost(), std::bind([](DeviceInfo & deviceInfo)
+ {
+ std::cout << "###Device Information received...." << std::endl;
+ std::ostringstream out;
+ out << "Device name: " << deviceInfo.getName() << std::endl;
+ out << "Device ID: " << deviceInfo.getID() << std::endl;
+ out << "Device Spec version: " << deviceInfo.getSpecVersion() << std::endl;
+ out << "Device dat model version: " << deviceInfo.getDataModelVersion() << std::endl;
+
+ std::cout << out.str() << std::endl;
+ }, std::placeholders::_1));
+ }
+ catch (InvalidArgsException &e)
+ {
+ std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]"
+ << std::endl;
+ }
+ catch (SimulatorException &e)
+ {
+ std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" <<
+ std::endl;
+ }
+ }
+
+ void getPlatformInfo()
+ {
+ SimulatorRemoteResourceSP resource = selectResource();
+ if (!resource)
+ return;
+
+ try
+ {
+ SimulatorManager::getInstance()->getPlatformInfo(resource->getHost(), std::bind([](PlatformInfo & platformInfo)
+ {
+ std::cout << "###Platform Information received...." << std::endl;
+ std::ostringstream out;
+ out << "Platform ID: " << platformInfo.getPlatformID() << std::endl;
+ out << "Platform version: " << platformInfo.getPlatformVersion() << std::endl;
+ out << "Manufacturer name: " << platformInfo.getManufacturerName() << std::endl;
+ out << "Manufacturer url: " << platformInfo.getManufacturerUrl() << std::endl;
+ out << "Modle number: " << platformInfo.getModelNumber() << std::endl;
+ out << "Date of manufacture: " << platformInfo.getDateOfManfacture() << std::endl;
+ out << "Operatio system version: " << platformInfo.getOSVersion() << std::endl;
+ out << "Hardware version: " << platformInfo.getHardwareVersion() << std::endl;
+ out << "Firmware version: " << platformInfo.getFirmwareVersion() << std::endl;
+ out << "Support url: " << platformInfo.getSupportUrl() << std::endl;
+ out << "System time: " << platformInfo.getSystemTime() << std::endl;
+
+ std::cout << out.str() << std::endl;
+ }, std::placeholders::_1));
+ }
+ catch (InvalidArgsException &e)
+ {
+ std::cout << "InvalidArgsException occured [code : " << e.code()
+ << " Detail: " << e.what() << "]" << std::endl;
+ }
+ catch (SimulatorException &e)
+ {
+ std::cout << "SimulatorException occured [code : " << e.code()
+ << " Detail: " << e.what() << "]" << std::endl;
+ }
+ }
+
private:
std::recursive_mutex m_mutex;
std::map<std::string, SimulatorRemoteResourceSP> m_resList;
{
std::cout << "############### MAIN MENU###############" << std::endl;
std::cout << "1. Client Controller Test" << std::endl;
- std::cout << "2. Get device information" << std::endl;
- std::cout << "3. Get platform information" << std::endl;
- std::cout << "4. Set Logger" << std::endl;
- std::cout << "5. Help" << std::endl;
+ std::cout << "2. Set Logger" << std::endl;
+ std::cout << "3. Help" << std::endl;
std::cout << "0. Exit" << std::endl;
std::cout << "######################################" << std::endl;
}
std::cout << "Welcome back to main menu !" << std::endl;
break;
- case 2:
- {
- try
- {
- SimulatorManager::getInstance()->getDeviceInfo(std::bind([](DeviceInfo & deviceInfo)
- {
- std::cout << "###Device Information received...." << std::endl;
- std::ostringstream out;
- out << "Device name: " << deviceInfo.getName() << std::endl;
- out << "Device ID: " << deviceInfo.getID() << std::endl;
- out << "Device Spec version: " << deviceInfo.getSpecVersion() << std::endl;
- out << "Device dat model version: " << deviceInfo.getDataModelVersion() << std::endl;
-
- std::cout << out.str() << std::endl;
- }, std::placeholders::_1));
- }
- catch (InvalidArgsException &e)
- {
- std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]"
- << std::endl;
- }
- catch (SimulatorException &e)
- {
- std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" <<
- std::endl;
- }
- }
- break;
-
- case 3:
- {
- try
- {
- SimulatorManager::getInstance()->getPlatformInfo(std::bind([](PlatformInfo & platformInfo)
- {
- std::cout << "###Platform Information received...." << std::endl;
- std::ostringstream out;
- out << "Platform ID: " << platformInfo.getPlatformID() << std::endl;
- out << "Platform version: " << platformInfo.getPlatformVersion() << std::endl;
- out << "Manufacturer name: " << platformInfo.getManufacturerName() << std::endl;
- out << "Manufacturer url: " << platformInfo.getManufacturerUrl() << std::endl;
- out << "Modle number: " << platformInfo.getModelNumber() << std::endl;
- out << "Date of manufacture: " << platformInfo.getDateOfManfacture() << std::endl;
- out << "Operatio system version: " << platformInfo.getOSVersion() << std::endl;
- out << "Hardware version: " << platformInfo.getHardwareVersion() << std::endl;
- out << "Firmware version: " << platformInfo.getFirmwareVersion() << std::endl;
- out << "Support url: " << platformInfo.getSupportUrl() << std::endl;
- out << "System time: " << platformInfo.getSystemTime() << std::endl;
-
- std::cout << out.str() << std::endl;
- }, std::placeholders::_1));
- }
- catch (InvalidArgsException &e)
- {
- std::cout << "InvalidArgsException occured [code : " << e.code()
- << " Detail: " << e.what() << "]" << std::endl;
- }
- catch (SimulatorException &e)
- {
- std::cout << "SimulatorException occured [code : " << e.code()
- << " Detail: " << e.what() << "]" << std::endl;
- }
- }
- break;
-
- case 4: setLogger(); break;
+ case 2: setLogger(); break;
- case 5: printMainMenu(); break;
+ case 3: printMainMenu(); break;
case 0: cont = false;
}
*
* NOTE: API throws @InvalidArgsException and @SimulatorException on error.
*/
- void getDeviceInfo(DeviceInfoCallback callback);
+ void getDeviceInfo(const std::string &host, DeviceInfoCallback callback);
/**
* API for registering device information with stack.
*
* NOTE: API throws @InvalidArgsException and @SimulatorException on error.
*/
- void getPlatformInfo(PlatformInfoCallback callback);
+ void getPlatformInfo(const std::string &host, PlatformInfoCallback callback);
/**
* API for registering platform information with stack.
import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
import oic.simulator.clientcontroller.listener.IVerificationUIListener;
import oic.simulator.clientcontroller.remoteresource.MetaProperty;
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
import oic.simulator.clientcontroller.remoteresource.RemoteResource;
-import oic.simulator.clientcontroller.remoteresource.RemoteResourceAttribute;
-import oic.simulator.clientcontroller.utils.AttributeValueBuilder;
import oic.simulator.clientcontroller.utils.Constants;
import oic.simulator.clientcontroller.utils.Utility;
// Get the device and platform information
try {
- SimulatorManager.findDevices(deviceListener);
- SimulatorManager
- .getPlatformInformation(platformListener);
+ SimulatorManager.findDevices(resource
+ .getRemoteResourceRef().getHost(),
+ deviceListener);
+ SimulatorManager.getPlatformInformation(resource
+ .getRemoteResourceRef().getHost(),
+ platformListener);
} catch (SimulatorException e) {
Activator
.getDefault()
return null;
}
- resource.setResourceModelRef(resourceModelN);
- Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModelN);
- if (resource.isConfigUploaded()) {
- updateResourceAttributesFromResponse(resource, attributeMap);
+ // if(!resource.isConfigUploaded() || null ==
+ // resource.getResourceModelRef())
+ SimulatorResourceModel resourceModel = resource.getResourceModelRef();
+ if (null == resourceModel) {
+ resource.setResourceModelRef(resourceModelN);
} else {
- resource.setResourceAttributesMap(attributeMap);
+ resourceModel.update(resourceModelN);
}
- // TODO: Printing the values for debugging
- if (null != attributeMap) {
- RemoteResourceAttribute.printAttributes(attributeMap);
- }
- return resource;
- }
- private void updateResourceAttributesFromResponse(RemoteResource res,
- Map<String, RemoteResourceAttribute> newAttributeMap) {
- if (null == res || null == newAttributeMap) {
- return;
- }
- Map<String, RemoteResourceAttribute> oldAttributeMap = res
- .getResourceAttributesMap();
- if (null == oldAttributeMap) {
- return;
- }
- Iterator<String> itr = oldAttributeMap.keySet().iterator();
- String attName;
- RemoteResourceAttribute newAtt;
- RemoteResourceAttribute oldAtt;
- while (itr.hasNext()) {
- attName = itr.next();
- newAtt = newAttributeMap.get(attName);
- if (null == newAtt) {
- // Attribute does not exist in the received model. Hence
- // removing it from local model.
- itr.remove();
- } else {
- oldAtt = oldAttributeMap.get(attName);
- if (null != oldAtt) {
- oldAtt.setAttributeValue(newAtt.getAttributeValue());
- } else {
- itr.remove();
- }
- newAttributeMap.remove(attName);
- }
- }
- // Adding new attributes in the received model.
- itr = newAttributeMap.keySet().iterator();
- while (itr.hasNext()) {
- attName = itr.next();
- oldAttributeMap.put(attName, newAttributeMap.get(attName));
- }
+ resource.setResourceRepresentation(resourceModelN, false);
+
+ return resource;
}
public synchronized DeviceInfo getDeviceInfo() {
public void addObservedResourceURI(String resourceURI) {
synchronized (observedResourceURIList) {
- observedResourceURIList.add(resourceURI);
+ if (!observedResourceURIList.contains(resourceURI))
+ observedResourceURIList.add(resourceURI);
}
}
return resource;
}
- private Map<String, RemoteResourceAttribute> fetchResourceAttributesFromModel(
- SimulatorResourceModel resourceModelN) {
- Map<String, RemoteResourceAttribute> resourceAttributeMap = null;
- if (null != resourceModelN) {
- Map<String, SimulatorResourceAttribute> attributeMapN;
- attributeMapN = resourceModelN.getAttributes();
- if (null != attributeMapN) {
- resourceAttributeMap = new HashMap<String, RemoteResourceAttribute>();
-
- Set<String> attNameSet = attributeMapN.keySet();
- String attName;
- Object attValueObj;
- AttributeValue attValueN;
- AttributeProperty attPropN;
- TypeInfo typeInfo;
- Type valuesType;
- SimulatorResourceAttribute attributeN;
- RemoteResourceAttribute attribute;
- Iterator<String> attNameItr = attNameSet.iterator();
- while (attNameItr.hasNext()) {
- attName = attNameItr.next();
- attributeN = attributeMapN.get(attName);
- if (null != attributeN) {
- attribute = new RemoteResourceAttribute();
- attribute.setResourceAttributeRef(attributeN);
- attribute.setAttributeName(attName);
-
- attValueN = attributeN.value();
- if (null != attValueN) {
- attValueObj = attValueN.get();
- if (null != attValueObj) {
- attribute.setAttributeValue(attValueObj);
- }
-
- // Set the attribute type
- typeInfo = attValueN.typeInfo();
- if (null != typeInfo) {
- attribute.setAttValBaseType(typeInfo.mBaseType);
- attribute.setAttValType(typeInfo.mType);
- attribute.setDepth(typeInfo.mDepth);
- }
-
- }
-
- // Set the range and allowed values
- attPropN = attributeN.property();
- valuesType = attPropN.type();
- attribute.setValuesType(valuesType);
- if (valuesType == Type.RANGE) {
- attribute.setMinValue(attPropN.min());
- attribute.setMaxValue(attPropN.max());
- } else if (valuesType == Type.VALUESET) {
- Object[] values = attPropN.valueSet();
- if (null != values && values.length > 0) {
- List<Object> valueList = new ArrayList<Object>();
- for (Object obj : values) {
- valueList.add(((AttributeValue) obj).get());
- }
- attribute.setAllowedValues(valueList);
- }
- }
- resourceAttributeMap.put(attName, attribute);
- }
- }
- }
- }
- return resourceAttributeMap;
- }
-
private void newResourceFoundNotification(RemoteResource resource) {
synchronized (findResourceUIListeners) {
if (findResourceUIListeners.size() > 0) {
return resourceList;
}
- public String getAttributeValue(RemoteResource res, String attName) {
- if (null == res || null == attName) {
+ public List<String> getAllValuesOfAttribute(SimulatorResourceAttribute att) {
+ if (null == att) {
+ return null;
+ }
+
+ AttributeValue val = att.value();
+ if (null == val) {
return null;
}
- return res.getAttributeValue(attName);
+
+ List<String> values = new ArrayList<String>();
+
+ TypeInfo type = val.typeInfo();
+
+ AttributeProperty prop = att.property();
+ if (null == prop || prop.type().ordinal() == Type.UNKNOWN.ordinal()) {
+ values.add(Utility.getAttributeValueAsString(val));
+ 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);
+ }
+ } else if (valuesType.ordinal() == Type.VALUESET
+ .ordinal()) {
+ List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
+ childProp.valueSet(), type.mBaseType);
+ if (null != list) {
+ values.addAll(list);
+ }
+ }
+ }
+ }
+ } else {
+ if (valuesType.ordinal() == Type.RANGE.ordinal()) {
+ List<String> list = getRangeForPrimitiveNonArrayAttributes(
+ prop, type.mType);
+ if (null != list) {
+ values.addAll(list);
+ }
+ } else if (valuesType.ordinal() == Type.VALUESET.ordinal()) {
+ List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
+ prop.valueSet(), type.mType);
+ if (null != list) {
+ values.addAll(list);
+ }
+ }
+ }
+ }
+
+ if (values.isEmpty()) {
+ values.add(Utility.getAttributeValueAsString(val));
+ }
+
+ return values;
+ }
+
+ public List<String> getRangeForPrimitiveNonArrayAttributes(
+ AttributeProperty prop, ValueType type) {
+ if (null == prop) {
+ return null;
+ }
+
+ if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
+ return null;
+ }
+
+ 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:
+ }
+ 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;
+ }
+
+ Object obj;
+ List<String> values = new ArrayList<String>();
+ for (AttributeValue val : attValues) {
+ if (null == val) {
+ continue;
+ }
+ obj = val.get();
+ if (null == obj) {
+ continue;
+ }
+ values.add(String.valueOf(obj));
+ }
+ 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) {
if (null == resource) {
return;
}
public void sendPutRequest(RemoteResource resource,
- List<PutPostAttributeModel> putPostModelList) {
- if (null == resource) {
+ SimulatorResourceModel model) {
+ if (null == resource || null == model) {
return;
}
SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
if (null == resourceN) {
return;
}
- Map<String, RemoteResourceAttribute> attMap = resource
- .getResourceAttributesMap();
- if (null == attMap || attMap.size() < 1) {
- return;
- }
try {
- SimulatorResourceModel resourceModel = getUpdatedResourceModel(
- attMap, putPostModelList);
- resourceN.put(null, resourceModel, putListener);
+ resourceN.put(null, model, putListener);
} catch (Exception e) {
String addlInfo;
addlInfo = "Invalid Attribute Value. Cannot send PUT request.";
}
public void sendPostRequest(RemoteResource resource,
- List<PutPostAttributeModel> putPostModelList) {
- if (null == resource) {
+ SimulatorResourceModel model) {
+ if (null == resource || null == model) {
return;
}
SimulatorRemoteResource resourceN = resource.getRemoteResourceRef();
if (null == resourceN) {
return;
}
- Map<String, RemoteResourceAttribute> attMap = resource
- .getResourceAttributesMap();
- if (null == attMap || attMap.size() < 1) {
- return;
- }
- // Filter out the attributes whose modification status is true.
- Iterator<PutPostAttributeModel> itr = putPostModelList.iterator();
- PutPostAttributeModel model;
- while (itr.hasNext()) {
- model = itr.next();
- if (!model.isModified()) {
- itr.remove();
- }
- }
try {
- SimulatorResourceModel resourceModel = getUpdatedResourceModel(
- attMap, putPostModelList);
- resourceN.post(null, resourceModel, postListener);
+ resourceN.post(null, model, postListener);
} catch (Exception e) {
String addlInfo;
addlInfo = "Invalid Attribute Value. Cannot send POST request.";
}
}
- private SimulatorResourceModel getUpdatedResourceModel(
- Map<String, RemoteResourceAttribute> attMap,
- List<PutPostAttributeModel> putPostModelList) throws Exception {
- SimulatorResourceModel resourceModel = new SimulatorResourceModel();
- for (PutPostAttributeModel putPostAttribute : putPostModelList)
- {
- String attributeName = putPostAttribute.getAttName();
- RemoteResourceAttribute resourceAttribute = attMap.get(attributeName);
- AttributeValue attributeValue = AttributeValueBuilder.build(
- putPostAttribute.getAttValue(), resourceAttribute.getAttValBaseType());
- resourceModel.addAttribute(attributeName, attributeValue);
- }
-
- return resourceModel;
- }
-
public boolean sendObserveRequest(RemoteResource resource) {
if (null == resource) {
return false;
return false;
}
try {
- SimulatorResourceModel resourceModel;
- resourceModel = resourceN.setConfigInfo(configFilePath);
- if (null == resourceModel) {
+ SimulatorResourceModel configuredResourceModel;
+ configuredResourceModel = resourceN.setConfigInfo(configFilePath);
+ if (null == configuredResourceModel) {
return false;
}
+
// Store the resource model in the local cache
- resource.setResourceModelRef(resourceModel);
-
- // Fetching the allowed values and range for all the attributes
- Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModel);
- resource.setResourceAttributesMap(attributeMap);
- // TODO: Printing the values for debugging
- if (null != attributeMap) {
- RemoteResourceAttribute.printAttributes(attributeMap);
+ SimulatorResourceModel resourceModel = resource
+ .getResourceModelRef();
+ if (null != resourceModel) {
+ configuredResourceModel.update(resourceModel);
}
+ resource.setResourceModelRef(configuredResourceModel);
} catch (SimulatorException e) {
Activator
.getDefault()
--- /dev/null
+package oic.simulator.clientcontroller.remoteresource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
+
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class AttributeElement {
+ private Object mParent = null;
+ private SimulatorResourceAttribute mAttribute = null;
+ private Map<String, AttributeElement> mChildAttributes = new HashMap<String, AttributeElement>();
+ private boolean mPostState = false;
+
+ public AttributeElement(Object parent, SimulatorResourceAttribute attribute) {
+ mParent = parent;
+ mAttribute = attribute;
+ AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+ if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+ SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+ .value().get();
+ for (Map.Entry<String, SimulatorResourceAttribute> entrySet : resModel
+ .getAttributes().entrySet())
+ mChildAttributes.put(entrySet.getKey(), new AttributeElement(
+ this, entrySet.getValue()));
+ } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
+ && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+ if (typeInfo.mDepth == 1) {
+ SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ new AttributeElement(this, indexAttribute));
+ }
+ } else if (typeInfo.mDepth == 2) {
+ SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ new AttributeElement(this, indexAttribute));
+ }
+ } else if (typeInfo.mDepth == 3) {
+ SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ new AttributeElement(this, indexAttribute));
+ }
+ }
+ }
+ }
+
+ public Object getParent() {
+ return mParent;
+ }
+
+ public boolean hasChildren() {
+ if (mChildAttributes != null && mChildAttributes.size() > 0)
+ return true;
+ return false;
+ }
+
+ public Map<String, AttributeElement> getChildren() {
+ if (hasChildren() == true)
+ return mChildAttributes;
+ return null;
+ }
+
+ public SimulatorResourceAttribute getSimulatorResourceAttribute() {
+ return mAttribute;
+ }
+
+ public boolean isPostSupported() {
+ /* Auto update is disabled for ARRAY and RESOURCEMODEL type values */
+ AttributeValue.TypeInfo typeInfo = mAttribute.value().typeInfo();
+ return (!(typeInfo.mType == AttributeValue.ValueType.ARRAY && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) && typeInfo.mType != AttributeValue.ValueType.RESOURCEMODEL);
+ }
+
+ public void update(SimulatorResourceAttribute attribute) {
+ if (attribute == null)
+ return;
+
+ AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+ if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+ SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+ .value().get();
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : resModel
+ .getAttributes().entrySet()) {
+ AttributeElement attributeElement = mChildAttributes.get(entry
+ .getKey());
+ if (attributeElement != null) {
+ attributeElement.update(entry.getValue());
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(this,
+ entry.getValue());
+ mChildAttributes.put(entry.getKey(), newAttribute);
+ }
+ }
+ } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
+ && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+ if (typeInfo.mDepth == 1) {
+ SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.update(indexAttribute);
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ }
+ }
+ }
+ if (typeInfo.mDepth == 2) {
+ SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.update(indexAttribute);
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ }
+ }
+ }
+ if (typeInfo.mDepth == 3) {
+ SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.update(indexAttribute);
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ }
+ }
+ }
+ } else {
+ String currentValue = new AttributeValueStringConverter(
+ mAttribute.value()).toString();
+ String newValue = new AttributeValueStringConverter(
+ attribute.value()).toString();
+ if (currentValue != newValue) {
+ mAttribute.setValue(attribute.value());
+ }
+ }
+ }
+
+ public void updateForRAMLUpload(SimulatorResourceAttribute attribute) {
+ if (attribute == null)
+ return;
+
+ AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+ if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+ SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+ .value().get();
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : resModel
+ .getAttributes().entrySet()) {
+ AttributeElement attributeElement = mChildAttributes.get(entry
+ .getKey());
+ if (attributeElement != null) {
+ attributeElement.update(entry.getValue());
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(this,
+ entry.getValue());
+ mChildAttributes.put(entry.getKey(), newAttribute);
+ }
+ }
+ } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
+ && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+ if (typeInfo.mDepth == 1) {
+ SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.update(indexAttribute);
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ }
+ }
+ }
+ if (typeInfo.mDepth == 2) {
+ SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.update(indexAttribute);
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ }
+ }
+ }
+ if (typeInfo.mDepth == 3) {
+ SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.update(indexAttribute);
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ }
+ }
+ }
+ } else {
+ mAttribute.setProperty(attribute.property());
+ }
+ }
+
+ public boolean getPostState() {
+ return mPostState;
+ }
+
+ public void setPostState(boolean mPostState) {
+ this.mPostState = mPostState;
+ }
+
+ public void deepSetChildValue(SimulatorResourceAttribute attribute)
+ throws InvalidArgsException {
+ if (null == attribute || null == attribute.name())
+ return;
+
+ AttributeValue.TypeInfo myValuetypeInfo = mAttribute.value().typeInfo();
+ if (myValuetypeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+ SimulatorResourceModel resModel = (SimulatorResourceModel) mAttribute
+ .value().get();
+ if (resModel.containsAttribute(attribute.name()))
+ resModel.setAttributeValue(attribute.name(), attribute.value());
+ else
+ return;
+ }
+
+ if (mParent instanceof AttributeElement)
+ ((AttributeElement) mParent).deepSetChildValue(mAttribute);
+ }
+}
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.clientcontroller.remoteresource;
-
-import java.util.List;
-
-/**
- * This is a helper class for showing the resource attributes in PUT and POST
- * dialogs.
- */
-public class PutPostAttributeModel {
-
- private String attName;
- private String attValue;
- private List<String> values;
- boolean modified;
-
- public String getAttName() {
- return attName;
- }
-
- public void setAttName(String attName) {
- this.attName = attName;
- }
-
- public String getAttValue() {
- return attValue;
- }
-
- public void setAttValue(String attValue) {
- this.attValue = attValue;
- }
-
- public List<String> getValues() {
- return values;
- }
-
- public void setValues(List<String> values) {
- this.values = values;
- }
-
- public void prependNewValue(String customValue) {
- if (values.contains(customValue)) {
- values.remove(customValue);
- }
- values.add(0, customValue);
- }
-
- public boolean isModified() {
- return modified;
- }
-
- public void setModified(boolean modified) {
- this.modified = modified;
- }
-
- public static PutPostAttributeModel getModel(
- RemoteResourceAttribute attribute) {
- PutPostAttributeModel putPostModel = null;
- if (null != attribute) {
- putPostModel = new PutPostAttributeModel();
- putPostModel.setAttName(attribute.getAttributeName());
- putPostModel.setAttValue(String.valueOf(attribute
- .getAttributeValue()));
- putPostModel.setValues(attribute.getAllValues());
- putPostModel.setModified(false);
- }
- return putPostModel;
- }
-
- @Override
- public String toString() {
- return attName + "," + attValue + "\n";
- }
-}
package oic.simulator.clientcontroller.remoteresource;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
import oic.simulator.clientcontroller.utils.Constants;
import org.oic.simulator.SimulatorResourceModel;
*/
public class RemoteResource {
- private boolean observed;
+ private boolean observed;
// Native object references
- private SimulatorRemoteResource remoteResourceRef;
- private SimulatorResourceModel resourceModelRef;
- private Map<String, RemoteResourceAttribute> resourceAttributesMap;
+ private SimulatorRemoteResource remoteResourceRef;
+ private SimulatorResourceModel resourceModelRef;
+ private ResourceRepresentation mResourceRepresentation;
+ // private Map<String, RemoteResourceAttribute> resourceAttributesMap;
- private boolean configUploaded;
+ private boolean configUploaded;
- private boolean getAutomtnInProgress;
- private boolean putAutomtnInProgress;
- private boolean postAutomtnInProgress;
+ private boolean getAutomtnInProgress;
+ private boolean putAutomtnInProgress;
+ private boolean postAutomtnInProgress;
- private int getAutomtnId;
- private int putAutomtnId;
- private int postAutomtnId;
+ private int getAutomtnId;
+ private int putAutomtnId;
+ private int postAutomtnId;
- private boolean isFavorite;
+ private boolean isFavorite;
public SimulatorResourceModel getResourceModelRef() {
return resourceModelRef;
this.resourceModelRef = resourceModel;
}
- public Map<String, RemoteResourceAttribute> getResourceAttributesMap() {
- return resourceAttributesMap;
- }
-
- public void setResourceAttributesMap(
- Map<String, RemoteResourceAttribute> resourceAttributesMap) {
- this.resourceAttributesMap = resourceAttributesMap;
- }
-
+ /*
+ * public Map<String, RemoteResourceAttribute> getResourceAttributesMap() {
+ * return resourceAttributesMap; }
+ *
+ * public void setResourceAttributesMap( Map<String,
+ * RemoteResourceAttribute> resourceAttributesMap) {
+ * this.resourceAttributesMap = resourceAttributesMap; }
+ */
public int getGetAutomtnId() {
return getAutomtnId;
}
this.observed = observed;
}
- public List<PutPostAttributeModel> getPutPostModel() {
- Map<String, RemoteResourceAttribute> attMap = getResourceAttributesMap();
- if (null == attMap || attMap.size() < 1) {
- return null;
- }
- List<PutPostAttributeModel> putPostModelList = new ArrayList<PutPostAttributeModel>();
- String attName;
- RemoteResourceAttribute attribute;
- PutPostAttributeModel putPostModel;
- Iterator<String> attItr = attMap.keySet().iterator();
- while (attItr.hasNext()) {
- attName = attItr.next();
- attribute = attMap.get(attName);
- putPostModel = PutPostAttributeModel.getModel(attribute);
- if (null != putPostModel) {
- putPostModelList.add(putPostModel);
- }
- }
- return putPostModelList;
- }
-
- public String getAttributeValue(String attName) {
- RemoteResourceAttribute attribute = resourceAttributesMap.get(attName);
- if (null == attribute) {
- return null;
- }
- return String.valueOf(attribute.getAttributeValue());
- }
-
+ /*
+ * public List<PutPostAttributeModel> getPutPostModel() { Map<String,
+ * RemoteResourceAttribute> attMap = getResourceAttributesMap(); if (null ==
+ * attMap || attMap.size() < 1) { return null; } List<PutPostAttributeModel>
+ * putPostModelList = new ArrayList<PutPostAttributeModel>(); String
+ * attName; RemoteResourceAttribute attribute; PutPostAttributeModel
+ * putPostModel; Iterator<String> attItr = attMap.keySet().iterator(); while
+ * (attItr.hasNext()) { attName = attItr.next(); attribute =
+ * attMap.get(attName); putPostModel =
+ * PutPostAttributeModel.getModel(attribute); if (null != putPostModel) {
+ * putPostModelList.add(putPostModel); } } return putPostModelList; }
+ *
+ * public String getAttributeValue(String attName) { RemoteResourceAttribute
+ * attribute = resourceAttributesMap.get(attName); if (null == attribute) {
+ * return null; } return String.valueOf(attribute.getAttributeValue()); }
+ */
public int getAutomationtype(int autoId) {
if (getAutomtnId == autoId) {
return Constants.GET_AUTOMATION_INDEX;
public void setFavorite(boolean isFavorite) {
this.isFavorite = isFavorite;
}
+
+ public void setResourceRepresentation(SimulatorResourceModel resModel,
+ boolean ramlUploaded) {
+ if (mResourceRepresentation == null)
+ mResourceRepresentation = new ResourceRepresentation(resModel);
+ else
+ mResourceRepresentation.update(resModel, ramlUploaded);
+ }
+
+ public ResourceRepresentation getResourceRepresentation() {
+ return mResourceRepresentation;
+ }
}
import java.util.Map;
import org.oic.simulator.AttributeProperty.Type;
-import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.ValueType;
import org.oic.simulator.SimulatorResourceAttribute;
--- /dev/null
+package oic.simulator.clientcontroller.remoteresource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class ResourceRepresentation {
+ private Map<String, AttributeElement> mAttributes = new HashMap<String, AttributeElement>();
+
+ public ResourceRepresentation(SimulatorResourceModel resourceModel) {
+ if (resourceModel != null && resourceModel.size() > 0) {
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
+ .getAttributes().entrySet())
+ mAttributes.put(entry.getKey(), new AttributeElement(this,
+ entry.getValue()));
+ }
+ }
+
+ public Map<String, AttributeElement> getAttributes() {
+ return mAttributes;
+ }
+
+ public void update(SimulatorResourceModel resourceModel,
+ boolean ramlUploaded) {
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
+ .getAttributes().entrySet()) {
+ AttributeElement attributeElement = mAttributes.get(entry.getKey());
+ if (attributeElement != null) {
+ if (ramlUploaded)
+ attributeElement.updateForRAMLUpload(entry.getValue());
+ else
+ attributeElement.update(entry.getValue());
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(this,
+ entry.getValue());
+ mAttributes.put(entry.getKey(), newAttribute);
+ }
+ }
+ }
+
+ public SimulatorResourceModel getModel() {
+ if (null == mAttributes || mAttributes.isEmpty()) {
+ return null;
+ }
+ SimulatorResourceModel model = new SimulatorResourceModel();
+ for (Map.Entry<String, AttributeElement> entry : mAttributes.entrySet()) {
+ AttributeElement attributeElement = mAttributes.get(entry.getKey());
+ if (attributeElement != null) {
+ try {
+ model.addAttribute(attributeElement
+ .getSimulatorResourceAttribute());
+ } catch (InvalidArgsException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return model;
+ }
+
+ public SimulatorResourceModel getSelectedModel() {
+ if (null == mAttributes || mAttributes.isEmpty()) {
+ return null;
+ }
+ SimulatorResourceModel model = new SimulatorResourceModel();
+ for (Map.Entry<String, AttributeElement> entry : mAttributes.entrySet()) {
+ AttributeElement attributeElement = mAttributes.get(entry.getKey());
+ if (attributeElement != null && attributeElement.getPostState()) {
+ try {
+ model.addAttribute(attributeElement
+ .getSimulatorResourceAttribute());
+ } catch (InvalidArgsException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return model;
+ }
+}
\ No newline at end of file
--- /dev/null
+package oic.simulator.clientcontroller.utils;
+
+import java.util.Map;
+
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValueVisitor;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class AttributeValueStringConverter implements
+ AttributeValueVisitor.VisitingMethods<String> {
+
+ private AttributeValue mValue;
+
+ public AttributeValueStringConverter(AttributeValue value) {
+ mValue = value;
+ }
+
+ @Override
+ public String toString() {
+ AttributeValueVisitor visitor = new AttributeValueVisitor(mValue, this);
+ return (String) visitor.visit();
+ }
+
+ @Override
+ public String visitingValue(Integer value) {
+ return value.toString();
+ }
+
+ @Override
+ public String visitingValue(Double value) {
+ return value.toString();
+ }
+
+ @Override
+ public String visitingValue(Boolean value) {
+ return value.toString();
+ }
+
+ @Override
+ public String visitingValue(String value) {
+ return new String(value);
+ }
+
+ @Override
+ public String visitingValue(SimulatorResourceModel value) {
+ StringBuilder result = new StringBuilder();
+ result.append("{");
+ boolean first = true;
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : value
+ .getAttributes().entrySet()) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ result.append("\"" + entry.getKey() + "\":");
+ AttributeValue attributeValue = entry.getValue().value();
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("}");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Integer[] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Integer value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ result.append(value.toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Double[] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Double value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ result.append(value.toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Boolean[] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Boolean value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ result.append(value.toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(String[] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (String value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ result.append(value);
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(SimulatorResourceModel[] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (SimulatorResourceModel value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Integer[][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Integer[] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Double[][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Double[] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Boolean[][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Boolean[] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(String[][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (String[] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(SimulatorResourceModel[][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (SimulatorResourceModel[] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Integer[][][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Integer[][] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Double[][][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Double[][] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Boolean[][][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Boolean[][] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(String[][][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (String[][] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(SimulatorResourceModel[][][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (SimulatorResourceModel[][] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+}
import java.util.List;
import java.util.Set;
+import org.oic.simulator.AttributeValue;
import org.oic.simulator.SimulatorException;
+import org.oic.simulator.AttributeValue.TypeInfo;
+import org.oic.simulator.AttributeValue.ValueType;
/**
* This class has common utility methods.
}
return detail;
}
+
+ // This method only works for attributes whose values are of type int,
+ // double, bool, string and 1-D array of primitive types
+ public static String getAttributeValueAsString(AttributeValue val) {
+ if (null == val) {
+ return null;
+ }
+ Object value = val.get();
+ if (null == value) {
+ return null;
+ }
+ TypeInfo type = val.typeInfo();
+ if (type.mType == ValueType.RESOURCEMODEL
+ || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL)
+ || (type.mType == ValueType.ARRAY && type.mDepth > 1)) {
+ return null;
+ }
+ if (type.mType == ValueType.ARRAY) {
+ if (type.mBaseType == ValueType.INTEGER) {
+ Integer[] values = (Integer[]) value;
+ if (null == values || values.length < 1) {
+ return null;
+ }
+ List<Integer> list = new ArrayList<Integer>();
+ for (Integer i : values) {
+ list.add(i);
+ }
+ return list.toString();
+ } else if (type.mBaseType == ValueType.DOUBLE) {
+ Double[] values = (Double[]) value;
+ if (null == values || values.length < 1) {
+ return null;
+ }
+ List<Double> list = new ArrayList<Double>();
+ for (Double i : values) {
+ list.add(i);
+ }
+ return list.toString();
+ } else if (type.mBaseType == ValueType.BOOLEAN) {
+ Boolean[] values = (Boolean[]) value;
+ if (null == values || values.length < 1) {
+ return null;
+ }
+ List<Boolean> list = new ArrayList<Boolean>();
+ for (Boolean i : values) {
+ list.add(i);
+ }
+ return list.toString();
+ } else if (type.mBaseType == ValueType.STRING) {
+ String[] values = (String[]) value;
+ if (null == values || values.length < 1) {
+ return null;
+ }
+ List<String> list = new ArrayList<String>();
+ for (String i : values) {
+ list.add(i);
+ }
+ return list.toString();
+ } else {
+ return null;
+ }
+ } else {
+ return String.valueOf(value);
+ }
+ }
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.clientcontroller.view;
+
+import java.util.List;
+
+import oic.simulator.clientcontroller.Activator;
+import oic.simulator.clientcontroller.manager.ResourceManager;
+import oic.simulator.clientcontroller.remoteresource.AttributeElement;
+import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.utils.AttributeValueBuilder;
+import oic.simulator.clientcontroller.utils.Utility;
+import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog;
+
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValue.TypeInfo;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorResourceAttribute;
+
+/**
+ * This class provides editing support to the resources attributes table in the
+ * attributes view.
+ */
+public class AttributeEditingSupport {
+
+ private AttributeValueEditor attValueEditor;
+ private PostRequestEditor postReqEditor;
+
+ public AttributeValueEditor createAttributeValueEditor(TreeViewer viewer,
+ TitleAreaDialog dialog) {
+ attValueEditor = new AttributeValueEditor(viewer, dialog);
+ return attValueEditor;
+ }
+
+ public PostRequestEditor createAutomationEditor(TreeViewer viewer) {
+ postReqEditor = new PostRequestEditor(viewer);
+ return postReqEditor;
+ }
+
+ class AttributeValueEditor extends EditingSupport {
+
+ private final TreeViewer viewer;
+ private CCombo comboBox;
+ private TitleAreaDialog dialog;
+
+ public AttributeValueEditor(TreeViewer viewer, TitleAreaDialog dialog) {
+ super(viewer);
+ this.viewer = viewer;
+ this.dialog = dialog;
+ }
+
+ @Override
+ protected boolean canEdit(Object arg0) {
+ return true;
+ }
+
+ @Override
+ protected CellEditor getCellEditor(final Object element) {
+ ResourceManager resourceManager = Activator.getDefault()
+ .getResourceManager();
+
+ RemoteResource res = resourceManager
+ .getCurrentResourceInSelection();
+ if (null == res) {
+ return null;
+ }
+
+ final SimulatorResourceAttribute attribute;
+ if (!(element instanceof AttributeElement)) {
+ return null;
+ }
+
+ final AttributeElement attributeElement = ((AttributeElement) element);
+ attribute = attributeElement.getSimulatorResourceAttribute();
+ if (null == attribute) {
+ return null;
+ }
+
+ final AttributeValue val = attribute.value();
+ if (null == val) {
+ return null;
+ }
+
+ final TypeInfo type = val.typeInfo();
+ if (type.mBaseType == ValueType.RESOURCEMODEL) {
+ return null;
+ }
+
+ String values[] = null;
+ List<String> valueSet = resourceManager
+ .getAllValuesOfAttribute(attribute);
+ values = convertListToStringArray(valueSet);
+
+ ComboBoxCellEditor comboEditor;
+ comboEditor = new ComboBoxCellEditor(viewer.getTree(), values);
+ comboBox = (CCombo) comboEditor.getControl();
+ comboBox.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent event) {
+
+ String newValue = comboBox.getText();
+
+ if (null != newValue && !newValue.isEmpty()) {
+ attributeElement.setPostState(true);
+ } else {
+ attributeElement.setPostState(false);
+ }
+
+ /*
+ * if (type.mType == ValueType.ARRAY) { return; }
+ */
+ /*
+ * String oldValue = String.valueOf(Utility
+ * .getAttributeValueAsString(val)); String newValue =
+ * comboBox.getText();
+ *
+ * if (null != newValue && !newValue.isEmpty()) {
+ * attributeElement.setPostState(true); } else {
+ * attributeElement.setPostState(false); }
+ *
+ * if (!oldValue.equals(newValue)) { // Get the
+ * AttriuteValue from the string AttributeValue value =
+ * AttributeValueBuilder.build( newValue, type.mBaseType);
+ * TypeInfo resTypeInfo = value.typeInfo(); if (null ==
+ * value || type.mDepth != resTypeInfo.mDepth || type.mType
+ * != resTypeInfo.mType || type.mBaseType !=
+ * resTypeInfo.mBaseType) { MessageBox dialog = new
+ * MessageBox(viewer.getTree() .getShell(), SWT.ICON_ERROR |
+ * SWT.OK); dialog.setText("Invalid Value");
+ * dialog.setMessage("Given value is invalid");
+ * dialog.open(); } else { updateAttributeValue(attribute,
+ * value); } }
+ */
+ if (dialog instanceof PostRequestDialog) {
+ viewer.update(attributeElement, null);
+ // comboBox.setVisible(false);
+ }
+ }
+ });
+ return comboEditor;
+ }
+
+ @Override
+ protected Object getValue(Object element) {
+ int indexOfItem = 0;
+ SimulatorResourceAttribute att = null;
+
+ if (element instanceof AttributeElement) {
+ att = ((AttributeElement) element)
+ .getSimulatorResourceAttribute();
+ }
+
+ if (att == null) {
+ return 0;
+ }
+
+ String valueString = Utility.getAttributeValueAsString(att.value());
+ List<String> valueSet = Activator.getDefault().getResourceManager()
+ .getAllValuesOfAttribute(att);
+ if (null != valueSet) {
+ indexOfItem = valueSet.indexOf(valueString);
+ }
+ if (indexOfItem == -1) {
+ indexOfItem = 0;
+ }
+ return indexOfItem;
+ }
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ SimulatorResourceAttribute att = null;
+ if (element instanceof AttributeElement) {
+ att = ((AttributeElement) element)
+ .getSimulatorResourceAttribute();
+ }
+
+ if (att == null) {
+ return;
+ }
+
+ AttributeValue val = att.value();
+ if (null == val) {
+ return;
+ }
+
+ TypeInfo type = val.typeInfo();
+ /*
+ * if (type.mType == ValueType.ARRAY) { int index; try { index =
+ * Integer.parseInt(String.valueOf(value)); } catch
+ * (NumberFormatException nfe) { index = -1; } if (index == -1) {
+ * String oldValue = String.valueOf(Utility
+ * .getAttributeValueAsString(val)); String newValue =
+ * comboBox.getText(); if (!oldValue.equals(newValue)) { // Get the
+ * AttriuteValue from the string AttributeValue attValue =
+ * AttributeValueBuilder.build( newValue, type.mBaseType); TypeInfo
+ * resTypeInfo = attValue.typeInfo(); if (null == attValue ||
+ * type.mDepth != resTypeInfo.mDepth || type.mType !=
+ * resTypeInfo.mType || type.mBaseType != resTypeInfo.mBaseType) {
+ * MessageBox dialog = new MessageBox(viewer.getTree() .getShell(),
+ * SWT.ICON_ERROR | SWT.OK); dialog.setText("Invalid Value");
+ * dialog.setMessage("Given value is invalid"); dialog.open(); }
+ * else { updateAttributeValue(att, attValue); } } } }
+ */
+
+ String oldValue = String.valueOf(Utility
+ .getAttributeValueAsString(val));
+ String newValue = comboBox.getText();
+ if (!oldValue.equals(newValue)) {
+ // Get the AttriuteValue from the string
+ AttributeValue attValue = AttributeValueBuilder.build(newValue,
+ type.mBaseType);
+ TypeInfo resTypeInfo = attValue.typeInfo();
+ if (null == attValue || type.mDepth != resTypeInfo.mDepth
+ || type.mType != resTypeInfo.mType
+ || type.mBaseType != resTypeInfo.mBaseType) {
+ MessageBox dialog = new MessageBox(viewer.getTree()
+ .getShell(), SWT.ICON_ERROR | SWT.OK);
+ dialog.setText("Invalid Value");
+ dialog.setMessage("Given value is invalid");
+ dialog.open();
+ } else {
+ updateAttributeValue(att, attValue);
+ }
+ }
+
+ viewer.update(element, null);
+ }
+
+ public String[] convertListToStringArray(List<String> values) {
+ String[] strArr;
+ if (null != values && values.size() > 0) {
+ strArr = values.toArray(new String[1]);
+ } else {
+ strArr = new String[1];
+ }
+ return strArr;
+ }
+
+ public void updateAttributeValue(SimulatorResourceAttribute att,
+ AttributeValue value) {
+ att.setValue(value);
+
+ IStructuredSelection selection = (IStructuredSelection) viewer
+ .getSelection();
+ if (null == selection) {
+ return;
+ }
+
+ Object obj = selection.getFirstElement();
+ if (null == obj) {
+ return;
+ }
+
+ Tree t = viewer.getTree();
+ TreeItem item = t.getSelection()[0];
+ if (null == item) {
+ return;
+ }
+
+ TreeItem parent = item.getParentItem();
+ if (null != parent) {
+ while (parent.getParentItem() != null) {
+ parent = parent.getParentItem();
+ }
+ Object data = parent.getData();
+ ((AttributeElement) data).setPostState(true);
+ }
+
+ if (item.getData() instanceof AttributeElement) {
+ AttributeElement attributeElement = (AttributeElement) item
+ .getData();
+ attributeElement.getSimulatorResourceAttribute()
+ .setValue(value);
+
+ parent = item.getParentItem();
+ if (null != parent) {
+ Object data = parent.getData();
+ try {
+ ((AttributeElement) data).deepSetChildValue(att);
+ } catch (InvalidArgsException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public AttributeValue getResultantValue(AttributeValue newValue) {
+ AttributeValue val = null;
+ IStructuredSelection selection = (IStructuredSelection) viewer
+ .getSelection();
+ if (null == selection) {
+ return null;
+ }
+
+ Object obj = selection.getFirstElement();
+ if (null == obj) {
+ return null;
+ }
+
+ Tree t = viewer.getTree();
+ TreeItem item = t.getSelection()[0];
+ if (null == item) {
+ return null;
+ }
+
+ TreeItem parent = item.getParentItem();
+ if (null == parent) {
+ val = newValue;
+ } else {
+ while (parent.getParentItem() != null) {
+ parent = parent.getParentItem();
+ }
+ // Parent will point to the top-level attribute of type
+ // LocalResourceAttribute
+ Object data = parent.getData();
+ val = ((AttributeElement) data).getSimulatorResourceAttribute()
+ .value();
+ }
+
+ return val;
+ }
+ }
+
+ class PostRequestEditor extends EditingSupport {
+
+ private final TreeViewer viewer;
+
+ public PostRequestEditor(TreeViewer viewer) {
+ super(viewer);
+ this.viewer = viewer;
+ }
+
+ @Override
+ protected boolean canEdit(Object arg0) {
+ return true;
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ SimulatorResourceAttribute att = null;
+ if (element instanceof AttributeElement) {
+ att = ((AttributeElement) element)
+ .getSimulatorResourceAttribute();
+ }
+
+ if (null == att) {
+ return null;
+ }
+
+ AttributeValue val = att.value();
+ if (null == val) {
+ return null;
+ }
+
+ TypeInfo type = val.typeInfo();
+
+ if (type.mType == ValueType.RESOURCEMODEL
+ || type.mBaseType == ValueType.RESOURCEMODEL) {
+ return null;
+ }
+
+ return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
+ }
+
+ @Override
+ protected Object getValue(Object element) {
+ if (element instanceof AttributeElement) {
+ return ((AttributeElement) element).getPostState();
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ if (!(element instanceof AttributeElement)) {
+ return;
+ }
+ boolean status = (Boolean) value;
+ ((AttributeElement) element).setPostState(status);
+ viewer.update(element, null);
+ }
+ }
+}
package oic.simulator.clientcontroller.view;
-import java.util.List;
import java.util.Map;
import oic.simulator.clientcontroller.Activator;
import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
import oic.simulator.clientcontroller.listener.IVerificationUIListener;
import oic.simulator.clientcontroller.manager.ResourceManager;
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
+import oic.simulator.clientcontroller.remoteresource.AttributeElement;
import oic.simulator.clientcontroller.remoteresource.RemoteResource;
-import oic.simulator.clientcontroller.remoteresource.RemoteResourceAttribute;
+import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog;
import oic.simulator.clientcontroller.view.dialogs.PutRequestDialog;
import oic.simulator.clientcontroller.view.dialogs.VerificationDialog;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.client.SimulatorRemoteResource.VerificationType;
/**
public static final String VIEW_ID = "oic.simulator.clientcontroller.view.attribute";
- private TableViewer attTblViewer;
+ private TreeViewer attViewer;
private Button getButton;
private Button putButton;
setVisibility((resource == null) ? false : true);
// Update the attribute table
- if (null != attTblViewer
- && !attTblViewer.getControl().isDisposed()) {
- updateViewer(getData(resource));
+ if (null != attViewer
+ && !attViewer.getControl().isDisposed()) {
+ updateViewer(resource);
}
// Update the observe status
if (resourceInSelection != resource) {
return;
}
- updateViewer(getData(resource));
+ updateViewer(resource);
// Update the observe status
updateObserve(resource);
if (resourceInSelection != resource) {
return;
}
- updateViewer(getData(resource));
+ updateViewer(resource);
// Update the observe status
updateObserve(resource);
if (resourceInSelection != resource) {
return;
}
- updateViewer(getData(resource));
+ updateViewer(resource);
// Update the observe status
updateObserve(resource);
if (resourceInSelection != resource) {
return;
}
- updateViewer(getData(resource));
+ updateViewer(resource);
// Update the observe status
updateObserve(resource);
}
}
- private Map<String, RemoteResourceAttribute> getData(RemoteResource resource) {
- if (null == resource) {
- return null;
+ private void updateViewer(RemoteResource resource) {
+ if (null == attViewer) {
+ return;
}
- Map<String, RemoteResourceAttribute> attMap = resource
- .getResourceAttributesMap();
- return attMap;
- }
-
- private void updateViewer(Map<String, RemoteResourceAttribute> attMap) {
- if (null != attTblViewer) {
- Table tbl = attTblViewer.getTable();
- if (null != attMap) {
- attTblViewer.setInput(attMap.entrySet().toArray());
- if (!tbl.isDisposed()) {
- tbl.setLinesVisible(true);
- }
- } else {
- if (!tbl.isDisposed()) {
- tbl.removeAll();
- tbl.setLinesVisible(false);
- }
+ Tree tree = attViewer.getTree();
+ if (null != resource) {
+ attViewer.setInput(resource.getResourceRepresentation());
+ if (!tree.isDisposed()) {
+ tree.setLinesVisible(true);
+ }
+ } else {
+ if (!tree.isDisposed()) {
+ tree.removeAll();
+ tree.setLinesVisible(false);
}
}
}
setVisibility(false);
// Updating the data in the UI as per the resource in selection.
- if (null != attTblViewer && !attTblViewer.getControl().isDisposed()) {
- updateViewer(getData(resourceManager
- .getCurrentResourceInSelection()));
+ if (null != attViewer && !attViewer.getControl().isDisposed()) {
+ updateViewer(resourceManager.getCurrentResourceInSelection());
}
}
}
private void setupAttributeTable(Group attGroup) {
- attTblViewer = new TableViewer(attGroup, SWT.SINGLE | SWT.H_SCROLL
- | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+ Tree addressTree = new Tree(attGroup, SWT.SINGLE | SWT.BORDER
+ | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+ addressTree.setHeaderVisible(true);
- createAttributeColumns(attTblViewer);
+ attViewer = new TreeViewer(addressTree);
+
+ createAttributeColumns(attViewer);
// make lines and header visible
- Table table = attTblViewer.getTable();
- table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
+ Tree tree = attViewer.getTree();
+ tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ tree.setHeaderVisible(true);
+ tree.setLinesVisible(true);
- attTblViewer.setContentProvider(new AttributeContentProvider());
+ attViewer.setContentProvider(new AttributeContentProvider());
+ attViewer.setLabelProvider(new AttributeLabelProvider());
}
- public void createAttributeColumns(TableViewer tableViewer) {
+ public void createAttributeColumns(TreeViewer viewer) {
+ Tree tree = viewer.getTree();
- TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
- attName.getColumn().setWidth(attTblColWidth[0]);
- attName.getColumn().setText(attTblHeaders[0]);
- attName.setLabelProvider(new StyledCellLabelProvider() {
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- if (element instanceof Map.Entry) {
- @SuppressWarnings("unchecked")
- Map.Entry<String, RemoteResourceAttribute> entry = (Map.Entry<String, RemoteResourceAttribute>) element;
- cell.setText(entry.getKey());
- }
- }
- });
+ TreeColumn attName = new TreeColumn(tree, SWT.NONE);
+ attName.setWidth(attTblColWidth[0]);
+ attName.setText(attTblHeaders[0]);
- TableViewerColumn attValue = new TableViewerColumn(tableViewer,
- SWT.NONE);
- attValue.getColumn().setWidth(attTblColWidth[1]);
- attValue.getColumn().setText(attTblHeaders[1]);
- attValue.setLabelProvider(new StyledCellLabelProvider() {
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- if (element instanceof Map.Entry) {
- @SuppressWarnings("unchecked")
- Map.Entry<String, RemoteResourceAttribute> entry = (Map.Entry<String, RemoteResourceAttribute>) element;
- Object value = entry.getValue().getAttributeValue();
- if (null == value) {
- cell.setText("");
- } else {
- cell.setText(String.valueOf(value));
- }
- }
- }
- });
+ TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
+ attValue.setWidth(attTblColWidth[1]);
+ attValue.setText(attTblHeaders[1]);
}
private void setUIListeners() {
"PUT Automation is in progress. Please wait or stop the automation.");
return;
}
- List<PutPostAttributeModel> putPostModelList;
- putPostModelList = resourceInSelection
- .getPutPostModel();
- if (null == putPostModelList) {
+ if (resourceInSelection.getResourceRepresentation()
+ .getAttributes().size() < 1) {
MessageDialog
.openInformation(Display.getDefault()
.getActiveShell(), "PUT Request",
return;
}
PutRequestDialog putDialog = new PutRequestDialog(
- Display.getDefault().getActiveShell(),
- putPostModelList);
+ Display.getDefault().getActiveShell());
if (putDialog.open() == Window.OK) {
// Call the native PUT method
resourceManager.sendPutRequest(resourceInSelection,
- putPostModelList);
+ putDialog.getUpdatedRepresentation()
+ .getModel());
}
}
});
"POST Automation is in progress. Please wait or stop the automation.");
return;
}
- List<PutPostAttributeModel> putPostModelList;
- putPostModelList = resourceInSelection
- .getPutPostModel();
- if (null == putPostModelList) {
+ if (resourceInSelection.getResourceRepresentation()
+ .getAttributes().size() < 1) {
MessageDialog
.openInformation(Display.getDefault()
- .getActiveShell(), "PUT Request",
+ .getActiveShell(), "POST Request",
"No attributes exist in the resource model.");
return;
}
PostRequestDialog postDialog = new PostRequestDialog(
- Display.getDefault().getActiveShell(),
- putPostModelList);
+ Display.getDefault().getActiveShell());
if (postDialog.open() == Window.OK) {
// Call the native POST method
+ ResourceRepresentation representation = postDialog
+ .getUpdatedRepresentation();
resourceManager.sendPostRequest(
- resourceInSelection, putPostModelList);
+ resourceInSelection,
+ representation.getSelectedModel());
}
}
});
observeResButton.setEnabled(visibility);
}
- class AttributeContentProvider implements IStructuredContentProvider {
+ class AttributeContentProvider implements ITreeContentProvider {
@Override
public void dispose() {
}
@Override
- public void inputChanged(Viewer viewer, Object arg1, Object arg2) {
+ public void inputChanged(Viewer viewer, Object oldAttribute,
+ Object newAttribute) {
+ }
+
+ @Override
+ public Object[] getChildren(Object attribute) {
+ if (attribute instanceof AttributeElement) {
+ return ((AttributeElement) attribute).getChildren().values()
+ .toArray();
+ }
+
+ return new Object[0];
+ }
+
+ @Override
+ public Object getParent(Object attribute) {
+ if (attribute instanceof AttributeElement)
+ return ((AttributeElement) attribute).getParent();
+ return null;
}
@Override
- public Object[] getElements(Object element) {
- return (Object[]) element;
+ public boolean hasChildren(Object attribute) {
+ if (attribute instanceof AttributeElement)
+ return ((AttributeElement) attribute).hasChildren();
+ return false;
}
+ @Override
+ public Object[] getElements(Object resourceModel) {
+ if (resourceModel instanceof ResourceRepresentation) {
+ return ((ResourceRepresentation) resourceModel).getAttributes()
+ .values().toArray();
+ }
+
+ return new Object[0];
+ }
+ }
+
+ class AttributeLabelProvider implements ITableLabelProvider {
+
+ @Override
+ public void addListener(ILabelProviderListener arg0) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public boolean isLabelProperty(Object arg0, String arg1) {
+ return false;
+ }
+
+ @Override
+ public void removeListener(ILabelProviderListener arg0) {
+
+ }
+
+ @Override
+ public Image getColumnImage(Object element, int col) {
+ return null;
+ }
+
+ @Override
+ public String getColumnText(Object element, int column) {
+ if (element instanceof AttributeElement) {
+ AttributeElement attrElement = (AttributeElement) element;
+ switch (column) {
+ case 0: // Attribute name column
+ {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+ return attribute.name();
+ }
+
+ case 1: // Attribute value column
+ {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+
+ if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
+ return Utility.getAttributeValueAsString(attribute
+ .value());
+ return null;
+ }
+ }
+ }
+ return null;
+ }
}
@Override
package oic.simulator.clientcontroller.view.dialogs;
-import java.util.Iterator;
-import java.util.List;
-
import oic.simulator.clientcontroller.Activator;
-import oic.simulator.clientcontroller.manager.ResourceManager;
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
+import oic.simulator.clientcontroller.remoteresource.AttributeElement;
+import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
+import oic.simulator.clientcontroller.view.AttributeEditingSupport;
import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ComboBoxCellEditor;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.SimulatorResourceAttribute;
/**
* This dialog is used for generating a POST request.
*/
public class PostRequestDialog extends TitleAreaDialog {
- private TableViewer attTblViewer;
+ private TreeViewer attViewer;
+
+ private AttributeEditingSupport attributeEditor;
- private final String[] attTblHeaders = { "Name", "Value",
- "Select" };
- private final Integer[] attTblColWidth = { 200, 200, 50 };
+ private ResourceRepresentation updatedRepresentation;
- private List<PutPostAttributeModel> modelList = null;
+ private final String[] attTblHeaders = { "Name", "Value",
+ "Select" };
+ private final Integer[] attTblColWidth = { 200, 200, 50 };
- public PostRequestDialog(Shell parentShell,
- List<PutPostAttributeModel> modelList) {
+ public PostRequestDialog(Shell parentShell) {
super(parentShell);
- this.modelList = modelList;
}
@Override
layout.marginTop = 10;
container.setLayout(layout);
- createTableViewer(container);
-
- attTblViewer.setInput(modelList.toArray());
+ createTreeViewer(container);
- return compLayout;
- }
+ RemoteResource resource = Activator.getDefault().getResourceManager()
+ .getCurrentResourceInSelection();
- private void createTableViewer(Composite parent) {
- attTblViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
- | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+ updatedRepresentation = new ResourceRepresentation(
+ resource.getResourceModelRef());
- createAttributeColumns(attTblViewer);
+ attViewer.setInput(updatedRepresentation);
- // make lines and header visible
- Table table = attTblViewer.getTable();
- table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
-
- attTblViewer.setContentProvider(new AttributeContentProvider());
+ return compLayout;
}
- public void createAttributeColumns(TableViewer tableViewer) {
-
- // attributeEditor = new AttributeEditingSupport();
+ private void createTreeViewer(Composite parent) {
+ Tree addressTree = new Tree(parent, SWT.SINGLE | SWT.BORDER
+ | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+ addressTree.setHeaderVisible(true);
- TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
- attName.getColumn().setWidth(attTblColWidth[0]);
- attName.getColumn().setText(attTblHeaders[0]);
- attName.setLabelProvider(new StyledCellLabelProvider() {
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- if (element instanceof PutPostAttributeModel) {
- PutPostAttributeModel entry = (PutPostAttributeModel) element;
- cell.setText(entry.getAttName());
- }
- }
- });
-
- TableViewerColumn attValue = new TableViewerColumn(tableViewer,
- SWT.NONE);
- attValue.getColumn().setWidth(attTblColWidth[1]);
- attValue.getColumn().setText(attTblHeaders[1]);
- attValue.setLabelProvider(new StyledCellLabelProvider() {
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- if (element instanceof PutPostAttributeModel) {
- PutPostAttributeModel entry = (PutPostAttributeModel) element;
- cell.setText(entry.getAttValue());
- }
- }
- });
-
- attValue.setEditingSupport(new AttributeValueEditor(attTblViewer));
-
- TableViewerColumn updateColumn = new TableViewerColumn(tableViewer,
- SWT.NONE);
- updateColumn.getColumn().setWidth(attTblColWidth[2]);
- updateColumn.getColumn().setText(attTblHeaders[2]);
- updateColumn.setLabelProvider(new ColumnLabelProvider() {
- @Override
- public String getText(Object element) {
- return "";
- }
+ attViewer = new TreeViewer(addressTree);
- @Override
- public Image getImage(Object element) {
- PutPostAttributeModel model = (PutPostAttributeModel) element;
- if (model.isModified()) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.CHECKED);
- }
- return Activator.getDefault().getImageRegistry()
- .get(Constants.UNCHECKED);
- }
- });
- updateColumn.setEditingSupport(new UpdateEditor(attTblViewer));
- }
+ createAttributeColumns(attViewer);
- @Override
- protected boolean isResizable() {
- return true;
- }
+ // make lines and header visible
+ Tree tree = attViewer.getTree();
+ tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ tree.setHeaderVisible(true);
+ tree.setLinesVisible(true);
- @Override
- public boolean isHelpAvailable() {
- return false;
+ attViewer.setContentProvider(new AttributeContentProvider());
+ attViewer.setLabelProvider(new AttributeLabelProvider());
}
- @Override
- protected Button createButton(Composite parent, int id, String label,
- boolean defaultButton) {
- if (id == IDialogConstants.OK_ID) {
- label = "POST";
- }
- return super.createButton(parent, id, label, defaultButton);
+ public void createAttributeColumns(TreeViewer viewer) {
+ Tree tree = viewer.getTree();
+
+ attributeEditor = new AttributeEditingSupport();
+
+ TreeColumn attName = new TreeColumn(tree, SWT.NONE);
+ attName.setWidth(attTblColWidth[0]);
+ attName.setText(attTblHeaders[0]);
+
+ TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
+ attValue.setWidth(attTblColWidth[1]);
+ attValue.setText(attTblHeaders[1]);
+ TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer,
+ attValue);
+ attValueVwrCol.setEditingSupport(attributeEditor
+ .createAttributeValueEditor(attViewer, this));
+
+ TreeColumn updateColumn = new TreeColumn(tree, SWT.NONE);
+ updateColumn.setWidth(attTblColWidth[2]);
+ updateColumn.setText(attTblHeaders[2]);
+ TreeViewerColumn updateVwrCol = new TreeViewerColumn(attViewer,
+ updateColumn);
+ updateVwrCol.setEditingSupport(attributeEditor
+ .createAutomationEditor(attViewer));
}
- class AttributeContentProvider implements IStructuredContentProvider {
+ class AttributeContentProvider implements ITreeContentProvider {
@Override
public void dispose() {
}
@Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+ public void inputChanged(Viewer viewer, Object oldAttribute,
+ Object newAttribute) {
}
@Override
- public Object[] getElements(Object element) {
- return (Object[]) element;
- }
-
- }
-
- class AttributeValueEditor extends EditingSupport {
- private final TableViewer viewer;
- private CCombo comboBox;
+ public Object[] getChildren(Object attribute) {
+ if (attribute instanceof AttributeElement) {
+ return ((AttributeElement) attribute).getChildren().values()
+ .toArray();
+ }
- public AttributeValueEditor(TableViewer viewer) {
- super(viewer);
- this.viewer = viewer;
+ return new Object[0];
}
@Override
- protected boolean canEdit(Object arg0) {
- return true;
- }
-
- @Override
- protected CellEditor getCellEditor(Object element) {
- PutPostAttributeModel attributeInSelection = (PutPostAttributeModel) element;
-
- String values[] = null;
- List<String> valueSet = attributeInSelection.getValues();
- values = convertListToStringArray(valueSet);
-
- ComboBoxCellEditor comboEditor = new ComboBoxCellEditor(
- viewer.getTable(), values);
- comboBox = (CCombo) comboEditor.getControl();
- if (null != comboBox) {
- comboBox.addModifyListener(new ModifyListener() {
- @Override
- public void modifyText(ModifyEvent e) {
- IStructuredSelection selection = (IStructuredSelection) AttributeValueEditor.this.viewer
- .getSelection();
- PutPostAttributeModel att = (PutPostAttributeModel) selection
- .getFirstElement();
- if (null == att) {
- return;
- }
- String newValue = comboBox.getText();
- if (null != newValue && !newValue.isEmpty()) {
- att.setModified(true);
- } else {
- att.setModified(false);
- }
- AttributeValueEditor.this.viewer.update(att, null);
- }
- });
- }
- return comboEditor;
+ public Object getParent(Object attribute) {
+ if (attribute instanceof AttributeElement)
+ return ((AttributeElement) attribute).getParent();
+ return null;
}
@Override
- protected Object getValue(Object element) {
- int indexOfItem = 0;
- PutPostAttributeModel att = (PutPostAttributeModel) element;
- String valueString = att.getAttValue();
- List<String> valueSet = att.getValues();
- if (null != valueSet) {
- indexOfItem = valueSet.indexOf(valueString);
- }
- if (indexOfItem == -1) {
- indexOfItem = 0;
- }
- return indexOfItem;
+ public boolean hasChildren(Object attribute) {
+ if (attribute instanceof AttributeElement)
+ return ((AttributeElement) attribute).hasChildren();
+ return false;
}
@Override
- protected void setValue(Object element, Object value) {
- PutPostAttributeModel att = (PutPostAttributeModel) element;
- int index;
- try {
- index = Integer.parseInt(String.valueOf(value));
- } catch (NumberFormatException nfe) {
- index = -1;
+ public Object[] getElements(Object resourceModel) {
+ if (resourceModel instanceof ResourceRepresentation) {
+ return ((ResourceRepresentation) resourceModel).getAttributes()
+ .values().toArray();
}
- String newValue;
- if (index == -1) {
- newValue = comboBox.getText();
- att.prependNewValue(newValue);
- } else {
- newValue = att.getValues().get(index);
- }
- att.setAttValue(newValue);
- viewer.update(element, null);
- }
- public String[] convertListToStringArray(List<String> valueList) {
- String[] strArr;
- if (null != valueList && valueList.size() > 0) {
- strArr = valueList.toArray(new String[1]);
- } else {
- strArr = new String[1];
- }
- return strArr;
+ return new Object[0];
}
}
- class UpdateEditor extends EditingSupport {
+ class AttributeLabelProvider implements ITableLabelProvider {
- private final TableViewer viewer;
+ @Override
+ public void addListener(ILabelProviderListener arg0) {
+ }
- public UpdateEditor(TableViewer viewer) {
- super(viewer);
- this.viewer = viewer;
+ @Override
+ public void dispose() {
}
@Override
- protected boolean canEdit(Object arg0) {
- return true;
+ public boolean isLabelProperty(Object arg0, String arg1) {
+ return false;
}
@Override
- protected CellEditor getCellEditor(Object element) {
- return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
+ public void removeListener(ILabelProviderListener arg0) {
+
}
@Override
- protected Object getValue(Object element) {
- PutPostAttributeModel model = (PutPostAttributeModel) element;
- return model.isModified();
+ public Image getColumnImage(Object element, int col) {
+ if (col == 2) {
+ if (element instanceof AttributeElement) {
+
+ AttributeElement attrElement = (AttributeElement) element;
+ if (attrElement.isPostSupported()) {
+ if (attrElement.getPostState()) {
+ return Activator.getDefault().getImageRegistry()
+ .get(Constants.CHECKED);
+ } else {
+ return Activator.getDefault().getImageRegistry()
+ .get(Constants.UNCHECKED);
+ }
+ }
+ }
+ }
+
+ return null;
}
@Override
- protected void setValue(Object element, Object value) {
- PutPostAttributeModel model = (PutPostAttributeModel) element;
- boolean status = (Boolean) value;
- model.setModified(status);
- viewer.update(element, null);
+ public String getColumnText(Object element, int column) {
+ if (element instanceof AttributeElement) {
+ AttributeElement attrElement = (AttributeElement) element;
+ switch (column) {
+ case 0: // Attribute name column
+ {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+ return attribute.name();
+ }
+
+ case 1: // Attribute value column
+ {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+
+ if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
+ return Utility.getAttributeValueAsString(attribute
+ .value());
+ return null;
+ }
+
+ case 2: {
+ return "";
+ }
+ }
+ }
+ return null;
}
}
@Override
- protected void okPressed() {
- String value;
- PutPostAttributeModel attModel;
- Iterator<PutPostAttributeModel> itr;
- itr = modelList.iterator();
- while (itr.hasNext()) {
- attModel = itr.next();
- if (null == attModel) {
- return;
- }
- value = attModel.getAttValue();
- if (null == value || value.isEmpty()) {
- MessageDialog.openError(Display.getDefault().getActiveShell(),
- "Empty value", "Attribute value should not be empty.");
- return;
- }
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ public boolean isHelpAvailable() {
+ return false;
+ }
+
+ @Override
+ protected Button createButton(Composite parent, int id, String label,
+ boolean defaultButton) {
+ if (id == IDialogConstants.OK_ID) {
+ label = "POST";
}
- close();
+ return super.createButton(parent, id, label, defaultButton);
+ }
+
+ public ResourceRepresentation getUpdatedRepresentation() {
+ return updatedRepresentation;
}
}
package oic.simulator.clientcontroller.view.dialogs;
-import java.util.Iterator;
-import java.util.List;
-
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
+import oic.simulator.clientcontroller.Activator;
+import oic.simulator.clientcontroller.remoteresource.AttributeElement;
+import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
+import oic.simulator.clientcontroller.utils.Utility;
+import oic.simulator.clientcontroller.view.AttributeEditingSupport;
import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ComboBoxCellEditor;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.SimulatorResourceAttribute;
/**
* This dialog is used for generating a PUT request.
*/
public class PutRequestDialog extends TitleAreaDialog {
- private TableViewer attTblViewer;
+ private TreeViewer attViewer;
+
+ private AttributeEditingSupport attributeEditor;
- private final String[] attTblHeaders = { "Name", "Value" };
- private final Integer[] attTblColWidth = { 200, 200 };
+ private ResourceRepresentation updatedRepresentation;
- private List<PutPostAttributeModel> modelList = null;
+ private final String[] attTblHeaders = { "Name", "Value" };
+ private final Integer[] attTblColWidth = { 200, 200 };
- public PutRequestDialog(Shell parentShell,
- List<PutPostAttributeModel> modelList) {
+ public PutRequestDialog(Shell parentShell) {
super(parentShell);
- this.modelList = modelList;
}
@Override
layout.marginTop = 10;
container.setLayout(layout);
- createTableViewer(container);
+ createTreeViewer(container);
+
+ RemoteResource resource = Activator.getDefault().getResourceManager()
+ .getCurrentResourceInSelection();
- attTblViewer.setInput(modelList.toArray());
+ updatedRepresentation = new ResourceRepresentation(
+ resource.getResourceModelRef());
+
+ attViewer.setInput(updatedRepresentation);
return compLayout;
}
- private void createTableViewer(Composite parent) {
- attTblViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
- | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+ private void createTreeViewer(Composite parent) {
+ Tree addressTree = new Tree(parent, SWT.SINGLE | SWT.BORDER
+ | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+ addressTree.setHeaderVisible(true);
+
+ attViewer = new TreeViewer(addressTree);
- createAttributeColumns(attTblViewer);
+ createAttributeColumns(attViewer);
// make lines and header visible
- Table table = attTblViewer.getTable();
- table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
+ Tree tree = attViewer.getTree();
+ tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ tree.setHeaderVisible(true);
+ tree.setLinesVisible(true);
- attTblViewer.setContentProvider(new AttributeContentProvider());
+ attViewer.setContentProvider(new AttributeContentProvider());
+ attViewer.setLabelProvider(new AttributeLabelProvider());
}
- public void createAttributeColumns(TableViewer tableViewer) {
-
- TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
- attName.getColumn().setWidth(attTblColWidth[0]);
- attName.getColumn().setText(attTblHeaders[0]);
- attName.setLabelProvider(new StyledCellLabelProvider() {
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- if (element instanceof PutPostAttributeModel) {
- PutPostAttributeModel entry = (PutPostAttributeModel) element;
- cell.setText(entry.getAttName());
- }
- }
- });
-
- TableViewerColumn attValue = new TableViewerColumn(tableViewer,
- SWT.NONE);
- attValue.getColumn().setWidth(attTblColWidth[1]);
- attValue.getColumn().setText(attTblHeaders[1]);
- attValue.setLabelProvider(new StyledCellLabelProvider() {
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- if (element instanceof PutPostAttributeModel) {
- PutPostAttributeModel entry = (PutPostAttributeModel) element;
- cell.setText(entry.getAttValue());
- }
- }
- });
- attValue.setEditingSupport(new AttributeValueEditor(attTblViewer));
+ public void createAttributeColumns(TreeViewer viewer) {
+ Tree tree = viewer.getTree();
+
+ attributeEditor = new AttributeEditingSupport();
+
+ TreeColumn attName = new TreeColumn(tree, SWT.NONE);
+ attName.setWidth(attTblColWidth[0]);
+ attName.setText(attTblHeaders[0]);
+
+ TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
+ attValue.setWidth(attTblColWidth[1]);
+ attValue.setText(attTblHeaders[1]);
+ TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer,
+ attValue);
+ attValueVwrCol.setEditingSupport(attributeEditor
+ .createAttributeValueEditor(attViewer, this));
}
- class AttributeContentProvider implements IStructuredContentProvider {
+ class AttributeContentProvider implements ITreeContentProvider {
@Override
public void dispose() {
}
@Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+ public void inputChanged(Viewer viewer, Object oldAttribute,
+ Object newAttribute) {
}
@Override
- public Object[] getElements(Object element) {
- return (Object[]) element;
+ public Object[] getChildren(Object attribute) {
+ if (attribute instanceof AttributeElement) {
+ return ((AttributeElement) attribute).getChildren().values()
+ .toArray();
+ }
+
+ return new Object[0];
}
- }
- class AttributeValueEditor extends EditingSupport {
- private final TableViewer viewer;
- private CCombo comboBox;
+ @Override
+ public Object getParent(Object attribute) {
+ if (attribute instanceof AttributeElement)
+ return ((AttributeElement) attribute).getParent();
+ return null;
+ }
- public AttributeValueEditor(TableViewer viewer) {
- super(viewer);
- this.viewer = viewer;
+ @Override
+ public boolean hasChildren(Object attribute) {
+ if (attribute instanceof AttributeElement)
+ return ((AttributeElement) attribute).hasChildren();
+ return false;
}
@Override
- protected boolean canEdit(Object arg0) {
- return true;
+ public Object[] getElements(Object resourceModel) {
+ if (resourceModel instanceof ResourceRepresentation) {
+ return ((ResourceRepresentation) resourceModel).getAttributes()
+ .values().toArray();
+ }
+
+ return new Object[0];
}
+ }
+
+ class AttributeLabelProvider implements ITableLabelProvider {
@Override
- protected CellEditor getCellEditor(Object element) {
- PutPostAttributeModel attributeInSelection = (PutPostAttributeModel) element;
+ public void addListener(ILabelProviderListener arg0) {
+ }
- String values[] = null;
- List<String> valueSet = attributeInSelection.getValues();
- values = convertListToStringArray(valueSet);
+ @Override
+ public void dispose() {
+ }
- ComboBoxCellEditor comboEditor = new ComboBoxCellEditor(
- viewer.getTable(), values);
- comboBox = (CCombo) comboEditor.getControl();
- return comboEditor;
+ @Override
+ public boolean isLabelProperty(Object arg0, String arg1) {
+ return false;
}
@Override
- protected Object getValue(Object element) {
- int indexOfItem = 0;
- PutPostAttributeModel att = (PutPostAttributeModel) element;
- String valueString = att.getAttValue();
- List<String> valueSet = att.getValues();
- if (null != valueSet) {
- indexOfItem = valueSet.indexOf(valueString);
- }
- if (indexOfItem == -1) {
- indexOfItem = 0;
- }
- return indexOfItem;
+ public void removeListener(ILabelProviderListener arg0) {
+
}
@Override
- protected void setValue(Object element, Object value) {
- PutPostAttributeModel att = (PutPostAttributeModel) element;
- int index;
- try {
- index = Integer.parseInt(String.valueOf(value));
- } catch (NumberFormatException nfe) {
- index = -1;
- }
- if (index == -1) {
- String customValue = comboBox.getText();
- att.prependNewValue(customValue);
- att.setAttValue(customValue);
- } else {
- String attValue = att.getValues().get(index);
- att.setAttValue(attValue);
- }
- viewer.update(element, null);
+ public Image getColumnImage(Object element, int col) {
+ return null;
}
- public String[] convertListToStringArray(List<String> valueList) {
- String[] strArr;
- if (null != valueList && valueList.size() > 0) {
- strArr = valueList.toArray(new String[1]);
- } else {
- strArr = new String[1];
+ @Override
+ public String getColumnText(Object element, int column) {
+ if (element instanceof AttributeElement) {
+ AttributeElement attrElement = (AttributeElement) element;
+ switch (column) {
+ case 0: // Attribute name column
+ {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+ return attribute.name();
+ }
+
+ case 1: // Attribute value column
+ {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+
+ if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
+ return Utility.getAttributeValueAsString(attribute
+ .value());
+ return null;
+ }
+ }
}
- return strArr;
+ return null;
}
}
- public List<PutPostAttributeModel> getUpdatedModel() {
- return modelList;
- }
-
@Override
protected boolean isResizable() {
return true;
return super.createButton(parent, id, label, defaultButton);
}
- @Override
- protected void okPressed() {
- String value;
- PutPostAttributeModel attModel;
- Iterator<PutPostAttributeModel> itr;
- itr = modelList.iterator();
- while (itr.hasNext()) {
- attModel = itr.next();
- if (null == attModel) {
- return;
- }
- value = attModel.getAttValue();
- if (null == value || value.isEmpty()) {
- MessageDialog.openError(Display.getDefault().getActiveShell(),
- "Empty value", "Attribute value should not be empty.");
- return;
- }
- }
- close();
+ public ResourceRepresentation getUpdatedRepresentation() {
+ return updatedRepresentation;
}
+
}
import java.util.Set;
import java.util.Vector;
-import oic.simulator.serviceprovider.Activator;
-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;
-
+import org.eclipse.swt.widgets.Display;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeProperty.Type;
import org.oic.simulator.AttributeValue;
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
return;
}
- Resource resource = data.getResourceByURI(resourceURI);
- if (null == resource) {
- return;
- }
-
- resource.setResourceModel(resourceModelN);
-
- // 7. Fetch the resource attributes.
- Map<String, LocalResourceAttribute> resourceAttributeMap;
- try {
- resourceAttributeMap = fetchResourceAttributesFromModel(resourceModelN);
- if (null != resourceAttributeMap) {
- resource.setResourceAttributes(resourceAttributeMap);
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ Resource resource = data
+ .getResourceByURI(resourceURI);
+ if (null != resource) {
+ resource.setResourceRepresentation(resourceModelN);
+ }
}
- } catch (SimulatorException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- UiListenerHandler.getInstance()
- .resourceModelChangedUINotification(resource);
+ });
}
});
}
null);
} else if (resource.isAttributeAutomationInProgress()) {
// Find the attribute with the given automation id
- LocalResourceAttribute attribute;
- attribute = getAttributeWithGivenAutomationId(
+ final AttributeElement attribute = getAttributeWithGivenAutomationId(
resource, automationId);
if (null != attribute) {
- attribute.setAutomationInProgress(false);
+ // 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
- .getResourceAttributeRef()
- .name());
+ /*
+ * UiListenerHandler .getInstance()
+ * .automationCompleteUINotification( resource,
+ * attribute
+ * .getSimulatorResourceAttribute().name());
+ */
} else {
// TODO: Temporarily reset the attribute
// automation status to false for making
// 6. Get the resource model java object reference.
resource.setResourceModel(jSimulatorSingleResource
.getResourceModel());
+
+ resource.setResourceRepresentation(resource.getResourceModel());
}
// 7. Register the resource with the platform.
jSimulatorCollectionResource
.setResourceModelChangeListener(resourceModelChangeListener);
+ // set resource model
+ resource.setResourceRepresentation(jSimulatorCollectionResource
+ .getResourceModel());;
+
// 5. Register the resource with the platform.
jSimulatorCollectionResource.start();
resource.setStarted(true);
jSimulatorSingleResource.start();
singleRes.setStarted(true);
+ singleRes.setResourceRepresentation(jResModel);
+
// 7. Fetch the resource attributes.
Map<String, LocalResourceAttribute> resourceAttributeMap;
resourceAttributeMap = fetchResourceAttributesFromModel(jResModel);
jSimulatorCollectionResource.start();
collectionRes.setStarted(true);
+ collectionRes.setResourceRepresentation(jResModel);
+
// 7. Fetch the resource attributes.
Map<String, LocalResourceAttribute> resourceAttributeMap;
resourceAttributeMap = fetchResourceAttributesFromModel(jResModel);
return Utility.getCollectionResourceListFromSet(childs);
}
- /*
- * public void deleteResourceByURI(String resourceURI) { if (null !=
- * resourceURI) { Resource resource =
- * getSimulatorResourceByURI(resourceURI); if (null != resource) { //
- * Unregister the resource from the platform deleteResource(resource);
- *
- * // Delete from the local data structure deleteLocalResourceDetails(null,
- * resourceURI);
- *
- * // Notify the UI listener for removing this resource // from UI //
- * resourceDeletedUINotification(); if (resource ==
- * getCurrentResourceInSelection()) { // Listeners might query the resource
- * being deleted // if exists. So set the currently selection to // null.
- * setCurrentResourceInSelection(null);
- *
- * // Notify all observers for resource selection // change event //
- * resourceSelectionChangedUINotification(); } } } }
- *
- * private SingleResource getSimulatorResourceByURI(String resourceURI) {
- * SingleResource resource = null; if (null != resourceURI) { synchronized
- * (resourceMap) { resource = resourceMap.get(resourceURI); } } return
- * resource; }
- *
- * private void deleteResource(SingleResource resource) { if (null !=
- * resource) { SimulatorResourceServer resourceServerN = resource
- * .getResourceServer(); if (null != resourceServerN) { try {
- * SimulatorManager.deleteResource(resourceServerN); } catch
- * (SimulatorException e) { Activator .getDefault() .getLogManager()
- * .log(Level.ERROR.ordinal(), new Date(),
- * Utility.getSimulatorErrorString(e, null)); } } } }
- *
- * public void deleteResourceByType(final String resourceType) {
- * System.out.println(resourceType + "to be deleted."); if (null !=
- * resourceType) { new Thread() {
- *
- * @Override public void run() { // Unregister the resources from the
- * platform deleteResource(resourceType);
- *
- * // Delete from the local data structure
- * deleteLocalResourceDetails(resourceType, null);
- *
- * // Notify the UI listener for removing this resource from UI
- * resourceDeletedUINotification();
- *
- * if (null != currentResourceInSelection &&
- * currentResourceInSelection.getResourceTypes() .contains(resourceType)) {
- * // Listeners might query the resource being deleted if // exists. So set
- * the currently selection to null. setCurrentResourceInSelection(null);
- *
- * // Notify all observers for resource selection change // event
- * resourceSelectionChangedUINotification(null); } } }.start(); } }
- *
- * private void deleteResource(String resourceType) { if (null !=
- * resourceType) { try { SimulatorManager.deleteResources(resourceType); }
- * catch (SimulatorException e) { Activator .getDefault() .getLogManager()
- * .log(Level.ERROR.ordinal(), new Date(),
- * Utility.getSimulatorErrorString(e, null)); } } }
- *
- * public void deleteAllResources() { new Thread() {
- *
- * @Override public void run() { // Unregister the resources from the
- * platform deleteResource();
- *
- * // Delete from the local data structure deleteLocalResourceDetails(null,
- * null);
- *
- * // Notify the UI listener for removing this resource from UI
- * resourceDeletedUINotification();
- *
- * // Listeners might query the resource being deleted if exists. // So set
- * the currently selection to null. setCurrentResourceInSelection(null);
- *
- * // Notify all observers for resource selection change event
- * resourceSelectionChangedUINotification(null); } }.start(); }
- *
- * private void deleteResource() { try {
- * SimulatorManager.deleteResources(null); } catch (SimulatorException e) {
- * Activator .getDefault() .getLogManager() .log(Level.ERROR.ordinal(), new
- * Date(), Utility.getSimulatorErrorString(e, null)); } }
- *
- * private void deleteLocalResourceDetails(String resourceType, String
- * resourceURI) { synchronized (resourceMap) { if (null == resourceType &&
- * null == resourceURI) { resourceMap.clear(); } else if (null !=
- * resourceType) { Set<String> uriSet = resourceMap.keySet(); if (null ==
- * uriSet) { return; } String uri; SingleResource simpleRes;
- * Iterator<String> uriItr = uriSet.iterator(); while (uriItr.hasNext()) {
- * uri = uriItr.next(); simpleRes = resourceMap.get(uri); if
- * (simpleRes.getResourceTypes().contains(resourceType)) { uriItr.remove();
- * } } } else { removeResourceFromMap(resourceURI); } } }
- *
- *
- *
- * public Set<String> getResourceTypeList() { Set<String> types = null;
- * synchronized (resourceMap) { if (resourceMap.size() > 0) { types = new
- * TreeSet<String>(); Set<String> typeSet = resourceMap.keySet();
- * Iterator<String> typeItr = typeSet.iterator(); SingleResource resource;
- * while (typeItr.hasNext()) { resource = resourceMap.get(typeItr.next());
- * Set<String> subTypes = resource.getResourceTypes();
- * types.addAll(subTypes); } } } return types; }
- */
-
public void resourceSelectionChanged(final Resource selectedResource) {
new Thread() {
@Override
}
}
- /*
- * private ModelChangeNotificationType compareAndUpdateLocalAttributes(
- * Map<String, LocalResourceAttribute> resourceAttributeMapOld, Map<String,
- * LocalResourceAttribute> resourceAttributeMapNew,
- * Set<LocalResourceAttribute> valueChangeSet) { ModelChangeNotificationType
- * notificationType = ModelChangeNotificationType.NONE; if (null !=
- * resourceAttributeMapOld && null != resourceAttributeMapNew) { Set<String>
- * oldMapKeySet = resourceAttributeMapOld.keySet(); Iterator<String>
- * attributeMapOldItr = oldMapKeySet.iterator(); String attName;
- * LocalResourceAttribute attributeOld; LocalResourceAttribute attributeNew;
- * Object attValueOld; Object attValueNew; String oldValueStr; String
- * newValueStr; while (attributeMapOldItr.hasNext()) { attName =
- * attributeMapOldItr.next(); if
- * (resourceAttributeMapNew.containsKey(attName)) { attributeOld =
- * resourceAttributeMapOld.get(attName); attributeNew =
- * resourceAttributeMapNew.get(attName); // Copy the attribute value from
- * new to old if the value // has been changed // Comparing only the
- * attribute's value considering the // fact that only the value can be
- * changed if (null != attributeOld && null != attributeNew) { attValueOld =
- * attributeOld.getAttributeValue(); attValueNew =
- * attributeNew.getAttributeValue();
- *
- * oldValueStr = String.valueOf(attValueOld); newValueStr =
- * String.valueOf(attValueNew);
- *
- * if (null != oldValueStr && null != newValueStr) { if
- * (!oldValueStr.equals(newValueStr)) {
- * attributeOld.setAttributeValue(attValueNew); notificationType =
- * ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED;
- * valueChangeSet.add(attributeOld); } } }
- * resourceAttributeMapNew.remove(attName); } else { // Attribute doesn't
- * exist in the new model. Hence // removing it from the model.
- * resourceAttributeMapOld.remove(attName); notificationType =
- * ModelChangeNotificationType.ATTRIBUTE_REMOVED; } } // Check for new
- * attributes in the new model if (resourceAttributeMapNew.size() > 0) {
- * Set<String> remainingAttSet = resourceAttributeMapNew.keySet();
- * Iterator<String> remainingAttItr = remainingAttSet.iterator();
- * LocalResourceAttribute attribute; while (remainingAttItr.hasNext()) {
- * attName = remainingAttItr.next(); if (null != attName) { attribute =
- * resourceAttributeMapNew.get(attName); if (null != attribute) {
- * resourceAttributeMapOld.put(attName, attribute); } } } notificationType =
- * ModelChangeNotificationType.ATTRIBUTE_ADDED; } } return notificationType;
- * }
- */
-
// TODO: This method should get the status from the native layer.
public boolean isResourceStarted(Resource resource) {
if (null == resource) {
}
public int startAutomation(SingleResource resource,
- LocalResourceAttribute attribute, AutoUpdateType autoType,
+ AttributeElement attribute, AutoUpdateType autoType,
int autoUpdateInterval) {
int autoId = -1;
if (null != resource && null != attribute) {
SimulatorSingleResource server = (SimulatorSingleResource) resource
.getSimulatorResource();
if (null != server) {
- String attrName = attribute.getResourceAttributeRef().name();
+ String attrName = attribute.getSimulatorResourceAttribute()
+ .name();
try {
autoId = server.startAttributeUpdation(attrName, autoType,
autoUpdateInterval, automationListener);
return -1;
}
if (-1 != autoId) {
- attribute.setAutomationId(autoId);
- attribute.setAutomationType(autoType);
- attribute.setAutomationUpdateInterval(autoUpdateInterval);
- attribute.setAutomationInProgress(true);
+ attribute.setAutoUpdateId(autoId);
+ attribute.setAutoUpdateType(autoType);
+ attribute.setAutoUpdateInterval(autoUpdateInterval);
+ attribute.setAutoUpdateState(true);
resource.setAttributeAutomationInProgress(true);
- } else {
- attribute.setAutomationInProgress(false);
}
}
}
return autoId;
}
- public void stopAutomation(SingleResource resource,
- LocalResourceAttribute att, int autoId) {
+ public void stopAutomation(SingleResource resource, AttributeElement att,
+ int autoId) {
if (null != resource) {
SimulatorSingleResource server = (SimulatorSingleResource) resource
.getSimulatorResource();
return;
}
// Change the automation status
- att.setAutomationInProgress(false);
+ att.setAutoUpdateState(false);
resource.setAttributeAutomationInProgress(isAnyAttributeInAutomation(resource));
}
}
}
private boolean isAnyAttributeInAutomation(SingleResource resource) {
- if (null == resource) {
+ if (null == resource || null == resource.getResourceRepresentation()) {
return false;
}
- Map<String, LocalResourceAttribute> attMap = resource
- .getResourceAttributes();
- if (null == attMap) {
+
+ Map<String, AttributeElement> attributes = resource
+ .getResourceRepresentation().getAttributes();
+ if (null == attributes || 0 == attributes.size())
return false;
+
+ for (Map.Entry<String, AttributeElement> entry : attributes.entrySet()) {
+ if (entry.getValue().isAutoUpdateInProgress())
+ return true;
}
- boolean status = false;
- Set<String> keySet = attMap.keySet();
- Iterator<String> attItr = keySet.iterator();
- while (attItr.hasNext()) {
- LocalResourceAttribute attribute = attMap.get(attItr.next());
- if (attribute.isAutomationInProgress()) {
- status = true;
- break;
- }
- }
- return status;
+
+ return false;
}
// Changes the automation state of the resource and its attributes
private void changeResourceLevelAutomationStatus(SingleResource resource,
boolean status) {
- Map<String, LocalResourceAttribute> attributeMap = resource
- .getResourceAttributes();
- if (null != attributeMap) {
- Set<String> attrNameSet = attributeMap.keySet();
- Iterator<String> attrNameItr = attrNameSet.iterator();
- String attrName;
- LocalResourceAttribute attribute;
- while (attrNameItr.hasNext()) {
- attrName = attrNameItr.next();
- attribute = attributeMap.get(attrName);
- if (null != attribute) {
- attribute.setAutomationInProgress(status);
- }
- }
+ if (null == resource || null == resource.getResourceRepresentation()) {
+ return;
+ }
+
+ Map<String, AttributeElement> attributes = resource
+ .getResourceRepresentation().getAttributes();
+ if (null == attributes || 0 == attributes.size())
+ return;
+
+ for (Map.Entry<String, AttributeElement> entry : attributes.entrySet()) {
+ entry.getValue().setAutoUpdateState(status);
}
+
resource.setResourceAutomationInProgress(status);
}
- private LocalResourceAttribute getAttributeWithGivenAutomationId(
+ private AttributeElement getAttributeWithGivenAutomationId(
SingleResource resource, int automationId) {
- LocalResourceAttribute targetAttribute = null;
- if (null != resource) {
- Map<String, LocalResourceAttribute> attributeMap = resource
- .getResourceAttributes();
- if (null != attributeMap) {
- Set<String> attNameSet = attributeMap.keySet();
- Iterator<String> attNameItr = attNameSet.iterator();
- String attName;
- LocalResourceAttribute attribute;
- while (attNameItr.hasNext()) {
- attName = attNameItr.next();
- if (null != attName) {
- attribute = attributeMap.get(attName);
- if (null != attribute) {
- if (attribute.isAutomationInProgress()
- && (attribute.getAutomationId() == automationId)) {
- targetAttribute = attribute;
- break;
- }
- }
- }
- }
- }
+ if (null == resource || null == resource.getResourceRepresentation()) {
+ return null;
+ }
+
+ Map<String, AttributeElement> attributes = resource
+ .getResourceRepresentation().getAttributes();
+ if (null == attributes || 0 == attributes.size())
+ return null;
+
+ for (Map.Entry<String, AttributeElement> entry : attributes.entrySet()) {
+ if (automationId == entry.getValue().getAutoUpdateId())
+ return entry.getValue();
}
- return targetAttribute;
+
+ return null;
}
public boolean isResourceAutomationStarted(SingleResource resource) {
--- /dev/null
+package oic.simulator.serviceprovider.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
+
+import oic.simulator.serviceprovider.utils.AttributeValueStringConverter;
+import oic.simulator.serviceprovider.utils.Constants;
+
+public class AttributeElement {
+ private Object mParent = null;
+ private SimulatorResourceAttribute mAttribute = null;
+ private Map<String, AttributeElement> mChildAttributes = new HashMap<String, AttributeElement>();
+ private DataChangeListener mListener = null;
+ private boolean mAutoUpdateSupport = false;
+ private int mAutoUpdateId = -1;
+ private boolean mAutoUpdateState = false;
+ private int mAutoUpdateInterval = Constants.DEFAULT_AUTOMATION_INTERVAL;
+ private AutoUpdateType mAutoUpdateType = Constants.DEFAULT_AUTOMATION_TYPE;
+
+ public AttributeElement(Object parent,
+ SimulatorResourceAttribute attribute, boolean autoUpdateSupport) {
+ mParent = parent;
+ mAttribute = attribute;
+ mAutoUpdateSupport = autoUpdateSupport;
+ AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+ if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+ mAutoUpdateSupport = false;
+ SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+ .value().get();
+ for (Map.Entry<String, SimulatorResourceAttribute> entrySet : resModel
+ .getAttributes().entrySet())
+ mChildAttributes.put(entrySet.getKey(), new AttributeElement(
+ this, entrySet.getValue(), false));
+ } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY) {
+ mAutoUpdateSupport = false;
+ if (typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+ if (typeInfo.mDepth == 1) {
+ SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ new AttributeElement(this, indexAttribute,
+ false));
+ }
+ } else if (typeInfo.mDepth == 2) {
+ SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ new AttributeElement(this, indexAttribute,
+ false));
+ }
+ } else if (typeInfo.mDepth == 3) {
+ SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ new AttributeElement(this, indexAttribute,
+ false));
+ }
+ }
+ }
+ }
+ }
+
+ public Object getParent() {
+ return mParent;
+ }
+
+ public boolean hasChildren() {
+ if (mChildAttributes != null && mChildAttributes.size() > 0)
+ return true;
+ return false;
+ }
+
+ public Map<String, AttributeElement> getChildren() {
+ if (hasChildren() == true)
+ return mChildAttributes;
+ return null;
+ }
+
+ public SimulatorResourceAttribute getSimulatorResourceAttribute() {
+ return mAttribute;
+ }
+
+ public int getAutoUpdateId() {
+ return mAutoUpdateId;
+ }
+
+ public void setAutoUpdateId(int id) {
+ mAutoUpdateId = id;
+ }
+
+ public boolean isAutoUpdateInProgress() {
+ return mAutoUpdateState;
+ }
+
+ public void setAutoUpdateState(boolean state) {
+ if (mAutoUpdateState != state) {
+ mAutoUpdateState = state;
+ if (mListener != null)
+ mListener.update(this);
+ }
+ }
+
+ public int getAutoUpdateInterval() {
+ return mAutoUpdateInterval;
+ }
+
+ public void setAutoUpdateInterval(int interval) {
+ mAutoUpdateInterval = interval;
+ }
+
+ public AutoUpdateType getAutoUpdateType() {
+ return mAutoUpdateType;
+ }
+
+ public void setAutoUpdateType(AutoUpdateType type) {
+ mAutoUpdateType = type;
+ }
+
+ public boolean isAutoUpdateSupport() {
+ return mAutoUpdateSupport;
+ }
+
+ public boolean isReadOnly() {
+ return (null == mAttribute.property());
+ }
+
+ public void setListener(DataChangeListener listener) {
+ mListener = listener;
+ for (Map.Entry<String, AttributeElement> entry : mChildAttributes
+ .entrySet())
+ entry.getValue().setListener(listener);
+ }
+
+ public DataChangeListener getListener() {
+ return mListener;
+ }
+
+ public void update(SimulatorResourceAttribute attribute) {
+ if (attribute == null)
+ return;
+
+ AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+ if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+ SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+ .value().get();
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : resModel
+ .getAttributes().entrySet()) {
+ AttributeElement attributeElement = mChildAttributes.get(entry
+ .getKey());
+ if (attributeElement != null) {
+ attributeElement.update(entry.getValue());
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(this,
+ entry.getValue(), false);
+ mChildAttributes.put(entry.getKey(), newAttribute);
+ if (mListener != null)
+ mListener.add(newAttribute);
+ }
+ }
+ } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
+ && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+ if (typeInfo.mDepth == 1) {
+ SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.update(indexAttribute);
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute, false);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ if (mListener != null)
+ mListener.add(newAttribute);
+ }
+ }
+ }
+ if (typeInfo.mDepth == 2) {
+ SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.update(indexAttribute);
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute, false);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ if (mListener != null)
+ mListener.add(newAttribute);
+ }
+ }
+ }
+ if (typeInfo.mDepth == 3) {
+ SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), null);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.update(indexAttribute);
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute, false);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ if (mListener != null)
+ mListener.add(newAttribute);
+ }
+ }
+ }
+ } else {
+ String currentValue = new AttributeValueStringConverter(
+ mAttribute.value()).toString();
+ String newValue = new AttributeValueStringConverter(
+ attribute.value()).toString();
+ if (!currentValue.equals(newValue)) {
+ mAttribute = attribute;
+ if (mListener != null)
+ mListener.update(this);
+ }
+ }
+ }
+
+ public void deepSetChildValue(SimulatorResourceAttribute attribute)
+ throws InvalidArgsException {
+ if (null == attribute || null == attribute.name())
+ return;
+
+ AttributeValue.TypeInfo myValuetypeInfo = mAttribute.value().typeInfo();
+ if (myValuetypeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+ SimulatorResourceModel resModel = (SimulatorResourceModel) mAttribute
+ .value().get();
+ if (resModel.containsAttribute(attribute.name()))
+ resModel.setAttributeValue(attribute.name(), attribute.value());
+ else
+ return;
+ }
+
+ if (mParent instanceof AttributeElement)
+ ((AttributeElement) mParent).deepSetChildValue(mAttribute);
+ }
+}
import java.util.Iterator;
import java.util.List;
-import oic.simulator.serviceprovider.utils.Constants;
-
import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
+import oic.simulator.serviceprovider.utils.Constants;
+
/**
* This is a helper class for providing the automation settings information to
* UI.
}
public static List<AutomationSettingHelper> getAutomationSettings(
- LocalResourceAttribute attribute) {
+ AttributeElement attribute) {
List<AutomationSettingHelper> settingList = null;
boolean invalidSetting;
.equals(Constants.AUTOMATION_TYPE)) {
setting.setSettingID(Constants.AUTOMATION_TYPE);
if (null != attribute) {
- setting.setSettingValue(attribute.getAutomationType()
+ setting.setSettingValue(attribute.getAutoUpdateType()
.toString());
} else {
setting.setSettingValue(AutoUpdateType.ONE_TIME.toString());
setting.setSettingID(Constants.UPDATE_INTERVAL_IN_MS);
if (null != attribute) {
setting.setSettingValue(String.valueOf(attribute
- .getAutomationUpdateInterval()));
+ .getAutoUpdateInterval()));
} else {
setting.setSettingValue(String
.valueOf(Constants.DEFAULT_AUTOMATION_INTERVAL));
--- /dev/null
+package oic.simulator.serviceprovider.model;
+
+public interface DataChangeListener {
+ public void add(AttributeElement attribute);
+
+ public void remove(AttributeElement attribute);
+
+ public void update(AttributeElement attribute);
+}
// Java SDK object reference
SimulatorResource simulatorResource;
private SimulatorResourceModel resourceModel;
+ private ResourceRepresentation mResourceRepresentation;
private String resourceURI;
private String resourceName;
this.attributes = attributes;
}
- // Added for debugging purpose
- public void printResourceInfo() {
- System.out.println("Resource URI: " + getResourceURI());
- System.out.println("Resource Name: " + getResourceName());
- System.out.println("Resource types: " + getResourceTypes());
- System.out.println("Resource Interfaces: " + getResourceInterfaces());
- System.out.println("Resource Attributes:-");
- /*
- * if (null != resourceAttributesMap) { Iterator<String> attItr =
- * resourceAttributesMap.keySet().iterator(); while (attItr.hasNext()) {
- * resourceAttributesMap.get(attItr.next()) .printAttributeDetails();; }
- * }
- */
+ public void setResourceRepresentation(SimulatorResourceModel resModel) {
+ if (mResourceRepresentation == null)
+ mResourceRepresentation = new ResourceRepresentation(resModel);
+ else
+ mResourceRepresentation.update(resModel);
+ }
+
+ public ResourceRepresentation getResourceRepresentation() {
+ return mResourceRepresentation;
}
}
--- /dev/null
+package oic.simulator.serviceprovider.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class ResourceRepresentation {
+ private DataChangeListener mListener = null;
+ private Map<String, AttributeElement> mAttributes = new HashMap<String, AttributeElement>();
+
+ public ResourceRepresentation(SimulatorResourceModel resourceModel) {
+ if (resourceModel != null && resourceModel.size() > 0) {
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
+ .getAttributes().entrySet())
+ mAttributes.put(entry.getKey(), new AttributeElement(this,
+ entry.getValue(), true));
+ }
+ }
+
+ public Map<String, AttributeElement> getAttributes() {
+ return mAttributes;
+ }
+
+ public void setListener(DataChangeListener listener) {
+ mListener = listener;
+ for (Map.Entry<String, AttributeElement> entry : mAttributes.entrySet())
+ entry.getValue().setListener(listener);
+ }
+
+ public DataChangeListener getListener() {
+ return mListener;
+ }
+
+ public void update(SimulatorResourceModel resourceModel) {
+ if (null == resourceModel)
+ return;
+
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
+ .getAttributes().entrySet()) {
+ AttributeElement attributeElement = mAttributes.get(entry.getKey());
+ if (attributeElement != null) {
+ attributeElement.update(entry.getValue());
+ } else // Display new attribute in UI
+ {
+ AttributeElement newAttribute = new AttributeElement(this,
+ entry.getValue(), true);
+ mAttributes.put(entry.getKey(), newAttribute);
+ if (mListener != null)
+ mListener.add(newAttribute);
+ }
+ }
+ }
+}
--- /dev/null
+package oic.simulator.serviceprovider.utils;
+
+import java.util.Map;
+
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValueVisitor;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.SimulatorResourceModel;
+
+public class AttributeValueStringConverter implements
+ AttributeValueVisitor.VisitingMethods<String> {
+
+ private AttributeValue mValue;
+
+ public AttributeValueStringConverter(AttributeValue value) {
+ mValue = value;
+ }
+
+ @Override
+ public String toString() {
+ AttributeValueVisitor visitor = new AttributeValueVisitor(mValue, this);
+ return (String) visitor.visit();
+ }
+
+ @Override
+ public String visitingValue(Integer value) {
+ return value.toString();
+ }
+
+ @Override
+ public String visitingValue(Double value) {
+ return value.toString();
+ }
+
+ @Override
+ public String visitingValue(Boolean value) {
+ return value.toString();
+ }
+
+ @Override
+ public String visitingValue(String value) {
+ return new String(value);
+ }
+
+ @Override
+ public String visitingValue(SimulatorResourceModel value) {
+ StringBuilder result = new StringBuilder();
+ result.append("{");
+ boolean first = true;
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : value
+ .getAttributes().entrySet()) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ result.append("\"" + entry.getKey() + "\":");
+ AttributeValue attributeValue = entry.getValue().value();
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("}");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Integer[] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Integer value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ result.append(value.toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Double[] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Double value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ result.append(value.toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Boolean[] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Boolean value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ result.append(value.toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(String[] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (String value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ result.append(value);
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(SimulatorResourceModel[] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (SimulatorResourceModel value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Integer[][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Integer[] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Double[][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Double[] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Boolean[][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Boolean[] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(String[][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (String[] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(SimulatorResourceModel[][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (SimulatorResourceModel[] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Integer[][][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Integer[][] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Double[][][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Double[][] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(Boolean[][][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (Boolean[][] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(String[][][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (String[][] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+ @Override
+ public String visitingValue(SimulatorResourceModel[][][] values) {
+ StringBuilder result = new StringBuilder();
+ result.append("[");
+ boolean first = true;
+ for (SimulatorResourceModel[][] value : values) {
+ if (!first)
+ result.append(", ");
+ first = false;
+ AttributeValue attributeValue = new AttributeValue(value);
+ result.append(new AttributeValueStringConverter(attributeValue)
+ .toString());
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+
+}
return null;
}
Set<Object> resultSet = new HashSet<Object>();
- if (type.equals(Constants.INT)) {
+ if (AttributeValue.ValueType.INTEGER == type) {
int val;
Iterator<String> itr = values.iterator();
while (itr.hasNext()) {
// Added for safety. Nothing to do.
}
}
- } else if (type.equals(Constants.DOUBLE)) {
+ } else if (AttributeValue.ValueType.DOUBLE == type) {
double val;
Iterator<String> itr = values.iterator();
while (itr.hasNext()) {
// Added for safety. Nothing to do.
}
}
- } else if (type.equals(Constants.BOOL)) {
+ } else if (AttributeValue.ValueType.BOOLEAN == type) {
resultSet.add(true);
resultSet.add(false);
- } else {
+ } else if (AttributeValue.ValueType.STRING == type) {
Iterator<String> itr = values.iterator();
while (itr.hasNext()) {
resultSet.add(itr.next());
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.manager.ResourceManager;
+import oic.simulator.serviceprovider.model.AttributeElement;
import oic.simulator.serviceprovider.model.AutomationSettingHelper;
import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.LocalResourceAttribute;
import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.SRMItem;
+import oic.simulator.serviceprovider.model.ResourceRepresentation;
import oic.simulator.serviceprovider.model.SingleResource;
import oic.simulator.serviceprovider.utils.AttributeValueBuilder;
import oic.simulator.serviceprovider.utils.Utility;
import org.oic.simulator.AttributeValue.ValueType;
import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.SimulatorResourceAttribute;
-import org.oic.simulator.SimulatorResourceModel;
import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
/**
return null;
}
- final SimulatorResourceAttribute att;
- if (element instanceof SimulatorResourceAttribute
- || element instanceof LocalResourceAttribute) {
- if (element instanceof LocalResourceAttribute) {
- LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
- att = localAtt.getResourceAttributeRef();
- } else {
- att = (SimulatorResourceAttribute) element;
- }
- } else {
+ final SimulatorResourceAttribute attribute;
+ if (!(element instanceof AttributeElement)) {
return null;
}
- if (null == att) {
+ AttributeElement attributeElement = ((AttributeElement) element);
+ attribute = attributeElement.getSimulatorResourceAttribute();
+ if (null == attribute) {
return null;
}
- final AttributeValue val = att.value();
- if (null == val) {
+ // CellEditor is not required as the automation is in progress.
+ if (attributeElement.isAutoUpdateInProgress()) {
return null;
}
- final TypeInfo type = val.typeInfo();
- if (type.mType == ValueType.RESOURCEMODEL
- || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL)) {
+ final AttributeValue val = attribute.value();
+ if (null == val) {
return null;
}
- AttributeProperty prop = att.property();
- if (null == prop) {
+ final TypeInfo type = val.typeInfo();
+ if (type.mBaseType == ValueType.RESOURCEMODEL) {
return null;
}
- if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
+ AttributeProperty prop = attribute.property();
+ if (null == prop) {
return null;
}
- // CellEditor is not required as the automation is in progress.
- if (element instanceof LocalResourceAttribute
- && ((LocalResourceAttribute) element)
- .isAutomationInProgress()) {
+ if (!resourceManager.isAttHasRangeOrAllowedValues(attribute)) {
return null;
}
String values[] = null;
List<String> valueSet = resourceManager
- .getAllValuesOfAttribute(att);
+ .getAllValuesOfAttribute(attribute);
values = convertListToStringArray(valueSet);
ComboBoxCellEditor comboEditor;
dialog.setMessage("Given value is invalid");
dialog.open();
} else {
- updateAttributeValue(att, value);
+ updateAttributeValue(attribute, value);
MessageBox dialog = new MessageBox(viewer.getTree()
.getShell(), SWT.ICON_QUESTION | SWT.OK
| SWT.CANCEL);
if (retval != SWT.OK) {
value = AttributeValueBuilder.build(oldValue,
type.mBaseType);
- updateAttributeValue(att, value);
+ updateAttributeValue(attribute, value);
} else {
ResourceManager resourceManager;
resourceManager = Activator.getDefault()
Resource resource = resourceManager
.getCurrentResourceInSelection();
- AttributeValue resultValue = getResultantValue(value);
+ SimulatorResourceAttribute result = getResultantValue(value);
resourceManager.attributeValueUpdated(
- (SingleResource) resource, att.name(),
- resultValue);
+ (SingleResource) resource,
+ result.name(), result.value());
}
}
@Override
protected Object getValue(Object element) {
int indexOfItem = 0;
- SimulatorResourceAttribute att;
+ SimulatorResourceAttribute att = null;
- if (element instanceof LocalResourceAttribute) {
- LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
- att = localAtt.getResourceAttributeRef();
- if (null == att) {
- return 0;
- }
- } else if (element instanceof SimulatorResourceAttribute) {
- att = (SimulatorResourceAttribute) element;
- } else {
+ if (element instanceof AttributeElement) {
+ att = ((AttributeElement) element)
+ .getSimulatorResourceAttribute();
+ }
+
+ if (att == null) {
return 0;
}
@Override
protected void setValue(Object element, Object value) {
- SimulatorResourceAttribute att;
+ SimulatorResourceAttribute att = null;
- if (element instanceof LocalResourceAttribute) {
- LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
- att = localAtt.getResourceAttributeRef();
- if (null == att) {
- return;
- }
- } else if (element instanceof SimulatorResourceAttribute) {
- att = (SimulatorResourceAttribute) element;
- } else {
+ if (element instanceof AttributeElement) {
+ att = ((AttributeElement) element)
+ .getSimulatorResourceAttribute();
+ }
+
+ if (att == null) {
return;
}
Resource resource = resourceManager
.getCurrentResourceInSelection();
- AttributeValue resultValue = getResultantValue(attValue);
+ SimulatorResourceAttribute result = getResultantValue(attValue);
resourceManager.attributeValueUpdated(
- (SingleResource) resource, att.name(),
- resultValue);
+ (SingleResource) resource,
+ result.name(), result.value());
}
}
}
if (null == item) {
return;
}
- TreeItem parent = item.getParentItem();
- // Get the parent model
- if (null == parent) {
- // Top-level attribute
- Resource res = Activator.getDefault().getResourceManager()
- .getCurrentResourceInSelection();
- if (null == res) {
- return;
- }
- SimulatorResourceModel model = res.getResourceModel();
- if (null == model) {
- return;
- }
- try {
- model.setAttributeValue(att.name(), value);
- } catch (InvalidArgsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else {
- SimulatorResourceModel model;
- Object data = parent.getData();
- if (null == data) {
- return;
- }
- if (data instanceof SRMItem) {
- model = ((SRMItem) data).getModel();
- } else {
- SimulatorResourceAttribute parentAtt;
- if (data instanceof LocalResourceAttribute) {
- parentAtt = ((LocalResourceAttribute) data)
- .getResourceAttributeRef();
- } else {
- parentAtt = (SimulatorResourceAttribute) data;
+ if (item.getData() instanceof AttributeElement) {
+ AttributeElement attributeElement = (AttributeElement) item
+ .getData();
+ attributeElement.getSimulatorResourceAttribute()
+ .setValue(value);
+
+ TreeItem parent = item.getParentItem();
+ if (null != parent) {
+ Object data = parent.getData();
+ try {
+ ((AttributeElement) data).deepSetChildValue(att);
+ } catch (InvalidArgsException e) {
+ e.printStackTrace();
}
- model = (SimulatorResourceModel) parentAtt.value().get();
- }
- try {
- model.setAttributeValue(att.name(), value);
- } catch (InvalidArgsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
}
}
- public AttributeValue getResultantValue(AttributeValue newValue) {
+ public SimulatorResourceAttribute getResultantValue(
+ AttributeValue newValue) {
AttributeValue val = null;
IStructuredSelection selection = (IStructuredSelection) viewer
.getSelection();
return null;
}
+ SimulatorResourceAttribute result = null;
TreeItem parent = item.getParentItem();
if (null == parent) {
Object data = item.getData();
- // SimulatorResourceAttribute att =
- // ((LocalResourceAttribute)data).getResourceAttributeRef();
- val = newValue;
+ result = ((AttributeElement) data)
+ .getSimulatorResourceAttribute();
} else {
while (parent.getParentItem() != null) {
parent = parent.getParentItem();
}
+
// Parent will point to the top-level attribute of type
- // LocalResourceAttribute
Object data = parent.getData();
- val = ((LocalResourceAttribute) data).getResourceAttributeRef()
- .value();
+ result = ((AttributeElement) data)
+ .getSimulatorResourceAttribute();
}
- return val;
+ return result;
}
}
}
SimulatorResourceAttribute att = null;
- if (element instanceof LocalResourceAttribute) {
- LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
- att = localAtt.getResourceAttributeRef();
+ if (element instanceof AttributeElement) {
+ att = ((AttributeElement) element)
+ .getSimulatorResourceAttribute();
}
if (null == att) {
return null;
}
+ Object parent = ((AttributeElement) element).getParent();
+ if (null != parent && !(parent instanceof ResourceRepresentation)) {
+ return null;
+ }
+
return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
}
@Override
protected Object getValue(Object element) {
- LocalResourceAttribute att = (LocalResourceAttribute) element;
- return att.isAutomationInProgress();
+ if (element instanceof AttributeElement) {
+ return ((AttributeElement) element).isAutoUpdateInProgress();
+ }
+
+ return false;
}
@Override
protected void setValue(Object element, Object value) {
+ if (!(element instanceof AttributeElement)) {
+ return;
+ }
+
ResourceManager resourceManager = Activator.getDefault()
.getResourceManager();
// As automation depends on the current resource in selection, its
return;
}
- LocalResourceAttribute att = (LocalResourceAttribute) element;
+ AttributeElement att = (AttributeElement) element;
boolean checked = (Boolean) value;
if (checked) {
// Start the automation
.getActiveShell(), "Automation Status",
"Automation start failed!!");
} else {
- viewer.update(element, null);
+ // viewer.update(element, null);
}
}
} else {
// Stop the automation
resourceManager.stopAutomation((SingleResource) resource, att,
- att.getAutomationId());
+ att.getAutoUpdateId());
MessageDialog.openInformation(Display.getDefault()
.getActiveShell(), "Automation Status",
"Automation stopped.");
- viewer.update(element, null);
+ // viewer.update(element, null);
}
}
}
package oic.simulator.serviceprovider.view;
import java.util.List;
-import java.util.Map;
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.listener.IAutomationUIListener;
import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener;
import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
-import oic.simulator.serviceprovider.model.CollectionResource;
+import oic.simulator.serviceprovider.model.AttributeElement;
+import oic.simulator.serviceprovider.model.DataChangeListener;
import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.LocalResourceAttribute;
import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.SRMItem;
+import oic.simulator.serviceprovider.model.ResourceRepresentation;
import oic.simulator.serviceprovider.model.SingleResource;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
import org.oic.simulator.SimulatorResourceAttribute;
-import org.oic.simulator.SimulatorResourceModel;
/**
* This class manages and shows the attribute view in the perspective.
@Override
public void run() {
if (null != attViewer) {
- updateViewer(getData(resource));
- Tree tree = attViewer.getTree();
- if (!tree.isDisposed()) {
- if (null != resource
- && (resource instanceof SingleResource && ((SingleResource) resource)
- .isResourceAutomationInProgress())) {
- tree.setEnabled(false);
- } else {
- tree.setEnabled(true);
- }
- }
+ if (null != resource
+ && null != resource
+ .getResourceRepresentation())
+ attViewer.setInput(resource
+ .getResourceRepresentation());
+ /*
+ * updateViewer(getData(resource)); Tree tree =
+ * attViewer.getTree(); if (!tree.isDisposed()) { if
+ * (null != resource && (resource instanceof
+ * SingleResource && ((SingleResource) resource)
+ * .isResourceAutomationInProgress())) {
+ * tree.setEnabled(false); } else {
+ * tree.setEnabled(true); } }
+ */
}
}
});
if (null == resourceInSelection) {
return;
}
- if (resource != resourceInSelection) {
- // This notification is for a different resource
- // whose attributes are not
- // currently not being shown in UI. So ignoring this
- // notification.
- return;
- }
- // Refresh the table viewers which will display
- // the updated values
- if (null != attViewer) {
- if (resource instanceof CollectionResource) {
- updateViewer(getData(resource));
- } else {
- updateViewer(getData(resource));
- }
- }
+ /*
+ * if (resource != resourceInSelection) { // This
+ * notification is for a different resource // whose
+ * attributes are not // currently not being shown in
+ * UI. So ignoring this // notification. return; } //
+ * Refresh the table viewers which will display // the
+ * updated values if (null != attViewer) { if (resource
+ * instanceof CollectionResource) {
+ * updateViewer(getData(resource)); } else {
+ * updateViewer(getData(resource)); } }
+ */
}
});
}
addManagerListeners();
// Check whether there is any resource selected already
- List<LocalResourceAttribute> propertyList = getData(resourceManager
- .getCurrentResourceInSelection());
- if (null != propertyList) {
- updateViewer(propertyList);
+ Resource resource = resourceManager.getCurrentResourceInSelection();
+ if (resource != null) {
+ attViewer.setInput(resource.getResourceRepresentation());
}
}
}
}
- class AttributeContentProvider implements ITreeContentProvider {
+ class AttributeContentProvider implements ITreeContentProvider,
+ DataChangeListener {
+
+ private TreeViewer mTreeViewer;
@Override
public void dispose() {
}
@Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+ public void inputChanged(Viewer viewer, Object oldAttribute,
+ Object newAttribute) {
+ mTreeViewer = (TreeViewer) viewer;
}
@Override
- public Object[] getChildren(Object element) {
- if (element instanceof SimulatorResourceAttribute
- || element instanceof LocalResourceAttribute) {
- SimulatorResourceAttribute att;
- if (element instanceof LocalResourceAttribute) {
- LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
- att = localAtt.getResourceAttributeRef();
- if (null == att) {
- return new Object[1];
- }
- } else {
- att = (SimulatorResourceAttribute) element;
- }
- AttributeValue val = att.value();
- if (null == val) {
- return new Object[1];
- }
- TypeInfo type = val.typeInfo();
- if (type.mType == ValueType.RESOURCEMODEL) {
- SimulatorResourceModel model = (SimulatorResourceModel) val
- .get();
- if (null == model) {
- return new Object[1];
- }
- return resourceManager.getAttributes(model).toArray();
- } else if (type.mType == ValueType.ARRAY
- && type.mBaseType == ValueType.RESOURCEMODEL
- && type.mDepth == 1) {
- SimulatorResourceModel[] model = (SimulatorResourceModel[]) val
- .get();
- if (null == model || model.length < 1) {
- return new Object[1];
- }
- return resourceManager.getIndexedAttributes(model)
- .toArray();
- }
- } else if (element instanceof SRMItem) {
- SRMItem item = (SRMItem) element;
- SimulatorResourceModel model = (SimulatorResourceModel) item
- .getModel();
- if (null == model) {
- return new Object[1];
- }
- return resourceManager.getAttributes(model).toArray();
+ public Object[] getChildren(Object attribute) {
+ if (attribute instanceof AttributeElement) {
+ return ((AttributeElement) attribute).getChildren().values()
+ .toArray();
}
- return new Object[1];
+
+ return new Object[0];
}
@Override
- public Object[] getElements(Object element) {
- Object[] elements = (Object[]) element;
- return elements;
+ public Object getParent(Object attribute) {
+ if (attribute instanceof AttributeElement)
+ return ((AttributeElement) attribute).getParent();
+ return null;
}
@Override
- public Object getParent(Object element) {
- return null;
+ public boolean hasChildren(Object attribute) {
+ if (attribute instanceof AttributeElement)
+ return ((AttributeElement) attribute).hasChildren();
+ return false;
}
@Override
- public boolean hasChildren(Object element) {
- if (element instanceof SimulatorResourceAttribute
- || element instanceof LocalResourceAttribute) {
- SimulatorResourceAttribute att;
- if (element instanceof LocalResourceAttribute) {
- LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
- att = localAtt.getResourceAttributeRef();
- if (null == att) {
- return false;
- }
- } else {
- att = (SimulatorResourceAttribute) element;
- }
- AttributeValue val = att.value();
- if (null == val) {
- return false;
- }
- TypeInfo type = val.typeInfo();
- if (type.mType == ValueType.RESOURCEMODEL) {
- SimulatorResourceModel model = (SimulatorResourceModel) val
- .get();
- if (null == model) {
- return false;
- }
- Map<String, SimulatorResourceAttribute> attributes = model
- .getAttributes();
- if (null != attributes && attributes.size() > 0) {
- return true;
- }
- } else if (type.mType == ValueType.ARRAY
- && type.mBaseType == ValueType.RESOURCEMODEL
- && type.mDepth == 1) {
- SimulatorResourceModel[] model = (SimulatorResourceModel[]) val
- .get();
- if (null != model && model.length > 0) {
- return true;
- }
+ public Object[] getElements(Object resourceModel) {
+ if (resourceModel instanceof ResourceRepresentation) {
+ ((ResourceRepresentation) resourceModel).setListener(this);
+ return ((ResourceRepresentation) resourceModel).getAttributes()
+ .values().toArray();
+ }
+
+ return new Object[0];
+ }
+
+ @Override
+ public void add(final AttributeElement attribute) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ mTreeViewer.refresh(attribute.getParent());
}
- } else if (element instanceof SRMItem) {
- SRMItem srmItem = (SRMItem) element;
- SimulatorResourceModel model = srmItem.getModel();
- if (null == model) {
- return false;
+ });
+ }
+
+ @Override
+ public void remove(final AttributeElement attribute) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ mTreeViewer.refresh(attribute.getParent());
}
- Map<String, SimulatorResourceAttribute> attributes = model
- .getAttributes();
- if (null != attributes && attributes.size() > 0) {
- return true;
+ });
+ }
+
+ @Override
+ public void update(final AttributeElement attribute) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ mTreeViewer.update(attribute, null);
}
- }
- return false;
+ });
}
}
@Override
public Image getColumnImage(Object element, int col) {
if (col == 2) {
- if (element instanceof SimulatorResourceAttribute
- || element instanceof LocalResourceAttribute) {
- SimulatorResourceAttribute att;
- if (element instanceof LocalResourceAttribute) {
- LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
- att = localAtt.getResourceAttributeRef();
- } else {
- att = (SimulatorResourceAttribute) element;
- }
- AttributeValue val = att.value();
- if (null == val) {
- return null;
- }
- TypeInfo type = val.typeInfo();
- if (type.mType == ValueType.RESOURCEMODEL
- || type.mType == ValueType.ARRAY) {
- return null;
- }
- if (element instanceof LocalResourceAttribute) {
- if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
- System.out.println("No range or allowed values");
- return null;
- }
- if (((LocalResourceAttribute) element)
- .isAutomationInProgress()) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.CHECKED);
+ if (element instanceof AttributeElement) {
+ // Ignore for collection resource
+ Resource res = resourceManager
+ .getCurrentResourceInSelection();
+ if (res instanceof SingleResource) {
+ AttributeElement attrElement = (AttributeElement) element;
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+ TypeInfo type = attribute.value().typeInfo();
+ if (attrElement.isAutoUpdateSupport()
+ && !attrElement.isReadOnly()) {
+ if (attrElement.isAutoUpdateInProgress()) {
+ return Activator.getDefault()
+ .getImageRegistry()
+ .get(Constants.CHECKED);
+ } else {
+ return Activator.getDefault()
+ .getImageRegistry()
+ .get(Constants.UNCHECKED);
+ }
}
- return Activator.getDefault().getImageRegistry()
- .get(Constants.UNCHECKED);
}
- return null;
}
}
return null;
}
@Override
- public String getColumnText(Object element, int col) {
- if (element instanceof SimulatorResourceAttribute
- || element instanceof LocalResourceAttribute) {
- SimulatorResourceAttribute att;
- if (element instanceof LocalResourceAttribute) {
- LocalResourceAttribute localAtt = (LocalResourceAttribute) element;
- att = localAtt.getResourceAttributeRef();
- } else {
- att = (SimulatorResourceAttribute) element;
- }
- AttributeValue val = att.value();
- if (null == val) {
- return "";
- }
- TypeInfo type = val.typeInfo();
- switch (col) {
- case 0:
- return att.name();
- case 1:
- if (!(type.mType == ValueType.RESOURCEMODEL || (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL))) {
- String value = Utility
- .getAttributeValueAsString(val);
- if (null == value) {
- value = "";
- }
- return value;
- } else {
- return "";
- }
- case 2:
+ public String getColumnText(Object element, int column) {
+ if (element instanceof AttributeElement) {
+ AttributeElement attrElement = (AttributeElement) element;
+ switch (column) {
+ case 0: // Attribute name column
+ {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+ return attribute.name();
+ }
+
+ case 1: // Attribute value column
+ {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+
+ if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
+ return Utility.getAttributeValueAsString(attribute
+ .value());
+ return null;
+ }
+
+ case 2: {
+ // Ignore for collection resource
Resource res = resourceManager
.getCurrentResourceInSelection();
- if (null != res && res instanceof CollectionResource) {
- return "-";
- }
-
- if (type.mType == ValueType.RESOURCEMODEL
- || type.mType == ValueType.ARRAY) {
- return "";
- }
- if (element instanceof LocalResourceAttribute) {
- if (!resourceManager
- .isAttHasRangeOrAllowedValues(att)) {
- System.out
- .println("No range or allowed values");
- return "Read Only";
- }
- if (((LocalResourceAttribute) element)
- .isAutomationInProgress()) {
- return Constants.ENABLED;
+ if (res instanceof SingleResource) {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+ TypeInfo type = attribute.value().typeInfo();
+ if (type.mType == AttributeValue.ValueType.ARRAY) {
+ if (type.mBaseType != AttributeValue.ValueType.RESOURCEMODEL) {
+ return "NA";
+ }
+ } else if (type.mType != AttributeValue.ValueType.RESOURCEMODEL) {
+ Object parent = attrElement.getParent();
+ if (null != parent
+ && !(parent instanceof ResourceRepresentation)) {
+ return "NA";
+ } else if (attrElement.isReadOnly()) {
+ return "Read-only";
+ } else if (attrElement.isAutoUpdateSupport()) {
+ if (attrElement.isAutoUpdateInProgress())
+ return Constants.ENABLED;
+ else
+ return Constants.DISABLED;
+ }
}
- return Constants.DISABLED;
}
- return "NA";
- }
- } else if (element instanceof SRMItem) {
- SRMItem item = (SRMItem) element;
- switch (col) {
- case 0:
- return "[" + item.getIndex() + "]";
- case 1:
- return "";
- case 2:
+
return "";
+ }
}
}
+
return null;
}
.createSingleResource(resource);
if (result) {
status = "Resource created.";
- resource.printResourceInfo();
} else {
status = "Failed to create resource.";
}
if (result) {
status = "Resource created.";
- loadRamlPage.getResource().printResourceInfo();
} else {
status = "Failed to create resource.";
}
JNIEXPORT void JNICALL
Java_org_oic_simulator_SimulatorManager_findDevices
-(JNIEnv *env, jobject object, jobject listener)
+(JNIEnv *env, jobject object, jstring hostUri, jobject listener)
{
VALIDATE_CALLBACK(env, listener)
try
{
- SimulatorManager::getInstance()->getDeviceInfo(callback);
+ JniString jniHostUri(env, hostUri);
+ SimulatorManager::getInstance()->getDeviceInfo(jniHostUri.get(), callback);
}
catch (InvalidArgsException &e)
{
JNIEXPORT void JNICALL
Java_org_oic_simulator_SimulatorManager_getPlatformInformation
-(JNIEnv *env, jobject object, jobject listener)
+(JNIEnv *env, jobject object, jstring hostUri, jobject listener)
{
VALIDATE_CALLBACK(env, listener)
try
{
- SimulatorManager::getInstance()->getPlatformInfo(callback);
+ JniString jniHostUri(env, hostUri);
+ SimulatorManager::getInstance()->getPlatformInfo(jniHostUri.get(), callback);
}
catch (InvalidArgsException &e)
{
void getValue(jobject &jValue, SimulatorResourceModel &value)
{
+ simulatorResourceModelToCpp(m_env, jValue, value);
}
void getValue(jobject &jValue, std::vector<SimulatorResourceModel> &value)
{
+ jobjectArray array = (jobjectArray) jValue;
+ size_t length = m_env->GetArrayLength(array);
+ std::vector<SimulatorResourceModel> result(length);
+ for (size_t i = 0; i < length; i++)
+ {
+ jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+ SimulatorResourceModel element;
+ getValue(jElement, element);
+ result[i] = element;
+ }
+
+ value = result;
}
void getValue(jobject &jValue, std::vector<std::vector<SimulatorResourceModel>> &value)
{
+ jobjectArray array = (jobjectArray) jValue;
+ size_t length = m_env->GetArrayLength(array);
+ std::vector<std::vector<SimulatorResourceModel>> result(length);
+ for (size_t i = 0; i < length; i++)
+ {
+ jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+ std::vector<SimulatorResourceModel> childArray;
+ getValue(jElement, childArray);
+ value[i] = childArray;
+ }
+
+ value = result;
}
void getValue(jobject &jValue, std::vector<std::vector<std::vector<SimulatorResourceModel>>> &value)
{
+ jobjectArray array = (jobjectArray) jValue;
+ size_t length = m_env->GetArrayLength(array);
+ std::vector<std::vector<std::vector<SimulatorResourceModel>>> result(length);
+ for (size_t i = 0; i < length; i++)
+ {
+ jobject jElement = m_env->GetObjectArrayElement(array, i);
+
+ std::vector<std::vector<SimulatorResourceModel>> childArray;
+ getValue(jElement, childArray);
+ value[i] = childArray;
+ }
+
+ value = result;
}
JNIEnv *m_env;
jAttributeProperty = env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
property.min(), property.max());
}
- else
+ else if (SimulatorResourceModel::AttributeProperty::Type::VALUE_SET == property.type())
{
static jmethodID propertyCtor = env->GetMethodID(
gSimulatorClassRefs.attributePropertyCls, "<init>", "([Lorg/oic/simulator/AttributeValue;)V");
jAttributeProperty = env->NewObject(gSimulatorClassRefs.attributePropertyCls, propertyCtor,
jValueSet);
}
+ else
+ {
+ return jAttributeProperty;
+ }
// Add child property
if (jAttributeProperty && property.getChildProperty())
addEntryToHashMap(env, attributesMap, jAttrName, jAttributeValue);
jobject jAttributeProperty = JniAttributeProperty::toJava(env, attributeEntry.second.getProperty());
- addEntryToHashMap(env, propertiesMap, jAttrName, jAttributeProperty);
+ if (jAttributeProperty)
+ addEntryToHashMap(env, propertiesMap, jAttrName, jAttributeProperty);
}
static jmethodID simulatorResourceModelCtor = env->GetMethodID(
*/
public class AttributeProperty {
- private Type mType = Type.UNKNOWN;
- private double mMin = -1;
- private double mMax = -1;
- private AttributeValue[] mValueSet = null;
+ private Type mType = Type.UNKNOWN;
+ private double mMin = -1;
+ private double mMax = -1;
+ private AttributeValue[] mValueSet = null;
private AttributeProperty mChildProperty = null;
/**
* API to set child attribute propety.
*
* @param childProperty
- * Child element property this property used if the
- * Attribute value is of array type.
+ * Child element property this property used if the Attribute
+ * value is of array type.
*/
public void setChildProperty(AttributeProperty childProperty) {
mChildProperty = childProperty;
package org.oic.simulator;
-public class AttributeValueValidation implements AttributeValueVisitor.VisitingMethods<Boolean> {
+public class AttributeValueValidation implements
+ AttributeValueVisitor.VisitingMethods<Boolean> {
private AttributeProperty mProperty = null;
public AttributeValueValidation(AttributeProperty property) {
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (Integer value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (Double value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (Boolean value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (String value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (Integer[] value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (Double[] value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (Boolean[] value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (String[] value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (Integer[][] value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (Double[][] value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (Boolean[][] value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
return false;
if (mProperty.getChildProperty() != null) {
- AttributeValueValidation rangeValidation = new AttributeValueValidation(mProperty.getChildProperty());
+ AttributeValueValidation rangeValidation = new AttributeValueValidation(
+ mProperty.getChildProperty());
for (String[][] value : values) {
if (rangeValidation.visitingValue(value) == false)
return false;
}
private <T> boolean checkValueSet(T value) {
- if (AttributeProperty.Type.VALUESET == mProperty.type() && null != mProperty.valueSet()) {
+ if (AttributeProperty.Type.VALUESET == mProperty.type()
+ && null != mProperty.valueSet()) {
for (AttributeValue allowedValue : mProperty.valueSet()) {
if (allowedValue.get().equals(value))
return true;
package org.oic.simulator;
public class AttributeValueVisitor {
- private AttributeValue mValue;
+ private AttributeValue mValue;
private VisitingMethods mListener;
public interface VisitingMethods<T extends Object> {
if (2 == typeInfo.mDepth)
return mListener.visitingValue((Integer[][]) mValue.get());
if (3 == typeInfo.mDepth)
- return mListener.visitingValue((Integer[][][]) mValue.get());
+ return mListener
+ .visitingValue((Integer[][][]) mValue.get());
}
} else if (AttributeValue.ValueType.DOUBLE == typeInfo.mBaseType) {
if (AttributeValue.ValueType.DOUBLE == typeInfo.mType)
if (2 == typeInfo.mDepth)
return mListener.visitingValue((Boolean[][]) mValue.get());
if (3 == typeInfo.mDepth)
- return mListener.visitingValue((Boolean[][][]) mValue.get());
+ return mListener
+ .visitingValue((Boolean[][][]) mValue.get());
}
} else if (AttributeValue.ValueType.STRING == typeInfo.mBaseType) {
if (AttributeValue.ValueType.STRING == typeInfo.mType)
}
} else if (AttributeValue.ValueType.RESOURCEMODEL == typeInfo.mBaseType) {
if (AttributeValue.ValueType.RESOURCEMODEL == typeInfo.mType)
- return mListener.visitingValue((SimulatorResourceModel) mValue.get());
+ return mListener.visitingValue((SimulatorResourceModel) mValue
+ .get());
else if (AttributeValue.ValueType.ARRAY == typeInfo.mType) {
if (1 == typeInfo.mDepth)
- return mListener.visitingValue((SimulatorResourceModel[]) mValue.get());
+ return mListener
+ .visitingValue((SimulatorResourceModel[]) mValue
+ .get());
if (2 == typeInfo.mDepth)
- return mListener.visitingValue((SimulatorResourceModel[][]) mValue.get());
+ return mListener
+ .visitingValue((SimulatorResourceModel[][]) mValue
+ .get());
if (3 == typeInfo.mDepth)
- return mListener.visitingValue((SimulatorResourceModel[][][]) mValue.get());
+ return mListener
+ .visitingValue((SimulatorResourceModel[][][]) mValue
+ .get());
}
}
/**
* API to search for devices in the network.
*
+ * @param hostUri
+ * URI of the host device.
* @param listener
* Listener for receiving the device information.
*/
- public static native void findDevices(DeviceListener listener)
- throws InvalidArgsException, SimulatorException;
+ public static native void findDevices(String hostUri,
+ DeviceListener listener) throws InvalidArgsException,
+ SimulatorException;
/**
* API to set the platform information.
/**
* API to find all devices' platform information in the network.
*
+ * @param hostUri
+ * URI of the host device.
* @param listener
* Listener for receiving the platform information.
*/
- public static native void getPlatformInformation(PlatformListener listener)
- throws InvalidArgsException, SimulatorException;
+ public static native void getPlatformInformation(String hostUri,
+ PlatformListener listener) throws InvalidArgsException,
+ SimulatorException;
/**
* API to set the listener for receiving log messages.
}
/**
- * API to get propety of attribute's value.
+ * API to get property of attribute's value.
*
- * @return Attribute's value property {@AttributeProperty
- * }.
+ * @return Attribute's value property {@AttributeProperty}.
*/
public AttributeProperty property() {
return mProperty;
/**
* API to set the value of attribute.
- *
+ *
* @param value
* Value of the attribute.
*/
public void setValue(AttributeValue value) {
this.mValue = value;
}
+
+ /**
+ * API to set the property of attribute.
+ *
+ * @param value
+ * Property of the attribute.
+ */
+ public void setProperty(AttributeProperty property) {
+ this.mProperty = property;
+ }
}
* @param attrName
* Name of the attribute.
*
- * @return Attribute value type information {@AttributeValue.TypeInfo
- * }.
+ * @return Attribute value type information {@AttributeValue.TypeInfo}.
*/
public AttributeValue.TypeInfo getAttributeType(String attrName) {
if (mValues.containsKey(attrName))
return mValues.size();
}
+ /**
+ * API to update the attribute values from given
+ * {@link SimulatorResourceModel}.
+ */
+ public void update(SimulatorResourceModel resourceModel) {
+ if (null == resourceModel || 0 == resourceModel.size())
+ return;
+
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
+ .getAttributes().entrySet()) {
+ SimulatorResourceAttribute newAttribute = entry.getValue();
+ SimulatorResourceAttribute attribute = getAttribute(entry.getKey());
+ if (null != newAttribute && null != attribute) {
+ if (null != attribute.property()) {
+ AttributeValueValidation validation = new AttributeValueValidation(
+ attribute.property());
+ if (!validation.validate(newAttribute.value())) {
+ mValues.put(entry.getKey(), newAttribute.value());
+ }
+ } else {
+ mValues.put(entry.getKey(), newAttribute.value());
+ }
+ }
+ }
+ }
+
// Methods used in native code
private SimulatorResourceModel(Map<String, AttributeValue> values,
Map<String, AttributeProperty> properties) {
m_resourceHandle(NULL)
{
m_property = static_cast<OCResourceProperty>(OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ std::vector<SimulatorResourceModel> links;
+ m_resModel.add("links", links);
}
std::string SimulatorCollectionResourceImpl::getName() const
m_actionTypes = actionType;
}
+void SimulatorCollectionResourceImpl::setActionType(std::map<RAML::ActionType, RAML::ActionPtr> &actionType)
+{
+ m_actionTypes = actionType;
+}
+
std::vector<ObserverInfo> SimulatorCollectionResourceImpl::getObserversList()
{
return m_observersList;
return RAML::ActionType::DELETE;
return RAML::ActionType::NONE;
-}
\ No newline at end of file
+}
VALIDATE_INPUT(configPath.empty(), "Empty path!")
std::shared_ptr<SimulatorResource> resource =
- SimulatorResourceFactory::getInstance()->createResource(configPath);
+ SimulatorResourceFactory::getInstance()->createResource(configPath);
if (!resource)
throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!");
return resource;
VALIDATE_INPUT(!count, "Count is zero!")
std::vector<std::shared_ptr<SimulatorResource>> resources =
- SimulatorResourceFactory::getInstance()->createResource(configPath, count);
+ SimulatorResourceFactory::getInstance()->createResource(configPath, count);
if (!resources.size())
throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!");
return resources;
CT_DEFAULT, findCallback);
}
-void SimulatorManager::getDeviceInfo(DeviceInfoCallback callback)
+void SimulatorManager::getDeviceInfo(const std::string &host, DeviceInfoCallback callback)
{
VALIDATE_CALLBACK(callback)
callback(deviceInfo);
}, std::placeholders::_1, callback);
- std::ostringstream uri;
- uri << OC_MULTICAST_PREFIX << OC_RSRVD_DEVICE_URI;
-
typedef OCStackResult (*GetDeviceInfo)(const std::string &, const std::string &,
OCConnectivityType, OC::FindDeviceCallback);
- invokeocplatform(static_cast<GetDeviceInfo>(OC::OCPlatform::getDeviceInfo), "",
- uri.str(), CT_DEFAULT, deviceCallback);
+ invokeocplatform(static_cast<GetDeviceInfo>(OC::OCPlatform::getDeviceInfo), host.c_str(),
+ "/oic/d", CT_DEFAULT, deviceCallback);
}
void SimulatorManager::setDeviceInfo(const std::string &deviceName)
ocDeviceInfo);
}
-void SimulatorManager::getPlatformInfo(PlatformInfoCallback callback)
+void SimulatorManager::getPlatformInfo(const std::string &host, PlatformInfoCallback callback)
{
VALIDATE_CALLBACK(callback)
callback(platformInfo);
}, std::placeholders::_1, callback);
- std::ostringstream uri;
- uri << OC_MULTICAST_PREFIX << OC_RSRVD_PLATFORM_URI;
-
typedef OCStackResult (*GetPlatformInfo)(const std::string &, const std::string &,
OCConnectivityType, OC::FindPlatformCallback);
- invokeocplatform(static_cast<GetPlatformInfo>(OC::OCPlatform::getPlatformInfo), "",
- uri.str(), CT_DEFAULT, platformCallback);
+ invokeocplatform(static_cast<GetPlatformInfo>(OC::OCPlatform::getPlatformInfo), host.c_str(),
+ "/oic/p", CT_DEFAULT, platformCallback);
}
void SimulatorManager::setPlatformInfo(PlatformInfo &platformInfo)
}
public void testValidateInt_N03() {
- AttributeValueValidation validation = new AttributeValueValidation(
- null);
+ AttributeValueValidation validation = new AttributeValueValidation(null);
assertFalse(validation.validate(new AttributeValue(6)));
}
}
public void testValidateDouble_N03() {
- AttributeValueValidation validation = new AttributeValueValidation(
- null);
+ AttributeValueValidation validation = new AttributeValueValidation(null);
assertFalse(validation.validate(new AttributeValue(6.0)));
}
try {
SimulatorManager.setDeviceInfo("Samsung");
- SimulatorManager.findDevices(listener);
+ SimulatorManager.findDevices(null, listener);
syncResult = true;
} catch (InvalidArgsException e) {
e.printStackTrace();
ExceptionType exType = ExceptionType.UNKNOWN;
try {
- SimulatorManager.findDevices(null);
+ SimulatorManager.findDevices(null, null);
} catch (InvalidArgsException e) {
exType = ExceptionType.INVALID_ARGS;
} catch (SimulatorException e) {
infoHolder);
try {
- SimulatorManager.getPlatformInformation(listener);
+ SimulatorManager.getPlatformInformation(null, listener);
syncResult = true;
} catch (InvalidArgsException e) {
e.printStackTrace();
ExceptionType exType = ExceptionType.UNKNOWN;
try {
- SimulatorManager.getPlatformInformation(null);
+ SimulatorManager.getPlatformInformation(null, null);
} catch (InvalidArgsException e) {
exType = ExceptionType.INVALID_ARGS;
} catch (SimulatorException e) {