Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.fmap.dal.file.jimi / src / main / java / org / gvsig / fmap / dal / file / jimi / JimiFileSystemServerProvider.java @ 6287

History | View | Annotate | Download (4.07 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal.file.jimi;
24

    
25
import java.io.File;
26
import java.io.IOException;
27

    
28
import org.gvsig.fmap.dal.DataServerExplorer;
29
import org.gvsig.fmap.dal.DataStoreParameters;
30
import org.gvsig.fmap.dal.NewDataStoreParameters;
31
import org.gvsig.fmap.dal.exception.CreateException;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.exception.FileNotFoundException;
34
import org.gvsig.fmap.dal.exception.RemoveException;
35
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
36
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
37
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
38
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider;
39
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
40

    
41
/**
42
 * Filesystem Provider for JIMI. Initially, accepts png files
43
 * @author dmartinezizquierdo
44
 *
45
 */
46
public class JimiFileSystemServerProvider extends AbstractFilesystemServerExplorerProvider
47
implements FilesystemServerExplorerProvider, ResourceConsumer{
48

    
49
    protected FilesystemServerExplorerProviderServices serverExplorer;
50

    
51
    public int getMode() {
52
        return DataServerExplorer.MODE_RASTER;
53
    }
54

    
55
    @Override
56
    public boolean canCreate() {
57
        return false;
58
    }
59

    
60
    @Override
61
    public boolean canCreate(NewDataStoreParameters arg0) {
62
        return false;
63
    }
64

    
65
    @Override
66
    public void create(NewDataStoreParameters arg0, boolean arg1)
67
        throws CreateException {
68
        throw new UnsupportedOperationException();
69

    
70
    }
71

    
72
    @Override
73
    public NewDataStoreParameters getCreateParameters() throws DataException {
74
        throw new UnsupportedOperationException();
75
    }
76

    
77
    @Override
78
    public void initialize(FilesystemServerExplorerProviderServices serverExplorer) {
79
        this.serverExplorer = serverExplorer;
80
    }
81

    
82
    @Override
83
    public void remove(DataStoreParameters parameters) throws RemoveException {
84
        JimiRasterStoreProviderParameters params = (JimiRasterStoreProviderParameters) parameters;
85
        File file = params.getFile();
86
        if (!file.exists()) {
87
            throw new RemoveException(this.getDataStoreProviderName(),
88
                    new FileNotFoundException(params.getFile()));
89
        }
90
        if (!file.delete()) {
91
            throw new RemoveException(this.getDataStoreProviderName(),
92
                    new IOException("Error deleting file: "+file.getName()));
93
        }
94

    
95
    }
96

    
97
    @Override
98
    public String getDataStoreProviderName() {
99
        return JimiRasterStoreProvider.NAME;
100
    }
101

    
102
    @Override
103
    public String getDescription() {
104
        return JimiRasterStoreProvider.DESCRIPTION;
105
    }
106

    
107
    @Override
108
    public boolean accept(File pathname) {
109
        //TODO Creo que deber?a de preguntar al provider que a su vez preguntar?a a la librer?a
110
        return (pathname.getName().toLowerCase().endsWith(".png"));
111
    }
112

    
113
    @Override
114
    public boolean closeResourceRequested(ResourceProvider resource) {
115
        return !(this.equals(resource));
116
    }
117

    
118
    @Override
119
    public void resourceChanged(ResourceProvider resource) {
120
        //Do nothing
121
    }
122

    
123
}