From 87fa65d9895225c516d66cbb33395327f9908e8a Mon Sep 17 00:00:00 2001 From: G S Senthil Kumar Date: Tue, 9 Feb 2016 15:53:49 +0530 Subject: [PATCH] Integrated resource model related changes with eclipse plug-ins. Made changes in ServiceProvider and ClientController plug-ins as per the changes in the resource model related APIs. Change-Id: I41cf20d2d8c59756dacb4c869bd6ae009f16995a Signed-off-by: G S Senthil Kumar Reviewed-on: https://gerrit.iotivity.org/gerrit/4957 Tested-by: jenkins-iotivity Reviewed-by: Radha Bhavani Reviewed-by: Madan Lanka --- .../clientcontroller/manager/ResourceManager.java | 234 ++++++++------ .../remoteresource/AttributeElement.java | 283 +++++++++-------- .../remoteresource/ResourceRepresentation.java | 37 +-- .../utils/AttributeValueStringConverter.java | 6 +- .../view/AttributeEditingSupport.java | 18 ++ .../view/MultiResourceOrchestrationView.java | 4 - .../clientcontroller/view/ResourceManagerView.java | 2 - .../view/dialogs/LoadRAMLDialog.java | 2 - .../serviceprovider/manager/ResourceManager.java | 337 ++++++++++++--------- .../serviceprovider/model/AttributeElement.java | 143 +++++++-- .../serviceprovider/model/AttributeHelper.java | 94 ++++-- .../simulator/serviceprovider/model/Resource.java | 22 +- .../model/ResourceRepresentation.java | 27 +- .../utils/AttributeValueStringConverter.java | 6 +- .../simulator/serviceprovider/utils/Utility.java | 10 + .../view/AttributeEditingSupport.java | 12 +- .../serviceprovider/view/AttributeView.java | 2 +- .../view/dialogs/AddAttributeDialog.java | 13 +- .../view/dialogs/CreateResourceWizard.java | 6 +- .../serviceprovider/view/dialogs/LoadRamlPage.java | 2 - .../dialogs/SimpleResourceAddAttributePage.java | 5 +- .../dialogs/SimpleResourceBasicDetailsPage.java | 20 +- 22 files changed, 770 insertions(+), 515 deletions(-) diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java index e20e18a..0b6b3a3 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java @@ -32,17 +32,22 @@ import oic.simulator.clientcontroller.Activator; import oic.simulator.clientcontroller.remoteresource.DeviceAndPlatformInfo; import oic.simulator.clientcontroller.remoteresource.MetaProperty; import oic.simulator.clientcontroller.remoteresource.RemoteResource; +import oic.simulator.clientcontroller.utils.AttributeValueStringConverter; import oic.simulator.clientcontroller.utils.Constants; import oic.simulator.clientcontroller.utils.Utility; +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; @@ -50,6 +55,7 @@ import org.oic.simulator.SimulatorManager; 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; @@ -506,13 +512,7 @@ public class ResourceManager { 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; @@ -1076,120 +1076,162 @@ public class ResourceManager { } AttributeValue val = att.value(); - if (null == val) { + if (null == val || null == val.get()) { return null; } - List values = new ArrayList(); - TypeInfo type = val.typeInfo(); + if (type.mType == ValueType.RESOURCEMODEL + || type.mBaseType == ValueType.RESOURCEMODEL) { + return null; + } + + List values = new ArrayList(); + 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 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 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 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 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 getRangeForPrimitiveNonArrayAttributes( - AttributeProperty prop, ValueType type) { - if (null == prop) { - return null; - } + public List getAllValues(IntegerProperty intProperty, + AttributeProperty.Type type) { + List values = new ArrayList(); - 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 getAllValues(DoubleProperty dblProperty, + AttributeProperty.Type type) { List values = new ArrayList(); - 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 getAllowedValuesForPrimitiveNonArrayAttributes( - AttributeValue[] attValues, ValueType type) { - if (null == attValues || attValues.length < 1) { - return null; - } - - if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) { - return null; - } + public List getAllValues(BooleanProperty boolProperty, + AttributeProperty.Type type) { + List values = new ArrayList(); + values.add("true"); + values.add("false"); + return values; + } - Object obj; + public List getAllValues(StringProperty stringProperty, + AttributeProperty.Type type) { List values = new ArrayList(); - 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; } @@ -1271,7 +1313,7 @@ public class ResourceManager { 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. @@ -1433,12 +1475,12 @@ public class ResourceManager { } // 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() 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..ff992ff 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 @@ -21,8 +21,11 @@ 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; @@ -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); + 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()); } } @@ -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; } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java index ef8cef7..f2c3f18 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java @@ -19,6 +19,7 @@ package oic.simulator.clientcontroller.remoteresource; 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; @@ -28,10 +29,12 @@ public class ResourceRepresentation { public ResourceRepresentation(SimulatorResourceModel resourceModel) { if (resourceModel != null && resourceModel.size() > 0) { - for (Map.Entry entry : resourceModel - .getAttributes().entrySet()) - mAttributes.put(entry.getKey(), new AttributeElement(this, - entry.getValue())); + for (Map.Entry entry : resourceModel.get() + .entrySet()) + mAttributes.put(entry.getKey(), + new AttributeElement(this, + new SimulatorResourceAttribute(entry.getKey(), + entry.getValue()))); } } @@ -41,18 +44,18 @@ public class ResourceRepresentation { public void update(SimulatorResourceModel resourceModel, boolean ramlUploaded) { - for (Map.Entry entry : resourceModel - .getAttributes().entrySet()) { + for (Map.Entry 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); } } @@ -67,8 +70,8 @@ public class ResourceRepresentation { 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(); } @@ -86,8 +89,8 @@ public class ResourceRepresentation { 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(); } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java index ed9f42f..bcceb5e 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java @@ -20,7 +20,6 @@ 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 @@ -63,13 +62,12 @@ public class AttributeValueStringConverter implements StringBuilder result = new StringBuilder(); result.append("{"); boolean first = true; - for (Map.Entry entry : value - .getAttributes().entrySet()) { + for (Map.Entry 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()); } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java index f304257..eec9622 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java @@ -332,9 +332,27 @@ public class AttributeEditingSupport { 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); + } } } } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/MultiResourceOrchestrationView.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/MultiResourceOrchestrationView.java index 67ae7ce..ef67547 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/MultiResourceOrchestrationView.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/MultiResourceOrchestrationView.java @@ -29,14 +29,10 @@ public class MultiResourceOrchestrationView extends ViewPart { @Override public void createPartControl(Composite arg0) { - // TODO Auto-generated method stub - } @Override public void setFocus() { - // TODO Auto-generated method stub - } } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java index f970b73..5af4ec1 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java @@ -658,8 +658,6 @@ public class ResourceManagerView extends ViewPart { @Override public void setFocus() { - // TODO Auto-generated method stub - } public synchronized void setFoundResource(boolean value) { diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/LoadRAMLDialog.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/LoadRAMLDialog.java index 90ace2b..8d6e562 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/LoadRAMLDialog.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/LoadRAMLDialog.java @@ -130,8 +130,6 @@ public class LoadRAMLDialog extends TitleAreaDialog { 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(); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java index 9368c6d..3d22bd7 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java @@ -38,19 +38,24 @@ import oic.simulator.serviceprovider.utils.Utility; 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; @@ -140,7 +145,7 @@ public class ResourceManager { .getResourceByURI(resourceURI); if (null != resource) { try { - resource.setResourceRepresentation(resourceModelN); + resource.updateResourceRepresentation(resourceModelN); } catch (NumberFormatException e) { Activator .getDefault() @@ -544,6 +549,11 @@ public class ResourceManager { 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); @@ -572,21 +582,18 @@ public class ResourceManager { 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 newIfSet = resource.getResourceInterfaces(); - // Get the default interface(s) if any configured by the platform. - // These interfaces will be overwritten by the new interfaces. - Set ifSetFromPlatform = Utility - .convertVectorToSet(jSimulatorSingleResource.getInterface()); - resource.setResourceInterfaces(ifSetFromPlatform); - updateResourceInterfaces(resource, newIfSet); } catch (SimulatorException e) { Activator .getDefault() @@ -713,7 +720,8 @@ public class ResourceManager { .getInterface())); // Fetch the resource attributes. - singleRes.setResourceRepresentation(jResModel); + singleRes.createResourceRepresentation(jSimulatorSingleResource + .getAttributes()); // Register the resource with the platform. jSimulatorSingleResource.start(); @@ -1100,65 +1108,45 @@ public class ResourceManager { 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; } @@ -1263,10 +1251,30 @@ public class ResourceManager { 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; } @@ -1523,48 +1531,82 @@ public class ResourceManager { List values = new ArrayList(); - 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 list = getRangeForPrimitiveNonArrayAttributes( - childProp, type.mBaseType); - if (null != list) { - values.addAll(list); - } - } else if (valuesType == Type.VALUESET) { - List 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 list = getRangeForPrimitiveNonArrayAttributes( - prop, type.mType); - if (null != list) { - values.addAll(list); - } - } else if (valuesType == Type.VALUESET) { - List 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; } } } @@ -1572,58 +1614,67 @@ public class ResourceManager { return values; } - public List getRangeForPrimitiveNonArrayAttributes( - AttributeProperty prop, ValueType type) { - if (null == prop) { - return null; - } + public List getAllValues(IntegerProperty intProperty, + AttributeProperty.Type type) { + List values = new ArrayList(); - 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 getAllValues(DoubleProperty dblProperty, + AttributeProperty.Type type) { List values = new ArrayList(); - 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 getAllowedValuesForPrimitiveNonArrayAttributes( - AttributeValue[] attValues, ValueType type) { - if (null == attValues || attValues.length < 1) { - return null; - } - - if (type == ValueType.ARRAY || type == ValueType.RESOURCEMODEL) { - return null; - } + public List getAllValues(BooleanProperty boolProperty, + AttributeProperty.Type type) { + List values = new ArrayList(); + values.add("true"); + values.add("false"); + return values; + } - Object obj; + public List getAllValues(StringProperty stringProperty, + AttributeProperty.Type type) { List values = new ArrayList(); - 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; } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java index 8dc36a0..5e05bb7 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java @@ -23,10 +23,16 @@ import oic.simulator.serviceprovider.manager.UiListenerHandler; 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 { @@ -51,10 +57,22 @@ public class AttributeElement { mAutoUpdateSupport = false; SimulatorResourceModel resModel = (SimulatorResourceModel) attribute .value().get(); - for (Map.Entry 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 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; @@ -62,10 +80,20 @@ public class AttributeElement { 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)); @@ -73,10 +101,29 @@ public class AttributeElement { } 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)); @@ -84,10 +131,36 @@ public class AttributeElement { } 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)); @@ -159,7 +232,31 @@ public class AttributeElement { } 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() { @@ -178,16 +275,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())); + } 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() @@ -207,8 +306,8 @@ public class AttributeElement { .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) + "]", @@ -229,8 +328,8 @@ public class AttributeElement { .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) + "]", @@ -251,8 +350,8 @@ public class AttributeElement { .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) + "]", @@ -284,8 +383,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; } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeHelper.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeHelper.java index f2ae3d7..5b53964 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeHelper.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeHelper.java @@ -19,15 +19,19 @@ package oic.simulator.serviceprovider.model; 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; @@ -37,11 +41,15 @@ public class AttributeHelper { private Set allowedValues; private String attributeDflValue; - private Type validValuesType; + public enum ValidValuesType { + RANGE, VALUESET, UNKNOWN + } + + private ValidValuesType validValuesType; public AttributeHelper() { allowedValues = new HashSet(); - setValidValuesType(Type.UNKNOWN); + setValidValuesType(ValidValuesType.UNKNOWN); min = max = ""; } @@ -134,11 +142,11 @@ public class AttributeHelper { this.attributeDflValue = attributeDflValue; } - public Type getValidValuesType() { + public ValidValuesType getValidValuesType() { return validValuesType; } - public void setValidValuesType(Type validValuesType) { + public void setValidValuesType(ValidValuesType validValuesType) { this.validValuesType = validValuesType; } @@ -223,7 +231,8 @@ public class AttributeHelper { } 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; @@ -234,7 +243,7 @@ public class AttributeHelper { result = false; } } else { - if (validValuesType == Type.RANGE) { + if (validValuesType == ValidValuesType.RANGE) { if (attributeType.equals(Constants.INT)) { int min, max, dflValue; try { @@ -267,7 +276,7 @@ public class AttributeHelper { result = false; } } - } else if (validValuesType == Type.VALUESET + } else if (validValuesType == ValidValuesType.VALUESET && null != allowedValues && !allowedValues.isEmpty()) { boolean found = false; if (attributeType.equals(Constants.INT)) { @@ -330,51 +339,74 @@ public class AttributeHelper { 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; diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java index 732ca64..31ae1b1 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java @@ -21,6 +21,7 @@ import java.util.HashSet; 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; @@ -38,6 +39,7 @@ public abstract class Resource { private Set resourceInterfaces; private boolean started; private boolean observable; + private boolean discoverable; private Map observers; @@ -113,6 +115,14 @@ public abstract class Resource { 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; @@ -160,12 +170,16 @@ public abstract class Resource { observers.remove(observer.getId()); } - public void setResourceRepresentation(SimulatorResourceModel resModel) + public void createResourceRepresentation( + Map 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() { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java index 8b385c4..275a7e6 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java @@ -21,17 +21,19 @@ import java.util.Map; 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 mAttributes = new HashMap(); - public ResourceRepresentation(SimulatorResourceModel resourceModel) + public ResourceRepresentation( + Map attributes) throws NullPointerException { - if (resourceModel != null && resourceModel.size() > 0) { - for (Map.Entry entry : resourceModel - .getAttributes().entrySet()) { + if (attributes != null && attributes.size() > 0) { + for (Map.Entry entry : attributes + .entrySet()) { mAttributes.put(entry.getKey(), new AttributeElement(this, entry.getValue(), true)); } @@ -42,20 +44,21 @@ public class ResourceRepresentation { return mAttributes; } - public void update(SimulatorResourceModel resourceModel) { - if (null == resourceModel) + public void update(SimulatorResourceModel model) { + if (null == model) return; - for (Map.Entry entry : resourceModel - .getAttributes().entrySet()) { + for (Map.Entry 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( diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java index 4b5efb4..50d0e0b 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java @@ -20,7 +20,6 @@ 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 @@ -63,13 +62,12 @@ public class AttributeValueStringConverter implements StringBuilder result = new StringBuilder(); result.append("{"); boolean first = true; - for (Map.Entry entry : value - .getAttributes().entrySet()) { + for (Map.Entry 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()); } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java index d95b33e..b7e7761 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java @@ -354,6 +354,16 @@ public class Utility { return resultSet; } + public static String[] convertListToStringArray(List 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 resourceComparator = new Comparator() { public int compare( Resource res1, diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java index 98dbfb9..7137a11 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java @@ -221,7 +221,7 @@ public class AttributeEditingSupport { String values[] = null; List valueSet = resourceManager .getAllValuesOfAttribute(attribute); - values = convertListToStringArray(valueSet); + values = Utility.convertListToStringArray(valueSet); ComboBoxCellEditor comboEditor; if (type.mType == ValueType.ARRAY) { @@ -351,16 +351,6 @@ public class AttributeEditingSupport { viewer.update(element, null); } - public String[] convertListToStringArray(List 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 diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java index a4bde78..a4bb01e 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java @@ -451,7 +451,7 @@ public class AttributeView extends ViewPart { && !(parent instanceof ResourceRepresentation)) { return "NA"; } else if (attrElement.isReadOnly()) { - return "Read-only"; + return "NA"; } else if (attrElement.isAutoUpdateSupport()) { if (attrElement.isAutoUpdateInProgress()) return Constants.ENABLED; diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java index bbda598..186ea6c 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java @@ -20,6 +20,7 @@ import java.util.Iterator; 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; @@ -290,14 +291,14 @@ public class AddAttributeDialog extends TitleAreaDialog { 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); @@ -627,7 +628,7 @@ public class AddAttributeDialog extends TitleAreaDialog { maxRangeTxt.setFocus(); return; } - attHelper.setValidValuesType(Type.RANGE); + attHelper.setValidValuesType(ValidValuesType.RANGE); attHelper.setMin(min); attHelper.setMax(max); @@ -644,7 +645,7 @@ public class AddAttributeDialog extends TitleAreaDialog { maxRangeTxt.setFocus(); return; } - attHelper.setValidValuesType(Type.VALUESET); + attHelper.setValidValuesType(ValidValuesType.VALUESET); attHelper.setAllowedValuesByArray(cusItems); if (editOperation) { @@ -653,7 +654,7 @@ public class AddAttributeDialog extends TitleAreaDialog { 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); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java index 20d0523..07c560f 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java @@ -184,8 +184,6 @@ public class CreateResourceWizard extends Wizard { 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; } @@ -263,8 +261,6 @@ public class CreateResourceWizard extends Wizard { 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; } @@ -337,6 +333,8 @@ public class CreateResourceWizard extends Wizard { resource.setResourceName(simpleResourceBasicDetailsPage.getResName()); resource.setResourceType(simpleResourceBasicDetailsPage.getResType()); resource.setObservable(simpleResourceBasicDetailsPage.isObservable()); + resource.setDiscoverable(simpleResourceBasicDetailsPage + .isDiscoverable()); resource.setResourceInterfaces(simpleResourceBasicDetailsPage .getInterfaceTypes()); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/LoadRamlPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/LoadRamlPage.java index 5224274..da3694d 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/LoadRamlPage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/LoadRamlPage.java @@ -252,8 +252,6 @@ public class LoadRamlPage extends WizardPage { 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; } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java index a54853e..da3ccc3 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java @@ -23,6 +23,7 @@ import java.util.List; 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; @@ -153,7 +154,7 @@ public class SimpleResourceAddAttributePage extends WizardPage { return; } AttributeHelper att = (AttributeHelper) e; - if (att.getValidValuesType() != Type.RANGE) { + if (att.getValidValuesType() != ValidValuesType.RANGE) { cell.setText("Nil"); } else { String min = att.getMin(); @@ -180,7 +181,7 @@ public class SimpleResourceAddAttributePage extends WizardPage { return; } AttributeHelper att = (AttributeHelper) e; - if (att.getValidValuesType() != Type.VALUESET) { + if (att.getValidValuesType() != ValidValuesType.VALUESET) { cell.setText("Nil"); } else { cell.setText(att.getAllowedValues().toString()); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java index dcd4131..0932566 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java @@ -53,6 +53,7 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { private Text resTypeTxt; private Button observeBtn; + private Button discoverBtn; private Button addIfTypeBtn; private Button removeIfTypeBtn; @@ -62,6 +63,7 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { private String resURI; private String resType; private boolean observable; + private boolean discoverable; private Map ifTypes; private Set selectedIfTypes; @@ -164,6 +166,11 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { 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); @@ -216,6 +223,13 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { } }); + discoverBtn.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + discoverable = discoverBtn.getSelection(); + } + }); + observeBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -318,8 +332,6 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { 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; } @@ -362,4 +374,8 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { public boolean isObservable() { return observable; } + + public boolean isDiscoverable() { + return discoverable; + } } -- 2.7.4