コード例 #1
0
  /**
   * Returns the IRI of the resource if it has one, or else Object's toString() value. This method
   * uses the IRIMap in the currently active KnowledgeBase.
   *
   * @return the String of the resource
   */
  @Override
  public String toString() {
    Optional<IRI> iri = SemanticSystem.getActiveKnowledgeBase().getIRIMap().getIRI(this);

    String str;

    if (iri.isPresent()) {
      str = iri.get().toString();
    } else {
      str = super.toString();
    }

    return str;
  }
コード例 #2
0
  /**
   * Constructs the resource with an IRI.
   *
   * @param iri the IRI for the resource
   * @throws IRIInUseException if the IRI is already in use by another resource
   * @throws NullPointerException if the argument "iri" is null
   */
  public ResourceNoAttributes(IRI iri) throws IRIInUseException, NullPointerException {
    // remaining code is in ResourceInitializationAspect

    if (iri == null) {
      throw new NullPointerException("The argument 'iri' cannot be null");
    }

    IRIMap iriMap = SemanticSystem.getIRIMap();

    if (iriMap.getResource(iri).isPresent()) {
      throw new IRIInUseException("The IRI " + iri + " is already in use.");
    }

    iriMap.setIRI(this, iri);
  }