text: 'use strict';
  
  /**
   *
   * Port
   *
   * TODO: Each object should make sense to be used seperatly.
   * The port must solve a generic problem.
   *
   * First just at least refactor, so all this port logic is not
   * inside node.js
   *
   * It is in fact not that hard to use this Port.
   * As long as I keep the structure the same as the object.
   * Only must watch out with some tests which access the internals.
   * Which immediatly shows why you never should reach into internals.
   *
   * Distinct between input & output port
   * Most methods are for input ports.
   *
   * Ok, I could question whether context belongs to port at all.
   * Probably not, it just belongs to Node, yepp.
   * Ok that's also easier to implement.
   *
   * Validation belongs to port, both input & output could use it.
   * This also makes it possible to disable/enable validation per port.
   * Most of the time you would only validate the outerparts of the graph.
   * During debug you enable it for all ports on all nodes.
   *
   * It could be possible to create typed ports, this way a boolean
   * port only has to check whether it's a boolean, right now it's done
   * with a switch, this will make it much clearer. And ofcourse
   * it's already necessary for ArrayPorts and ObjectPorts, so it will
   * just be an extension of that.
   *
   * @example
   *
   *  var port = new Port();
   *  port.receive(p);
   *  port.receive(p); // rejected
   *  port.read();
   *  port.read();
   *  port.receive(p);
   *
   *
   */
  function Port() {
  
    //if (!(this instanceof Port)) return new Port(options);
  
    // important to just name it input for refactor.
  	// eventually can be renamed to something else.
    //
  	// node.input[port] becomes node.getPort(port).input
    //
    this.input = undefined;
  
    this._open = false;
  
    // If async the value will pass right through a.k.a. non-blocking
  	// If there are multiple async ports, the code implementation
  	// consequently must be a state machine.
  	// async + sync is still possible. One async port is just one
  	// function call and thus not a state machine.
    this.async = false;
    this._connections = [];
  
  }
  
  /**
   *
   * Used from within a component to receive the port data
   *
   */
  Port.prototype.receive = function() {
  };
  
  /**
   *
   * Used from within a component to close the port
   *
   * A component receives an open port.
   * When the port closes it's ready to be filled.
   * This also means there are two sides on a port
   * Open for input and open for output to the component.
   *
   */
  Port.prototype.close = function() {
    this._open = false;
  };
  
  Port.prototype.open = function() {
    this._open = true;
  };
  
  // TODO: after refactor these will end up elsewhere
  Port.prototype.hasConnection = function(link) {
    return this._connections && this._connections.indexOf(link) >= 0;
  };
  Port.prototype.hasConnections = function() {
    return this._connections.length > 0;
  };
  
  Port.prototype.getConnections = function() {
    return this._connections;
  };
  
  // this seems to be a wrong check?
  // ah no, no property means not filled.
  // but this is just wrong. array port for example is not filled, if it's set.
  // it's being taken care of, but only causes more code to be necessary
  Port.prototype.isFilled = function() {
    return this.input !== undefined;
  };
  
  Port.prototype.clearInput = function() {
    this.input = undefined;
  };
  
  Port.prototype.isAvailable = function() {
  };
  
  // Node freePort
  Port.prototype.free = function() {
  
    var persist = this.getOption('persist');
    if (persist) {
      // persist, chi, hmz, seeze to exist.
      // but wouldn't matter much, with peristent ports.
      // TODO: this.filled is not used anymore.
  
      // indexes are persisted per index.
      if (Array.isArray(persist)) {
        for (var k in this.input) {
          if (persist.indexOf(k) === -1) {
            // remove
            delete this.input[k];
          }
        }
      }
  
    } else {
  
      // not sure, activeConnections could stay a node thing.
  
      // this also removes context and default..
      this.clearInput();
  
      this.event(':freePort', {
        node: this.export(),
        link: this._activeConnections,
        port: this.name
      });
  
      this.emit('freePort', {
        node: this.export(),
        link: this._activeConnections,
        port: this.name
      });
  
      // delete reference to active connection (if there was one)
      delete this._activeConnections;
    }
  
  };
  
  //Node.prototype.getPortOption = function(type, name, opt) {
  
  // could become this.setting[opt], but that will change things too much
  Port.prototype.getOption = function(opt) {
    if (this.hasOwnProperty(opt)) {
      return this[opt];
    } else {
      return undefined;
    }
  };
  
  /**
   *
   * Sets an input port option.
   *
   * The node schema for instance can specifiy whether a port is persistent.
   *
   * At the moment a connection can override these values.
   * It's a way of saying I give you this once so take care of it.
   *
   */
  //Node.prototype.setPortOption = function(type, name, opt, value) {
  Port.prototype.setOption = function(opt, value) {
    this[opt] = value;
  };
  
  //Node.prototype.setPortOptions = function(type, options) {
  Port.prototype.setOptions = function(options) {
    var opt;
    var port;
    for (port in options) {
      if (options.hasOwnProperty(port)) {
        for (opt in options[port]) {
          if (options[port].hasOwnProperty(opt)) {
            if (options.hasOwnProperty(opt)) {
              this.setOption(opt, options[opt]);
            }
          }
        }
      }
    }
  };
  
  module.exports = Port;
  