import oic.simulator.clientcontroller.remoteresource.DeviceAndPlatformInfo;
import oic.simulator.clientcontroller.remoteresource.MetaProperty;
import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
import oic.simulator.clientcontroller.utils.Constants;
import oic.simulator.clientcontroller.utils.Utility;
+import org.oic.simulator.ArrayProperty;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeProperty.Type;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.BooleanProperty;
import org.oic.simulator.DeviceInfo;
import org.oic.simulator.DeviceListener;
+import org.oic.simulator.DoubleProperty;
import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.IntegerProperty;
import org.oic.simulator.PlatformInfo;
import org.oic.simulator.PlatformListener;
import org.oic.simulator.SimulatorException;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
import org.oic.simulator.SimulatorResult;
+import org.oic.simulator.StringProperty;
import org.oic.simulator.client.FindResourceListener;
import org.oic.simulator.client.SimulatorRemoteResource;
import org.oic.simulator.client.SimulatorRemoteResource.GetResponseListener;
return null;
}
- SimulatorResourceModel resourceModel = resource.getResourceModelRef();
- if (null == resourceModel) {
- resource.setResourceModelRef(resourceModelN);
- } else {
- resourceModel.update(resourceModelN);
- }
-
+ resource.setResourceModelRef(resourceModelN);
resource.setResourceRepresentation(resourceModelN, false);
return resource;
}
AttributeValue val = att.value();
- if (null == val) {
+ if (null == val || null == val.get()) {
return null;
}
- List<String> values = new ArrayList<String>();
-
TypeInfo type = val.typeInfo();
+ if (type.mType == ValueType.RESOURCEMODEL
+ || type.mBaseType == ValueType.RESOURCEMODEL) {
+ return null;
+ }
+
+ List<String> values = new ArrayList<String>();
+
AttributeProperty prop = att.property();
- if (null == prop || prop.type().ordinal() == Type.UNKNOWN.ordinal()) {
- values.add(Utility.getAttributeValueAsString(val));
+ if (null == prop) {
+ values.add(new AttributeValueStringConverter(val).toString());
return values;
}
- Type valuesType = prop.type();
-
- if (type.mType != ValueType.RESOURCEMODEL) {
- if (type.mType == ValueType.ARRAY) {
- if (type.mDepth == 1) {
- AttributeProperty childProp = prop.getChildProperty();
- if (null != childProp) {
- valuesType = childProp.type();
- if (valuesType.ordinal() == Type.RANGE.ordinal()) {
- List<String> list = getRangeForPrimitiveNonArrayAttributes(
- childProp, type.mBaseType);
- if (null != list) {
- values.addAll(list);
+ if (type.mType == ValueType.ARRAY) {
+ if (type.mDepth == 1) {
+ ArrayProperty arrayProperty = prop.asArray();
+ if (null != arrayProperty) {
+ AttributeProperty childProp = arrayProperty
+ .getElementProperty();
+ switch (childProp.getType()) {
+ case INTEGER:
+ IntegerProperty intProperty = childProp.asInteger();
+ if (null != intProperty) {
+ values.addAll(getAllValues(intProperty,
+ Type.INTEGER));
}
- } else if (valuesType.ordinal() == Type.VALUESET
- .ordinal()) {
- List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
- childProp.valueSet(), type.mBaseType);
- if (null != list) {
- values.addAll(list);
+ break;
+ case DOUBLE:
+ DoubleProperty dblProperty = childProp.asDouble();
+ if (null != dblProperty) {
+ values.addAll(getAllValues(dblProperty,
+ Type.DOUBLE));
}
- }
+ break;
+ case BOOLEAN:
+ BooleanProperty boolProperty = childProp
+ .asBoolean();
+ if (null != boolProperty) {
+ values.addAll(getAllValues(boolProperty,
+ Type.BOOLEAN));
+ }
+ break;
+ case STRING:
+ StringProperty stringProperty = childProp
+ .asString();
+ if (null != stringProperty) {
+ values.addAll(getAllValues(stringProperty,
+ Type.STRING));
+ }
+ break;
+ default:
+ break;
}
}
- } else {
- if (valuesType.ordinal() == Type.RANGE.ordinal()) {
- List<String> list = getRangeForPrimitiveNonArrayAttributes(
- prop, type.mType);
- if (null != list) {
- values.addAll(list);
+ }
+ } else {
+ switch (prop.getType()) {
+ case INTEGER:
+ IntegerProperty intProperty = prop.asInteger();
+ if (null != intProperty) {
+ values.addAll(getAllValues(intProperty, Type.INTEGER));
}
- } else if (valuesType.ordinal() == Type.VALUESET.ordinal()) {
- List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
- prop.valueSet(), type.mType);
- if (null != list) {
- values.addAll(list);
+ break;
+ case DOUBLE:
+ DoubleProperty dblProperty = prop.asDouble();
+ if (null != dblProperty) {
+ values.addAll(getAllValues(dblProperty, Type.DOUBLE));
}
- }
+ break;
+ case BOOLEAN:
+ BooleanProperty boolProperty = prop.asBoolean();
+ if (null != boolProperty) {
+ values.addAll(getAllValues(boolProperty, Type.BOOLEAN));
+ }
+ break;
+ case STRING:
+ StringProperty stringProperty = prop.asString();
+ if (null != stringProperty) {
+ values.addAll(getAllValues(stringProperty, Type.STRING));
+ }
+ break;
+ default:
+ break;
}
}
- if (values.isEmpty()) {
- values.add(Utility.getAttributeValueAsString(val));
- }
-
return values;
}
- public List<String> getRangeForPrimitiveNonArrayAttributes(
- AttributeProperty prop, ValueType type) {
- if (null == prop) {
- return null;
- }
+ public List<String> getAllValues(IntegerProperty intProperty,
+ AttributeProperty.Type type) {
+ List<String> values = new ArrayList<String>();
- if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
- return null;
+ if (intProperty.hasRange()) {
+ int min = (int) intProperty.min();
+ int max = (int) intProperty.max();
+ for (int iVal = min; iVal <= max; iVal++) {
+ values.add(String.valueOf(iVal));
+ }
+ } else if (intProperty.hasValues()) {
+ for (Integer val : intProperty.getValues()) {
+ values.add(String.valueOf(val));
+ }
+ } else {
+ // Adding the default value.
+ values.add(String.valueOf(intProperty.getDefaultValue()));
}
+ return values;
+ }
+ public List<String> getAllValues(DoubleProperty dblProperty,
+ AttributeProperty.Type type) {
List<String> values = new ArrayList<String>();
- switch (type) {
- case INTEGER:
- int min = (int) prop.min();
- int max = (int) prop.max();
- for (int iVal = min; iVal <= max; iVal++) {
- values.add(String.valueOf(iVal));
- }
- break;
- case DOUBLE:
- double minD = (double) prop.min();
- double maxD = (double) prop.max();
- for (double iVal = minD; iVal <= maxD; iVal = iVal + 1.0) {
- values.add(String.valueOf(iVal));
- }
- break;
- default:
+
+ if (dblProperty.hasRange()) {
+ double min = (double) dblProperty.min();
+ double max = (double) dblProperty.max();
+ for (double iVal = min; iVal <= max; iVal = iVal + 1) {
+ values.add(String.valueOf(iVal));
+ }
+ } else if (dblProperty.hasValues()) {
+ for (Double val : dblProperty.getValues()) {
+ values.add(String.valueOf(val));
+ }
+ } else {
+ // Adding the default value.
+ values.add(String.valueOf(dblProperty.getDefaultValue()));
}
return values;
}
- public List<String> getAllowedValuesForPrimitiveNonArrayAttributes(
- AttributeValue[] attValues, ValueType type) {
- if (null == attValues || attValues.length < 1) {
- return null;
- }
-
- if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
- return null;
- }
+ public List<String> getAllValues(BooleanProperty boolProperty,
+ AttributeProperty.Type type) {
+ List<String> values = new ArrayList<String>();
+ values.add("true");
+ values.add("false");
+ return values;
+ }
- Object obj;
+ public List<String> getAllValues(StringProperty stringProperty,
+ AttributeProperty.Type type) {
List<String> values = new ArrayList<String>();
- for (AttributeValue val : attValues) {
- if (null == val) {
- continue;
- }
- obj = val.get();
- if (null == obj) {
- continue;
+
+ if (stringProperty.hasValues()) {
+ for (String val : stringProperty.getValues()) {
+ values.add(String.valueOf(val));
}
- values.add(String.valueOf(obj));
+ } else {
+ // Adding the default value.
+ values.add(String.valueOf(stringProperty.getDefaultValue()));
}
return values;
}
return false;
}
try {
- resourceN.startObserve(null, observeListener);
+ resourceN.observe(observeListener);
resource.setObserved(true);
// Add observed resource URI to show the proper status after every
// find/refresh operations.
}
// Store the resource model in the local cache
- SimulatorResourceModel resourceModel = resource
- .getResourceModelRef();
- if (null != resourceModel) {
- configuredResourceModel.update(resourceModel);
- }
- resource.setResourceModelRef(configuredResourceModel);
+ /*
+ * SimulatorResourceModel resourceModel = resource
+ * .getResourceModelRef(); if (null != resourceModel) {
+ * configuredResourceModel.update(resourceModel); }
+ * resource.setResourceModelRef(configuredResourceModel);
+ */
} catch (SimulatorException e) {
Activator
.getDefault()
import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
+import org.oic.simulator.ArrayProperty;
+import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.ModelProperty;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
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));
+ ModelProperty modelProp = null;
+ if (null != attribute.property()) {
+ modelProp = attribute.property().asModel();
+ }
+ String attName;
+ for (Map.Entry<String, AttributeValue> entry : resModel.get()
+ .entrySet()) {
+ attName = entry.getKey();
+ AttributeProperty prop = null;
+ if (null != modelProp)
+ prop = modelProp.get(attName);
+ mChildAttributes.put(
+ attName,
+ new AttributeElement(this,
+ new SimulatorResourceAttribute(attName, entry
+ .getValue(), prop)));
+ }
+ } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY) {
+ if (typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+ if (typeInfo.mDepth == 1) {
+ SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+ .value().get();
+
+ ArrayProperty arrProp = null;
+ ModelProperty modelProp = null;
+ if (null != attribute.property()) {
+ arrProp = attribute.property().asArray();
+ if (null != arrProp
+ && null != arrProp.getElementProperty()) {
+ modelProp = arrProp.getElementProperty().asModel();
+ }
+ }
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), modelProp);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ new AttributeElement(this, indexAttribute));
+ }
+ } else if (typeInfo.mDepth == 2) {
+ SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+ .value().get();
+
+ ArrayProperty arrProp = null;
+ ArrayProperty arrChildPropLevel1 = null;
+ ModelProperty modelProp = null;
+ if (null != attribute.property()) {
+ arrProp = attribute.property().asArray();
+ if (null != arrProp
+ && null != arrProp.getElementProperty()) {
+ arrChildPropLevel1 = arrProp.getElementProperty()
+ .asArray();
+ if (null != arrChildPropLevel1
+ && null != arrChildPropLevel1
+ .getElementProperty()) {
+ modelProp = arrProp.getElementProperty()
+ .asModel();
+ }
+ }
+ }
+
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), modelProp);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ new AttributeElement(this, indexAttribute));
+ }
+ } else if (typeInfo.mDepth == 3) {
+ SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+ .value().get();
+
+ ArrayProperty arrProp = null;
+ ArrayProperty arrChildPropLevel1 = null;
+ ArrayProperty arrChildPropLevel2 = null;
+ ModelProperty modelProp = null;
+ if (null != attribute.property()) {
+ arrProp = attribute.property().asArray();
+ if (null != arrProp
+ && null != arrProp.getElementProperty()) {
+ arrChildPropLevel1 = arrProp.getElementProperty()
+ .asArray();
+ if (null != arrChildPropLevel1
+ && null != arrChildPropLevel1
+ .getElementProperty()) {
+ arrChildPropLevel2 = arrChildPropLevel1
+ .getElementProperty().asArray();
+ if (null != arrChildPropLevel2
+ && null != arrChildPropLevel2
+ .getElementProperty()) {
+ modelProp = arrChildPropLevel2
+ .getElementProperty().asModel();
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]), modelProp);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ new AttributeElement(this, indexAttribute));
+ }
}
}
}
return (!(typeInfo.mType == AttributeValue.ValueType.ARRAY && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) && typeInfo.mType != AttributeValue.ValueType.RESOURCEMODEL);
}
- public void update(SimulatorResourceAttribute attribute) {
+ public void update(SimulatorResourceAttribute attribute,
+ boolean ramlUploaded) {
if (attribute == null)
return;
if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
.value().get();
- for (Map.Entry<String, SimulatorResourceAttribute> entry : resModel
- .getAttributes().entrySet()) {
+ for (Map.Entry<String, AttributeValue> entry : resModel.get()
+ .entrySet()) {
AttributeElement attributeElement = mChildAttributes.get(entry
.getKey());
if (attributeElement != null) {
- attributeElement.update(entry.getValue());
- } else // Display new attribute in UI
- {
+ attributeElement.update(new SimulatorResourceAttribute(
+ entry.getKey(), entry.getValue()), ramlUploaded);
+ } else {
+ // Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(this,
- entry.getValue());
+ new SimulatorResourceAttribute(entry.getKey(),
+ entry.getValue()));
mChildAttributes.put(entry.getKey(), newAttribute);
}
}
AttributeElement attributeElement = mChildAttributes
.get("[" + Integer.toString(i) + "]");
if (attributeElement != null) {
- attributeElement.update(indexAttribute);
- } else // Display new attribute in UI
- {
+ attributeElement.update(indexAttribute, ramlUploaded);
+ } else {
+ // Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(
this, indexAttribute);
mChildAttributes.put("[" + Integer.toString(i) + "]",
AttributeElement attributeElement = mChildAttributes
.get("[" + Integer.toString(i) + "]");
if (attributeElement != null) {
- attributeElement.update(indexAttribute);
- } else // Display new attribute in UI
- {
+ attributeElement.update(indexAttribute, ramlUploaded);
+ } else {
+ // Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(
this, indexAttribute);
mChildAttributes.put("[" + Integer.toString(i) + "]",
AttributeElement attributeElement = mChildAttributes
.get("[" + Integer.toString(i) + "]");
if (attributeElement != null) {
- attributeElement.update(indexAttribute);
- } else // Display new attribute in UI
- {
+ attributeElement.update(indexAttribute, ramlUploaded);
+ } else {
+ // Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(
this, indexAttribute);
mChildAttributes.put("[" + Integer.toString(i) + "]",
}
}
} 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);
+ if (ramlUploaded) {
+ mAttribute.setProperty(attribute.property());
+ } else {
+ String currentValue = new AttributeValueStringConverter(
+ mAttribute.value()).toString();
+ String newValue = new AttributeValueStringConverter(
+ attribute.value()).toString();
+ if (!currentValue.equals(newValue)) {
+ mAttribute.setValue(attribute.value());
}
}
- } 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());
}
}
if (myValuetypeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
SimulatorResourceModel resModel = (SimulatorResourceModel) mAttribute
.value().get();
- if (resModel.containsAttribute(attribute.name()))
- resModel.setAttributeValue(attribute.name(), attribute.value());
+ if (resModel.contains(attribute.name()))
+ resModel.set(attribute.name(), attribute.value());
else
return;
}
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;
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()));
+ for (Map.Entry<String, AttributeValue> entry : resourceModel.get()
+ .entrySet())
+ mAttributes.put(entry.getKey(),
+ new AttributeElement(this,
+ new SimulatorResourceAttribute(entry.getKey(),
+ entry.getValue())));
}
}
public void update(SimulatorResourceModel resourceModel,
boolean ramlUploaded) {
- for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
- .getAttributes().entrySet()) {
+ for (Map.Entry<String, AttributeValue> entry : resourceModel.get()
+ .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.update(
+ new SimulatorResourceAttribute(entry.getKey(), entry
+ .getValue()), ramlUploaded);
+ } else {
+ // Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(this,
- entry.getValue());
+ new SimulatorResourceAttribute(entry.getKey(),
+ entry.getValue()));
mAttributes.put(entry.getKey(), newAttribute);
}
}
AttributeElement attributeElement = mAttributes.get(entry.getKey());
if (attributeElement != null) {
try {
- model.addAttribute(attributeElement
- .getSimulatorResourceAttribute());
+ model.set(entry.getKey(), attributeElement
+ .getSimulatorResourceAttribute().value());
} catch (InvalidArgsException e) {
e.printStackTrace();
}
AttributeElement attributeElement = mAttributes.get(entry.getKey());
if (attributeElement != null && attributeElement.getPostState()) {
try {
- model.addAttribute(attributeElement
- .getSimulatorResourceAttribute());
+ model.set(entry.getKey(), attributeElement
+ .getSimulatorResourceAttribute().value());
} catch (InvalidArgsException e) {
e.printStackTrace();
}
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValueVisitor;
-import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
public class AttributeValueStringConverter implements
StringBuilder result = new StringBuilder();
result.append("{");
boolean first = true;
- for (Map.Entry<String, SimulatorResourceAttribute> entry : value
- .getAttributes().entrySet()) {
+ for (Map.Entry<String, AttributeValue> entry : value.get().entrySet()) {
if (!first)
result.append(", ");
first = false;
result.append("\"" + entry.getKey() + "\":");
- AttributeValue attributeValue = entry.getValue().value();
+ AttributeValue attributeValue = entry.getValue();
result.append(new AttributeValueStringConverter(attributeValue)
.toString());
}
if (!(element instanceof AttributeElement)) {
return;
}
+
boolean status = (Boolean) value;
((AttributeElement) element).setPostState(status);
viewer.update(element, null);
+
+ Tree t = viewer.getTree();
+ TreeItem item = t.getSelection()[0];
+ if (null == item) {
+ return;
+ }
+
+ // Set the post state of the top-most parent of this attribute to
+ // false.
+ TreeItem parent = item.getParentItem();
+ if (null != parent) {
+ while (parent.getParentItem() != null) {
+ parent = parent.getParentItem();
+ }
+ Object data = parent.getData();
+ ((AttributeElement) data).setPostState(status);
+ }
}
}
}
@Override
public void createPartControl(Composite arg0) {
- // TODO Auto-generated method stub
-
}
@Override
public void setFocus() {
- // TODO Auto-generated method stub
-
}
}
@Override
public void setFocus() {
- // TODO Auto-generated method stub
-
}
public synchronized void setFoundResource(boolean value) {
MessageDialog
.openError(getShell(), "Invalid File",
"File doesn't exist. Either the file path or file name is invalid.");
- // TODO: Instead of MessageDialog, errors may be shown on wizard
- // itself.
return;
}
close();
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.widgets.Display;
+import org.oic.simulator.ArrayProperty;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeProperty.Type;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.BooleanProperty;
import org.oic.simulator.DeviceInfo;
import org.oic.simulator.DeviceListener;
+import org.oic.simulator.DoubleProperty;
import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.IntegerProperty;
import org.oic.simulator.PlatformInfo;
import org.oic.simulator.SimulatorException;
import org.oic.simulator.SimulatorManager;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.StringProperty;
import org.oic.simulator.server.Observer;
import org.oic.simulator.server.SimulatorResource;
import org.oic.simulator.server.SimulatorResource.AutoUpdateListener;
.getResourceByURI(resourceURI);
if (null != resource) {
try {
- resource.setResourceRepresentation(resourceModelN);
+ resource.updateResourceRepresentation(resourceModelN);
} catch (NumberFormatException e) {
Activator
.getDefault()
SimulatorSingleResource jSimulatorSingleResource = (SimulatorSingleResource) jSimulatorResource;
resource.setSimulatorResource(jSimulatorSingleResource);
+ // Cancel discoverable property if requested by user.
+ if (!resource.isDiscoverable()) {
+ jSimulatorSingleResource.setDiscoverable(false);
+ }
+
// Cancel observable property if requested by user.
if (!resource.isObservable()) {
jSimulatorSingleResource.setObservable(false);
resource.setResourceModel(jSimulatorSingleResource
.getResourceModel());
- resource.setResourceRepresentation(resource.getResourceModel());
+ resource.createResourceRepresentation(jSimulatorSingleResource
+ .getAttributes());
}
+ // Set the resource interfaces.
+ jSimulatorSingleResource
+ .setInterface(Utility.convertSetToVectorString(resource
+ .getResourceInterfaces()));
+
// Register the resource with the platform.
jSimulatorSingleResource.start();
resource.setStarted(true);
-
- // Add the resource interfaces
- Set<String> newIfSet = resource.getResourceInterfaces();
- // Get the default interface(s) if any configured by the platform.
- // These interfaces will be overwritten by the new interfaces.
- Set<String> ifSetFromPlatform = Utility
- .convertVectorToSet(jSimulatorSingleResource.getInterface());
- resource.setResourceInterfaces(ifSetFromPlatform);
- updateResourceInterfaces(resource, newIfSet);
} catch (SimulatorException e) {
Activator
.getDefault()
.getInterface()));
// Fetch the resource attributes.
- singleRes.setResourceRepresentation(jResModel);
+ singleRes.createResourceRepresentation(jSimulatorSingleResource
+ .getAttributes());
// Register the resource with the platform.
jSimulatorSingleResource.start();
boolean resourceRestartRequired = false;
while (itr.hasNext()) {
interfaceType = itr.next();
- if (newIfSet.contains(interfaceType)) {
- newIfSet.remove(interfaceType);
- } else {
- // Remove this interface support from the resource.
- try {
- if (!resourceRestartRequired) {
- resourceRestartRequired = true;
- }
- jResource.removeInterface(interfaceType);
- itr.remove();
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "There is an error while removing the interface type("
- + interfaceType
- + ").\n"
- + Utility.getSimulatorErrorString(
- e, null));
- throw e;
- }
+ if (!newIfSet.contains(interfaceType)) {
+ resourceRestartRequired = true;
+ break;
}
}
- // Add all remaining interfaces.
- itr = newIfSet.iterator();
- while (itr.hasNext()) {
- interfaceType = itr.next();
- // Add this interface support to the resource.
- try {
- jResource.addInterface(interfaceType);
- curIfSet.add(interfaceType);
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "There is an error while adding the interface type("
- + interfaceType
- + ").\n"
- + Utility.getSimulatorErrorString(e,
- null));
- throw e;
+ try {
+ // As there is no support from native layer for interface removal,
+ // supporting it from the simulator requires restarting the resource
+ // if any existing interfaces are removed.
+
+ if (resourceRestartRequired) {
+ stopResource(resource);
+ jResource.setInterface(Utility
+ .convertSetToVectorString(newIfSet));
+ startResource(resource);
+ } else {
+ // Existing interfaces are not removed.
+ itr = newIfSet.iterator();
+ while (itr.hasNext()) {
+ interfaceType = itr.next();
+ if (!curIfSet.contains(interfaceType)) {
+ jResource.addInterface(interfaceType);
+ }
+ }
}
- }
-
- // As there is no support from native layer for interface removal,
- // supporting it from the simulator requires restarting the resource if
- // any existing interfaces are removed.
- if (resourceRestartRequired) {
- stopResource(resource);
- startResource(resource);
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while changing the interface types."
+ + Utility.getSimulatorErrorString(e, null));
+ throw e;
}
// Set the resource interfaces.
- resource.setResourceInterfaces(curIfSet);
+ resource.setResourceInterfaces(newIfSet);
return true;
}
if (null == prop) {
return false;
}
- Type attProp = prop.type();
- if (attProp == Type.UNKNOWN) {
- return false;
+
+ if (prop.getType() == Type.INTEGER) {
+ IntegerProperty intProperty = prop.asInteger();
+ if (null != intProperty) {
+ return (intProperty.hasRange() || intProperty.hasValues());
+ } else {
+ return false;
+ }
+ } else if (prop.getType() == Type.DOUBLE) {
+ DoubleProperty dblProperty = prop.asDouble();
+ if (null != dblProperty) {
+ return (dblProperty.hasRange() || dblProperty.hasValues());
+ } else {
+ return false;
+ }
+ } else if (prop.getType() == Type.STRING) {
+ StringProperty stringProperty = prop.asString();
+ if (null != stringProperty) {
+ return stringProperty.hasValues();
+ } else {
+ return false;
+ }
}
+
return true;
}
List<String> values = new ArrayList<String>();
- Type valuesType = prop.type();
-
- if (valuesType == Type.UNKNOWN) {
- // Adding the default value
- values.add(Utility.getAttributeValueAsString(val));
- return values;
- }
-
if (type.mType != ValueType.RESOURCEMODEL) {
if (type.mType == ValueType.ARRAY) {
if (type.mDepth == 1) {
- AttributeProperty childProp = prop.getChildProperty();
- if (null != childProp) {
- valuesType = childProp.type();
- if (valuesType == Type.RANGE) {
- List<String> list = getRangeForPrimitiveNonArrayAttributes(
- childProp, type.mBaseType);
- if (null != list) {
- values.addAll(list);
- }
- } else if (valuesType == Type.VALUESET) {
- List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
- childProp.valueSet(), type.mBaseType);
- if (null != list) {
- values.addAll(list);
- }
+ ArrayProperty arrayProperty = prop.asArray();
+ if (null != arrayProperty) {
+ AttributeProperty childProp = arrayProperty
+ .getElementProperty();
+ switch (childProp.getType()) {
+ case INTEGER:
+ IntegerProperty intProperty = childProp
+ .asInteger();
+ if (null != intProperty) {
+ values.addAll(getAllValues(intProperty,
+ Type.INTEGER));
+ }
+ break;
+ case DOUBLE:
+ DoubleProperty dblProperty = childProp
+ .asDouble();
+ if (null != dblProperty) {
+ values.addAll(getAllValues(dblProperty,
+ Type.DOUBLE));
+ }
+ break;
+ case BOOLEAN:
+ BooleanProperty boolProperty = childProp
+ .asBoolean();
+ if (null != boolProperty) {
+ values.addAll(getAllValues(boolProperty,
+ Type.BOOLEAN));
+ }
+ break;
+ case STRING:
+ StringProperty stringProperty = childProp
+ .asString();
+ if (null != stringProperty) {
+ values.addAll(getAllValues(stringProperty,
+ Type.STRING));
+ }
+ break;
+ default:
+ break;
}
}
}
} else {
- if (valuesType == Type.RANGE) {
- List<String> list = getRangeForPrimitiveNonArrayAttributes(
- prop, type.mType);
- if (null != list) {
- values.addAll(list);
- }
- } else if (valuesType == Type.VALUESET) {
- List<String> list = getAllowedValuesForPrimitiveNonArrayAttributes(
- prop.valueSet(), type.mType);
- if (null != list) {
- values.addAll(list);
- }
+ switch (prop.getType()) {
+ case INTEGER:
+ IntegerProperty intProperty = prop.asInteger();
+ if (null != intProperty) {
+ values.addAll(getAllValues(intProperty,
+ Type.INTEGER));
+ }
+ break;
+ case DOUBLE:
+ DoubleProperty dblProperty = prop.asDouble();
+ if (null != dblProperty) {
+ values.addAll(getAllValues(dblProperty, Type.DOUBLE));
+ }
+ break;
+ case BOOLEAN:
+ BooleanProperty boolProperty = prop.asBoolean();
+ if (null != boolProperty) {
+ values.addAll(getAllValues(boolProperty,
+ Type.BOOLEAN));
+ }
+ break;
+ case STRING:
+ StringProperty stringProperty = prop.asString();
+ if (null != stringProperty) {
+ values.addAll(getAllValues(stringProperty,
+ Type.STRING));
+ }
+ break;
+ default:
+ break;
}
}
}
return values;
}
- public List<String> getRangeForPrimitiveNonArrayAttributes(
- AttributeProperty prop, ValueType type) {
- if (null == prop) {
- return null;
- }
+ public List<String> getAllValues(IntegerProperty intProperty,
+ AttributeProperty.Type type) {
+ List<String> values = new ArrayList<String>();
- if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
- return null;
+ if (intProperty.hasRange()) {
+ int min = (int) intProperty.min();
+ int max = (int) intProperty.max();
+ for (int iVal = min; iVal <= max; iVal++) {
+ values.add(String.valueOf(iVal));
+ }
+ } else if (intProperty.hasValues()) {
+ for (Integer val : intProperty.getValues()) {
+ values.add(String.valueOf(val));
+ }
+ } else {
+ // Adding the default value.
+ values.add(String.valueOf(intProperty.getDefaultValue()));
}
+ return values;
+ }
+ public List<String> getAllValues(DoubleProperty dblProperty,
+ AttributeProperty.Type type) {
List<String> values = new ArrayList<String>();
- switch (type) {
- case INTEGER:
- int min = (int) prop.min();
- int max = (int) prop.max();
- for (int iVal = min; iVal <= max; iVal++) {
- values.add(String.valueOf(iVal));
- }
- break;
- case DOUBLE:
- double minD = (double) prop.min();
- double maxD = (double) prop.max();
- for (double iVal = minD; iVal <= maxD; iVal = iVal + 1.0) {
- values.add(String.valueOf(iVal));
- }
- break;
- default:
+
+ if (dblProperty.hasRange()) {
+ double min = (double) dblProperty.min();
+ double max = (double) dblProperty.max();
+ for (double iVal = min; iVal <= max; iVal = iVal + 1) {
+ values.add(String.valueOf(iVal));
+ }
+ } else if (dblProperty.hasValues()) {
+ for (Double val : dblProperty.getValues()) {
+ values.add(String.valueOf(val));
+ }
+ } else {
+ // Adding the default value.
+ values.add(String.valueOf(dblProperty.getDefaultValue()));
}
return values;
}
- public List<String> getAllowedValuesForPrimitiveNonArrayAttributes(
- AttributeValue[] attValues, ValueType type) {
- if (null == attValues || attValues.length < 1) {
- return null;
- }
-
- if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) {
- return null;
- }
+ public List<String> getAllValues(BooleanProperty boolProperty,
+ AttributeProperty.Type type) {
+ List<String> values = new ArrayList<String>();
+ values.add("true");
+ values.add("false");
+ return values;
+ }
- Object obj;
+ public List<String> getAllValues(StringProperty stringProperty,
+ AttributeProperty.Type type) {
List<String> values = new ArrayList<String>();
- for (AttributeValue val : attValues) {
- if (null == val) {
- continue;
- }
- obj = val.get();
- if (null == obj) {
- continue;
+
+ if (stringProperty.hasValues()) {
+ for (String val : stringProperty.getValues()) {
+ values.add(String.valueOf(val));
}
- values.add(String.valueOf(obj));
+ } else {
+ // Adding the default value.
+ values.add(String.valueOf(stringProperty.getDefaultValue()));
}
return values;
}
import oic.simulator.serviceprovider.utils.AttributeValueStringConverter;
import oic.simulator.serviceprovider.utils.Constants;
+import org.oic.simulator.ArrayProperty;
+import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeValue;
+import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.IntegerProperty;
import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.ModelProperty;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.StringProperty;
import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
public class AttributeElement {
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));
+ ModelProperty modelProp = null;
+ if (null != attribute.property()) {
+ modelProp = attribute.property().asModel();
+ }
+ String attName;
+ for (Map.Entry<String, AttributeValue> entry : resModel.get()
+ .entrySet()) {
+ attName = entry.getKey();
+ AttributeProperty prop = null;
+ if (null != modelProp)
+ prop = modelProp.get(attName);
+ mChildAttributes.put(
+ attName,
+ new AttributeElement(this,
+ new SimulatorResourceAttribute(attName, entry
+ .getValue(), prop), false));
}
} else if (typeInfo.mType == AttributeValue.ValueType.ARRAY) {
mAutoUpdateSupport = false;
if (typeInfo.mDepth == 1) {
SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
.value().get();
+
+ ArrayProperty arrProp = null;
+ ModelProperty modelProp = null;
+ if (null != attribute.property()) {
+ arrProp = attribute.property().asArray();
+ if (null != arrProp
+ && null != arrProp.getElementProperty()) {
+ modelProp = arrProp.getElementProperty().asModel();
+ }
+ }
for (int i = 0; i < resModelArray.length; i++) {
SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
"[" + Integer.toString(i) + "]",
- new AttributeValue(resModelArray[i]), null);
+ new AttributeValue(resModelArray[i]), modelProp);
mChildAttributes.put("[" + Integer.toString(i) + "]",
new AttributeElement(this, indexAttribute,
false));
} else if (typeInfo.mDepth == 2) {
SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
.value().get();
+
+ ArrayProperty arrProp = null;
+ ArrayProperty arrChildPropLevel1 = null;
+ ModelProperty modelProp = null;
+ if (null != attribute.property()) {
+ arrProp = attribute.property().asArray();
+ if (null != arrProp
+ && null != arrProp.getElementProperty()) {
+ arrChildPropLevel1 = arrProp.getElementProperty()
+ .asArray();
+ if (null != arrChildPropLevel1
+ && null != arrChildPropLevel1
+ .getElementProperty()) {
+ modelProp = arrProp.getElementProperty()
+ .asModel();
+ }
+ }
+ }
+
for (int i = 0; i < resModelArray.length; i++) {
SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
"[" + Integer.toString(i) + "]",
- new AttributeValue(resModelArray[i]), null);
+ new AttributeValue(resModelArray[i]), modelProp);
mChildAttributes.put("[" + Integer.toString(i) + "]",
new AttributeElement(this, indexAttribute,
false));
} else if (typeInfo.mDepth == 3) {
SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
.value().get();
+
+ ArrayProperty arrProp = null;
+ ArrayProperty arrChildPropLevel1 = null;
+ ArrayProperty arrChildPropLevel2 = null;
+ ModelProperty modelProp = null;
+ if (null != attribute.property()) {
+ arrProp = attribute.property().asArray();
+ if (null != arrProp
+ && null != arrProp.getElementProperty()) {
+ arrChildPropLevel1 = arrProp.getElementProperty()
+ .asArray();
+ if (null != arrChildPropLevel1
+ && null != arrChildPropLevel1
+ .getElementProperty()) {
+ arrChildPropLevel2 = arrChildPropLevel1
+ .getElementProperty().asArray();
+ if (null != arrChildPropLevel2
+ && null != arrChildPropLevel2
+ .getElementProperty()) {
+ modelProp = arrChildPropLevel2
+ .getElementProperty().asModel();
+ }
+ }
+ }
+ }
+
for (int i = 0; i < resModelArray.length; i++) {
SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
"[" + Integer.toString(i) + "]",
- new AttributeValue(resModelArray[i]), null);
+ new AttributeValue(resModelArray[i]), modelProp);
mChildAttributes.put("[" + Integer.toString(i) + "]",
new AttributeElement(this, indexAttribute,
false));
}
public boolean isReadOnly() {
- return (null == mAttribute.property());
+ AttributeProperty prop = mAttribute.property();
+ if (null == prop) {
+ return true;
+ }
+
+ if (prop.isInteger()) {
+ IntegerProperty intProperty = prop.asInteger();
+ return !(intProperty.hasRange() || intProperty.hasValues());
+ }
+
+ if (prop.isDouble()) {
+ DoubleProperty dblProperty = prop.asDouble();
+ return !(dblProperty.hasRange() || dblProperty.hasValues());
+ }
+
+ if (prop.isBoolean()) {
+ return false;
+ }
+
+ if (prop.isString()) {
+ StringProperty strProperty = prop.asString();
+ return !(strProperty.hasValues());
+ }
+
+ return true;
}
public synchronized boolean getEditLock() {
if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
.value().get();
- for (Map.Entry<String, SimulatorResourceAttribute> entry : resModel
- .getAttributes().entrySet()) {
+ for (Map.Entry<String, AttributeValue> entry : resModel.get()
+ .entrySet()) {
AttributeElement attributeElement = mChildAttributes.get(entry
.getKey());
if (attributeElement != null) {
- attributeElement.update(entry.getValue());
- } else // Display new attribute in UI
- {
+ attributeElement.update(new SimulatorResourceAttribute(
+ entry.getKey(), entry.getValue()));
+ } else {
+ // Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(this,
- entry.getValue(), false);
+ new SimulatorResourceAttribute(entry.getKey(),
+ entry.getValue()), false);
mChildAttributes.put(entry.getKey(), newAttribute);
UiListenerHandler.getInstance()
.get("[" + Integer.toString(i) + "]");
if (attributeElement != null) {
attributeElement.update(indexAttribute);
- } else // Display new attribute in UI
- {
+ } else {
+ // Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(
this, indexAttribute, false);
mChildAttributes.put("[" + Integer.toString(i) + "]",
.get("[" + Integer.toString(i) + "]");
if (attributeElement != null) {
attributeElement.update(indexAttribute);
- } else // Display new attribute in UI
- {
+ } else {
+ // Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(
this, indexAttribute, false);
mChildAttributes.put("[" + Integer.toString(i) + "]",
.get("[" + Integer.toString(i) + "]");
if (attributeElement != null) {
attributeElement.update(indexAttribute);
- } else // Display new attribute in UI
- {
+ } else {
+ // Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(
this, indexAttribute, false);
mChildAttributes.put("[" + Integer.toString(i) + "]",
if (myValuetypeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
SimulatorResourceModel resModel = (SimulatorResourceModel) mAttribute
.value().get();
- if (resModel.containsAttribute(attribute.name()))
- resModel.setAttributeValue(attribute.name(), attribute.value());
+ if (resModel.contains(attribute.name()))
+ resModel.set(attribute.name(), attribute.value());
else
return;
}
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
+import java.util.Vector;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
import org.oic.simulator.AttributeProperty;
-import org.oic.simulator.AttributeProperty.Type;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.BooleanProperty;
+import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.IntegerProperty;
import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.StringProperty;
public class AttributeHelper {
private String attributeName;
private Set<String> allowedValues;
private String attributeDflValue;
- private Type validValuesType;
+ public enum ValidValuesType {
+ RANGE, VALUESET, UNKNOWN
+ }
+
+ private ValidValuesType validValuesType;
public AttributeHelper() {
allowedValues = new HashSet<String>();
- setValidValuesType(Type.UNKNOWN);
+ setValidValuesType(ValidValuesType.UNKNOWN);
min = max = "";
}
this.attributeDflValue = attributeDflValue;
}
- public Type getValidValuesType() {
+ public ValidValuesType getValidValuesType() {
return validValuesType;
}
- public void setValidValuesType(Type validValuesType) {
+ public void setValidValuesType(ValidValuesType validValuesType) {
this.validValuesType = validValuesType;
}
}
boolean result = true;
if (attributeType.equals(Constants.STRING)) {
- if (validValuesType == Type.VALUESET && null != allowedValues) {
+ if (validValuesType == ValidValuesType.VALUESET
+ && null != allowedValues) {
result = allowedValues.contains(value);
} else {
result = true;
result = false;
}
} else {
- if (validValuesType == Type.RANGE) {
+ if (validValuesType == ValidValuesType.RANGE) {
if (attributeType.equals(Constants.INT)) {
int min, max, dflValue;
try {
result = false;
}
}
- } else if (validValuesType == Type.VALUESET
+ } else if (validValuesType == ValidValuesType.VALUESET
&& null != allowedValues && !allowedValues.isEmpty()) {
boolean found = false;
if (attributeType.equals(Constants.INT)) {
ValueType valueType = Utility.getAttributeTypeEnum(attributeType);
switch (valueType) {
case INTEGER:
+ IntegerProperty.Builder intPropertyBuilder = new IntegerProperty.Builder();
attValue = new AttributeValue(
Integer.parseInt(attributeDflValue));
- if (validValuesType == Type.VALUESET) {
- attProperty = new AttributeProperty(
- Utility.convertSetToArrayInt(Utility
+
+ // Set default value.
+ intPropertyBuilder.setDefaultValue(Integer
+ .parseInt(attributeDflValue));
+
+ if (validValuesType == ValidValuesType.VALUESET) {
+ // Set allowed values.
+ intPropertyBuilder.setValues(Utility
+ .convertSetToArrayInt(Utility
.convertSetStringToSetObject(allowedValues,
valueType)));
- } else if (validValuesType == Type.RANGE) {
- attProperty = new AttributeProperty(
- Double.parseDouble(min), Double.parseDouble(max));
- } else {
- attProperty = null;
+ } else if (validValuesType == ValidValuesType.RANGE) {
+ // Set Range.
+ intPropertyBuilder.setRange(Integer.parseInt(min),
+ Integer.parseInt(max));
}
+ attProperty = intPropertyBuilder.build();
break;
case DOUBLE:
+ DoubleProperty.Builder dblPropertyBuilder = new DoubleProperty.Builder();
attValue = new AttributeValue(
Double.parseDouble(attributeDflValue));
- if (validValuesType == Type.VALUESET) {
- attProperty = new AttributeProperty(
- Utility.convertSetToArrayDouble(Utility
+
+ // Set default value.
+ dblPropertyBuilder.setDefaultValue(Double
+ .parseDouble(attributeDflValue));
+
+ if (validValuesType == ValidValuesType.VALUESET) {
+ // Set allowed values.
+ dblPropertyBuilder.setValues(Utility
+ .convertSetToArrayDouble(Utility
.convertSetStringToSetObject(allowedValues,
valueType)));
- } else if (validValuesType == Type.RANGE) {
- attProperty = new AttributeProperty(
- Double.parseDouble(min), Double.parseDouble(max));
- } else {
- attProperty = null;
+ } else if (validValuesType == ValidValuesType.RANGE) {
+ // Set Range.
+ dblPropertyBuilder.setRange(Double.parseDouble(min),
+ Double.parseDouble(max));
}
+ attProperty = dblPropertyBuilder.build();
break;
case BOOLEAN:
attValue = new AttributeValue(
Boolean.parseBoolean(attributeDflValue));
- boolean[] arr = { true, false };
- attProperty = new AttributeProperty(arr);
+ BooleanProperty.Builder boolPropertyBuilder = new BooleanProperty.Builder();
+ // Set Default Value.
+ boolPropertyBuilder.setDefaultValue(Boolean
+ .parseBoolean(attributeDflValue));
+
+ attProperty = boolPropertyBuilder.build();
break;
case STRING:
attValue = new AttributeValue(attributeDflValue);
- if (validValuesType == Type.VALUESET) {
- attProperty = new AttributeProperty(
- Utility.convertSetToArrayString(Utility
+ StringProperty.Builder stringPropertyBuilder = new StringProperty.Builder();
+
+ // Set Default Value.
+ stringPropertyBuilder.setDefaultValue(attributeDflValue);
+
+ if (validValuesType == ValidValuesType.VALUESET) {
+ // Set Allowed Values.
+ stringPropertyBuilder.setValues(Utility
+ .convertSetToArrayString(Utility
.convertSetStringToSetObject(allowedValues,
valueType)));
- } else {
- attProperty = null;
}
+ attProperty = stringPropertyBuilder.build();
break;
default:
break;
import java.util.Map;
import java.util.Set;
+import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
import org.oic.simulator.server.Observer;
import org.oic.simulator.server.SimulatorResource;
private Set<String> resourceInterfaces;
private boolean started;
private boolean observable;
+ private boolean discoverable;
private Map<Integer, ObserverDetail> observers;
this.observable = observable;
}
+ public boolean isDiscoverable() {
+ return discoverable;
+ }
+
+ public void setDiscoverable(boolean discoverable) {
+ this.discoverable = discoverable;
+ }
+
public void addInterfaceType(String ifType) {
if (null == ifType) {
return;
observers.remove(observer.getId());
}
- public void setResourceRepresentation(SimulatorResourceModel resModel)
+ public void createResourceRepresentation(
+ Map<String, SimulatorResourceAttribute> attributes)
throws NullPointerException {
if (mResourceRepresentation == null)
- mResourceRepresentation = new ResourceRepresentation(resModel);
- else
- mResourceRepresentation.update(resModel);
+ mResourceRepresentation = new ResourceRepresentation(attributes);
+ }
+
+ public void updateResourceRepresentation(SimulatorResourceModel model)
+ throws NullPointerException {
+ mResourceRepresentation.update(model);
}
public ResourceRepresentation getResourceRepresentation() {
import oic.simulator.serviceprovider.manager.UiListenerHandler;
+import org.oic.simulator.AttributeValue;
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)
+ public ResourceRepresentation(
+ Map<String, SimulatorResourceAttribute> attributes)
throws NullPointerException {
- if (resourceModel != null && resourceModel.size() > 0) {
- for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
- .getAttributes().entrySet()) {
+ if (attributes != null && attributes.size() > 0) {
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : attributes
+ .entrySet()) {
mAttributes.put(entry.getKey(), new AttributeElement(this,
entry.getValue(), true));
}
return mAttributes;
}
- public void update(SimulatorResourceModel resourceModel) {
- if (null == resourceModel)
+ public void update(SimulatorResourceModel model) {
+ if (null == model)
return;
- for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
- .getAttributes().entrySet()) {
+ for (Map.Entry<String, AttributeValue> entry : model.get().entrySet()) {
AttributeElement attributeElement = mAttributes.get(entry.getKey());
if (null != attributeElement) {
if (!attributeElement.getEditLock())
- attributeElement.update(entry.getValue());
- } else // Display new attribute in UI
- {
+ attributeElement.update(new SimulatorResourceAttribute(
+ entry.getKey(), entry.getValue()));
+ } else {
+ // Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(this,
- entry.getValue(), true);
+ new SimulatorResourceAttribute(entry.getKey(),
+ entry.getValue()), true);
mAttributes.put(entry.getKey(), newAttribute);
UiListenerHandler.getInstance().attributeAddedUINotification(
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValueVisitor;
-import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
public class AttributeValueStringConverter implements
StringBuilder result = new StringBuilder();
result.append("{");
boolean first = true;
- for (Map.Entry<String, SimulatorResourceAttribute> entry : value
- .getAttributes().entrySet()) {
+ for (Map.Entry<String, AttributeValue> entry : value.get().entrySet()) {
if (!first)
result.append(", ");
first = false;
result.append("\"" + entry.getKey() + "\":");
- AttributeValue attributeValue = entry.getValue().value();
+ AttributeValue attributeValue = entry.getValue();
result.append(new AttributeValueStringConverter(attributeValue)
.toString());
}
return resultSet;
}
+ public static 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;
+ }
+
public static Comparator<Resource> resourceComparator = new Comparator<Resource>() {
public int compare(
Resource res1,
String values[] = null;
List<String> valueSet = resourceManager
.getAllValuesOfAttribute(attribute);
- values = convertListToStringArray(valueSet);
+ values = Utility.convertListToStringArray(valueSet);
ComboBoxCellEditor comboEditor;
if (type.mType == ValueType.ARRAY) {
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;
- }
-
public void updateAttributeValue(SimulatorResourceAttribute att,
AttributeValue value) {
IStructuredSelection selection = (IStructuredSelection) viewer
&& !(parent instanceof ResourceRepresentation)) {
return "NA";
} else if (attrElement.isReadOnly()) {
- return "Read-only";
+ return "NA";
} else if (attrElement.isAutoUpdateSupport()) {
if (attrElement.isAutoUpdateInProgress())
return Constants.ENABLED;
import java.util.Set;
import oic.simulator.serviceprovider.model.AttributeHelper;
+import oic.simulator.serviceprovider.model.AttributeHelper.ValidValuesType;
import oic.simulator.serviceprovider.utils.Constants;
import org.eclipse.jface.dialogs.MessageDialog;
attTypeCmb.select(attTypeCmb.indexOf(attHelper.getAttributeType()));
updateControls();
dflValueTxt.setText(attHelper.getAttributeDflValue());
- Type valuesType = attHelper.getValidValuesType();
- if (valuesType == Type.RANGE) {
+ ValidValuesType valuesType = attHelper.getValidValuesType();
+ if (valuesType == ValidValuesType.RANGE) {
rangeBtn.setSelection(true);
noneBtn.setSelection(false);
rangeOptionSelected(true);
minRangeTxt.setText(attHelper.getMin());
maxRangeTxt.setText(attHelper.getMax());
- } else if (valuesType == Type.VALUESET) {
+ } else if (valuesType == ValidValuesType.VALUESET) {
cusValuesBtn.setSelection(true);
noneBtn.setSelection(false);
customOptionSelected(true);
maxRangeTxt.setFocus();
return;
}
- attHelper.setValidValuesType(Type.RANGE);
+ attHelper.setValidValuesType(ValidValuesType.RANGE);
attHelper.setMin(min);
attHelper.setMax(max);
maxRangeTxt.setFocus();
return;
}
- attHelper.setValidValuesType(Type.VALUESET);
+ attHelper.setValidValuesType(ValidValuesType.VALUESET);
attHelper.setAllowedValuesByArray(cusItems);
if (editOperation) {
attHelper.setMax(null);
}
} else if (noneBtn.isEnabled() && noneBtn.getSelection()) {
- attHelper.setValidValuesType(Type.UNKNOWN);
+ attHelper.setValidValuesType(ValidValuesType.UNKNOWN);
if (editOperation) {
// Remove min, max and custom values
attHelper.setAllowedValues(null);
MessageDialog
.openError(getShell(), "Invalid File",
"File doesn't exist. Either the file path or file name is invalid.");
- // TODO: Instead of MessageDialog, errors may be shown on wizard
- // itself.
return false;
}
MessageDialog
.openError(getShell(), "Resource URI in use",
"Entered resource URI is in use. Please try a different one.");
- // TODO: Instead of MessageDialog, errors may be shown on wizard
- // itself.
return false;
}
resource.setResourceName(simpleResourceBasicDetailsPage.getResName());
resource.setResourceType(simpleResourceBasicDetailsPage.getResType());
resource.setObservable(simpleResourceBasicDetailsPage.isObservable());
+ resource.setDiscoverable(simpleResourceBasicDetailsPage
+ .isDiscoverable());
resource.setResourceInterfaces(simpleResourceBasicDetailsPage
.getInterfaceTypes());
MessageDialog
.openError(getShell(), "Invalid File",
"File doesn't exist. Either the file path or file name is invalid.");
- // TODO: Instead of MessageDialog, errors may be shown on wizard
- // itself.
return null;
}
import java.util.Set;
import oic.simulator.serviceprovider.model.AttributeHelper;
+import oic.simulator.serviceprovider.model.AttributeHelper.ValidValuesType;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
return;
}
AttributeHelper att = (AttributeHelper) e;
- if (att.getValidValuesType() != Type.RANGE) {
+ if (att.getValidValuesType() != ValidValuesType.RANGE) {
cell.setText("Nil");
} else {
String min = att.getMin();
return;
}
AttributeHelper att = (AttributeHelper) e;
- if (att.getValidValuesType() != Type.VALUESET) {
+ if (att.getValidValuesType() != ValidValuesType.VALUESET) {
cell.setText("Nil");
} else {
cell.setText(att.getAllowedValues().toString());
private Text resTypeTxt;
private Button observeBtn;
+ private Button discoverBtn;
private Button addIfTypeBtn;
private Button removeIfTypeBtn;
private String resURI;
private String resType;
private boolean observable;
+ private boolean discoverable;
private Map<String, String> ifTypes;
private Set<String> selectedIfTypes;
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
otherOptionsGrp.setLayoutData(gd);
+ discoverBtn = new Button(otherOptionsGrp, SWT.CHECK);
+ discoverBtn.setText("Discoverable");
+ discoverBtn.setSelection(true);
+ discoverable = true;
+
observeBtn = new Button(otherOptionsGrp, SWT.CHECK);
observeBtn.setText("Observable");
observeBtn.setSelection(true);
}
});
+ discoverBtn.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ discoverable = discoverBtn.getSelection();
+ }
+ });
+
observeBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
MessageDialog
.openError(getShell(), "Resource URI in use",
"Entered resource URI is in use. Please try a different one.");
- // TODO: Instead of MessageDialog, errors may be shown on wizard
- // itself.
return null;
}
public boolean isObservable() {
return observable;
}
+
+ public boolean isDiscoverable() {
+ return discoverable;
+ }
}