public String validateValue(String value) {
   String technicalName = UIUtils.formatTechnicalPortName(value, true);
   for (InPort p : fGraphModel.getOuterInPorts()) {
     if (p.getName().equals(technicalName)) {
       return "Name already exists.";
     }
   }
   technicalName = UIUtils.formatTechnicalPortName(value, false);
   for (OutPort p : fGraphModel.getOuterOutPorts()) {
     if (p.getName().equals(technicalName)) {
       return "Name already exists.";
     }
   }
   return null;
 }
Exemple #2
0
  private void connect(List<String> prevComps, List<String> newComps) {
    for (String prevComp : prevComps) {
      for (String newComp : newComps) {
        OutPort portPrevComp = pComps.get(prevComp).nextOutPortToConnect();
        if (portPrevComp == null) continue;
        String portTypePrev =
            getPortTypeOfComponentsPort(pComps.get(prevComp), portPrevComp /*, "OutPort"*/);
        // String portTypePrev = getPortTokenType(portPrevComp); // could not come up with such a
        // function. That information does not exist at run-time.
        // System.out.println("portTypePrev: " + portTypePrev);

        InPort portNewComp = pComps.get(newComp).nextInPortToConnect();
        if (portNewComp == null)
          continue; // SacreLib.logger.log(Level.SEVERE, "attempted to connect non-existing ports: "
                    // + pComps.get(prevComp).getName() + " <-> " + pComps.get(newComp).getName() );
        String portTypeNew =
            getPortTypeOfComponentsPort(pComps.get(newComp), portNewComp /*, "InPort"*/);
        // String portTypeNew = getPortTokenType(portNewComp); // could not come up with such a
        // function. That information does not exist at run-time.
        // System.out.println("portTypeNew: " + portTypeNew);

        boolean arePortsCompatible;
        if (portTypePrev == null || portTypeNew == null) {
          // the port is not statically declared as a field. It is dynamically created and add to
          // port list in the component's constructor. (e.g., Fork1xN)
          // in such cases, there is no way of inferring the token type of the port.
          // continue assuming ports are compatible.
          arePortsCompatible = true;
          portPrevComp.connect(portNewComp);
          SacreLib.logger.log(
              Level.WARNING,
              "Port compatibility could not be checked! Connected assuming they are compatible:"
                  + portPrevComp.getName()
                  + " <-> "
                  + portNewComp.getName());
        } else {
          arePortsCompatible = true;
          try {
            // if the previous output port has a token type that is a subclass of
            // the token of the next input port, then they are compatible.
            Class.forName(portTypePrev).asSubclass(Class.forName(portTypeNew));
            // SacreLib.logger.log(Level.FINE, "dest port type subclass of source port type: " +
            // portPrevComp.getName() + "<" + portTypePrev + ">" + " <-> " + portNewComp.getName() +
            // "<" + portTypeNew + ">"  );
          } catch (ClassCastException cce) {
            arePortsCompatible = false;
          } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
            System.exit(-1);
          }

          if (arePortsCompatible) // if( portTypePrev.equals(portTypeNew) )
          {
            portPrevComp.connect(portNewComp);
            SacreLib.logger.log(
                Level.FINE,
                "compatible ports connected: "
                    + portPrevComp.getName()
                    + "<"
                    + portTypePrev
                    + ">"
                    + " <-> "
                    + portNewComp.getName()
                    + "<"
                    + portTypeNew
                    + ">");
          } else // Token -> TextToken. This is OK if Token is actually a TextToken. Fork and Merge
                 // is likely to encounter such cases. Can be disallowed with a configuration
                 // variable
          {
            portPrevComp.connect(portNewComp);
            SacreLib.logger.log(
                Level.WARNING,
                "Ports are incompatible but they are connected anyhow. There may be problems while executing the pipeline: "
                    + portPrevComp.getName()
                    + "<"
                    + portTypePrev
                    + ">"
                    + " <-> "
                    + portNewComp.getName()
                    + "<"
                    + portTypeNew
                    + ">");
          }
        }

        //                else
        //                {
        // SacreLib.logger.log(Level.SEVERE, "attempted to connect incompatible ports: " +
        // portPrevComp.getName() + "<" + portTypePrev + ">" + " <-> " + portNewComp.getName() + "<"
        // + portTypeNew + ">" );
        // System.exit(-1);
        //                }
      }
    }
  }