@Override
  public synchronized OWLOntologyID addOntology(OntologyInputSource<?> ontologySource)
      throws UnmodifiableOntologyCollectorException {

    // Check for error conditions.
    if (locked) throw new UnmodifiableOntologyCollectorException(this);
    if (ontologySource == null)
      throw new IllegalArgumentException("Ontology source cannot be null.");

    log.debug("Adding ontology to collector {}", getID());
    OWLOntologyID key = null;

    if (ontologySource.hasRootOntology()) {
      long before = System.currentTimeMillis();
      Object o = ontologySource.getRootOntology();
      // // FIXME restore ownership management, but maybe not by directly setting the versionIRI
      // if (ontologyProvider.hasOntology(id.getOntologyIRI())) if (o instanceof MGraph)
      // claimOwnership((MGraph) o);
      // else if (o instanceof OWLOntology) claimOwnership((OWLOntology) o);

      // Check the origin anyhow, as it may be useful for setting aliases with physical locations
      // etc.
      if (ontologySource.hasOrigin())
        key = ontologyProvider.loadInStore(o, false, ontologySource.getOrigin());
      else key = ontologyProvider.loadInStore(o, false);
      if (key != null) {
        managedOntologies.add(key);
        // Note that imported ontologies are not considered as managed! TODO should we change this?
        log.info("Add ontology completed in {} ms.", (System.currentTimeMillis() - before));
        // Fire the event
        fireOntologyAdded(key);
      }
    } else if (ontologySource.hasOrigin()) {
      // Just the origin : see if it is satisfiable
      log.debug("Checking origin satisfiability...");
      Origin<?> origin = ontologySource.getOrigin();
      Object ref = origin.getReference();
      log.debug("Origin wraps a {}", ref.getClass().getCanonicalName());
      if (ref instanceof IRI)
        try {
          log.debug("Deferring addition to physical IRI {} (if available).", ref);
          key = addOntology(new RootOntologySource((IRI) ref));
        } catch (OWLOntologyCreationException e) {
          throw new RuntimeException(e);
        }
      else if (ref instanceof UriRef) {
        log.debug("Deferring addition to stored Clerezza graph {} (if available).", ref);
        key = addOntology(new GraphSource((UriRef) ref));
      } else if (ref instanceof OWLOntologyID) {
        OWLOntologyID idref = (OWLOntologyID) ref;
        log.debug("Deferring addition to stored ontology with public key {} (if available).", ref);
        if (!ontologyProvider.hasOntology(idref)) throw new MissingOntologyException(this, idref);
        key = idref;
        if (managedOntologies.add(idref)) fireOntologyAdded(idref);
      } else throw new IllegalArgumentException("Invalid origin " + origin);
    } else
      throw new IllegalArgumentException(
          "Ontology source must provide either an ontology object, or a way to reference one (i.e. an origin).");
    log.info("Public key : {}", key);
    return key;
  }