All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.semanticweb.owlapi.formats.OWLOntologyFormatFactoryRegistry Maven / Gradle / Ivy

The newest version!
/**
 * 
 */
package org.semanticweb.owlapi.formats;

import com.github.ansell.abstractserviceloader.AbstractServiceLoader;

/**
 * @author Peter Ansell [email protected]
 * 
 */
public class OWLOntologyFormatFactoryRegistry extends AbstractServiceLoader
{
    private static final OWLOntologyFormatFactoryRegistry instance = new OWLOntologyFormatFactoryRegistry();
    
    /**
     * @return the instance
     */
    public static OWLOntologyFormatFactoryRegistry getInstance()
    {
        return OWLOntologyFormatFactoryRegistry.instance;
    }
    
    public OWLOntologyFormatFactoryRegistry()
    {
        super(OWLOntologyFormatFactory.class);
    }
    
    @Override
    public String getKey(final OWLOntologyFormatFactory service)
    {
        return service.getKey();
    }
    
    /**
     * Returns the first OWLOntologyFormatFactory
     * 
     * NOTE: The order in which the services are loaded an examined is not deterministic so this
     * method may return different results if the MIME-Type matches more than one
     * OWLOntologyFormatFactory. However, if the default MIME-Types are always unique, the correct
     * factory will always be chosen
     * 
     * @param mimeType
     * @return
     */
    public OWLOntologyFormatFactory getByMIMEType(String mimeType)
    {
        if(mimeType == null)
        {
            throw new IllegalArgumentException("MIME-Type cannot be null");
        }
        
        for(OWLOntologyFormatFactory nextFactory : this.getAll())
        {
            if(mimeType.equals(nextFactory.getDefaultMIMEType()))
            {
                return nextFactory;
            }
        }
        
        for(OWLOntologyFormatFactory nextFactory : this.getAll())
        {
            if(nextFactory.getMIMETypes().contains((mimeType)))
            {
                return nextFactory;
            }
        }
        
        return null;
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy