Exemplo n.º 1
0
  private void buildClass(Frame frame) {

    String uri = frame.getUri();

    UmlClass umlClass = new UmlClass(frame, this);
    uri2Class.put(uri, umlClass);

    for (Field field : frame.getDeclaredFields()) {

      RdfType fieldType = field.getRdfType();

      if (fieldType.canAsDatatype()) {
        umlClass.add(field);
      }
    }
  }
Exemplo n.º 2
0
  private void addField(OntResource type, OntProperty p, OntProperty ancestor) {
    int minCardinality = 0;
    int maxCardinality = -1;
    OntResource range = null;

    String typeURI = type.getURI();
    if (typeURI == null) {
      // We only add fields to named types.
      return;
    }

    // Do not add abstract properties.
    if (isAbstract(p)) return;

    Frame frame = manager.getFrameByUri(typeURI);
    if (frame == null) {
      if (isStandard(typeURI)) return;
      logger.warn(
          "Ignoring property "
              + p.getLocalName()
              + " on class "
              + type.getLocalName()
              + ": frame not found");
      return;
    }

    if (frame.getDeclaredFieldByPropertyURI(p.getURI()) != null) return;

    if (p.hasRDFType(OWL.FunctionalProperty)) {
      maxCardinality = 1;
    }

    OntClass restriction = frame.getRestriction(p.getURI());
    range = p.getRange();
    if (range == null && ancestor != null) {
      range = ancestor.getRange();
    }
    if (range == null) {
      //      logger.warn("Ignoring property " + p.getLocalName() + " on class " +
      // type.getLocalName() + ": range not defined");
      //      return;
      range = THING;
    }
    if (restriction != null) {
      Resource onClass = restriction.getPropertyResourceValue(OWL2.onClass);
      if (onClass != null) {
        range = onClass.as(OntResource.class);
        if (restriction.hasProperty(OWL2.minQualifiedCardinality)) {
          minCardinality = restriction.getProperty(OWL2.minQualifiedCardinality).getInt();
        }
        if (restriction.hasProperty(OWL2.maxQualifiedCardinality)) {
          maxCardinality = restriction.getProperty(OWL2.maxQualifiedCardinality).getInt();
        }

      } else {
        if (restriction.hasProperty(OWL.minCardinality)) {
          minCardinality = restriction.getProperty(OWL.minCardinality).getInt();
        }
        if (restriction.hasProperty(OWL.maxCardinality)) {
          maxCardinality = restriction.getProperty(OWL.maxCardinality).getInt();
        }
      }
    }

    Field field = null;

    String rangeURI = range.getURI();
    if (rangeURI == null) {

      field = createListField(frame, p, range);

      if (field == null) {
        logger.warn(
            "Ignoring property "
                + p.getLocalName()
                + " on class "
                + type.getLocalName()
                + ": range has no URI");
        return;
      }
    } else {

      field = new Field(frame, p, range, minCardinality, maxCardinality);

      if (field.getRdfType() == null) {
        logger.warn(
            "Failed to create RdfType for field "
                + field.getLocalName()
                + " of type "
                + field.getType().getURI());
      }
    }

    Resource rawInverse = p.getPropertyResourceValue(OWL.inverseOf);
    if (rawInverse != null && rawInverse.canAs(OntProperty.class)) {
      field.setInverseOf(rawInverse.as(OntProperty.class));
    }
    frame.getDeclaredFields().add(field);
  }
Exemplo n.º 3
0
  private void addChildren(UmlClass umlClass, Frame frame) {

    List<UmlAssociation> parentList = new ArrayList<UmlAssociation>();

    for (Field field : frame.getDeclaredFields()) {
      RdfType fieldType = field.getRdfType();

      Field inverseField = field.getInverseField();

      UmlClass otherClass = null;
      if (fieldType.canAsFrame()) {
        otherClass = getUmlClassByURI(fieldType.getUri());
      } else if (fieldType.canAsListType()) {
        otherClass = getUmlClassByURI(fieldType.asListType().getElementType().getUri());
      }

      if (otherClass != null) {

        InverseProperty inverse = field.getInverseProperty();

        Encapsulation inverseEncapsulation =
            inverseField == null ? inverse.getEncapsulation() : inverseField.getEncapsulation();

        Encapsulation encapsulation = field.getEncapsulation();

        if (encapsulation == Encapsulation.NONE && inverseEncapsulation != Encapsulation.NONE) {
          //
          // The other class is the parent

          UmlAssociationEnd end0 = new UmlAssociationEnd(umlClass);
          end0.setMultiplicity(inverse.getMultiplicity());
          defineEnd(end0, inverseField, encapsulation);

          UmlAssociationEnd end1 = new UmlAssociationEnd(otherClass);
          defineEnd(end1, field, inverseEncapsulation);

          UmlAssociation assoc = new UmlAssociation(end0, end1);

          otherClass.addChild(assoc);
          parentList.add(assoc);

        } else {

          UmlAssociationEnd end0 = new UmlAssociationEnd(umlClass);
          UmlAssociationEnd end1 = new UmlAssociationEnd(otherClass);
          defineEnd(end0, inverseField, encapsulation);
          defineEnd(end1, field, inverseEncapsulation);

          UmlAssociation assoc = new UmlAssociation(end0, end1);

          umlClass.addChild(assoc);
          parentList.add(assoc);
        }

      } else {
        // TODO: handle other conditions

      }
    }

    addParentList(umlClass, parentList);
  }