Ejemplo n.º 1
0
  isRelatedToPlatform: function (kInstance) {
    if (Kotlin.isType(kInstance.typeDefinition, kevoree.impl.ComponentTypeImpl)) {
      // if parent is this node platform: it's ok
      return (kInstance.eContainer().name == this.node.getName());

    } else if (Kotlin.isType(kInstance.typeDefinition, kevoree.impl.ChannelTypeImpl)) {
      // if this channel has bindings with components hosted in this node platform: it's ok
      var bindings = kInstance.bindings;
      for (var i=0; i < bindings.size(); i++) {
        if (bindings.get(i).port.eContainer().eContainer().name == this.node.getName()) return true;
      }

    } else if (Kotlin.isType(kInstance.typeDefinition, kevoree.impl.GroupTypeImpl)) {
      var subNodes = kInstance.subNodes;
      for (var i=0; i < subNodes.size(); i++) {
        if (subNodes.get(i).name == this.node.name) return true;
      }

    } else if (Kotlin.isType(kInstance.typeDefinition, kevoree.impl.NodeTypeImpl)) {
      // TODO take subnodes in account
      return false;

    }

    return false;
  }
Ejemplo n.º 2
0
  function doRemove(instance) {
    if (Kotlin.isType(instance.typeDefinition, kevoree.impl.NodeTypeImpl)) {
      var groups = model.groups.iterator();
      while (groups.hasNext()) {
        var group = groups.next();
        var subNodes = group.subNodes.iterator()
        while (subNodes.hasNext()) {
          if (subNodes.next().name == instance.name) group.removeSubNodes(instance);
        }
        var dics = group.fragmentDictionary.iterator();
        while (dics.hasNext()) {
          var dic = dics.next();
          if (dic.name === instance.name) {
            group.removeFragmentDictionary(dic);
          }
        }
      }
      var networks = model.nodeNetworks.iterator();
      while (networks.hasNext()) {
        var net = networks.next();
        if (net.target.name === instance.name) {
          model.removeNodeNetworks(net);
        }
      }
      model.removeNodes(instance);

    } else if (Kotlin.isType(instance.typeDefinition, kevoree.impl.GroupTypeImpl)) {
      model.removeGroups(instance);
    } else if (Kotlin.isType(instance.typeDefinition, kevoree.impl.ChannelTypeImpl)) {
      var bindings = model.mBindings.iterator();
      while (bindings.hasNext()) {
        var binding = bindings.next();
        if (binding.hub.name === instance.name) {
          model.removeMBindings(binding);
        }
      }
      model.removeHubs(instance);
    } else if (Kotlin.isType(instance.typeDefinition, kevoree.impl.ComponentTypeImpl)) {
      instance.eContainer().removeComponents(instance);
    } else {
      return cb(new Error('Unable to remove instance "'+names[i]+'" from current model. (Are you sure it is a node, group, chan, component?)'));
    }
  }
Ejemplo n.º 3
0
  doSpecificTypeProcess: function (kInstance) {
    if (Kotlin.isType(kInstance.typeDefinition, kevoree.impl.ComponentTypeImpl)) {
      var provided = kInstance.provided;
      for (var i=0; i < provided.size(); i++) {
        var input = provided.get(i);
        this.mapper.addEntry(input.path(), new Port(input.portTypeRef.name, input.path()));
      }

      var required = kInstance.required;
      for (var i=0; i < required.size(); i++) {
        var output = required.get(i);
        this.mapper.addEntry(output.path(), new Port(output.portTypeRef.name, output.path()));
      }
    } else if (Kotlin.isType(kInstance.typeDefinition, kevoree.impl.ChannelTypeImpl)) {
      var bindings = kInstance.bindings.iterator();
      while (bindings.hasNext()) {
        var binding = bindings.next();
        this.mapper.addEntry(binding.port.path(), new Port(binding.port.portTypeRef.name, binding.port.path()));
      }
    }
  }
Ejemplo n.º 4
0
  execute: function (_super, callback) {
    _super.call(this, callback);

    var dicValue = this.adaptModel.findByPath(this.trace.srcPath),
        instance = this.findEntityInstance();

    var kDictionary = dicValue.eContainer();

    if (instance != null) {
      var dictionary = instance.getDictionary();
      this.oldDictionaryMap = dictionary.cloneMap();
      this.instance = instance;
      if (Kotlin.isType(kDictionary, kevoree.impl.FragmentDictionaryImpl)) {
        if (kDictionary.name == this.node.getName()) {
          dictionary.setEntry(dicValue.name, dicValue.value);
        }
      } else {
        dictionary.setEntry(dicValue.name, dicValue.value);
      }

      this.log.debug(this.toString(), 'job done for attribute '+dicValue.name+'@'+this.node.getName());
      return callback();

    } else {
      // TODO handle node's platform attributes
      // TODO(instance == null ==> maybe this attribute is related to the node and not one of its contained object)
//      if (Kotlin.isType(kDictionary, kevoree.impl.FragmentDictionaryImpl)) {
//        if (kDictionary.name == this.node.getName()) {
//          var dictionary = this.node.getDictionary();
//          this.oldDictionaryMap = dictionary.cloneMap();
//          this.instance = this.node;
//          dictionary.setEntry(dicValue.name, dicValue.value);
//        }
//      } else {
//        dictionary.setEntry(dicValue.name, dicValue.value);
//      }
//      // check if this attribute is related to the running platform node type
//      if (dicValue.eContainer().eContainer().name == this.node.toString()
//        || dicValue.eContainer().eContainer().name == this.node.getName()) {
//        var dictionary = this.node.getDictionary();
//        this.oldDictionary = dictionary.clone();
//        this.instance = this.node;
//        dictionary.setEntry(dicValue.attribute.name, dicValue.value);
//      }
    }

    return callback();
  },
