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

it.tidalwave.bluebill.othermarshallers.StatementMarshallerFactoryImpl Maven / Gradle / Ivy

There is a newer version: 1.0.16
Show newest version
/***********************************************************************************************************************
 *
 * 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.othermarshallers;

import it.tidalwave.semantic.io.spi.StatementMarshallerFactory;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Map;
import org.openide.util.lookup.ServiceProvider;
import it.tidalwave.util.As;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.semantic.io.spi.StatementMarshaller;
import it.tidalwave.mobile.media.Media;
import it.tidalwave.observation.Location;
import it.tidalwave.observation.Observable;
import it.tidalwave.observation.Observation;
import it.tidalwave.observation.ObservationItem;
import it.tidalwave.observation.ObservationSet;
import it.tidalwave.observation.Observer;
import it.tidalwave.observation.Source;
import it.tidalwave.observation.simple.rdf.SimpleLocationMarshaller;
import it.tidalwave.observation.simple.rdf.SimpleObservableMarshaller;
import it.tidalwave.observation.simple.rdf.SimpleObservationItemMarshaller;
import it.tidalwave.observation.simple.rdf.SimpleObservationSetMarshaller;
import it.tidalwave.observation.simple.rdf.SimpleObservationMarshaller;
import it.tidalwave.observation.simple.rdf.SimpleObserverMarshaller;
import it.tidalwave.observation.simple.rdf.SimpleSourceMarshaller;
import it.tidalwave.bluebill.othermarshallers.MediaMarshaller;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@ServiceProvider(service=StatementMarshallerFactory.class)
public class StatementMarshallerFactoryImpl implements StatementMarshallerFactory
  {
    private final Map, StatementMarshaller> marshallerMapByClass = new HashMap, StatementMarshaller>();

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public StatementMarshallerFactoryImpl()
      {
        // IXME: discover with Lookup
//        tripleMarshallerMapByClass.put(FactSheet.class, new FactSheetTripleMarshaller());
        marshallerMapByClass.put(Media.class,           new MediaMarshaller());
        marshallerMapByClass.put(ObservationSet.class,  new SimpleObservationSetMarshaller());
        marshallerMapByClass.put(Observation.class,     new SimpleObservationMarshaller());
        marshallerMapByClass.put(ObservationItem.class, new SimpleObservationItemMarshaller());
        marshallerMapByClass.put(Observable.class,      new SimpleObservableMarshaller());
        marshallerMapByClass.put(Observer.class,        new SimpleObserverMarshaller());
        marshallerMapByClass.put(Source.class,          new SimpleSourceMarshaller());
        marshallerMapByClass.put(Location.class,        new SimpleLocationMarshaller());
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    public StatementMarshaller findStatementMarshallerFor (final @Nonnull As object) // TODO: replace with object.as(TripleFactory)
      throws NotFoundException
      {
        final Class clazz = object.getClass();

        for (final Entry, StatementMarshaller> entry : marshallerMapByClass.entrySet())
          {
            if (entry.getKey().isAssignableFrom(clazz))
              {
                return entry.getValue();
              }
          }

        throw new NotFoundException(clazz.getName());
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy