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 @ 47638
History | View | Annotate | Download (6.3 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 boolean canCreate(NewDataStoreParameters parameters) { |
92 |
return false; |
93 |
} |
94 |
|
95 |
public void create(NewDataStoreParameters parameters, boolean overwrite) { |
96 |
throw new UnsupportedOperationException(); |
97 |
} |
98 |
|
99 |
protected NewDataStoreParameters createInstanceNewDataStoreParameters() {
|
100 |
throw new UnsupportedOperationException(); |
101 |
} |
102 |
|
103 |
@Override
|
104 |
public NewDataStoreParameters getCreateParameters() {
|
105 |
throw new UnsupportedOperationException(); |
106 |
} |
107 |
|
108 |
@Override
|
109 |
public void initialize(FilesystemServerExplorerProviderServices serverExplorer) { |
110 |
this.serverExplorer = serverExplorer;
|
111 |
|
112 |
} |
113 |
|
114 |
@Override
|
115 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
116 |
GMLStoreParameters params = (GMLStoreParameters) parameters; |
117 |
File file = params.getFile();
|
118 |
if (!file.exists()) {
|
119 |
throw new RemoveException(this.getDataStoreProviderName(), |
120 |
new FileNotFoundException(params.getFile())); |
121 |
} |
122 |
if (!file.delete()) {
|
123 |
throw new RemoveException(this.getDataStoreProviderName(), |
124 |
new IOException()); // FIXME Exception |
125 |
} |
126 |
} |
127 |
|
128 |
@Override
|
129 |
public boolean closeResourceRequested(ResourceProvider resource) { |
130 |
// while it is using a resource anyone can't close it
|
131 |
return !(this.equals(resource)); |
132 |
} |
133 |
|
134 |
/*
|
135 |
* (non-Javadoc)
|
136 |
*
|
137 |
* @see
|
138 |
* org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
|
139 |
* gvsig.fmap.dal.resource.spi.ResourceProvider)
|
140 |
*/
|
141 |
@Override
|
142 |
public void resourceChanged(ResourceProvider resource) { |
143 |
// Do nothing
|
144 |
} |
145 |
|
146 |
protected EditableFeatureType fixFeatureType(FeatureType featureType) {
|
147 |
EditableFeatureType newFeatureType; |
148 |
|
149 |
if (featureType instanceof EditableFeatureType) { |
150 |
newFeatureType = (EditableFeatureType) featureType.getCopy(); |
151 |
} else {
|
152 |
newFeatureType = featureType.getEditable(); |
153 |
} |
154 |
|
155 |
for (int i = 0; i < newFeatureType.size(); i++) { |
156 |
EditableFeatureAttributeDescriptor attr = (EditableFeatureAttributeDescriptor) newFeatureType.getAttributeDescriptor(i); |
157 |
String s;
|
158 |
switch (attr.getType()) {
|
159 |
case DataTypes.INT:
|
160 |
s = String.valueOf(Integer.MAX_VALUE); |
161 |
attr.setSize(18);
|
162 |
attr.setPrecision(0);
|
163 |
attr.setScale(0);
|
164 |
break;
|
165 |
case DataTypes.LONG:
|
166 |
s = String.valueOf(Long.MAX_VALUE); |
167 |
attr.setSize(18);
|
168 |
attr.setPrecision(0);
|
169 |
attr.setScale(0);
|
170 |
break;
|
171 |
case DataTypes.FLOAT:
|
172 |
attr.setSize(18);
|
173 |
attr.setPrecision(6);
|
174 |
attr.setScale(0);
|
175 |
break;
|
176 |
case DataTypes.DOUBLE:
|
177 |
attr.setSize(18);
|
178 |
attr.setPrecision(6);
|
179 |
attr.setScale(0);
|
180 |
break;
|
181 |
} |
182 |
} |
183 |
return newFeatureType;
|
184 |
} |
185 |
} |