/* (c) 2014 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.core.model.adapter; import javax.xml.bind.annotation.adapters.XmlAdapter; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; import com.vividsolutions.jts.io.WKTWriter; // TODO: Auto-generated Javadoc /** * The Class PolygonAdapter. */ public class PolygonAdapter extends XmlAdapter<String, Polygon> { /* (non-Javadoc) * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object) */ @Override public Polygon unmarshal(String val) throws ParseException { WKTReader wktReader = new WKTReader(); Geometry the_geom = wktReader.read(val); if (the_geom instanceof Polygon) { if (the_geom.getSRID() == 0) the_geom.setSRID(4326); return (Polygon) the_geom; } throw new ParseException("WKB val is not a Polygon."); } /* (non-Javadoc) * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object) */ @Override public String marshal(Polygon the_geom) throws ParseException { if (the_geom != null) { WKTWriter wktWriter = new WKTWriter(); if (the_geom.getSRID() == 0) the_geom.setSRID(4326); return wktWriter.write(the_geom); } else { throw new ParseException("Polygon obj is null."); } } }