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

it.tidalwave.geo.location.elmo.impl.ElmoGeoSchemaFactory Maven / Gradle / Ivy

/***********************************************************************************************************************
 *
 * forceTen - open source geography
 * Copyright (C) 2007-2012 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://forceten.tidalwave.it
 * SCM: https://bitbucket.org/tidalwave/forceten-src
 *
 **********************************************************************************************************************/
package it.tidalwave.geo.location.elmo.impl;

import javax.annotation.Nonnull;
import javax.xml.namespace.QName;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.geo.geocoding.GeoCoder;
import it.tidalwave.geo.location.GeoSchema;
import it.tidalwave.semantic.EntityFactory;
import static it.tidalwave.role.MutableDisplayable.MutableDisplayable;
import static it.tidalwave.semantic.OwlThing.OwlThing;
import static it.tidalwave.semantic.SkosConceptScheme.SkosConceptScheme; 

/***********************************************************************************************************************
 *
 * @author Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
public class ElmoGeoSchemaFactory 
  {
    private final static String CLASS = ElmoGeoSchemaFactory.class.getName();
    private final static Logger logger = Logger.getLogger(CLASS);

    private final static EntityFactory FACTORY =
                         EntityFactory.
                                      forInterface(GeoSchema.class).
                                      withImplementation(ElmoGeoSchema.class).
                                      andRoles(OwlThing, SkosConceptScheme).create();

    // FIXME: make it weak. Not identity, since QName is not flyweight
//    private static final HashMap FLYWEIGHT_CACHE =
//            new HashMap();

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public static GeoSchema findOrCreate (final @Nonnull GeoCoder geoCoder)
      {
        logger.fine("findOrCreate(%s)", geoCoder);
        final QName qName = new QName("http://www.geonames.org"); // FIXME: should be provided by GeoCoder.getId()
//          final QName qName = new QName(geoCoder.getId());
        final GeoSchema geoSchema = FACTORY.findOrCreate(qName, new EntityFactory.EntityInitializer()
          {
            @Override
            public void initialize (final @Nonnull ElmoGeoSchema elmoGeoSchema)
              {
                elmoGeoSchema.geoCoderName = geoCoder.getName();
                elmoGeoSchema.as(MutableDisplayable).setDisplayName(geoCoder.getName());
              }
          });

        logger.finer(">>>> returning %s", geoSchema);

        return geoSchema;
          
//        final GeoSchema flyWeightGeoSchema = flyWeight(geoSchema);
//
//        if (geoSchema == flyWeightGeoSchema) // new one - FIXME: move to a factory initializer
//          {
//          }
//
//        logger.finer(">>>> returning %s", flyWeightGeoSchema);
//
//        return flyWeightGeoSchema;
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Nonnull
//    private static synchronized GeoSchema flyWeight (final @Nonnull GeoSchema geoSchema)
//      {
//        final QName qName = geoSchema.as(Entity).getQName();
//        GeoSchema flyWeightSchema = FLYWEIGHT_CACHE.get(qName);
//
//        if (flyWeightSchema == null)
//          {
//            flyWeightSchema = geoSchema;
//            FLYWEIGHT_CACHE.put(qName, flyWeightSchema);
//          }
//
//        return flyWeightSchema;
//      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy