Пример #1
0
  private Element generatePortNode(Document doc, Port port) {
    Element portEl = doc.createElement(EL_PORT);

    portEl.setAttribute(ATR_NAME, port.getName());
    portEl.setAttribute(ATR_TYPE, port.getType());
    portEl.setAttribute(ATR_X, Integer.toString(port.getX()));
    portEl.setAttribute(ATR_Y, Integer.toString(port.getY()));
    portEl.setAttribute(ATR_PORT_CONNECTION, port.isArea() ? "area" : "");
    portEl.setAttribute(ATR_STRICT, Boolean.toString(port.isStrict()));
    portEl.setAttribute(ATR_MULTI, Boolean.toString(port.isMulti()));

    return portEl;
  }
Пример #2
0
  private void parsePort(PackageClass newClass, Element portNode) {
    String name = portNode.getAttribute(ATR_NAME);
    String type = portNode.getAttribute(ATR_TYPE);
    String x = portNode.getAttribute(ATR_X);
    String y = portNode.getAttribute(ATR_Y);
    String portConnection = portNode.getAttribute(ATR_PORT_CONNECTION);
    String strict = portNode.getAttribute(ATR_STRICT);
    String multi = portNode.getAttribute(ATR_MULTI);

    ClassField cf = newClass.getSpecField(name);

    if (newClass.getComponentType().hasSpec()) {

      if (name.indexOf(".") > -1) {
        // TODO - temporarily do not dig into hierarchy
        int idx = name.indexOf(".");
        String root = name.substring(0, idx);

        if (newClass.getSpecField(root) == null) {
          collector.collectDiagnostic(
              "Field "
                  + root
                  + " in class "
                  + newClass.getName()
                  + " is not declared in the specification, variable "
                  + type
                  + " "
                  + name
                  + " ignored ");
          return;
        }

        newClass.addSpecField(new ClassField(name, type));
      } else if (!TypeUtil.TYPE_THIS.equalsIgnoreCase(name)) {
        if (cf == null) {

          collector.collectDiagnostic(
              "Port "
                  + type
                  + " "
                  + name
                  + " in class "
                  + newClass.getName()
                  + " does not have the corresponding field in the specification");
        } else if (!cf.getType().equals(type)
            // type may be declared as "alias", however cf.getType() returns e.g. "double[]", ignore
            // it
            && !(cf.isAlias() && TypeUtil.TYPE_ALIAS.equals(type))) {

          collector.collectDiagnostic(
              "Port "
                  + type
                  + " "
                  + name
                  + " in class "
                  + newClass.getName()
                  + " does not match the field declared in the specification: "
                  + cf.getType()
                  + " "
                  + cf.getName());
        }
      }
    }

    Port newPort =
        new Port(
            name,
            type,
            Integer.parseInt(x),
            Integer.parseInt(y),
            portConnection,
            Boolean.parseBoolean(strict),
            Boolean.parseBoolean(multi));

    if (portNode.hasAttribute(ATR_ID)) newPort.setId(portNode.getAttribute(ATR_ID));

    Element gr;
    // open
    if ((gr = getElementByName(portNode, EL_OPEN)) != null
        && (gr = getElementByName(gr, EL_GRAPHICS)) != null) {
      newPort.setOpenGraphics(getGraphicsParser().parse(gr));
    }

    // closed
    if ((gr = getElementByName(portNode, EL_CLOSED)) != null
        && (gr = getElementByName(gr, EL_GRAPHICS)) != null) {
      newPort.setClosedGraphics(getGraphicsParser().parse(gr));
    }

    newClass.addPort(newPort);
  }