X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fsimulator%2Fjava%2Feclipse-plugin%2FClientControllerPlugin%2Fsrc%2Foic%2Fsimulator%2Fclientcontroller%2Fremoteresource%2FAttributeElement.java;h=c17c57e43a5a1438c251673e29dcde1585a17737;hb=b2b47c415c84402c1289ff0cae28cae46a72a55f;hp=4d22e9e0fcd9045c53a59d0b2316c47c2fc6d49b;hpb=b6000d631514604bb6f6ccc30e0ee00003fda8d1;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java index 4d22e9e..c17c57e 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java @@ -19,13 +19,16 @@ package oic.simulator.clientcontroller.remoteresource; 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; @@ -39,41 +42,110 @@ public class AttributeElement { if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) { SimulatorResourceModel resModel = (SimulatorResourceModel) attribute .value().get(); - for (Map.Entry 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 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)); + } } } } @@ -105,7 +177,8 @@ public class AttributeElement { 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; @@ -113,16 +186,18 @@ public class AttributeElement { if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) { SimulatorResourceModel resModel = (SimulatorResourceModel) attribute .value().get(); - for (Map.Entry entry : resModel - .getAttributes().entrySet()) { + for (Map.Entry 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); } } @@ -138,9 +213,9 @@ public class AttributeElement { 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) + "]", @@ -158,9 +233,9 @@ public class AttributeElement { 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) + "]", @@ -178,9 +253,9 @@ public class AttributeElement { 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) + "]", @@ -189,101 +264,17 @@ public class AttributeElement { } } } 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 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()); } } @@ -304,8 +295,8 @@ public class AttributeElement { 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; }