import java.util.HashMap;
import java.util.Map;
-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;
+import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
+
public class AttributeElement {
private Object mParent = null;
private SimulatorResourceAttribute mAttribute = null;
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);
- }
- }
- } 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);
- }
+ 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 {
- 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;
}