root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.app.jcrs / org.gvsig.projection.app.jcrs.common / src / main / java / org / gvsig / crs / persistence / RecentCRSsPersistence.java @ 578
History | View | Annotate | Download (3.77 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.crs.persistence; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
import java.util.Collections; |
23 |
import java.util.Iterator; |
24 |
import java.util.List; |
25 |
|
26 |
import org.gvsig.andami.PluginServices; |
27 |
import org.gvsig.andami.PluginsLocator; |
28 |
import org.gvsig.andami.PluginsManager; |
29 |
import org.gvsig.crs.JCrsExtension; |
30 |
import org.gvsig.tools.dynobject.DynObject; |
31 |
|
32 |
/**
|
33 |
* This class is used to save a list of CRSs (using the
|
34 |
* Andami persistence model).
|
35 |
*/
|
36 |
public class RecentCRSsPersistence { |
37 |
|
38 |
/**
|
39 |
* Constructor
|
40 |
*/
|
41 |
public RecentCRSsPersistence() {
|
42 |
} |
43 |
|
44 |
/**
|
45 |
* This method adds a CrsData using the Anadami
|
46 |
* persistence model. If the Crs exists just actualizes
|
47 |
* the type name and the wkt string.
|
48 |
*
|
49 |
* @param crs
|
50 |
* CrsData
|
51 |
*/
|
52 |
public void addCrsData(CrsData crs) { |
53 |
//Esto es para evitar introducir un crs con errores
|
54 |
if(crs.getAuthority()==null || crs.getCode()==0){ |
55 |
return;
|
56 |
} |
57 |
List crss = this.getRecentsCrsDatas(); |
58 |
boolean found = false; |
59 |
|
60 |
for ( int i = 0; i < crss.size(); i++ ) { |
61 |
CrsData curcrs = (CrsData) crss.get(i); |
62 |
if ( crs.getAuthority().equals(curcrs.getAuthority()) && crs.getCode() == curcrs.getCode() ) {
|
63 |
found = true;
|
64 |
curcrs.setName(crs.getName()); |
65 |
curcrs.setProperies(crs.getProperies()); |
66 |
curcrs.updateLastAccess(); |
67 |
} |
68 |
} |
69 |
|
70 |
if ( !found ) {
|
71 |
if ( crss.size() < 20 ) { //L?mite de almacenamiento: 20 CRSs |
72 |
crss.add(crs); |
73 |
} else {
|
74 |
Collections.sort(crss);
|
75 |
crss.set(0, crs);
|
76 |
} |
77 |
} |
78 |
} |
79 |
|
80 |
/**
|
81 |
* This method returns an array of CrsData objects that
|
82 |
* have been saved using the Andami persistence model.
|
83 |
*
|
84 |
* @return
|
85 |
* CrsData[]
|
86 |
*/
|
87 |
public CrsData[] getArrayOfCrsData() { |
88 |
|
89 |
List crss = this.getRecentsCrsDatas(); |
90 |
Collections.sort(crss);
|
91 |
CrsData[] x = (CrsData[]) crss.toArray(new CrsData[crss.size()]); |
92 |
return x;
|
93 |
} |
94 |
|
95 |
private List getRecentsCrsDatas() { |
96 |
PluginsManager manager = PluginsLocator.getManager(); |
97 |
PluginServices plugin = manager.getPlugin(JCrsExtension.class); |
98 |
DynObject properties = plugin.getPluginProperties(); |
99 |
|
100 |
List crss = (List) properties.getDynValue("recentCRSs"); |
101 |
if ( crss == null ) { |
102 |
crss = new ArrayList(); |
103 |
properties.setDynValue("recentCRSs", crss);
|
104 |
} |
105 |
//Para recuperarse de un posible error en los crs recientes persistidos
|
106 |
for (Iterator iterator = crss.iterator(); iterator.hasNext();) { |
107 |
CrsData crs = (CrsData) iterator.next(); |
108 |
if(crs.getAuthority()==null){ |
109 |
iterator.remove(); |
110 |
} |
111 |
} |
112 |
return crss;
|
113 |
} |
114 |
|
115 |
} |