Пример #1
0
 protected void toString(XMLElement el) {
   if (el instanceof Activity) {
     Activity act = (Activity) el;
     String str = "\n\tId=" + act.getId();
     str += "\n\tName=" + act.getName();
     str += "\n\tType=" + act.getActivityType();
     Tools ts = act.getActivityTypes().getImplementation().getImplementationTypes().getTools();
     if (ts.size() > 0) {
       Tool t = (Tool) ts.get(0);
       str += "\n\tToolId=" + t.getId();
       Iterator it = t.getActualParameters().toElements().iterator();
       int i = 1;
       while (it.hasNext()) {
         ActualParameter ap = (ActualParameter) it.next();
         str += "\n\t   Ap" + (i++) + "=" + ap.toValue();
       }
     }
     System.err.println("Activity data for " + act + " is:" + str);
   } else {
     if (el instanceof XMLSimpleElement) {
       System.err.println("\n\tElement type=" + el.toName());
     } else if (el instanceof XMLComplexElement) {
       List attributes = ((XMLComplexElement) el).getXMLAttributes();
       String str = "\n\tElement type=" + el.toName();
       for (int i = 0; i < attributes.size(); i++) {
         XMLAttribute attr = (XMLAttribute) attributes.get(i);
         str += "\n\t    " + i + ". attribute [" + attr.toName() + "," + attr.toValue() + "]";
       }
       List elems = ((XMLComplexElement) el).getXMLElements();
       for (int i = 0; i < elems.size(); i++) {
         XMLElement attr = (XMLElement) elems.get(i);
         if (attr instanceof XMLSimpleElement) {
           str += "\n\t    " + i + ". simple el [" + attr.toName() + "," + attr.toValue() + "]";
         } else {
           toString(attr);
         }
       }
       System.err.println(str);
     } else if (el instanceof XMLCollection) {
       String str = "\n\tElement type=" + el.toName();
       List elems = ((XMLCollection) el).toElements();
       for (int i = 0; i < elems.size(); i++) {
         XMLElement attr = (XMLElement) elems.get(i);
         if (attr instanceof XMLAttribute) {
           str += "\n\t    " + i + ". attribute [" + attr.toName() + "," + attr.toValue() + "]";
         }
         if (attr instanceof XMLSimpleElement) {
           str += "\n\t    " + i + ". simple el [" + attr.toName() + "," + attr.toValue() + "]";
         } else {
           toString(attr);
         }
       }
       System.err.println(str);
     }
   }
 }
Пример #2
0
  protected boolean compareToTemplate(XMLElement topEl, XMLElement el, XMLElement tmplEl) {
    boolean ret = true;
    System.out.println("Checking against template");
    if (tmplEl.getClass() == el.getClass()) {
      if (el instanceof XMLSimpleElement && !tmplEl.isEmpty()) {
        ret = el.toValue().equals(tmplEl.toValue());
      } else if (el instanceof XMLAttribute) {
        boolean checkIt = true;
        if ((el.toName().equals("Id") || el.toName().equals("Name"))
            && el.getParent() == topEl
            && !(el instanceof ExtendedAttribute)) {
          checkIt = false;
        } else if (el.toName().equals("Value")) {
          checkIt = false;
        }
        if (checkIt) {
          XMLAttribute attrEl = (XMLAttribute) el;
          XMLAttribute attrTmplEl = (XMLAttribute) tmplEl;
          ret =
              (attrEl.getChoices() == null
                  ? attrTmplEl.getChoices() == null
                  : attrEl.getChoices().equals(attrTmplEl.getChoices()));
          if (ret && !tmplEl.isEmpty()) {
            ret = el.toValue().equals(tmplEl.toValue());
          }
        }
      } else if (el instanceof XMLComplexElement) {
        if (!tmplEl.toValue().equals("") && !tmplEl.toValue().equals(el.toValue())) {
          ret = false;
        } else {
          XMLComplexElement cmplxEl = (XMLComplexElement) el;
          Iterator it = ((XMLComplexElement) tmplEl).toElementMap().entrySet().iterator();
          while (it.hasNext()) {
            Map.Entry me = (Map.Entry) it.next();
            String subElName = (String) me.getKey();
            XMLElement subEl = (XMLElement) me.getValue();
            if (!subEl.isEmpty()) {
              if (!compareToTemplate(topEl, cmplxEl.get(subElName), subEl)) {
                ret = false;
                break;
              }
            }
          }
        }
      } else if (el instanceof XMLCollection) {
        if (!tmplEl.toValue().equals("") && !tmplEl.toValue().equals(el.toValue())) {
          ret = false;
        } else {
          XMLCollection col = (XMLCollection) el;
          List cels = ((XMLCollection) tmplEl).toElements();
          for (int i = 0; i < cels.size(); i++) {
            XMLElement tcel = (XMLElement) cels.get(i);
            if (tcel instanceof ActualParameter || tcel instanceof FormalParameter) {
              if (!compareToTemplate(topEl, col.get(i), tcel)) {
                ret = false;
                break;
              }
            } else {
              boolean btt = false;
              for (int j = 0; j < col.size(); j++) {
                XMLElement e = (XMLElement) col.get(j);
                if (compareToTemplate(topEl, e, tcel)) {
                  btt = true;
                  break;
                }
              }
              if (!btt) {
                ret = btt;
              }
            }
          }
        }
      } else if (el instanceof XMLComplexChoice) {
        XMLElement tmplChsn = ((XMLComplexChoice) tmplEl).getChoosen();
        XMLElement elChsn = ((XMLComplexChoice) el).getChoosen();
        ret = compareToTemplate(topEl, elChsn, tmplChsn);
      }
    } else {
      ret = false;
    }

    return ret;
  }