Esempio n. 1
0
  private Node generateFieldNode(Document doc, ClassField field) {
    Element fieldEl = doc.createElement(EL_FIELD);

    fieldEl.setAttribute(ATR_NAME, field.getName());
    fieldEl.setAttribute(ATR_TYPE, field.getType());

    if (field.isInput()) fieldEl.setAttribute(ATR_NATURE, "input");
    else if (field.isGoal()) fieldEl.setAttribute(ATR_NATURE, "goal");

    if (field.getValue() != null) fieldEl.setAttribute(ATR_VALUE, field.getValue());

    return fieldEl;
  }
Esempio n. 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);
  }
Esempio n. 3
0
  private void parseField(PackageClass newClass, Element fieldNode) {
    String name = fieldNode.getAttribute(ATR_NAME);
    String type = fieldNode.getAttribute(ATR_TYPE);

    ClassField newField;

    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;
        }

        newField = new ClassField(name, type);
        newClass.addSpecField(newField);
      } else {
        newField = newClass.getSpecField(name);

        if (newField == null) {

          collector.collectDiagnostic(
              "Field "
                  + type
                  + " "
                  + name
                  + " in class "
                  + newClass.getName()
                  + " is not declared in the specification");
          return;
        } else if (!newField.getType().equals(type)) {

          collector.collectDiagnostic(
              "Field "
                  + type
                  + " "
                  + name
                  + " in class "
                  + newClass.getName()
                  + " does not match the field declared in the specification: "
                  + newField.getType()
                  + " "
                  + newField.getName());
          return;
        }
      }
    } else {
      newField = new ClassField(name, type);
      newClass.addSpecField(newField);
    }

    newField.setValue(fieldNode.hasAttribute(ATR_VALUE) ? fieldNode.getAttribute(ATR_VALUE) : null);
    newField.setDescription(fieldNode.getAttribute(ATR_DESCRIPTION));
    newField.setHidden(Boolean.parseBoolean(fieldNode.getAttribute(ATR_HIDDEN)));

    String nature = fieldNode.getAttribute(ATR_NATURE);
    if ("input".equals(nature)) newField.setInput(true);
    else if ("goal".equals(nature)) newField.setGoal(true);

    newClass.addField(newField);

    Element gr;
    // known
    if ((gr = getElementByName(fieldNode, EL_KNOWN)) != null
        && (gr = getElementByName(gr, EL_GRAPHICS)) != null) {
      newField.setKnownGraphics(getGraphicsParser().parse(gr));
    }
    // default
    if ((gr = getElementByName(fieldNode, EL_DEFAULT)) != null
        && (gr = getElementByName(gr, EL_GRAPHICS)) != null) {
      newField.setDefaultGraphics(getGraphicsParser().parse(gr));
    }
  }