+ if (resTypeChanged) {
+ if (!changeResourceType(resource, resType)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public boolean updateResourceInterfaces(Resource resource,
+ Set<String> newIfSet) throws SimulatorException {
+ if (null == resource || null == newIfSet || newIfSet.isEmpty()) {
+ return false;
+ }
+ SimulatorResource jResource = resource.getSimulatorResource();
+ if (null == jResource) {
+ return false;
+ }
+ Set<String> curIfSet = resource.getResourceInterfaces();
+ Iterator<String> itr = curIfSet.iterator();
+ String interfaceType;
+ boolean resourceRestartRequired = false;
+ while (itr.hasNext()) {
+ interfaceType = itr.next();
+ if (!newIfSet.contains(interfaceType)) {
+ resourceRestartRequired = true;
+ break;
+ }
+ }
+
+ 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);
+ }
+ }
+ }
+ } 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(newIfSet);
+