Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.csv / src / main / java / org / gvsig / fmap / dal / store / gml / GMLFilesystemServerProvider.java @ 47642

History | View | Annotate | Download (5.8 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.fmap.dal.store.gml;
25

    
26
import java.io.File;
27
import java.io.IOException;
28
import org.gvsig.fmap.dal.DALLocator;
29
import org.gvsig.fmap.dal.DataManager;
30

    
31
import org.gvsig.fmap.dal.DataServerExplorer;
32
import org.gvsig.fmap.dal.DataStoreParameters;
33
import org.gvsig.fmap.dal.NewDataStoreParameters;
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.exception.FileNotFoundException;
36
import org.gvsig.fmap.dal.exception.RemoveException;
37
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
38
import org.gvsig.fmap.dal.feature.EditableFeatureType;
39
import org.gvsig.fmap.dal.feature.FeatureType;
40
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
41
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
42
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
43
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider;
44
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
45
import org.gvsig.tools.dataTypes.DataTypes;
46

    
47
public class GMLFilesystemServerProvider extends AbstractFilesystemServerExplorerProvider
48
        implements FilesystemServerExplorerProvider, ResourceConsumer {
49

    
50
    protected FilesystemServerExplorerProviderServices serverExplorer;
51

    
52
    @Override
53
    public String getDataStoreProviderName() {
54
        return GMLStoreProvider.NAME;
55
    }
56

    
57
    @Override
58
    public int getMode() {
59
        return DataServerExplorer.MODE_FEATURE | DataServerExplorer.MODE_GEOMETRY;
60
    }
61

    
62
    @Override
63
    public boolean accept(File file) {
64
        String pathname = file.getName().toLowerCase();
65
        if ( pathname.endsWith(".gml")){
66
            return true;
67
        }
68
        return false;
69
    }
70

    
71
    @Override
72
    public String getDescription() {
73
        return GMLStoreProvider.DESCRIPTION;
74
    }
75

    
76
    @Override
77
    public DataStoreParameters getParameters(File file) throws DataException {
78
        DataManager manager = DALLocator.getDataManager();
79
        GMLStoreParameters params = (GMLStoreParameters) manager
80
                .createStoreParameters(this.getDataStoreProviderName());
81
        params.setFile(file);
82
        return params;
83
    }
84

    
85
    @Override
86
    public boolean canCreate() {
87
        return false;
88
    }
89

    
90
    @Override
91
    public void initialize(FilesystemServerExplorerProviderServices serverExplorer) {
92
        this.serverExplorer = serverExplorer;
93

    
94
    }
95

    
96
    @Override
97
    public void remove(DataStoreParameters parameters) throws RemoveException {
98
        GMLStoreParameters params = (GMLStoreParameters) parameters;
99
        File file = params.getFile();
100
        if (!file.exists()) {
101
            throw new RemoveException(this.getDataStoreProviderName(),
102
                    new FileNotFoundException(params.getFile()));
103
        }
104
        if (!file.delete()) {
105
            throw new RemoveException(this.getDataStoreProviderName(),
106
                    new IOException()); // FIXME Exception
107
        }
108
    }
109

    
110
    @Override
111
    public boolean closeResourceRequested(ResourceProvider resource) {
112
        // while it is using a resource anyone can't close it
113
        return !(this.equals(resource));
114
    }
115

    
116
    /*
117
         * (non-Javadoc)
118
         *
119
         * @see
120
         * org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
121
         * gvsig.fmap.dal.resource.spi.ResourceProvider)
122
     */
123
    @Override
124
    public void resourceChanged(ResourceProvider resource) {
125
        // Do nothing
126
    }
127

    
128
    protected EditableFeatureType fixFeatureType(FeatureType featureType) {
129
        EditableFeatureType newFeatureType;
130

    
131
        if (featureType instanceof EditableFeatureType) {
132
            newFeatureType = (EditableFeatureType) featureType.getCopy();
133
        } else {
134
            newFeatureType = featureType.getEditable();
135
        }
136

    
137
        for (int i = 0; i < newFeatureType.size(); i++) {
138
            EditableFeatureAttributeDescriptor attr = (EditableFeatureAttributeDescriptor) newFeatureType.getAttributeDescriptor(i);
139
            String s;
140
            switch (attr.getType()) {
141
                case DataTypes.INT:
142
                    s = String.valueOf(Integer.MAX_VALUE);
143
                    attr.setSize(18);
144
                    attr.setPrecision(0);
145
                    attr.setScale(0);
146
                    break;
147
                case DataTypes.LONG:
148
                    s = String.valueOf(Long.MAX_VALUE);
149
                    attr.setSize(18);
150
                    attr.setPrecision(0);
151
                    attr.setScale(0);
152
                    break;
153
                case DataTypes.FLOAT:
154
                    attr.setSize(18);
155
                    attr.setPrecision(6);
156
                    attr.setScale(0);
157
                    break;
158
                case DataTypes.DOUBLE:
159
                    attr.setSize(18);
160
                    attr.setPrecision(6);
161
                    attr.setScale(0);
162
                    break;
163
            }
164
        }
165
        return newFeatureType;
166
    }
167
}