Пример #1
0
  private void applyFilters() {
    // build filter set
    HashSet<String> filterSet = new HashSet<String>();
    // filter primtives
    if (this.parser.filterPrimitiveClasses) {
      for (UMLClass cl : classList) {
        if (cl.getPackageName().startsWith("java")) {
          filterSet.add(cl.getId());
        }
      }
    }
    // filter root class
    for (UMLClass cl : classList) {
      if (cl.getPackageName().equals("")) {
        filterSet.add(cl.getId());
      }
    }

    // filter classes
    List<UMLClass> filteredClasses = new ArrayList<UMLClass>(this.classList.size());
    for (UMLClass cl : this.classList) {
      if (!filterSet.contains(cl.getId())) {
        filteredClasses.add(cl);
      }
    }
    this.classList = filteredClasses;

    // filter assocations
    List<UMLAssociation> filteredAssociations =
        new ArrayList<UMLAssociation>(this.assocList.size());
    for (UMLAssociation assoc : this.assocList) {
      if (!filterSet.contains(
              assoc
                  .getSourceUMLAssociationEdge()
                  .getUMLAssociationEdge()
                  .getUMLClassReference()
                  .getRefid())
          && !filterSet.contains(
              assoc
                  .getTargetUMLAssociationEdge()
                  .getUMLAssociationEdge()
                  .getUMLClassReference()
                  .getRefid())) {
        filteredAssociations.add(assoc);
      }
    }
    this.assocList = filteredAssociations;

    // filter generalizations
    List<UMLGeneralization> filteredGeneralizations =
        new ArrayList<UMLGeneralization>(this.genList.size());
    for (UMLGeneralization gen : this.genList) {
      if (!filterSet.contains(gen.getSubClassReference().getRefid())
          && !filterSet.contains(gen.getSuperClassReference().getRefid())) {
        filteredGeneralizations.add(gen);
      }
    }
    this.genList = filteredGeneralizations;
  }
Пример #2
0
  private void handleAssociationEnd(Attributes atts) {
    // get the most recently found association
    UMLAssociation assoc = assocList.get(assocList.size() - 1);
    // TODO: something with type?
    String type = atts.getValue(XMIConstants.XMI_TYPE_ATTRIBUTE);
    boolean isNavigable =
        "true".equals(atts.getValue(XMIConstants.XMI_UML_ASSOCIATION_IS_NAVIGABLE));

    edge = new UMLAssociationEdge();
    if (assoc.getSourceUMLAssociationEdge() == null) {
      assoc.setSourceUMLAssociationEdge(new UMLAssociationSourceUMLAssociationEdge(edge));
      sourceNavigable = isNavigable;
    } else {
      assoc.setTargetUMLAssociationEdge(new UMLAssociationTargetUMLAssociationEdge(edge));
      targetNavigable = isNavigable;
    }
    edge.setRoleName(atts.getValue(XMIConstants.XMI_NAME_ATTRIBUTE));
    edge.setUMLClassReference(new UMLClassReference());
  }
Пример #3
0
  @Override
  public void endElement(String uri, String localName, String qName) throws SAXException {
    if (qName.equals(XMIConstants.XMI_UML_PACKAGE)) {
      int index = pkg.lastIndexOf('.');
      if (index == -1) {
        pkg = "";
      } else {
        pkg = pkg.substring(0, index);
      }
    } else if (qName.equals(XMIConstants.XMI_UML_CLASS) && isWithinPackage()) {
      UMLClass cl = classList.get(classList.size() - 1);
      cl.setUmlAttributeCollection(
          new UMLClassUmlAttributeCollection(attribList.toArray(new UMLAttribute[0])));
      attribList.clear();
    } else if (qName.equals(XMIConstants.XMI_UML_ASSOCIATION)) {
      UMLAssociation assoc = assocList.get(assocList.size() - 1);
      if (sourceNavigable && !targetNavigable) {
        UMLAssociationEdge assocEdge = assoc.getSourceUMLAssociationEdge().getUMLAssociationEdge();
        assoc
            .getSourceUMLAssociationEdge()
            .setUMLAssociationEdge(assoc.getTargetUMLAssociationEdge().getUMLAssociationEdge());
        assoc.getTargetUMLAssociationEdge().setUMLAssociationEdge(assocEdge);
      }
      assoc.setBidirectional(sourceNavigable && targetNavigable);
    }

    chars.delete(0, chars.length());
    elementStack.pop();
  }