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

it.tidalwave.bluebill.factsheet.semantic.io.FactSheetStatementUnmarshallerFactory Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * blueBill Mobile - Android - 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/mobile
 * SCM: https://java.net/hg/bluebill-mobile~android-src
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.factsheet.semantic.io;

import it.tidalwave.semantic.io.impl.Converter;
import javax.annotation.Nonnull;
import java.util.List;
import org.openrdf.model.Statement;
import it.tidalwave.semantic.io.spi.StatementUnmarshaller;
import it.tidalwave.semantic.io.spi.StatementUnmarshallerFactory;
import it.tidalwave.semantic.io.spi.StatementUnmarshallerSupport;
import it.tidalwave.util.Id;
import it.tidalwave.util.NotFoundException;
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import static it.tidalwave.semantic.vocabulary.FoafVocabulary.*;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@Slf4j
public class FactSheetStatementUnmarshallerFactory implements StatementUnmarshallerFactory
  {
    private static final GenericEntityUnmarshaller DEFAULT_UNMARSHALLER = new GenericEntityUnmarshaller();
    private static final Id ID_TAXON = new Id("http://rs.tdwg.org/dwc/2009-12-07/terms/Taxon"); // FIXME: put into a Vocabulary
    
    private final Map unmarshallerMapByType = new HashMap();

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public FactSheetStatementUnmarshallerFactory()
      {
        // FIXME: discover with Lookup
        unmarshallerMapByType.put(ID_TAXON,  new FactSheetUnmarshaller());
        unmarshallerMapByType.put(ID_FOAF_IMAGE,  new FoafImageUnmarshaller());
//        unmarshallerMapByType.put(new Id("http://xmlns.com/foaf/0.1/Agent"),  new GenericEntityUnmarshaller());
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    public StatementUnmarshaller findStatementUnmarshallerFor (final @Nonnull List statements)
      throws NotFoundException
      {
        StatementUnmarshaller unmarshaller = null; // = new EntityTripleUnmarshaller();

        // Find the best factory - FIXME: you should pick the most specialized one, but where to find hierarchy info?
        for (final Statement statement :statements)
          {
            StatementUnmarshallerSupport temp = null;

            if (statement.getPredicate().stringValue().equals(it.tidalwave.semantic.io.impl.Vocabulary.RDF_TYPE.stringValue()))
              {
                temp = unmarshallerMapByType.get(Converter.valueToId(statement.getObject()));
              }
//            else if (statement.getPredicate().stringValue().equals(Vocabulary.DC_TYPE.stringValue())
//                  && statement.getObject().stringValue().startsWith("http://purl.org/dc/dcmitype/"))
//              {
//                temp = new MediaUnmarshaller();
//              }

            if (temp != null)
              {
                unmarshaller = temp;
              }
          }

        if (unmarshaller == null)
          {
            unmarshaller = DEFAULT_UNMARSHALLER;
          }
        
//        log.trace(">>>> returning {} for {}", unmarshaller, statements);

        return unmarshaller;
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy