Revision 44160
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/H2SpatialHelper.java | ||
---|---|---|
28 | 28 |
import org.apache.commons.io.FilenameUtils; |
29 | 29 |
import org.apache.commons.lang3.StringUtils; |
30 | 30 |
import org.gvsig.fmap.dal.SQLBuilder; |
31 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
31 | 32 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
33 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
|
32 | 34 |
import org.gvsig.fmap.dal.store.h2.operations.H2SpatialOperationsFactory; |
33 | 35 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
34 | 36 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
35 | 37 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
36 | 38 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
37 | 39 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException; |
40 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
38 | 41 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
39 | 42 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase; |
40 | 43 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
44 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCServerExplorerBase; |
|
41 | 45 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverBase; |
42 | 46 |
import org.h2.tools.Server; |
43 | 47 |
import org.h2gis.ext.H2GISExtension; |
... | ... | |
362 | 366 |
return new H2SpatialExplorerParameters(); |
363 | 367 |
} |
364 | 368 |
|
369 |
@Override |
|
370 |
public JDBCServerExplorer createServerExplorer( |
|
371 |
JDBCServerExplorerParameters parameters, |
|
372 |
DataServerExplorerProviderServices providerServices |
|
373 |
) throws InitializeException { |
|
374 |
|
|
375 |
JDBCServerExplorer explorer = new JDBCServerExplorerBase( |
|
376 |
parameters, |
|
377 |
providerServices, |
|
378 |
this |
|
379 |
); |
|
380 |
this.initialize(explorer, parameters, null); |
|
381 |
return explorer; |
|
382 |
} |
|
365 | 383 |
} |
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 |
package org.gvsig.fmap.dal.store.h2; |
|
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.nio.file.FileSystem; |
|
11 |
import java.nio.file.FileSystems; |
|
12 |
import java.nio.file.Files; |
|
13 |
import java.nio.file.Path; |
|
14 |
import java.util.HashMap; |
|
15 |
import java.util.Map; |
|
16 |
import org.apache.commons.io.FilenameUtils; |
|
17 |
import org.apache.commons.io.IOUtils; |
|
18 |
import org.gvsig.fmap.dal.DataStore; |
|
19 |
import org.gvsig.fmap.dal.exception.DataException; |
|
20 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
21 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
|
22 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
23 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
24 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCServerExplorerBase; |
|
25 |
|
|
26 |
/** |
|
27 |
* |
|
28 |
* @author jjdelcerro |
|
29 |
*/ |
|
30 |
@SuppressWarnings("UseSpecificCatch") |
|
31 |
public class H2SpatialExplorer extends JDBCServerExplorerBase { |
|
32 |
|
|
33 |
private class H2Resource implements DataResource { |
|
34 |
|
|
35 |
private final File zipFile; |
|
36 |
private final String tableName; |
|
37 |
private InputStream in; |
|
38 |
private ByteArrayOutputStream out; |
|
39 |
private FileSystem fs; |
|
40 |
|
|
41 |
public H2Resource(File zipFile, String tableName) { |
|
42 |
this.zipFile = zipFile; |
|
43 |
this.tableName = tableName; |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public boolean exists() { |
|
48 |
if( !this.zipFile.exists() ) { |
|
49 |
return false; |
|
50 |
} |
|
51 |
try { |
|
52 |
Map<String, String> attributes = new HashMap<>(); |
|
53 |
attributes.put("create", "false"); |
|
54 |
URI zipURI = new URI("jar:"+this.zipFile.toURI().toString()); |
|
55 |
this.fs = FileSystems.newFileSystem(zipURI, attributes); |
|
56 |
Path tablePath = fs.getPath(this.tableName); |
|
57 |
if( tablePath==null ) { |
|
58 |
IOUtils.closeQuietly(fs); |
|
59 |
this.fs = null; |
|
60 |
return false; |
|
61 |
} |
|
62 |
return true; |
|
63 |
|
|
64 |
} catch(Exception ex) { |
|
65 |
IOUtils.closeQuietly(fs); |
|
66 |
this.fs = null; |
|
67 |
return false; |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public InputStream asInputStream() throws IOException { |
|
73 |
if( !this.zipFile.exists()) { |
|
74 |
return null; |
|
75 |
} |
|
76 |
if( this.in!=null || this.out!=null ) { |
|
77 |
throw new IllegalStateException("Resource is already open ("+this.zipFile.toString()+"!"+this.tableName+")"); |
|
78 |
} |
|
79 |
try { |
|
80 |
Map<String, String> attributes = new HashMap<>(); |
|
81 |
attributes.put("create", "false"); |
|
82 |
URI zipURI = new URI("jar:"+this.zipFile.toURI().toString()); |
|
83 |
this.fs = FileSystems.newFileSystem(zipURI, attributes); |
|
84 |
Path tablePath = fs.getPath(this.tableName); |
|
85 |
if( tablePath==null ) { |
|
86 |
IOUtils.closeQuietly(fs); |
|
87 |
this.fs = null; |
|
88 |
return null; |
|
89 |
} |
|
90 |
this.in = Files.newInputStream(tablePath); |
|
91 |
return this.in; |
|
92 |
|
|
93 |
} catch(Exception ex) { |
|
94 |
IOUtils.closeQuietly(fs); |
|
95 |
this.fs = null; |
|
96 |
return null; |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
@Override |
|
101 |
public OutputStream asOutputStream() throws IOException { |
|
102 |
if( !this.zipFile.exists() ) { |
|
103 |
return null; |
|
104 |
} |
|
105 |
if( this.in!=null || this.out!=null ) { |
|
106 |
throw new IllegalStateException("Resource is already open ("+this.zipFile.toString()+"!"+this.tableName+")"); |
|
107 |
} |
|
108 |
this.out = new ByteArrayOutputStream(); |
|
109 |
return this.out; |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public void close() { |
|
114 |
if( this.in!=null ) { |
|
115 |
IOUtils.closeQuietly(this.in); |
|
116 |
this.in = null; |
|
117 |
} |
|
118 |
if(this.out != null ) { |
|
119 |
try { |
|
120 |
Map<String, String> attributes = new HashMap<>(); |
|
121 |
attributes.put("create", "true"); |
|
122 |
URI zipURI = new URI("jar:"+this.zipFile.toURI().toString()); |
|
123 |
this.fs = FileSystems.newFileSystem(zipURI, attributes); |
|
124 |
Path tablePath = fs.getPath(this.tableName); |
|
125 |
ByteArrayInputStream lin = new ByteArrayInputStream(this.out.toByteArray()); |
|
126 |
Files.copy(lin, tablePath); |
|
127 |
|
|
128 |
} catch(Exception ex) { |
|
129 |
IOUtils.closeQuietly(this.out); |
|
130 |
this.out = null; |
|
131 |
} |
|
132 |
} |
|
133 |
if( this.fs!=null ) { |
|
134 |
IOUtils.closeQuietly(this.fs); |
|
135 |
this.fs = null; |
|
136 |
} |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
public H2SpatialExplorer(JDBCServerExplorerParameters parameters, DataServerExplorerProviderServices services, JDBCHelper helper) throws InitializeException { |
|
141 |
super(parameters, services, helper); |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public H2SpatialExplorerParameters getParameters() { |
|
146 |
return (H2SpatialExplorerParameters) super.getParameters(); |
|
147 |
} |
|
148 |
|
|
149 |
@Override |
|
150 |
public DataResource getResource(DataStore dataStore, String resourceName) throws DataException { |
|
151 |
String zipPath = this.getParameters().getFile().getAbsolutePath(); |
|
152 |
zipPath = FilenameUtils.removeExtension(zipPath); |
|
153 |
zipPath = zipPath + "." + resourceName; |
|
154 |
H2Resource resource = new H2Resource(new File(zipPath), dataStore.getName()); |
|
155 |
return resource; |
|
156 |
} |
|
157 |
|
|
158 |
} |
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/featuretable/table/DynFieldFacadeOfAFeatureAttributeDescriptor.java | ||
---|---|---|
407 | 407 |
public String getDataProfileName() { |
408 | 408 |
return null; |
409 | 409 |
} |
410 |
|
|
411 |
@Override |
|
412 |
public String[] getRequiredFieldNames() { |
|
413 |
return null; |
|
414 |
} |
|
410 | 415 |
} |
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/DummyFeatureAttributeDescriptor.java | ||
---|---|---|
392 | 392 |
return null; |
393 | 393 |
} |
394 | 394 |
|
395 |
@Override |
|
396 |
public String[] getRequiredFieldNames() { |
|
397 |
return null; |
|
398 |
} |
|
399 |
|
|
395 | 400 |
} |
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/FeatureAttributeDescriptor.java | ||
---|---|---|
254 | 254 |
|
255 | 255 |
public FeatureType getFeatureType(); |
256 | 256 |
|
257 |
public String[] getRequiredFieldNames(); |
|
257 | 258 |
} |
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 | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal; |
25 | 25 |
|
26 |
import java.io.Closeable; |
|
26 | 27 |
import java.io.File; |
28 |
import java.io.IOException; |
|
29 |
import java.io.InputStream; |
|
30 |
import java.io.OutputStream; |
|
27 | 31 |
import java.util.List; |
28 | 32 |
|
29 | 33 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
38 | 42 |
*/ |
39 | 43 |
public interface DataServerExplorer extends Disposable, DataFactoryUnit { |
40 | 44 |
|
45 |
public interface DataResource extends Closeable { |
|
46 |
public boolean exists(); |
|
47 |
|
|
48 |
public InputStream asInputStream() throws IOException; |
|
49 |
|
|
50 |
public OutputStream asOutputStream() throws IOException; |
|
51 |
|
|
52 |
public void close(); |
|
53 |
} |
|
54 |
|
|
41 | 55 |
/** |
42 | 56 |
* Returns the DataServerExplorer's name |
43 | 57 |
* |
... | ... | |
159 | 173 |
* @param resourceName |
160 | 174 |
* @return file resource or null |
161 | 175 |
* @throws DataException |
176 |
* @deprecated use getResource |
|
162 | 177 |
*/ |
163 | 178 |
public File getResourcePath(DataStore dataStore, String resourceName) throws DataException; |
164 | 179 |
|
180 |
/** |
|
181 |
* Return the DataResource associated to this name and store. If the |
|
182 |
* resource not exists or the explorer don't support this opperation return |
|
183 |
* null. |
|
184 |
* |
|
185 |
* @param dataStore |
|
186 |
* @param resourceName |
|
187 |
* @return the DataResource or null |
|
188 |
* @throws DataException |
|
189 |
*/ |
|
190 |
public DataResource getResource(DataStore dataStore, String resourceName) throws DataException; |
|
165 | 191 |
} |
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 | ||
---|---|---|
40 | 40 |
return null; |
41 | 41 |
} |
42 | 42 |
|
43 |
@Deprecated |
|
43 | 44 |
@Override |
44 | 45 |
public File getResourcePath(DataStore dataStore, String resourceName) throws DataException { |
45 | 46 |
return null; |
46 | 47 |
} |
48 |
|
|
49 |
@Override |
|
50 |
public DataResource getResource(DataStore dataStore, String resourceName) throws DataException { |
|
51 |
return null; |
|
52 |
} |
|
47 | 53 |
|
48 | 54 |
@Override |
49 | 55 |
public SQLBuilder createSQLBuilder() { |
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 | ||
---|---|---|
23 | 23 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.impl; |
24 | 24 |
|
25 | 25 |
import java.io.File; |
26 |
import java.io.FileInputStream; |
|
27 |
import java.io.FileOutputStream; |
|
28 |
import java.io.InputStream; |
|
29 |
import java.io.OutputStream; |
|
26 | 30 |
import java.util.ArrayList; |
27 | 31 |
import java.util.HashSet; |
28 | 32 |
import java.util.Iterator; |
29 | 33 |
import java.util.List; |
30 | 34 |
import java.util.Set; |
31 | 35 |
import org.apache.commons.io.FilenameUtils; |
36 |
import org.apache.commons.io.IOUtils; |
|
32 | 37 |
|
33 | 38 |
import org.gvsig.fmap.dal.DALFileLocator; |
34 | 39 |
import org.gvsig.fmap.dal.DALLocator; |
35 | 40 |
import org.gvsig.fmap.dal.DataManager; |
36 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
37 | 41 |
import org.gvsig.fmap.dal.DataStore; |
38 | 42 |
import org.gvsig.fmap.dal.DataStoreParameters; |
39 | 43 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
... | ... | |
57 | 61 |
import org.gvsig.tools.exception.BaseException; |
58 | 62 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
59 | 63 |
|
64 |
@SuppressWarnings("UseSpecificCatch") |
|
60 | 65 |
public class DefaultFilesystemServerExplorer extends AbstractDataServerExplorer |
61 | 66 |
implements FilesystemServerExplorerProviderServices, |
62 | 67 |
FilesystemFileFilter { |
63 | 68 |
|
69 |
private class FileResource implements DataResource { |
|
70 |
|
|
71 |
private final File f; |
|
72 |
private FileInputStream in; |
|
73 |
private FileOutputStream out; |
|
74 |
|
|
75 |
public FileResource(File f) { |
|
76 |
this.f = f; |
|
77 |
} |
|
78 |
|
|
79 |
public File getFile() { |
|
80 |
return this.f; |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public boolean exists() { |
|
85 |
return this.f.exists(); |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public InputStream asInputStream() throws java.io.FileNotFoundException { |
|
90 |
if( this.out != null || this.in!=null ) { |
|
91 |
throw new IllegalStateException("Input already open"); |
|
92 |
} |
|
93 |
this.in = new FileInputStream(this.f); |
|
94 |
return this.in; |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public OutputStream asOutputStream() throws java.io.FileNotFoundException { |
|
99 |
if( this.out != null || this.in!=null ) { |
|
100 |
throw new IllegalStateException("Input already open"); |
|
101 |
} |
|
102 |
this.out = new FileOutputStream(this.f); |
|
103 |
return this.out; |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public void close() { |
|
108 |
IOUtils.closeQuietly(out); |
|
109 |
IOUtils.closeQuietly(in); |
|
110 |
this.in = null; |
|
111 |
this.out = null; |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
64 | 115 |
private File root; |
65 | 116 |
private File current; // Current path |
66 | 117 |
private List<FilesystemServerExplorerProvider> serverProviders; |
... | ... | |
112 | 163 |
List providers = this.getProviders(mode); |
113 | 164 |
String allfiles[] = this.current.list(); |
114 | 165 |
|
115 |
for (int i = 0; i < allfiles.length; i++) {
|
|
116 |
File file = new File(this.root, allfiles[i]);
|
|
166 |
for (String f : allfiles) {
|
|
167 |
File file = new File(this.root, f);
|
|
117 | 168 |
Iterator providersit = providers.iterator(); |
118 | 169 |
while (providersit.hasNext()) { |
119 | 170 |
FilesystemServerExplorerProvider provider = (FilesystemServerExplorerProvider) providersit |
... | ... | |
135 | 186 |
throw new IllegalStateException(); // FIXME |
136 | 187 |
} |
137 | 188 |
if (!this.current.exists()) { |
138 |
// TODO crear excepcion de Data?? |
|
139 |
new org.gvsig.fmap.dal.exception.FileNotFoundException(this.current); |
|
189 |
throw new FileNotFoundException(this.current); |
|
140 | 190 |
} |
141 | 191 |
|
142 | 192 |
if (!this.current.isDirectory()) { |
143 |
new IllegalArgumentException(this.getProviderName() |
|
193 |
throw new IllegalArgumentException(this.getProviderName()
|
|
144 | 194 |
+ ": Path not a directory '" + this.current + "'"); |
145 | 195 |
} |
146 | 196 |
|
... | ... | |
148 | 198 |
int i; |
149 | 199 |
File theFile; |
150 | 200 |
ArrayList list = new ArrayList(); |
151 |
DataStoreParameters dsp = null;
|
|
201 |
DataStoreParameters dsp; |
|
152 | 202 |
|
153 | 203 |
for (i = 0; i < files.length; i++) { |
154 | 204 |
theFile = new File(this.root, files[i]); |
... | ... | |
210 | 260 |
ndsp.validate(); |
211 | 261 |
provider.create(ndsp, overwrite); |
212 | 262 |
return true; |
213 |
} catch (DataException e) { |
|
263 |
} catch (DataException | ValidateDataParametersException e) {
|
|
214 | 264 |
throw new ServerExplorerAddException(this.getProviderName(), e); |
215 |
} catch (ValidateDataParametersException e) { |
|
216 |
throw new ServerExplorerAddException(this.getProviderName(), e); |
|
217 | 265 |
} |
218 | 266 |
} |
219 | 267 |
|
... | ... | |
346 | 394 |
|
347 | 395 |
private void checkIsMine(DataStoreParameters dsp) |
348 | 396 |
throws IllegalArgumentException, DataException { |
349 |
// FIXME Exception ??? |
|
350 | 397 |
if (!(dsp instanceof FilesystemStoreParameters)) { |
351 |
new IllegalArgumentException( |
|
352 |
"not instance of FilesystemStoreParameters"); |
|
398 |
throw new IllegalArgumentException("not instance of FilesystemStoreParameters"); |
|
353 | 399 |
} |
354 | 400 |
Iterator filters = getFilters(); |
355 | 401 |
File file = ((FilesystemStoreParameters) dsp).getFile(); |
... | ... | |
493 | 539 |
return newParams; |
494 | 540 |
} |
495 | 541 |
|
542 |
@Deprecated |
|
496 | 543 |
@Override |
497 | 544 |
public File getResourcePath(DataStore dataStore, String resourceName) throws DataException { |
498 |
FilesystemServerExplorerProvider provider |
|
499 |
= this.getProvider(dataStore.getProviderName()); |
|
545 |
FileResource resource = (FileResource) this.getResource(dataStore, resourceName); |
|
546 |
if( resource==null ) { |
|
547 |
return null; |
|
548 |
} |
|
549 |
return resource.getFile(); |
|
550 |
} |
|
551 |
|
|
552 |
@Override |
|
553 |
public DataResource getResource(DataStore dataStore, String resourceName) throws DataException { |
|
554 |
FilesystemServerExplorerProvider provider = this.getProvider(dataStore.getProviderName()); |
|
500 | 555 |
if (provider == null) { |
501 | 556 |
return null; |
502 | 557 |
} |
... | ... | |
506 | 561 |
} |
507 | 562 |
File f = new File(FilenameUtils.getFullPathNoEndSeparator(rootPathName),resourceName); |
508 | 563 |
if( f.exists() ) { |
509 |
return f;
|
|
564 |
return new FileResource(f);
|
|
510 | 565 |
} |
511 |
return new File(rootPathName + "." + resourceName);
|
|
566 |
return new FileResource(new File(rootPathName + "." + resourceName));
|
|
512 | 567 |
} |
513 |
|
|
568 |
|
|
514 | 569 |
@Override |
515 | 570 |
public DataStoreParameters get(String name) throws DataException { |
516 | 571 |
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 | ||
---|---|---|
53 | 53 |
import org.gvsig.fmap.dal.DataManager; |
54 | 54 |
import org.gvsig.fmap.dal.DataQuery; |
55 | 55 |
import org.gvsig.fmap.dal.DataServerExplorer; |
56 |
import org.gvsig.fmap.dal.DataServerExplorer.DataResource; |
|
56 | 57 |
import org.gvsig.fmap.dal.DataSet; |
57 | 58 |
import org.gvsig.fmap.dal.DataStore; |
58 | 59 |
import org.gvsig.fmap.dal.DataStoreNotification; |
... | ... | |
1559 | 1560 |
if( explorer == null ) { |
1560 | 1561 |
return; |
1561 | 1562 |
} |
1562 |
File f = explorer.getResourcePath(this, "dal");
|
|
1563 |
if( f == null ) {
|
|
1563 |
DataResource resource = explorer.getResource(this, "dal");
|
|
1564 |
if( resource == null ) {
|
|
1564 | 1565 |
return; |
1565 | 1566 |
} |
1566 | 1567 |
DALFile dalFile = DALFile.getDALFile(); |
1567 | 1568 |
dalFile.setStore(this); |
1568 | 1569 |
if( !dalFile.isEmpty() ) { |
1569 |
dalFile.write(f);
|
|
1570 |
dalFile.write(resource);
|
|
1570 | 1571 |
} |
1571 | 1572 |
} catch (Exception ex) { |
1572 | 1573 |
LOG.warn("Can't save DAL File", ex); |
... | ... | |
1580 | 1581 |
if( explorer == null ) { |
1581 | 1582 |
return; |
1582 | 1583 |
} |
1583 |
File f = explorer.getResourcePath(this, "dal");
|
|
1584 |
if( f == null || !f.exists() ) {
|
|
1584 |
DataResource resource = explorer.getResource(this, "dal");
|
|
1585 |
if( resource == null || !resource.exists() ) {
|
|
1585 | 1586 |
return; |
1586 | 1587 |
} |
1587 |
DALFile dalFile = DALFile.getDALFile(f);
|
|
1588 |
DALFile dalFile = DALFile.getDALFile(resource);
|
|
1588 | 1589 |
if( !dalFile.isEmpty() ) { |
1589 | 1590 |
dalFile.updateStore(this); |
1590 | 1591 |
} |
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/DALFile.java | ||
---|---|---|
1 | 1 |
|
2 | 2 |
package org.gvsig.fmap.dal.feature.impl; |
3 | 3 |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileInputStream; |
|
6 |
import java.io.FileOutputStream; |
|
4 |
import java.io.InputStream; |
|
5 |
import java.io.OutputStream; |
|
7 | 6 |
import java.util.ArrayList; |
8 | 7 |
import java.util.HashSet; |
9 | 8 |
import java.util.Iterator; |
... | ... | |
12 | 11 |
import org.apache.commons.collections4.CollectionUtils; |
13 | 12 |
import org.apache.commons.io.IOUtils; |
14 | 13 |
import org.apache.commons.lang3.StringUtils; |
14 |
import org.gvsig.fmap.dal.DataServerExplorer.DataResource; |
|
15 | 15 |
import org.gvsig.fmap.dal.exception.DataException; |
16 | 16 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
17 | 17 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
... | ... | |
38 | 38 |
return f; |
39 | 39 |
} |
40 | 40 |
|
41 |
public static DALFile getDALFile(File f) {
|
|
41 |
public static DALFile getDALFile(DataResource resource) {
|
|
42 | 42 |
DALFile df = new DALFile(); |
43 |
df.read(f);
|
|
43 |
df.read(resource);
|
|
44 | 44 |
return df; |
45 | 45 |
} |
46 | 46 |
|
... | ... | |
187 | 187 |
return false; |
188 | 188 |
} |
189 | 189 |
|
190 |
public void write(File f) { |
|
191 |
FileOutputStream out = null; |
|
190 |
public void write(DataResource resource) { |
|
192 | 191 |
try { |
193 | 192 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
194 | 193 |
PersistentState state = manager.getState(this); |
195 |
out = new FileOutputStream(f);
|
|
194 |
OutputStream out = resource.asOutputStream();
|
|
196 | 195 |
manager.saveState(state, out); |
197 | 196 |
} catch(Exception ex) { |
198 |
throw new RuntimeException("Can't write DAL file.",ex);
|
|
197 |
throw new RuntimeException("Can't write DAL resource.",ex);
|
|
199 | 198 |
} finally { |
200 |
IOUtils.closeQuietly(out);
|
|
199 |
IOUtils.closeQuietly(resource);
|
|
201 | 200 |
} |
202 | 201 |
} |
203 | 202 |
|
204 |
public void read(File f) { |
|
205 |
FileInputStream in = null; |
|
203 |
public void read(DataResource resource) { |
|
206 | 204 |
try { |
207 | 205 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
208 |
in = new FileInputStream(f);
|
|
206 |
InputStream in = resource.asInputStream();
|
|
209 | 207 |
DALFile x = (DALFile) manager.getObject(in); |
210 | 208 |
this.attributes.clear(); |
211 | 209 |
this.attributes.addAll(x.attributes); |
212 | 210 |
} catch(Exception ex) { |
213 | 211 |
throw new RuntimeException("Can't read DAL file.",ex); |
214 | 212 |
} finally { |
215 |
IOUtils.closeQuietly(in);
|
|
213 |
IOUtils.closeQuietly(resource);
|
|
216 | 214 |
} |
217 | 215 |
} |
218 | 216 |
|
Also available in: Unified diff