X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fsimulator%2Fjava%2Feclipse-plugin%2FServiceProviderPlugin%2Fsrc%2Foic%2Fsimulator%2Fserviceprovider%2Fmanager%2FResourceManager.java;h=a1bed35d49db4844218beeb6eb3807d8458cf5e4;hb=b2b47c415c84402c1289ff0cae28cae46a72a55f;hp=9368c6da23bb4dfed22b4ff505ab868543052930;hpb=01f8d734c2a2e3734ac73f8559fa347251da17cb;p=platform%2Fupstream%2Fiotivity.git 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..a1bed35 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 @@ -16,6 +16,9 @@ package oic.simulator.serviceprovider.manager; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.swt.widgets.Display; + import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -27,30 +30,24 @@ import java.util.Map; import java.util.Set; import java.util.Vector; -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.AttributeElement; -import oic.simulator.serviceprovider.model.MetaProperty; -import oic.simulator.serviceprovider.model.Resource; -import oic.simulator.serviceprovider.model.ResourceType; -import oic.simulator.serviceprovider.model.SingleResource; -import oic.simulator.serviceprovider.utils.Constants; -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; @@ -59,6 +56,15 @@ import org.oic.simulator.server.SimulatorResource.ObserverListener; import org.oic.simulator.server.SimulatorResource.ResourceModelChangeListener; import org.oic.simulator.server.SimulatorSingleResource; +import oic.simulator.serviceprovider.Activator; +import oic.simulator.serviceprovider.model.AttributeElement; +import oic.simulator.serviceprovider.model.MetaProperty; +import oic.simulator.serviceprovider.model.Resource; +import oic.simulator.serviceprovider.model.ResourceType; +import oic.simulator.serviceprovider.model.SingleResource; +import oic.simulator.serviceprovider.utils.Constants; +import oic.simulator.serviceprovider.utils.Utility; + /** * This class acts as an interface between the simulator java SDK and the * various UI modules. It maintains all the details of resources and provides @@ -140,7 +146,7 @@ public class ResourceManager { .getResourceByURI(resourceURI); if (null != resource) { try { - resource.setResourceRepresentation(resourceModelN); + resource.updateResourceRepresentation(resourceModelN); } catch (NumberFormatException e) { Activator .getDefault() @@ -544,6 +550,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 +583,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 +721,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 +1109,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 +1252,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 +1532,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 +1615,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; }