it.tidalwave.bluebill.taxonomy.elmo.impl.ElmoAnonymousTaxon Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Core - open source birding
* Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* WWW: http://bluebill.tidalwave.it
* SCM: https://kenai.com/hg/bluebill~core-src
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.taxonomy.elmo.impl;
import it.tidalwave.bluebill.taxonomy.Finder;
import it.tidalwave.bluebill.taxonomy.Taxon;
import java.util.Locale;
import java.util.Map;
import javax.annotation.Nonnull;
import org.openrdf.elmo.Entity;
import it.tidalwave.bluebill.taxonomy.Taxonomy;
import it.tidalwave.bluebill.taxonomy.elmo.ElmoTaxonomyVocabulary;
import it.tidalwave.openrdf.elmo.ElmoManagerThreadLocal;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.util.logging.Logger;
import java.util.ArrayList;
import java.util.List;
import org.openrdf.elmo.ResourceManager;
import org.openrdf.elmo.sesame.SesameManager;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.model.impl.URIImpl;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.RepositoryResult;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
//@rdf(ElmoTaxonomyVocabulary.URI_ANONYMOUS_TAXON)
public class ElmoAnonymousTaxon extends Support implements InternalElmoAnonymousTaxon
{
private static final String CLASS = ElmoAnonymousTaxon.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
@Nonnull
private Repository repository;
@Nonnull
private Taxonomy taxonomy;
// @inverseOf(ElmoTaxonomyVocabulary.URI_TAXONOMY_SYNONYM)
// private Set synonyms;
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
public ElmoAnonymousTaxon (final @Nonnull Entity entity)
{
super(entity);
}
@Override @Nonnull
public Finder findSynonyms()
{
try // FIXME: workaround because the @rdf annotation of this.synonym doesn't work
{
final SesameManager em = (SesameManager)ElmoManagerThreadLocal.get();
final ResourceManager rm = em.getResourceManager();
final RepositoryResult triples = em.getConnection().getStatements(null,
new URIImpl(ElmoTaxonomyVocabulary.URI_SCIENTIFIC_NAME_ID),
rm.createResource(getLookup().lookup(Entity.class).getQName()));
final List synonyms = new ArrayList();
while (triples.hasNext())
{
final URI uri = (URI)triples.next().getSubject();
synonyms.add(((InternalElmoTaxonomy)taxonomy)._findConcept(uri.stringValue()));
}
return new YYYFinder(synonyms);
}
catch (NotFoundException e)
{
throw new RuntimeException(e);
}
catch (RepositoryException e)
{
throw new RuntimeException(e);
}
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public void setBindings (final @Nonnull Repository repository,
final @Nonnull Taxonomy taxonomy)
{
logger.finest("setBindings(%s, %s) - @%x", repository, taxonomy, System.identityHashCode(this));
this.taxonomy = taxonomy;
this.repository = repository;
}
public Map getDisplayNames()
{
throw new UnsupportedOperationException("Not supported yet.");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy