Revision 44297

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc/JDBCServerExplorerBase.java
204 204
    }
205 205

  
206 206
    @Override
207
    public NewDataStoreParameters getAddParameters() throws DataException {
207
    public JDBCNewStoreParameters getAddParameters() throws DataException {
208 208
        JDBCServerExplorerParameters parameters = getJDBCParameters();
209 209
        JDBCNewStoreParameters params = new JDBCNewStoreParameters();
210 210
        params.setHost(parameters.getHost());
......
600 600
    }
601 601

  
602 602
    @Override
603
    public DataStoreParameters get(String name) throws DataException {
603
    public JDBCStoreParameters get(String name) throws DataException {
604 604
        JDBCStoreParameters params = this.createStoreParams();
605 605
        params.setTable(name);
606 606
        return params;
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc/JDBCServerExplorer.java
19 19
    boolean canAdd();
20 20

  
21 21
    @Override
22
    DataStoreParameters get(String name) throws DataException;
22
    JDBCStoreParameters get(String name) throws DataException;
23 23

  
24
    NewDataStoreParameters getAddParameters() throws DataException;
24
    JDBCNewStoreParameters getAddParameters() throws DataException;
25 25

  
26 26
    @Override
27
    List getDataStoreProviderNames();
27
    List<String> getDataStoreProviderNames();
28 28

  
29 29
    FeatureType getFeatureType(DataStoreParameters dsp) throws DataException;
30 30

  
......
36 36
    String getStoreName();
37 37

  
38 38
    @Override
39
    List list(int mode) throws DataException;
39
    List<DataStoreParameters> list(int mode) throws DataException;
40 40

  
41 41
    DataStore open(DataStoreParameters dsp) throws DataException;
42 42

  
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/JDBCServerExplorer.java
4 4
import org.gvsig.fmap.dal.DataStore;
5 5
import org.gvsig.fmap.dal.DataStoreParameters;
6 6
import org.gvsig.fmap.dal.NewDataStoreParameters;
7
import org.gvsig.fmap.dal.OpenDataStoreParameters;
7 8
import org.gvsig.fmap.dal.exception.DataException;
8 9
import org.gvsig.fmap.dal.exception.RemoveException;
9 10
import org.gvsig.fmap.dal.feature.FeatureType;
......
36 37
    ) throws DataException;
37 38

  
38 39
    @Override
39
    public List<JDBCStoreParameters> list(int mode) throws DataException;
40
    public List<DataStoreParameters> list(int mode) throws DataException;
40 41

  
41 42
    @Override
42 43
    public DataStore open(DataStoreParameters params) throws DataException;
......
54 55
    public JDBCStoreParameters getOpenParameters() throws DataException;
55 56

  
56 57
    @Override
57
    public DataStoreParameters get(String name) throws DataException;
58
    public JDBCStoreParameters get(String name) throws DataException;
58 59

  
59 60
    @Override
60 61
    public List getDataStoreProviderNames();
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/JDBCHelperBase.java
1 1
package org.gvsig.fmap.dal.store.jdbc2.spi;
2 2

  
3
import java.sql.Blob;
3 4
import org.gvsig.fmap.dal.store.jdbc2.impl.ResulSetControlerBase;
4 5
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase;
5 6
import java.sql.Connection;
......
21 22
import org.gvsig.fmap.dal.exception.InitializeException;
22 23
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
23 24
import org.gvsig.fmap.dal.feature.FeatureQueryOrder;
24
import org.gvsig.fmap.dal.feature.FeatureStore;
25 25
import org.gvsig.fmap.dal.feature.FeatureType;
26 26

  
27 27
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
......
414 414
                        break;
415 415
                    default:
416 416
                        value = rs.getObject(index + 1);
417
                        if( value instanceof Blob ) {
418
                            Blob blob = (Blob)value;
419
                            value = blob.getBytes(0, (int) blob.length());
420
                            blob.free();
421
                        }
417 422
                }
418 423
                feature.set(column.getIndex(), value);
419 424
            }
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/JDBCResourcesStorage.java
1
package org.gvsig.fmap.dal.store.jdbc2.spi;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.io.OutputStream;
8
import java.net.URL;
9
import java.util.ArrayList;
10
import java.util.List;
11
import org.apache.commons.io.IOUtils;
12
import org.apache.commons.lang3.StringUtils;
13
import org.gvsig.expressionevaluator.ExpressionBuilder;
14
import org.gvsig.expressionevaluator.ExpressionUtils;
15
import org.gvsig.fmap.dal.DALLocator;
16
import org.gvsig.fmap.dal.DataManager;
17
import static org.gvsig.fmap.dal.DataManager.RESOURCES_FIELD_NAME;
18
import static org.gvsig.fmap.dal.DataManager.RESOURCES_FIELD_RESOURCE;
19
import static org.gvsig.fmap.dal.DataManager.RESOURCES_TABLE_NAME;
20
import org.gvsig.fmap.dal.feature.EditableFeature;
21
import org.gvsig.fmap.dal.feature.Feature;
22
import org.gvsig.fmap.dal.feature.FeatureStore;
23
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
24
import org.gvsig.tools.dispose.DisposeUtils;
25
import org.gvsig.tools.resourcesstorage.AbstractResourcesStorage;
26
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

  
30
/**
31
 *
32
 * @author jjdelcerro
33
 */
