svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / driver / impl / PersistenceBasedLegendReader.java @ 41055
History | View | Annotate | Download (3.47 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.driver.impl; |
25 |
|
26 |
import java.io.File; |
27 |
import java.io.FileInputStream; |
28 |
import java.io.IOException; |
29 |
import java.io.InputStream; |
30 |
|
31 |
import org.gvsig.fmap.geom.Geometry; |
32 |
import org.gvsig.fmap.geom.GeometryLocator; |
33 |
import org.gvsig.fmap.geom.type.GeometryType; |
34 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
35 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
36 |
import org.gvsig.fmap.mapcontext.exceptions.IncompatibleLegendReadException; |
37 |
import org.gvsig.fmap.mapcontext.exceptions.ReadLegendException; |
38 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
39 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
40 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
41 |
import org.gvsig.tools.ToolsLocator; |
42 |
import org.gvsig.tools.locator.LocatorException; |
43 |
import org.gvsig.tools.persistence.PersistenceManager; |
44 |
|
45 |
|
46 |
/**
|
47 |
* Legend reader that uses the standard persistence
|
48 |
*/
|
49 |
public class PersistenceBasedLegendReader implements ILegendReader { |
50 |
|
51 |
public ILegend read(File inFile, int geometryType) |
52 |
throws ReadLegendException, IncompatibleLegendReadException,
|
53 |
IOException {
|
54 |
|
55 |
InputStream istr = null; |
56 |
istr = new FileInputStream(inFile); |
57 |
ILegend resp = null;
|
58 |
|
59 |
try {
|
60 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
61 |
Object inobj = manager.getObject(istr);
|
62 |
resp = (ILegend) inobj; |
63 |
} catch (Exception exc) { |
64 |
throw new ReadLegendException(inFile, exc); |
65 |
} |
66 |
istr.close(); |
67 |
|
68 |
if (resp instanceof IVectorLegend) { |
69 |
IVectorLegend vleg = (IVectorLegend) resp; |
70 |
|
71 |
GeometryType foundgt = null;
|
72 |
try {
|
73 |
foundgt = GeometryLocator.getGeometryManager().getGeometryType( |
74 |
vleg.getShapeType(), Geometry.SUBTYPES.GEOM2D); |
75 |
} catch (Exception e) { |
76 |
throw new IncompatibleLegendReadException( |
77 |
inFile, geometryType, e); |
78 |
} |
79 |
|
80 |
if (geometryType != Geometry.TYPES.GEOMETRY &&
|
81 |
!foundgt.isTypeOf(geometryType)) { |
82 |
|
83 |
throw new IncompatibleLegendReadException( |
84 |
inFile, |
85 |
geometryType, |
86 |
new Exception("Geometry type found: " + vleg.getShapeType())); |
87 |
} |
88 |
} |
89 |
return resp;
|
90 |
} |
91 |
|
92 |
} |