Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / MemoryExpansionFile.java @ 35160

History | View | Annotate | Download (5.97 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. 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
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.edition;
42

    
43
import java.util.ArrayList;
44
import java.util.HashMap;
45

    
46
import com.iver.cit.gvsig.exceptions.expansionfile.CloseExpansionFileException;
47
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
48
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException;
49
import com.iver.cit.gvsig.exceptions.expansionfile.OpenExpansionFileException;
50
import com.iver.cit.gvsig.fmap.core.IRow;
51

    
52

    
53
/**
54
 * Implementaci?n en memoria de ExpansionFile.
55
 *
56
 * @author Vicente Caballero Navarro
57
 */
58
public class MemoryExpansionFile implements ExpansionFile {
59
        ArrayList rows = new ArrayList();
60
        EditableAdapter edAdapter;
61

    
62
        private MemoryExpansionFile() {
63
                // private makes sure nobody calls this
64
        }
65
        
66
        private class InternalRow
67
        {
68
                private IRowEdited row;
69
                private int indexInternalFields;
70
                public InternalRow(IRowEdited row, int indexInternalFields)
71
                {
72
                        this.row = row;
73
                        this.indexInternalFields = indexInternalFields;
74
                }
75
                public int getIndexInternalFields() {
76
                        return indexInternalFields;
77
                }
78
                public IRowEdited getRow() {
79
                        return row;
80
                }
81
        }
82

    
83
        public MemoryExpansionFile(EditableAdapter edAdapter)
84
        {
85
                this.edAdapter = edAdapter;
86
        }
87

    
88
        //BitSet invalidRows = new BitSet();
89
        /**
90
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#addRow(IRow, int)
91
         */
92
        public int addRow(IRow row, int status, int indexInternalFields) throws ExpansionFileWriteException {
93
                int newIndex = rows.size();
94
                IRowEdited edRow = new DefaultRowEdited(row,
95
                                status, newIndex);
96
                InternalRow iRow = new InternalRow(edRow, indexInternalFields);
97
                rows.add(iRow);
98

    
99
                return newIndex;
100
        }
101

    
102
        /**
103
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#modifyRow(int,
104
         *                 IRow)
105
         */
106
//        public int modifyRow(int index, IRow row, int indexInternalFields) throws IOException {
107
//                /*if (invalidRows.get(index)) {
108
//                        throw new RuntimeException(
109
//                                "Se ha intentado modificar una geometr?a que ha sido borrada anteriormente");
110
//                }
111
//*/
112
//                //invalidateRow(index);
113
//                IRowEdited edRow = new DefaultRowEdited(row,
114
//                                IRowEdited.STATUS_MODIFIED, index);
115
//
116
//                InternalRow iRow = new InternalRow(edRow, indexInternalFields);
117
//                rows.add(iRow);
118
//
119
//
120
//                return rows.size() - 1;
121
//        }
122

    
123
        public int modifyRow(int index, IRow row, int indexInternalFields) throws ExpansionFileWriteException {
124
                  /*if (invalidRows.get(index)) {
125
                   throw new RuntimeException(
126
                    "Se ha intentado modificar una geometr?a que ha sido borrada anteriormente");
127
                  }
128
                */
129
                  //invalidateRow(index);
130
                  InternalRow iOldRow = (InternalRow) rows.get(index);
131
                  IRowEdited edRow = new DefaultRowEdited(row,
132
                    iOldRow.getRow().getStatus(), index);
133

    
134
                  InternalRow iRow = new InternalRow(edRow, indexInternalFields);
135
                  rows.add(iRow);
136

    
137

    
138
                  return rows.size() - 1;
139
                 }
140

    
141
        /**
142
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#getRow(int)
143
         */
144
        public IRowEdited getRow(int index) throws ExpansionFileReadException {
145
                /*if (invalidRows.get(index)) {
146
                        return null;
147
                }
148
*/
149
                InternalRow iRow = (InternalRow) rows.get(index);
150
                int indexInternalFields = iRow.getIndexInternalFields();
151
                return edAdapter.createExternalRow(iRow.getRow(), indexInternalFields);
152
                // return iRow.getRow();
153
        }
154

    
155
        /**
156
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#invalidateRow(int)
157
         */
158
        /*public void invalidateRow(int index) {
159
                invalidRows.set(index, true);
160
        }
161
*/
162
        /**
163
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#compact()
164
         */
165
        public void compact(HashMap relations) {
166
        /*        ArrayList geoAux = new ArrayList();
167
                Iterator iter = relations.keySet().iterator();
168
                HashMap aux = new HashMap();
169
                int n = 0;
170

171
                while (iter.hasNext()) {
172
                        Integer virtualIndex = (Integer) iter.next();
173
                        Integer expansionIndex = (Integer) relations.get(virtualIndex);
174

175
                        if (!invalidRows.get(expansionIndex.intValue())){
176
                                geoAux.add(rows.get(expansionIndex.intValue()));
177
                                aux.put(new Integer(n), new Integer(geoAux.size()-1));
178
                                n++;
179
                        }
180
                }
181

182
                invalidRows.clear();
183
                rows = geoAux;
184
                relations.clear();
185
                relations.putAll(aux);
186
*/
187

    
188
        }
189

    
190
        /**
191
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#getRowCount()
192
         */
193
        /*public int getRowCount() {
194
                return rows.size() - invalidRows.cardinality();
195
        }
196
*/
197
        public void deleteLastRow() {
198
                //invalidRows.set(rows.size()-1,false);
199
                rows.remove(rows.size()-1);
200

    
201
        }
202

    
203
        public void open() throws OpenExpansionFileException {
204
                // TODO Auto-generated method stub
205

    
206
        }
207

    
208
        public void close() throws CloseExpansionFileException {
209
                rows.clear();
210
                System.gc();
211
        }
212

    
213
        public int getSize() {
214
                return rows.size();
215
        }
216

    
217
        /* (non-Javadoc)
218
         * @see com.iver.cit.gvsig.fmap.edition.ExpansionFile#validateRow(int)
219
         */
220
        /*public void validateRow(int previousExpansionFileIndex) {
221
                invalidRows.set(previousExpansionFileIndex, false);
222
        }
223

224
        public BitSet getInvalidRows() {
225
                return invalidRows;
226
        }*/
227
}
228

    
229
// [eiel-gestion-excepciones]