34
@SuppressWarnings("UseSpecificCatch")
35
public class JDBCResourcesStorage extends AbstractResourcesStorage {
36

  
37
    private static final Logger LOGGER = LoggerFactory.getLogger(JDBCResourcesStorage.class);
38

  
39
    private static class DataBaseResource implements Resource {
40

  
41
        private class ResourceInputStream extends InputStream {
42

  
43
            @Override
44
            public int read() throws IOException {
45
                return in.read();
46
            }
47

  
48
            @Override
49
            public void close() throws IOException {
50
                DataBaseResource.this.close();
51
            }
52
        }
53

  
54
        private class ResourceOutputStream extends OutputStream {
55

  
56
            @Override
57
            public void write(int b) throws IOException {
58
                out.write(b);
59
            }
60

  
61
            @Override
62
            public void flush() throws IOException {
63
                out.flush();
64
            }
65

  
66
            @Override
67
            public void close() throws IOException {
68
                DataBaseResource.this.close();
69
            }
70
        }
71

  
72
        private final JDBCStoreParameters storeParameters;
73
        private final String tableName;
74
        private final String name;
75

  
76
        private ByteArrayInputStream in;
77
        private ByteArrayOutputStream out;
78

  
79
        public DataBaseResource(JDBCStoreParameters storeParameters, String tableName, String name) {
80
            this.storeParameters = storeParameters;
81
            this.tableName = tableName;
82
            this.name = name;
83
        }
84

  
85
        @Override
86
        public boolean isReadOnly() {
87
            return false;
88
        }
89
        @Override
90
        public URL getURL() {
91
            try {
92
                String url = this.storeParameters.getUrl();
93
                return new URL(url + "&tableName=" + this.tableName + "&resourceName=" + this.name);
94
            } catch (Throwable ex) {
95
                return null;
96
            }
97
        }
98

  
99
        @Override
100
        public boolean exists() {
101
            FeatureStore store = null;
102
            try {
103
                DataManager dataManager = DALLocator.getDataManager();
104
                store = (FeatureStore) dataManager.openStore(
105
                        this.storeParameters.getDataStoreName(),
106
                        this.storeParameters
107
                );
108
                ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
109
                String filter = builder.eq(
110
                        builder.column(RESOURCES_FIELD_NAME),
111
                        builder.constant(this.tableName+"/"+this.name)
112
                ).toString();
113
                Feature feature = store.findFirst(filter);
114
                return feature!=null;
115
            } catch (Throwable ex) {
116
                LOGGER.warn("Can't access to the resoure '" + this.getURL() + "'.", ex);
117
            } finally {
118
                DisposeUtils.disposeQuietly(store);
119
            }
120
            return false;
121
        }
122

  
123
        @Override
124
        public InputStream asInputStream() throws IOException {
125
            if (this.in != null || this.out != null) {
126
                throw new IllegalStateException("Resource is already open (" + this.getURL() + ")");
127
            }
128
            FeatureStore store = null;
129
            try {
130
                DataManager dataManager = DALLocator.getDataManager();
131
                store = (FeatureStore) dataManager.openStore(
132
                        this.storeParameters.getDataStoreName(),
133
                        this.storeParameters
134
                );
135
                ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
136
                String filter = builder.eq(
137
                        builder.column(RESOURCES_FIELD_NAME),
138
                        builder.constant(this.tableName+"/"+this.name)
139
                ).toString();
140
                Feature feature = store.findFirst(filter);
141
                if (feature == null) {
142
                    return null;
143
                }
144
                byte[] resource = feature.getByteArray(RESOURCES_FIELD_RESOURCE);
145
                this.in = new ByteArrayInputStream(resource);
146
                return new ResourceInputStream();
147
            } catch (Throwable ex) {
148
                LOGGER.warn("Can't access to the resoure '" + this.getURL() + "'.", ex);
149
            } finally {
150
                DisposeUtils.disposeQuietly(store);
151
            }
152
            return null;
153
        }
154

  
155
        @Override
156
        public OutputStream asOutputStream() throws IOException {
157
            if (this.in != null || this.out != null) {
158
                throw new IllegalStateException("Resource is already open (" + this.getURL() + ").");
159
            }
160
            this.out = new ByteArrayOutputStream();
161
            return new ResourceOutputStream();
162
        }
163

  
164
        @Override
165
        public void close() {
166
            if (this.in != null) {
167
                IOUtils.closeQuietly(this.in);
168
                this.in = null;
169
            }
170
            if (this.out != null) {
171
                FeatureStore store = null;
172
                try {
173
                    DataManager dataManager = DALLocator.getDataManager();
174
                    store = (FeatureStore) dataManager.openStore(
175
                            this.storeParameters.getDataStoreName(),
176
                            this.storeParameters
177
                    );
178
                    store.edit();
179
                    ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
180
                    String filter = builder.eq(
181
                            builder.column(RESOURCES_FIELD_NAME),
182
                            builder.constant(this.tableName+"/"+this.name)
183
                    ).toString();
184
                    Feature feature = store.findFirst(filter);
185
                    EditableFeature efeature;
186
                    if (feature == null) {
187
                        efeature = store.createNewFeature();
188
                        efeature.set(RESOURCES_FIELD_NAME, this.tableName+"/"+this.name);
189
                        efeature.set(RESOURCES_FIELD_RESOURCE, this.out.toByteArray());
190
                        store.insert(efeature);
191
                    } else {
192
                        efeature = feature.getEditable();
193
                        efeature.set(RESOURCES_FIELD_RESOURCE, this.out.toByteArray());
194
                        store.update(efeature);
195
                    }
196
                    store.finishEditing();
197

  
198
                } catch (Throwable ex) {
199
                    LOGGER.warn("Can't write the resoure '" + this.getURL() + "'.", ex);
200
                } finally {
201
                    DisposeUtils.disposeQuietly(store);
202
                }
203
            }
204
        }
205
    }
206

  
207
    private final JDBCStoreParameters resourcesStoreParameters;
208
    private final String tableName;
209

  
210
    public JDBCResourcesStorage(JDBCStoreParameters resourcesStoreParameters, String tableName) {
211
        if( StringUtils.equals(RESOURCES_TABLE_NAME, tableName) ) {
212
            // No podemos buscar recursos de la tabla de recursos, ya que si no
213
            // al abrise la tabla de recursos entraria en bucle.
214
            this.resourcesStoreParameters = null;
215
        } else {
216
            this.resourcesStoreParameters = resourcesStoreParameters;
217
        }
218
        this.tableName = tableName;
219
    }
220

  
221
    @Override
222
    public boolean isEmpty() {
223
        return this.resourcesStoreParameters == null;
224
    }
225

  
226
    @Override
227
    public Resource getResource(String name) {
228
        if (this.resourcesStoreParameters == null) {
229
            return null;
230
        }
231
        return new DataBaseResource(
232
                this.resourcesStoreParameters, 
233
                this.tableName, 
234
                name
235
        );
236
    }
237

  
238
    @Override
239
    public List<Resource> getResources(String name) {
240
        if (this.resourcesStoreParameters == null) {
241
            return null;
242
        }
243
        FeatureStore store = null;
244
        try {
245
            DataManager dataManager = DALLocator.getDataManager();
246
            store = (FeatureStore) dataManager.openStore(
247
                    this.resourcesStoreParameters.getDataStoreName(),
248
                    this.resourcesStoreParameters
249
            );
250
            ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
251
            List<ResourcesStorage.Resource> ress = new ArrayList<>();
252
            int n = 0;
253
            while (true) {
254
                String multiresourceName;
255
                if (n == 0) {
256
                    multiresourceName = name;
257
                } else {
258
                    multiresourceName = String.valueOf(n) + "." + name;
259
                }
260
                String filter = builder.eq(
261
                        builder.column(RESOURCES_FIELD_NAME),
262
                        builder.constant(multiresourceName)
263
                ).toString();
264
                Feature feature = store.findFirst(filter);
265
                if( feature==null ) {
266
                    break;
267
                }
268
                ress.add(new DataBaseResource(
269
                        this.resourcesStoreParameters, 
270
                        this.tableName,
271
                        multiresourceName
272
                    )
273
                );
274
                n++;
275
            }
276
            if (ress.isEmpty()) {
277
                return null;
278
            }
279
            return ress;
280
        } catch (Throwable ex) {
281
            LOGGER.warn("Can't get resources for '" + this.resourcesStoreParameters.getUrl()+"&resourceName="+name + "'.", ex);
282
            return null;
283
            
284
        } finally {
285
            DisposeUtils.disposeQuietly(store);
286
        }
287

  
288
    }
289

  
290
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/JDBCServerExplorerBase.java
33 33
import org.apache.commons.lang3.tuple.ImmutablePair;
34 34
import org.apache.commons.lang3.tuple.Pair;
35 35
import org.gvsig.fmap.dal.DALLocator;
36
import static org.gvsig.fmap.dal.DataManager.RESOURCES_TABLE_NAME;
36 37
import org.gvsig.fmap.dal.DataStore;
37 38
import org.gvsig.fmap.dal.DataStoreParameters;
38 39
import org.gvsig.fmap.dal.NewDataStoreParameters;
......
65 66
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ExecuteOperation;
66 67
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.UpdateTableStatisticsOperation;
67 68
import org.gvsig.tools.exception.BaseException;
69
import org.gvsig.tools.resourcesstorage.EmptyResourcesStorage;
70
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
68 71
import org.slf4j.Logger;
69 72
import org.slf4j.LoggerFactory;
70 73

  
71 74

  
75
@SuppressWarnings("UseSpecificCatch")
72 76
public class JDBCServerExplorerBase extends AbstractDBServerExplorer implements JDBCServerExplorer {
73 77

  
74 78
    private static final Logger LOG = LoggerFactory.getLogger(JDBCServerExplorerBase.class);
......
370 374
    }
371 375

  
372 376
    @Override
373
    public DataStoreParameters get(String name) throws DataException {
377
    public JDBCStoreParameters get(String name) throws DataException {
374 378
        JDBCStoreParameters params = this.getOpenParameters();
375 379
        params.setTable(name);
376 380
        return params;
......
380 384
    public SQLBuilder createSQLBuilder() {
381 385
        return this.getHelper().createSQLBuilder();
382 386
    }
383
        
387

  
388
    @Override
389
    public ResourcesStorage getResourcesStorage(DataStore dataStore) {
390
        if( this.resourcesStorage==null ) {
391
            try {
392
                List<JDBCStoreParameters> tables = this.list();
393
                for (JDBCStoreParameters params : tables) {
394
                    String theTableName = params.getTable();
395
                    if (StringUtils.equals(theTableName, RESOURCES_TABLE_NAME)) {
396
                        this.resourcesStorage = new JDBCResourcesStorage(
397
                                params,
398
                                dataStore.getName()
399
                        );
400
                        return this.resourcesStorage;
401
                    }
402
                }
403
                this.resourcesStorage = new EmptyResourcesStorage();
404
            } catch (Throwable ex) {
405
                LOG.warn("Can't retrieve reources storage from table '" + RESOURCES_TABLE_NAME + "' in '"+this.getParameters().getUrl()+"'.", ex);
406
            }
407
        }
408
        return this.resourcesStorage;
409
    }
384 410
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialExplorer.java
1 1
package org.gvsig.fmap.dal.store.h2;
2 2

  
3
import java.io.File;
4
import java.util.ArrayList;
5
import java.util.List;
6 3
import org.apache.commons.io.FilenameUtils;
7 4
import org.gvsig.fmap.dal.DataStore;
8
import org.gvsig.fmap.dal.exception.DataException;
9 5
import org.gvsig.fmap.dal.exception.InitializeException;
10 6
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
11
import org.gvsig.fmap.dal.spi.FileMultiResource;
7
import org.gvsig.fmap.dal.spi.ZipResourcesStorage;
12 8
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
13 9
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
14 10
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCServerExplorerBase;
15
import org.gvsig.tools.util.ResourcesStorage.Resource;
11
import org.gvsig.tools.resourcesstorage.EmptyResourcesStorage;
12
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
16 13

  
17 14
/**
18 15
 *
......
31 28
    }
32 29

  
33 30
    @Override
34
    public Resource getResource(DataStore dataStore, String resourceName) throws DataException {
35
        String zipPath = this.getParameters().getFile().getAbsolutePath();
36
        zipPath = FilenameUtils.removeExtension(zipPath);
37
        FileMultiResource resource = new FileMultiResource(new File(zipPath), dataStore.getName(),resourceName);
38
        return resource;
39
    }
40
    
41
    @Override
42
    public List<Resource> getResources(DataStore dataStore, String resourceName) throws DataException {
43
        String zipPath = this.getParameters().getFile().getAbsolutePath();
44
        zipPath = FilenameUtils.removeExtension(zipPath);
45
        List<Resource>ress = new ArrayList<>();
46
        int n = 0;
47
        while(true) {
48
            String multiresourceName;
49
            if( n==0 ) {
50
                multiresourceName = resourceName;
51
            } else {
52
                multiresourceName = String.valueOf(n)+"."+resourceName;
53
            }
54
            FileMultiResource resource = new FileMultiResource(new File(zipPath), dataStore.getName(),multiresourceName);
55
            if( !resource.exists() ) {
56
                break;
57
            }
58
            ress.add(resource);
59
            n++;
31
    public ResourcesStorage getResourcesStorage(DataStore dataStore) {
32
        ResourcesStorage ress = super.getResourcesStorage(dataStore);
33
        if( ress instanceof EmptyResourcesStorage ) {
34
            String zipPath = this.getParameters().getFile().getAbsolutePath();
35
            String zipPathName = FilenameUtils.removeExtension(zipPath);
36
            this.resourcesStorage = new ZipResourcesStorage(zipPathName, dataStore.getName());
60 37
        }
61
        if( ress.isEmpty() ) {
62
            return null;
63
        }
64
        return ress;
38
        return this.resourcesStorage;
65 39
    }
40
    
41
    
66 42
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialSQLBuilder.java
55 55

  
56 56
        this.type_boolean = "BOOLEAN";
57 57
        this.type_byte = "TINYINT";
58
        this.type_bytearray = "TINYINT";
58
        this.type_bytearray = "BLOB";
59 59
        this.type_geometry = "GEOMETRY";
60 60
        this.type_char = "CHAR";
61 61
        this.type_date = "DATE";
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/featureform/swing/impl/DefaultJFeaturesForm.java
92 92
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
93 93
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
94 94
import org.gvsig.tools.swing.icontheme.IconTheme;
95
import org.gvsig.tools.util.ResourcesStorage;
95
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
96 96

  
97 97
/**
98 98
 * @author fdiaz
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/searchpanel/DefaultSearchPanel.java
133 133
            if (attrdesc == null) {
134 134
                return String.class;
135 135
            }
136
            return attrdesc.getDataType().getDefaultClass();
136
            Class theClass = attrdesc.getDataType().getDefaultClass();
137
            if( theClass==null ) {
138
                return String.class;
139
            }
140
            return theClass;
137 141
        }
138 142

  
139 143
        @Override
......
215 219
    private ExpressionPickerController advancedExpression;
216 220
    private final Map<String, ActionButtons> actions;
217 221
    private boolean showActions = true;
222
    private int maxSearhFields = 4;
218 223

  
219 224
    public DefaultSearchPanel(FeatureStore store) {
220 225
        this.store = store;
......
331 336
                    Search.STR_INT_LONG_LABEL_ORDER,
332 337
                    5
333 338
            );
339
            this.maxSearhFields = Integer.min(orderedAttributes.size(), 4);
334 340
            int n = 0;
335 341
            for (SearchFieldController searchField : searchFields) {
336
                searchField.setAttribute(orderedAttributes.get(n++).getName());
342
                if( n<this.maxSearhFields ) {
343
                    searchField.setAttribute(orderedAttributes.get(n++).getName());
344
                } else {
345
                    searchField.setEnabled(false);
346
                }
337 347
            }
338 348
        } catch (DataException ex) {
339 349
            LOGGER.warn("Can't determine order of attributes", ex);
......
384 394
        if( this.searchFields==null ) {
385 395
            initComponents();
386 396
        }
397
        int n=0;
387 398
        for (SearchFieldController searchField : searchFields) {
388
            searchField.setEnabled(enabled);
399
            if( n<this.maxSearhFields ) {
400
                searchField.setEnabled(enabled);
401
            } else {
402
                searchField.setEnabled(false);
403
            }
404
            n++;
389 405
        }
390 406
        this.btnClear.setEnabled(enabled);
391 407
        this.btnSearch.setEnabled(enabled);
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/featureform/swing/JFeaturesForm.java
24 24

  
25 25
import java.awt.Dimension;
26 26
import javax.swing.Action;
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.DataStore;
30 27
import org.gvsig.fmap.dal.StoresRepository;
31 28

  
32 29
import org.gvsig.fmap.dal.feature.Feature;
......
34 31
import org.gvsig.fmap.dal.feature.FeatureQuery;
35 32
import org.gvsig.fmap.dal.feature.FeatureStore;
36 33
import org.gvsig.fmap.dal.feature.FeatureType;
37
import org.gvsig.tools.dynform.JDynForm;
38 34
import org.gvsig.tools.dynform.JDynForm.DynFormContext;
39 35
import org.gvsig.tools.dynform.JDynFormSet;
40 36
import org.gvsig.tools.swing.api.Component;
41 37
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
42
import org.gvsig.tools.util.ResourcesStorage;
38
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
43 39

  
44 40
/**
45 41
 * @author fdiaz
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/test/java/org/gvsig/fmap/dal/feature/DummyFetureStore.java
34 34
import org.gvsig.tools.persistence.exception.PersistenceException;
35 35
import org.gvsig.tools.undo.RedoException;
36 36
import org.gvsig.tools.undo.UndoException;
37
import org.gvsig.tools.util.ResourcesStorage;
38
import org.gvsig.tools.util.ResourcesStorageEmpty;
37
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
38
import org.gvsig.tools.resourcesstorage.EmptyResourcesStorage;
39 39
import org.gvsig.tools.util.UnmodifiableBasicMap;
40 40
import org.gvsig.tools.visitor.Visitor;
41 41

  
......
745 745

  
746 746
    @Override
747 747
    public ResourcesStorage getResourcesStorage() {
748
        return new ResourcesStorageEmpty();
748
        return new EmptyResourcesStorage();
749 749
    }
750 750

  
751 751
    @Override
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataServerExplorer.java
28 28

  
29 29
import org.gvsig.fmap.dal.exception.DataException;
30 30
import org.gvsig.tools.dispose.Disposable;
31
import org.gvsig.tools.util.ResourcesStorage.Resource;
31
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
32 32

  
33 33
/**
34 34
 * DataServerExplorer is an abstraction for any type of data server. It allows
......
39 39
 */
40 40
public interface DataServerExplorer extends Disposable, DataFactoryUnit {
41 41

  
42
//    public interface DataResource extends Resource {
43
//        @Override
44
//        public URL getURL();
45
//        
46
//        @Override
47
//        public boolean exists();
48
//        
49
//        @Override
50
//        public InputStream asInputStream() throws IOException;
51
//        
52
//        @Override
53
//        public OutputStream asOutputStream() throws IOException;
54
//        
55
//        @Override
56
//        public void close();
57
//    }
58
//    
59 42
    /**
60 43
     * Returns the DataServerExplorer's name
61 44
     *
......
93 76
     *
94 77
     * @throws DataException
95 78
     */
96
    public List list() throws DataException;
79
    public List<DataStoreParameters> list() throws DataException;
97 80

  
98 81
    public DataStoreParameters get(String name) throws DataException;
99 82

  
......
113 96
     *
114 97
     * @throws DataException
115 98
     */
116
    public List list(int mode) throws DataException;
99
    public List<DataStoreParameters> list(int mode) throws DataException;
117 100

  
118 101
    /**
119 102
     * Creates a new DataStore in this server.
120 103
     *
104
     * @param provider
121 105
     * @param parameters , an instance of DataStoreParameters from
122 106
     * {@link DataServerExplorer#getAddParameters(String)} that describes the
123 107
     * new DataStore.
......
166 150
     *
167 151
     * @return List of provider names
168 152
     */
169
    public List getDataStoreProviderNames();
153
    public List<String> getDataStoreProviderNames();
170 154

  
171 155
    /**
172 156
     * Return the file resource associated to this name and store. If the
......
177 161
     * @param resourceName
178 162
     * @return file resource or null
179 163
     * @throws DataException
180
     * @deprecated use getResource
164
     * @deprecated use getResourcesStorage
181 165
     */
182 166
    public File getResourcePath(DataStore dataStore, String resourceName) throws DataException;
183 167

  
184
    /**
185
     * Return the DataResource associated to this name and store. If the
186
     * resource not exists or the explorer don't support this opperation return
187
     * null.
188
     *
189
     * @param dataStore
190
     * @param resourceName
191
     * @return the DataResource or null
192
     * @throws DataException
193
     */
194
    public Resource getResource(DataStore dataStore, String resourceName) throws DataException;
195

  
196
    public List<Resource> getResources(DataStore dataStore, String resourceName) throws DataException;
168
    public ResourcesStorage getResourcesStorage(DataStore dataStore);
197 169
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataStore.java
39 39
import org.gvsig.tools.observer.ComplexWeakReferencingObservable;
40 40
import org.gvsig.tools.observer.Observer;
41 41
import org.gvsig.tools.persistence.Persistent;
42
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
42 43
import org.gvsig.tools.service.spi.Services;
43 44
import org.gvsig.tools.util.UnmodifiableBasicList;
44 45
import org.gvsig.tools.util.UnmodifiableBasicMap;
......
342 343
     */
343 344
    public DataCache getCache();
344 345

  
346
    public ResourcesStorage getResourcesStorage();
347
    
348
    public StoresRepository getStoresRepository();
349

  
345 350
}
346 351

  
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataManager.java
49 49
import org.gvsig.tools.service.spi.Services;
50 50
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression;
51 51
import org.gvsig.fmap.dal.feature.DataProfile;
52
import org.gvsig.tools.util.GetItemByKey;
53 52
import org.gvsig.tools.util.UnmodifiableBasicMap;
54 53

  
55 54
/**
......
72 71
    public static final String DAL_SYMBOL_TABLE = "DAL.SymbolTable.Global";
73 72
    public static final String DAL_SYMBOL_TABLE_FEATURE = "DAL.SymbolTable.Feature";
74 73

  
75
//    public static final String DAL_PROFILE_FOREINGKEY = "DAL.Profile.ForeingKey";
76
//    public static final String DAL_PROFILE_SELECTABLEFOREINGKEY = "DAL.Profile.SelectableForeingKey";
77
    
78 74
    public static final String FUNCTION_FOREING_VALUE = "FOREING_VALUE";
79 75
    
76
    // Constant to manage ResourcesStorage in a DDBB.
77
    public static final String RESOURCES_TABLE_NAME = "gvsigd_resources";
78
    public static final String RESOURCES_FIELD_NAME = "name";
79
    public static final String RESOURCES_FIELD_RESOURCE = "resource";
80

  
80 81
    /**
81 82
     * 
82 83
     * Returns the default DAL's temporary directory
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/AbstractDataResource.java
4 4
import java.io.InputStream;
5 5
import java.io.OutputStream;
6 6
import java.net.URL;
7
import org.gvsig.tools.util.ResourcesStorage.Resource;
7
import org.gvsig.tools.resourcesstorage.ResourcesStorage.Resource;
8 8

  
9 9

  
10 10
/**
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/Feature.java
327 327
	 */
328 328
	public Geometry getGeometry(int index);
329 329

  
330
	/**
330
	public byte[] getByteArray(String name);
331

  
332
	public byte[] getByteArray(int index);
333

  
334
        /**
331 335
	 * Returns the array value of an attribute given its name.
332 336
	 *
333 337
	 * @param name
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureStore.java
46 46
import org.gvsig.tools.lang.Cloneable;
47 47
import org.gvsig.tools.observer.Observer;
48 48
import org.gvsig.tools.undo.UndoRedoStack;
49
import org.gvsig.tools.util.ResourcesStorage;
49
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
50 50

  
51 51
/**
52 52
 * <p>
......
933 933
     */
934 934
    public long getPendingChangesCount();
935 935
    
936
    public ResourcesStorage getResourcesStorage();
937
    
938
    public StoresRepository getStoresRepository();
939

  
940 936
    public Feature getSampleFeature();
941 937
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/spi/FileMultiResource.java
1
package org.gvsig.fmap.dal.spi;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.File;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.io.OutputStream;
9
import java.net.URI;
10
import java.net.URISyntaxException;
11
import java.net.URL;
12
import java.nio.file.FileSystem;
13
import java.nio.file.FileSystems;
14
import java.nio.file.Files;
15
import java.nio.file.Path;
16
import java.nio.file.StandardCopyOption;
17
import java.util.Collections;
18
import java.util.Objects;
19
import java.util.zip.ZipEntry;
20
import java.util.zip.ZipFile;
21
import org.apache.commons.io.IOUtils;
22
import org.apache.commons.lang3.StringUtils;
23
import org.gvsig.fmap.dal.AbstractDataResource;
24
import org.gvsig.tools.util.ResourcesStorage.Resource;
25
import org.slf4j.LoggerFactory;
26

  
27
/**
28
 *
29
 * @author jjdelcerro
30
 */
31
@SuppressWarnings("UseSpecificCatch")
32
public class FileMultiResource
33
        extends AbstractDataResource
34
        implements Resource {
35

  
36
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(FileMultiResource.class);
37

  
38
    private final File zipFile;
39
    private final String tableName;
40
    private final String resourceName;
41
    private ZipFile zip;
42
    private InputStream in;
43
    private ByteArrayOutputStream out;
44

  
45
    public FileMultiResource(File zipFile, String tableName, String resourceName) {
46
        this.zipFile = new File(zipFile.getAbsolutePath() + ".gvres");
47
        this.tableName = tableName;
48
        this.resourceName = resourceName;
49
        this.zip = null;
50
        this.in = null;
51
        this.out = null;
52
        if( StringUtils.isBlank(this.tableName) ) {
53
            LOGGER.warn("The table name is empty (URL="+this.getURL()+").");
54
        }
55
        if( StringUtils.isBlank(this.resourceName) ) {
56
            LOGGER.warn("The resource name is empty (URL="+this.getURL()+").");
57
        }
58
    }
59

  
60
    @Override
61
    public URL getURL() {
62
        try {
63
            return new URL("jar:" + this.zipFile.toURI().toString() + "!/" + this.tableName + "." + this.resourceName);
64
        } catch (Exception ex) {
65
            return null;
66
        }
67
    }
68

  
69
    @Override
70
    public boolean exists() {
71
        try {
72
            if (!this.zipFile.exists()) {
73
                return false;
74
            }
75
            ZipFile z = new ZipFile(zipFile);
76
            try {
77
                ZipEntry entry = z.getEntry(this.tableName + "." + this.resourceName);
78
                if (entry == null) {
79
                    return false;
80
                }
81
                return true;
82
            } finally {
83
                IOUtils.closeQuietly(z);
84
            }
85
        } catch (Exception ex) {
86
            LOGGER.warn("Can't access to the resource (" + Objects.toString(this.getURL()) + ").", ex);
87
            return false;
88
        }
89
    }
90

  
91
    @Override
92
    public InputStream asInputStream() throws IOException {
93
        if (!this.zipFile.exists()) {
94
            return null;
95
        }
96
        if (this.in != null || this.out != null) {
97
            throw new IllegalStateException("Resource is already open (" + this.zipFile.toString() + "!" + this.tableName + ")");
98
        }
99
        try {
100
            if( this.zip == null ) {
101
                this.zip = new ZipFile(zipFile);
102
            }
103
            ZipEntry entry = this.zip.getEntry(this.tableName + "." + this.resourceName);
104
            if (entry == null) {
105
                return null;
106
            }
107
            this.in = this.zip.getInputStream(entry);
108
            return this.in;
109
        } catch (Exception ex) {
110
            LOGGER.warn("Can't create input stream (" + Objects.toString(this.getURL()) + ").", ex);
111
            return null;
112
        }
113
    }
114

  
115
    @Override
116
    public OutputStream asOutputStream() throws IOException {
117
        if (this.in != null || this.out != null) {
118
            throw new IllegalStateException("Resource is already open (" + Objects.toString(this.getURL()) + ").");
119
        }
120
        this.out = new ByteArrayOutputStream();
121
        return this.out;
122
    }
123

  
124
    @Override
125
    public void close() {
126
        if (this.in != null) {
127
            IOUtils.closeQuietly(this.in);
128
            this.in = null;
129
        }
130
        if (this.out != null) {
131
            ByteArrayInputStream contents = new ByteArrayInputStream(this.out.toByteArray());
132
            try {
133
                this.updateZipEntry(zipFile, this.tableName + "." + this.resourceName, contents);
134
            } catch (Exception ex) {
135
                LOGGER.warn("Can't write resource (" + Objects.toString(this.getURL()) + ").", ex);
136
            } finally {
137
                IOUtils.closeQuietly(contents);
138
                IOUtils.closeQuietly(this.out);
139
                this.out = null;
140
            }
141
        }
142
        if (this.zip != null) {
143
            IOUtils.closeQuietly(this.zip);
144
            this.zip = null;
145
        }
146
    }
147

  
148
    private void updateZipEntry(File zip, String entryName, InputStream entryContents) throws URISyntaxException, IOException {
149
        FileSystem zipfs = null;
150
        try {
151
            URI zipfsuri = new URI("jar:" + zip.toURI().toString());
152
            zipfs = FileSystems.newFileSystem(zipfsuri, Collections.singletonMap("create", "true"));
153
            Path entryPath = zipfs.getPath(entryName);
154
            Files.copy(entryContents, entryPath, StandardCopyOption.REPLACE_EXISTING);
155
        } finally {
156
            IOUtils.closeQuietly(zipfs);
157
        }
158
    }
159
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/spi/ZipResourcesStorage.java
1
package org.gvsig.fmap.dal.spi;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.File;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.io.OutputStream;
9
import java.net.URI;
10
import java.net.URISyntaxException;
11
import java.net.URL;
12
import java.nio.file.FileSystem;
13
import java.nio.file.FileSystems;
14
import java.nio.file.Files;
15
import java.nio.file.Path;
16
import java.nio.file.StandardCopyOption;
17
import java.util.Collections;
18
import java.util.Objects;
19
import java.util.zip.ZipEntry;
20
import java.util.zip.ZipFile;
21
import org.apache.commons.io.FilenameUtils;
22
import org.apache.commons.io.IOUtils;
23
import org.apache.commons.lang3.StringUtils;
24
import org.gvsig.fmap.dal.AbstractDataResource;
25
import org.gvsig.tools.resourcesstorage.AbstractResourcesStorage;
26
import org.gvsig.tools.resourcesstorage.ResourcesStorage.Resource;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

  
30
/**
31
 *
32
 * @author jjdelcerro
33
 */
34
@SuppressWarnings("UseSpecificCatch")
35
public class ZipResourcesStorage extends AbstractResourcesStorage {
36

  
37
    private static final Logger LOGGER = LoggerFactory.getLogger(ZipResourcesStorage.class);
38

  
39
    public class ZipFileResource
40
            extends AbstractDataResource
41
            implements Resource {
42

  
43
        private class ResourceInputStream extends InputStream {
44

  
45
            @Override
46
            public int read() throws IOException {
47
                return in.read();
48
            }
49

  
50
            @Override
51
            public void close() throws IOException {
52
                ZipFileResource.this.close();
53
            }
54
        }
55

  
56
        private class ResourceOutputStream extends OutputStream {
57

  
58
            @Override
59
            public void write(int b) throws IOException {
60
                out.write(b);
61
            }
62

  
63
            @Override
64
            public void flush() throws IOException {
65
                out.flush();
66
            }
67

  
68
            @Override
69
            public void close() throws IOException {
70
                ZipFileResource.this.close();
71
            }
72
        }
73

  
74
        private final File zipFile;
75
        private final String tableName;
76
        private final String resourceName;
77
        private ZipFile zip;
78
        private InputStream in;
79
        private ByteArrayOutputStream out;
80

  
81
        public ZipFileResource(File zipFile, String tableName, String resourceName) {
82
            this.zipFile = zipFile;
83
            this.tableName = tableName;
84
            this.resourceName = resourceName;
85
            this.zip = null;
86
            this.in = null;
87
            this.out = null;
88
            if (StringUtils.isBlank(this.tableName)) {
89
                LOGGER.warn("The table name is empty (URL=" + this.getURL() + ").");
90
            }
91
            if (StringUtils.isBlank(this.resourceName)) {
92
                LOGGER.warn("The resource name is empty (URL=" + this.getURL() + ").");
93
            }
94
        }
95

  
96
        @Override
97
        public boolean isReadOnly() {
98
            return false;
99
        }
100
        
101
        @Override
102
        public final URL getURL() {
103
            try {
104
                return new URL("jar:" + this.zipFile.toURI().toString() + "!/" + this.tableName + "." + this.resourceName);
105
            } catch (Exception ex) {
106
                return null;
107
            }
108
        }
109

  
110
        @Override
111
        public boolean exists() {
112
            try {
113
                if (!this.zipFile.exists()) {
114
                    return false;
115
                }
116
                ZipFile z = new ZipFile(zipFile);
117
                try {
118
                    ZipEntry entry = z.getEntry(this.tableName + "." + this.resourceName);
119
                    if (entry == null) {
120
                        return false;
121
                    }
122
                    return true;
123
                } finally {
124
                    IOUtils.closeQuietly(z);
125
                }
126
            } catch (Exception ex) {
127
                LOGGER.warn("Can't access to the resource (" + Objects.toString(this.getURL()) + ").", ex);
128
                return false;
129
            }
130
        }
131

  
132
        @Override
133
        public InputStream asInputStream() throws IOException {
134
            if (!this.zipFile.exists()) {
135
                return null;
136
            }
137
            if (this.in != null || this.out != null) {
138
                throw new IllegalStateException("Resource is already open (" + this.zipFile.toString() + "!" + this.tableName + ")");
139
            }
140
            try {
141
                if (this.zip == null) {
142
                    this.zip = new ZipFile(zipFile);
143
                }
144
                ZipEntry entry = this.zip.getEntry(this.tableName + "." + this.resourceName);
145
                if (entry == null) {
146
                    return null;
147
                }
148
                this.in = this.zip.getInputStream(entry);
149
                return new ResourceInputStream();
150
            } catch (Exception ex) {
151
                LOGGER.warn("Can't create input stream (" + Objects.toString(this.getURL()) + ").", ex);
152
                return null;
153
            }
154
        }
155

  
156
        @Override
157
        public OutputStream asOutputStream() throws IOException {
158
            if (this.in != null || this.out != null) {
159
                throw new IllegalStateException("Resource is already open (" + Objects.toString(this.getURL()) + ").");
160
            }
161
            this.out = new ByteArrayOutputStream();
162
            return new ResourceOutputStream();
163
        }
164

  
165
        @Override
166
        public void close() {
167
            if (this.in != null) {
168
                IOUtils.closeQuietly(this.in);
169
                this.in = null;
170
            }
171
            if (this.out != null) {
172
                ByteArrayInputStream contents = new ByteArrayInputStream(this.out.toByteArray());
173
                try {
174
                    this.updateZipEntry(zipFile, this.tableName + "." + this.resourceName, contents);
175
                } catch (Exception ex) {
176
                    LOGGER.warn("Can't write resource (" + Objects.toString(this.getURL()) + ").", ex);
177
                } finally {
178
                    IOUtils.closeQuietly(contents);
179
                    IOUtils.closeQuietly(this.out);
180
                    this.out = null;
181
                }
182
            }
183
            if (this.zip != null) {
184
                IOUtils.closeQuietly(this.zip);
185
                this.zip = null;
186
            }
187
        }
188

  
189
        private void updateZipEntry(File zip, String entryName, InputStream entryContents) throws URISyntaxException, IOException {
190
            FileSystem zipfs = null;
191
            try {
192
                URI zipfsuri = new URI("jar:" + zip.toURI().toString());
193
                zipfs = FileSystems.newFileSystem(zipfsuri, Collections.singletonMap("create", "true"));
194
                Path entryPath = zipfs.getPath(entryName);
195
                Files.copy(entryContents, entryPath, StandardCopyOption.REPLACE_EXISTING);
196
            } finally {
197
                IOUtils.closeQuietly(zipfs);
198
            }
199
        }
200
    }
201

  
202
    private final File zipFile;
203
    private final String tableName;
204
    
205
    public ZipResourcesStorage(String pathName, String tableName) {
206
        this.zipFile = new File(pathName + ".gvres");
207
        this.tableName = tableName;
208
    }
209
    
210
    public static boolean existsStorage(String pathName) {
211
        File theZipFile = new File(pathName + ".gvres");
212
        return theZipFile.exists();
213
    }
214

  
215
    @Override
216
    public Resource getResource(String resourceName) {
217
        ZipFileResource res = new ZipFileResource(
218
                this.zipFile,
219
                this.tableName,
220
                resourceName
221
        );
222
        return res;
223
    }
224

  
225
    @Override
226
    public boolean isEmpty() {
227
        return !this.zipFile.exists();
228
    }
229

  
230
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/spi/AbstractDataServerExplorer.java
11 11
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase;
12 12
import org.gvsig.tools.dispose.impl.AbstractDisposable;
13 13
import org.gvsig.tools.exception.BaseException;
14
import org.gvsig.tools.util.ResourcesStorage.Resource;
14
import org.gvsig.tools.resourcesstorage.EmptyResourcesStorage;
15
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
16
import org.gvsig.tools.resourcesstorage.ResourcesStorage.Resource;
15 17

  
16 18
public abstract class AbstractDataServerExplorer extends AbstractDisposable implements DataServerExplorer_v2 {
17 19

  
18 20
    private DataServerExplorerParameters parameters;
19 21
    private final DataServerExplorerProviderServices providerServices;
22
    protected ResourcesStorage resourcesStorage = null;
20 23

  
21 24
    protected AbstractDataServerExplorer(DataServerExplorerParameters parameters, DataServerExplorerProviderServices providerServices) {
22 25
        this.parameters = parameters;
......
49 52
    }
50 53

  
51 54
    @Override
52
    public Resource getResource(DataStore dataStore, String resourceName) throws DataException {
53
        return null;
55
    public ResourcesStorage getResourcesStorage(DataStore dataStore) {
56
        if( this.resourcesStorage==null ) {
57
            this.resourcesStorage = new EmptyResourcesStorage();
58
        }
59
        return this.resourcesStorage;
54 60
    }
55
    
61

  
56 62
    @Override
57
    public List<Resource> getResources(DataStore dataStore, String resourceName) throws DataException {
58
        return null;
59
    }
60
    
61
    @Override
62 63
    public SQLBuilder createSQLBuilder() {
63 64
        return new SQLBuilderBase();
64 65
    }
65
    
66

  
66 67
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/impl/DefaultFilesystemServerExplorer.java
53 53
import org.gvsig.fmap.dal.spi.AbstractDataServerExplorer;
54 54
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
55 55
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
56
import org.gvsig.fmap.dal.spi.FileMultiResource;
56
import org.gvsig.fmap.dal.spi.ZipResourcesStorage;
57 57
import org.gvsig.tools.exception.BaseException;
58 58
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
59
import org.gvsig.tools.util.ResourcesStorage;
60
import org.gvsig.tools.util.SimpleFileResource;
59
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
60
import org.gvsig.tools.resourcesstorage.FilesResourcesStorage;
61 61

  
62 62
@SuppressWarnings("UseSpecificCatch")
63 63
public class DefaultFilesystemServerExplorer extends AbstractDataServerExplorer
......
494 494
    @Deprecated
495 495
    @Override
496 496
    public File getResourcePath(DataStore dataStore, String resourceName) throws DataException {
497
        SimpleFileResource resource = (SimpleFileResource) this.getResource(dataStore, resourceName);
498
        if( resource==null ) {
497
        try {
498
            ResourcesStorage theResourceStorage = this.getResourcesStorage(dataStore);
499
            if( theResourceStorage==null ) {
500
                return null;
501
            }
502
            FilesResourcesStorage.FileResource res = (FilesResourcesStorage.FileResource) theResourceStorage.getResource(resourceName);
503
            if( res==null ) {
504
                return null;
505
            }
506
            return res.getFile();
507
        } catch(Exception ex) {
499 508
            return null;
500 509
        }
501
        return resource.getFile();
502 510
    }
503 511

  
504 512
    @Override
505
    public org.gvsig.tools.util.ResourcesStorage.Resource getResource(DataStore dataStore, String resourceName) throws DataException {
506
        FilesystemServerExplorerProvider provider = this.getProvider(dataStore.getProviderName());
507
        if (provider == null) {
508
            return null;
509
        }
510
        String rootPathName = provider.getResourceRootPathName(dataStore);
511
        if (rootPathName == null) {
512
            return null;
513
        }
514
        if( !dataStore.getChildren().isEmpty() ) {
515
            FileMultiResource res = new FileMultiResource(
516
                    new File(rootPathName),
517
                    dataStore.getName(), 
518
                    resourceName
519
            );
520
            return res;
521
        }
522
        File f = new File(FilenameUtils.getFullPathNoEndSeparator(rootPathName),resourceName);
523
        if( f.exists() ) {
524
            return new SimpleFileResource(f);
525
        }
526
        return new SimpleFileResource(new File(rootPathName + "." + resourceName));
527
    }
528

  
529
    @Override
530
    public List<ResourcesStorage.Resource> getResources(DataStore dataStore, String resourceName) throws DataException {
531
        FilesystemServerExplorerProvider provider = this.getProvider(dataStore.getProviderName());
532
        if (provider == null) {
533
            return null;
534
        }
535
        String rootPathName = provider.getResourceRootPathName(dataStore);
536
        if (rootPathName == null) {
537
            return null;
538
        }
539
        List<ResourcesStorage.Resource>ress = new ArrayList<>();
540
        int n = 0;
541
        while(true) {
542
            String multiresourceName;
543
            if( n==0 ) {
544
                multiresourceName = resourceName;
545
            } else {
546
                multiresourceName = String.valueOf(n)+"."+resourceName;
513
    public ResourcesStorage getResourcesStorage(DataStore dataStore) {
514
        if( this.resourcesStorage==null ) {
515
            FilesystemServerExplorerProvider provider;
516
            try {
517
                provider = this.getProvider(dataStore.getProviderName());
518
            } catch (Exception ex) {
519
                return null;
547 520
            }
548
            File f = new File(rootPathName + "." + multiresourceName);
549
            if( !f.exists() ) {
550
                break;
521
            if (provider == null) {
522
                return null;
551 523
            }
552
            ress.add(new SimpleFileResource(f));
553
            n++;
524
            String pathName = provider.getResourceRootPathName(dataStore);
525
            if (pathName == null) {
526
                return null;
527
            }
528
            pathName = FilenameUtils.removeExtension(pathName);
529
            if( dataStore.getChildren().isEmpty() ) {
530
                if( ZipResourcesStorage.existsStorage(pathName) ) {
531
                    this.resourcesStorage = new ZipResourcesStorage(
532
                            pathName,
533
                            dataStore.getName()
534
                    );
535
                } else {
536
                    this.resourcesStorage = new FilesResourcesStorage(
537
                            pathName
538
                    );
539
                }
540
            } else {
541
                this.resourcesStorage = new ZipResourcesStorage(
542
                        pathName,
543
                        dataStore.getName()
544
                );
545
            }
554 546
        }
555
        if( ress.isEmpty() ) {
556
            return null;
557
        }
558
        return ress;
547
        return this.resourcesStorage;
559 548
    }
560 549
    
561
    
562 550
    @Override
563 551
    public DataStoreParameters get(String name) throws DataException {
564 552
        File theFile = new File(this.current,name);
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java
128 128
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
129 129
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProvider;
130 130
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices;
131
import org.gvsig.fmap.dal.impl.DALResourcesStorage;
132 131
import org.gvsig.fmap.dal.impl.DefaultDataManager;
133 132
import org.gvsig.fmap.dal.resource.Resource;
134 133
import org.gvsig.fmap.dal.spi.DataStoreInitializer2;
......
167 166
import org.gvsig.tools.undo.UndoException;
168 167
import org.gvsig.tools.undo.command.Command;
169 168
import org.gvsig.tools.util.HasAFile;
170
import org.gvsig.tools.util.ResourcesStorage;
169
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
171 170
import org.gvsig.tools.util.UnmodifiableBasicMap;
172 171
import org.gvsig.tools.util.UnmodifiableBasicSet;
173 172
import org.gvsig.tools.util.UnmodifiableBasicSetChained;
......
1586 1585
    
1587 1586

  
1588 1587
    private void saveDALFile() {       
1589
        org.gvsig.tools.util.ResourcesStorage.Resource resource = null;
1588
        org.gvsig.tools.resourcesstorage.ResourcesStorage.Resource resource = null;
1590 1589
        try {
1591
            DataServerExplorer explorer = this.getExplorer();
1592
            if( explorer == null ) {
1590
            ResourcesStorage resourcesStorage = this.getResourcesStorage();
1591
            if( resourcesStorage == null || resourcesStorage.isReadOnly() ) {
1593 1592
                return;
1594 1593
            }
1595
            resource = explorer.getResource(this, "dal");
1596
            if( resource == null ) {
1594
            resource = resourcesStorage.getResource("dal");
1595
            if( resource == null || resource.isReadOnly() ) {
1597 1596
                return;
1598 1597
            }
1599 1598
            DALFile dalFile = DALFile.getDALFile();
......
1609 1608
    }
1610 1609
    
1611 1610
    private void loadDALFile() {
1612
        org.gvsig.tools.util.ResourcesStorage.Resource resource = null;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff