/* * $Id: Decoders.java 163 2010-03-08 22:29:37Z maesenka $ * * This file is part of Hibernate Spatial, an extension to the * hibernate ORM solution for geographic data. * * Copyright © 2007-2010 Geovise BVBA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * For more information, visit: http://www.hibernatespatial.org/ */ package org.hibernatespatial.sqlserver.convertors; import com.vividsolutions.jts.geom.Geometry; import org.hibernatespatial.HBSpatialExtension; import org.hibernatespatial.mgeom.MGeometryFactory; import java.util.ArrayList; import java.util.List; /** * @author Karel Maesen, Geovise BVBA. * Date: Nov 2, 2009 */ public class Decoders { final private static List> DECODERS = new ArrayList>(); static { MGeometryFactory factory = HBSpatialExtension.getDefaultGeomFactory(); //Decoders DECODERS.add(new PointDecoder(factory)); DECODERS.add(new LineStringDecoder(factory)); DECODERS.add(new PolygonDecoder(factory)); DECODERS.add(new MultiLineStringDecoder(factory)); DECODERS.add(new MultiPolygonDecoder(factory)); DECODERS.add(new MultiPointDecoder(factory)); DECODERS.add(new GeometryCollectionDecoder(factory)); } private static Decoder decoderFor(SqlServerGeometry object) { for (Decoder decoder : DECODERS) { if (decoder.accepts(object)) return decoder; } throw new IllegalArgumentException("No decoder for type " + object.openGisType()); } public static Geometry decode(byte[] raw) { SqlServerGeometry sqlServerGeom = SqlServerGeometry.load(raw); Decoder decoder = decoderFor(sqlServerGeom); return decoder.decode(sqlServerGeom); } public static Decoder decoderFor(OpenGisType type) { for (Decoder decoder : DECODERS) { if (decoder.accepts(type)) return decoder; } throw new IllegalArgumentException("No decoder for type " + type); } }