Ejemplo n.º 5
0
module.exports = function (model, statements, stmt, opts, cb) {
  var nameList = statements[stmt.children[0].type](model, statements, stmt.children[0], opts, cb);

  function doRemove1(nodeName, third) {
    var node = model.findNodesByID(nodeName);
    if (node) {
      if (third === '*') {
        // remove all components within this node
        var compz = node.components.iterator();
        while (compz.hasNext()) doRemove(compz.next());

      } else {
        var comp = node.findComponentsByID(third);
        if (comp) {
          doRemove(comp);
        } else {
          return cb(new Error('Unable to find component instance "'+third+'" in node instance "'+nodeName+'" in model (remove '+nameList.toString()+')'));
        }
      }
    } else {
      return cb(new Error('Unable to find node instance "'+nodeName+'" in model (remove '+nameList.toString()+')'));
    }
  }

  function doRemove(instance) {
    if (Kotlin.isType(instance.typeDefinition, kevoree.impl.NodeTypeImpl)) {
      var groups = model.groups.iterator();
      while (groups.hasNext()) {
        var group = groups.next();
        var subNodes = group.subNodes.iterator()
        while (subNodes.hasNext()) {
          if (subNodes.next().name == instance.name) group.removeSubNodes(instance);
        }
        var dics = group.fragmentDictionary.iterator();
        while (dics.hasNext()) {
          var dic = dics.next();
          if (dic.name === instance.name) {
            group.removeFragmentDictionary(dic);
          }
        }
      }
      var networks = model.nodeNetworks.iterator();
      while (networks.hasNext()) {
        var net = networks.next();
        if (net.target.name === instance.name) {
          model.removeNodeNetworks(net);
        }
      }
      model.removeNodes(instance);

    } else if (Kotlin.isType(instance.typeDefinition, kevoree.impl.GroupTypeImpl)) {
      model.removeGroups(instance);
    } else if (Kotlin.isType(instance.typeDefinition, kevoree.impl.ChannelTypeImpl)) {
      var bindings = model.mBindings.iterator();
      while (bindings.hasNext()) {
        var binding = bindings.next();
        if (binding.hub.name === instance.name) {
          model.removeMBindings(binding);
        }
      }
      model.removeHubs(instance);
    } else if (Kotlin.isType(instance.typeDefinition, kevoree.impl.ComponentTypeImpl)) {
      instance.eContainer().removeComponents(instance);
    } else {
      return cb(new Error('Unable to remove instance "'+names[i]+'" from current model. (Are you sure it is a node, group, chan, component?)'));
    }
  }

  for (var i in nameList) {
    nameList[i].expect(1, 3, function (err, first, second, third) {
      if (err) {
        err.message = ' (remove '+nameList.toString()+')';
        return cb(err);
      }

      if (first) {
        // TODO there is at least 3 parts in path so it must refer to a namespace 'first.second.third'
        return cb(new Error('Namespaces are not handled yet :/ Sorry (remove '+nameList.toString()+')'));

      } else {
        if (second) {
          // two parts path: 'second.third'
          if (second === '*') {
            var nodes = model.nodes.iterator();
            while (nodes.hasNext()) doRemove1(nodes.next().name, third);
          } else {
            doRemove1(second, third);
          }
        } else {
          // one part path: 'third'
          if (third === '*') {
            var nodes = model.nodes.iterator();
            var groups = model.groups.iterator();
            var hubs = model.hubs.iterator();

            while (nodes.hasNext())  doRemove(nodes.next());
            while (groups.hasNext()) doRemove(groups.next());
            while (hubs.hasNext())   doRemove(hubs.next());

          } else {
            var instance = helper.findEntityByName(model, third);
            if (instance)
              doRemove(instance);
            else
              return cb(new Error('Unable to find instance "'+third+'" in model (remove '+nameList.toString()+')'));
          }
        }
      }
    });
  }

  var names = [];

  if (stmt.children[0].type == 'nameList') {
    for (var i in stmt.children[0].children) {
      names.push(stmt.children[0].children[i].children.join(''));
    }
  } else {
    names.push(stmt.children[0].children.join(''));
  }

  for (var i in names) {
    var entity = helper.findEntityByName(model, names[i]);
    if (entity != null) {
      if (Kotlin.isType(entity.typeDefinition, kevoree.impl.NodeTypeImpl)) {
        var groups = (model.groups) ? model.groups.iterator() : null;
        if (groups != null) {
          while (groups.hasNext()) {
            var group = groups.next();
            var subNodes = group.subNodes.iterator()
            while (subNodes.hasNext()) {
              if (subNodes.next().name == entity.name) group.removeSubNodes(entity);
            }
            var values = group.dictionary.values.iterator();
            while (values.hasNext()) {
              var val = values.next();
              if (val.targetNode.name == entity.name) group.dictionary.removeValues(val);
            }
          }
        }
        model.removeNodes(entity);

      } else if (Kotlin.isType(entity.typeDefinition, kevoree.impl.GroupTypeImpl)) {
        model.removeGroups(entity);
      } else if (Kotlin.isType(entity.typeDefinition, kevoree.impl.ChannelTypeImpl)) {
        model.removeHubs(entity);
      } else if (Kotlin.isType(entity.typeDefinition, kevoree.impl.ComponentTypeImpl)) {
        entity.eContainer().removeComponents(entity);
      } else {
        return cb(new Error('Unable to remove instance "'+names[i]+'" from current model. (Are you sure it is a node, group, chan, component?)'));
      }
    }
  }

  cb();
}