Revision 53
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.3/org.gvsig.seismic/org.gvsig.seismic.provider/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.seismic.provider</artifactId> |
|
7 |
<name>${project.artifactId}</name> |
|
8 |
<parent> |
|
9 |
<groupId>org.gvsig</groupId> |
|
10 |
<artifactId>org.gvsig.seismic</artifactId> |
|
11 |
<version>1.0.3</version> |
|
12 |
</parent> |
|
13 |
|
|
14 |
<dependencies> |
|
15 |
<dependency> |
|
16 |
<groupId>commons-io</groupId> |
|
17 |
<artifactId>commons-io</artifactId> |
|
18 |
<scope>compile</scope> |
|
19 |
</dependency> |
|
20 |
|
|
21 |
<dependency> |
|
22 |
<groupId>org.gvsig</groupId> |
|
23 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
24 |
<scope>compile</scope> |
|
25 |
</dependency> |
|
26 |
|
|
27 |
<dependency> |
|
28 |
<groupId>org.gvsig</groupId> |
|
29 |
<artifactId>org.gvsig.seismic.lib.api</artifactId> |
|
30 |
<scope>compile</scope> |
|
31 |
</dependency> |
|
32 |
|
|
33 |
</dependencies> |
|
34 |
|
|
35 |
<build> |
|
36 |
<plugins> |
|
37 |
<plugin> |
|
38 |
<groupId>org.apache.maven.plugins</groupId> |
|
39 |
<artifactId>maven-compiler-plugin</artifactId> |
|
40 |
<configuration> |
|
41 |
<source>1.5</source> |
|
42 |
<target>1.5</target> |
|
43 |
<encoding>ISO-8859-1</encoding> |
|
44 |
</configuration> |
|
45 |
</plugin> |
|
46 |
|
|
47 |
</plugins> |
|
48 |
</build> |
|
49 |
|
|
50 |
|
|
51 |
</project> |
|
0 | 52 |
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.3/org.gvsig.seismic/org.gvsig.seismic.provider/src/test/java/org/gvsig/fmap/dal/store/seismic/test.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.seismic; |
|
2 |
|
|
3 |
|
|
4 |
public class test { |
|
5 |
/* |
|
6 |
public static void main(String[] args) throws IOException { |
|
7 |
new test().doMain(args); |
|
8 |
} |
|
9 |
|
|
10 |
public void doMain(String[] args) throws IOException { |
|
11 |
CSVFormat format = CSVFormat.DEFAULT |
|
12 |
.withHeader() |
|
13 |
.withSkipHeaderRecord(true) |
|
14 |
.withIgnoreEmptyLines(true) |
|
15 |
.withDelimiter(';'); |
|
16 |
URL data = this.getClass().getResource("/test1.csv"); |
|
17 |
CSVParser parser = CSVParser.parse(data,Charset.forName("UTF-8"), format); |
|
18 |
Map headerMap = parser.getHeaderMap(); |
|
19 |
String header[] = new String[headerMap.size()]; |
|
20 |
int i=0; |
|
21 |
Iterator it = headerMap.keySet().iterator(); |
|
22 |
while(it.hasNext()) { |
|
23 |
header[i++] = (String) it.next(); |
|
24 |
} |
|
25 |
for(i=0; i<header.length;i++) { |
|
26 |
System.out.println("header["+i+"]="+header[i]); |
|
27 |
} |
|
28 |
List r = parser.getRecords(); |
|
29 |
System.out.println(r.toString()); |
|
30 |
} |
|
31 |
*/ |
|
32 |
} |
|
0 | 33 |
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.3/org.gvsig.seismic/org.gvsig.seismic.provider/src/main/resources/org/gvsig/fmap/dal/store/seismic/SeismicMetadata.xml | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<!-- |
|
3 |
Definitions of metadata fields of a seismic file. |
|
4 |
--> |
|
5 |
<definitions> |
|
6 |
<version>1.0.0</version> |
|
7 |
<classes> |
|
8 |
|
|
9 |
<class name="Seismic" namespace="Metadata"> |
|
10 |
<extends> |
|
11 |
<class namespace="Metadata" name="SpatialProvider"/> |
|
12 |
</extends> |
|
13 |
<description>Metadata of a Seismic store</description> |
|
14 |
<fields> |
|
15 |
</fields> |
|
16 |
</class> |
|
17 |
|
|
18 |
</classes> |
|
19 |
</definitions> |
|
0 | 20 |
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.3/org.gvsig.seismic/org.gvsig.seismic.provider/src/main/resources/org/gvsig/fmap/dal/store/seismic/SeismicParameters.xml | ||
---|---|---|
1 |
<?xml version= "1.0 "?> |
|
2 |
<definitions> |
|
3 |
<version>1.0.0</version> |
|
4 |
<classes> |
|
5 |
<class name="SeismicStoreParameters"> |
|
6 |
<extends> |
|
7 |
<class namespace="dal" name="ProviderParameters"/> |
|
8 |
</extends> |
|
9 |
<description>Store the parameters need to open a Seismic file</description> |
|
10 |
<fields> |
|
11 |
<field name="File" type="file" mandatory="true" group="Basic"> |
|
12 |
<description>Seismic file</description> |
|
13 |
</field> |
|
14 |
<field name="Parser" type="String" hidden="true" mandatory="true" group="Basic"> |
|
15 |
<description>Parser name used to get the data from the file.</description> |
|
16 |
</field> |
|
17 |
<field name="CRS" type="crs" mandatory="false" group="Basic"> |
|
18 |
<description>The coordinate reference system used in this seismic file if contains geometries</description> |
|
19 |
</field> |
|
20 |
<field name="point" type="string" hidden="true" mandatory="false" defaultValue="" group="Basic"> |
|
21 |
<description>This field allow to add a Geometry column to the table. It is a list of field names separated by commas used as dimensions for the attribute GEOM of type point to add to the table.</description> |
|
22 |
</field> |
|
23 |
<field name="ProjectID" type="string" mandatory="false" defaultValue="" group="Advanced"> |
|
24 |
<description>This field allow to add a Geometry column to the table. It is a list of field names separated by commas used as dimensions for the attribute GEOM of type point to add to the table.</description> |
|
25 |
</field> |
|
26 |
<field name="Project" type="string" mandatory="false" defaultValue="" group="Advanced"> |
|
27 |
<description>This field allow to add a Geometry column to the table. It is a list of field names separated by commas used as dimensions for the attribute GEOM of type point to add to the table.</description> |
|
28 |
</field> |
|
29 |
<field name="State" type="string" mandatory="false" defaultValue="" group="Advanced"> |
|
30 |
<description>This field allow to add a Geometry column to the table. It is a list of field names separated by commas used as dimensions for the attribute GEOM of type point to add to the table.</description> |
|
31 |
</field> |
|
32 |
<field name="Year" type="string" mandatory="false" defaultValue="" group="Advanced"> |
|
33 |
<description>This field allow to add a Geometry column to the table. It is a list of field names separated by commas used as dimensions for the attribute GEOM of type point to add to the table.</description> |
|
34 |
</field> |
|
35 |
</fields> |
|
36 |
</class> |
|
37 |
</classes> |
|
38 |
</definitions> |
|
0 | 39 |
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.3/org.gvsig.seismic/org.gvsig.seismic.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.fmap.dal.store.seismic.SeismicStoreProviderLibrary |
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.3/org.gvsig.seismic/org.gvsig.seismic.provider/src/main/java/org/gvsig/fmap/dal/store/seismic/SeismicFilesystemServerProvider.java | ||
---|---|---|
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.seismic; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
import org.gvsig.fmap.dal.DALLocator; |
|
29 |
import org.gvsig.fmap.dal.DataManager; |
|
30 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
31 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
32 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
33 |
import org.gvsig.fmap.dal.exception.CreateException; |
|
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.resource.spi.ResourceConsumer; |
|
38 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
39 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider; |
|
40 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider; |
|
41 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
|
42 |
|
|
43 |
public class SeismicFilesystemServerProvider extends AbstractFilesystemServerExplorerProvider |
|
44 |
implements FilesystemServerExplorerProvider, ResourceConsumer { |
|
45 |
|
|
46 |
private FilesystemServerExplorerProviderServices serverExplorer; |
|
47 |
|
|
48 |
public String getDataStoreProviderName() { |
|
49 |
return SeismicStoreProvider.NAME; |
|
50 |
} |
|
51 |
|
|
52 |
public int getMode() { |
|
53 |
return DataServerExplorer.MODE_FEATURE | DataServerExplorer.MODE_GEOMETRY; |
|
54 |
} |
|
55 |
|
|
56 |
public boolean accept(File pathname) { |
|
57 |
return (pathname.getName().toLowerCase().endsWith(".uk")); |
|
58 |
} |
|
59 |
|
|
60 |
public String getDescription() { |
|
61 |
return SeismicStoreProvider.DESCRIPTION; |
|
62 |
} |
|
63 |
|
|
64 |
public DataStoreParameters getParameters(File file) throws DataException { |
|
65 |
DataManager manager = DALLocator.getDataManager(); |
|
66 |
SeismicStoreParameters params = (SeismicStoreParameters) manager |
|
67 |
.createStoreParameters(this |
|
68 |
.getDataStoreProviderName()); |
|
69 |
params.setFile(file); |
|
70 |
return params; |
|
71 |
} |
|
72 |
|
|
73 |
public boolean canCreate() { |
|
74 |
return false; |
|
75 |
} |
|
76 |
|
|
77 |
public boolean canCreate(NewDataStoreParameters parameters) { |
|
78 |
throw new UnsupportedOperationException(); |
|
79 |
} |
|
80 |
|
|
81 |
public void create(NewDataStoreParameters parameters, boolean overwrite) |
|
82 |
throws CreateException { |
|
83 |
throw new UnsupportedOperationException(); |
|
84 |
} |
|
85 |
|
|
86 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
|
87 |
throw new UnsupportedOperationException(); |
|
88 |
} |
|
89 |
|
|
90 |
public void initialize( |
|
91 |
FilesystemServerExplorerProviderServices serverExplorer) { |
|
92 |
this.serverExplorer = serverExplorer; |
|
93 |
} |
|
94 |
|
|
95 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
|
96 |
File file = ((SeismicStoreParameters) parameters).getFile(); |
|
97 |
if (!file.exists()) { |
|
98 |
throw new RemoveException(this.getDataStoreProviderName(), |
|
99 |
new FileNotFoundException(file)); |
|
100 |
} |
|
101 |
if (!file.delete()) { |
|
102 |
// FIXME throws ??? |
|
103 |
} |
|
104 |
|
|
105 |
} |
|
106 |
|
|
107 |
public boolean closeResourceRequested(ResourceProvider resource) { |
|
108 |
// while it is using a resource anyone can't close it |
|
109 |
return false; |
|
110 |
} |
|
111 |
|
|
112 |
public void resourceChanged(ResourceProvider resource) { |
|
113 |
//Do nothing |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
|
|
118 |
} |
|
0 | 119 |
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.3/org.gvsig.seismic/org.gvsig.seismic.provider/src/main/java/org/gvsig/fmap/dal/store/seismic/SeismicStoreProvider.java | ||
---|---|---|
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.seismic; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.Iterator; |
|
30 |
import java.util.List; |
|
31 |
import java.util.Map; |
|
32 |
|
|
33 |
import org.apache.commons.io.FilenameUtils; |
|
34 |
import org.cresques.cts.IProjection; |
|
35 |
import org.gvsig.fmap.dal.DataStore; |
|
36 |
import org.gvsig.fmap.dal.DataStoreNotification; |
|
37 |
import org.gvsig.fmap.dal.DataTypes; |
|
38 |
import org.gvsig.fmap.dal.FileHelper; |
|
39 |
import org.gvsig.fmap.dal.exception.DataException; |
|
40 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
41 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
42 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
43 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
44 |
import org.gvsig.fmap.dal.feature.Feature; |
|
45 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
46 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
47 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
48 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
49 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
|
50 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
51 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
|
52 |
import org.gvsig.fmap.dal.feature.spi.memory.AbstractMemoryStoreProvider; |
|
53 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
|
54 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
|
55 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
|
56 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
57 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
58 |
import org.gvsig.fmap.geom.Geometry; |
|
59 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
60 |
import org.gvsig.fmap.geom.GeometryManager; |
|
61 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
62 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
63 |
import org.gvsig.seismic.Parser; |
|
64 |
import org.gvsig.seismic.SeismicLocator; |
|
65 |
import org.gvsig.seismic.SeismicManager; |
|
66 |
import org.gvsig.tools.ToolsLocator; |
|
67 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
68 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
|
69 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
70 |
import org.gvsig.tools.dynobject.DynField; |
|
71 |
import org.gvsig.tools.dynobject.DynObject; |
|
72 |
import org.gvsig.tools.dynobject.DynStruct; |
|
73 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
|
74 |
import org.gvsig.tools.exception.BaseException; |
|
75 |
import org.gvsig.tools.exception.NotYetImplemented; |
|
76 |
import org.gvsig.tools.persistence.PersistentState; |
|
77 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
78 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
79 |
import org.gvsig.tools.task.TaskStatusManager; |
|
80 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
81 |
import org.gvsig.tools.visitor.Visitor; |
|
82 |
import org.slf4j.Logger; |
|
83 |
import org.slf4j.LoggerFactory; |
|
84 |
|
|
85 |
|
|
86 |
public class SeismicStoreProvider extends AbstractMemoryStoreProvider implements |
|
87 |
ResourceConsumer { |
|
88 |
private static final Logger logger = LoggerFactory.getLogger(SeismicStoreProvider.class); |
|
89 |
|
|
90 |
public static final String NAME = "Seismic"; |
|
91 |
public static final String DESCRIPTION = "Seismic file"; |
|
92 |
|
|
93 |
public static final String METADATA_DEFINITION_NAME = NAME; |
|
94 |
|
|
95 |
private ResourceProvider resource; |
|
96 |
|
|
97 |
private long counterNewsOIDs = 0; |
|
98 |
private Envelope envelope; |
|
99 |
private boolean need_calculate_envelope = false; |
|
100 |
private SimpleTaskStatus taskStatus; |
|
101 |
|
|
102 |
private SeismicManager driverManager; |
|
103 |
|
|
104 |
private boolean isOpenedPreviously = false; |
|
105 |
|
|
106 |
|
|
107 |
public SeismicStoreProvider(SeismicStoreParameters parameters, |
|
108 |
DataStoreProviderServices storeServices) throws InitializeException { |
|
109 |
super( |
|
110 |
parameters, |
|
111 |
storeServices, |
|
112 |
FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME) |
|
113 |
); |
|
114 |
|
|
115 |
TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
|
116 |
this.taskStatus = manager.createDefaultSimpleTaskStatus("Seismic"); |
|
117 |
|
|
118 |
driverManager = SeismicLocator.getDriverManager(); |
|
119 |
|
|
120 |
counterNewsOIDs = 0; |
|
121 |
|
|
122 |
File file = getDriverParameters().getFile(); |
|
123 |
resource = this.createResource( |
|
124 |
FileResource.NAME, |
|
125 |
new Object[] { file.getAbsolutePath() } |
|
126 |
); |
|
127 |
|
|
128 |
resource.addConsumer(this); |
|
129 |
initializeFeatureTypes(); |
|
130 |
} |
|
131 |
|
|
132 |
public SeismicManager getDriverManager(){ |
|
133 |
return this.driverManager; |
|
134 |
} |
|
135 |
|
|
136 |
public SeismicStoreParameters getDriverParameters() { |
|
137 |
return (SeismicStoreParameters) this.getParameters(); |
|
138 |
} |
|
139 |
|
|
140 |
public String getProviderName() { |
|
141 |
return NAME; |
|
142 |
} |
|
143 |
|
|
144 |
public boolean allowWrite() { |
|
145 |
return true; |
|
146 |
} |
|
147 |
|
|
148 |
private String getFullFileName() { |
|
149 |
// Usar solo para mostrar mensajes en el logger. |
|
150 |
String s = "(unknow)"; |
|
151 |
try { |
|
152 |
s = getDriverParameters().getFile().getAbsolutePath(); |
|
153 |
} catch(Exception e2) { |
|
154 |
s = "(unknow)"; |
|
155 |
} |
|
156 |
return s; |
|
157 |
} |
|
158 |
|
|
159 |
public void open() throws OpenException { |
|
160 |
this.isOpenedPreviously = true; |
|
161 |
|
|
162 |
if (this.data != null) { |
|
163 |
return; |
|
164 |
} |
|
165 |
this.data = new ArrayList<FeatureProvider>(); |
|
166 |
resource.setData(new HashMap()); |
|
167 |
counterNewsOIDs = 0; |
|
168 |
try { |
|
169 |
loadFeatures(); |
|
170 |
} catch (RuntimeException e) { |
|
171 |
logger.warn("Can't load features from Seismic '"+getFullFileName()+"'.", e); |
|
172 |
throw e; |
|
173 |
} catch (Exception e) { |
|
174 |
logger.warn("Can't load features from Seismic '"+getFullFileName()+"'.", e); |
|
175 |
throw new RuntimeException(e); |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
// public DataServerExplorer getExplorer() throws ReadException { |
|
180 |
// DataManager manager = DALLocator.getDataManager(); |
|
181 |
// FilesystemServerExplorerParameters params; |
|
182 |
// try { |
|
183 |
// params = (FilesystemServerExplorerParameters) manager |
|
184 |
// .createServerExplorerParameters(FilesystemServerExplorer.NAME); |
|
185 |
// params.setRoot(this.getDriverParameters().getFile().getParent()); |
|
186 |
// return manager.openServerExplorer(FilesystemServerExplorer.NAME,params); |
|
187 |
// } catch (DataException e) { |
|
188 |
// throw new ReadException(this.getProviderName(), e); |
|
189 |
// } catch (ValidateDataParametersException e) { |
|
190 |
// throw new ReadException(this.getProviderName(), e); |
|
191 |
// } |
|
192 |
// |
|
193 |
// } |
|
194 |
// |
|
195 |
// class Writer { |
|
196 |
// private Envelope envelope = null; |
|
197 |
// private boolean calculate_envelope = false; |
|
198 |
// private CsvListWriter listWriter = null; |
|
199 |
// private CsvPreference csvpreferences = null; |
|
200 |
// private FileWriter fwriter = null; |
|
201 |
// private FeatureType ftype; |
|
202 |
// private File file; |
|
203 |
// private String[] values; |
|
204 |
// private FeatureAttributeDescriptor[] descriptors; |
|
205 |
// private Coercion convert = null; |
|
206 |
// private int errorcounts =0; |
|
207 |
// private Throwable lasterror = null; |
|
208 |
// private Locale locale = null; |
|
209 |
// |
|
210 |
// public void initialize(File file, FeatureType ftype, CsvPreference csvpreferences) { |
|
211 |
// this.file = file; |
|
212 |
// this.ftype = ftype; |
|
213 |
// this.csvpreferences = csvpreferences; |
|
214 |
// this.locale = DriverStoreParameters.getLocale(getDriverParameters()); |
|
215 |
// if( csvpreferences == null ) { |
|
216 |
// this.csvpreferences = CsvPreference.STANDARD_PREFERENCE; |
|
217 |
// } |
|
218 |
// if( ftype.getDefaultGeometryAttributeName() != null ) { |
|
219 |
// this.calculate_envelope = true; |
|
220 |
// } |
|
221 |
// this.descriptors = this.ftype.getAttributeDescriptors(); |
|
222 |
// this.convert = ToolsLocator.getDataTypesManager().getCoercion(org.gvsig.tools.dataTypes.DataTypes.STRING); |
|
223 |
// this.errorcounts = 0; |
|
224 |
// } |
|
225 |
// |
|
226 |
// public void begin() { |
|
227 |
// try { |
|
228 |
// this.fwriter = new FileWriter(file); |
|
229 |
// } catch (IOException e) { |
|
230 |
// logger.warn("Can't open file for write ("+file.getAbsolutePath()+").",e); |
|
231 |
// throw new RuntimeException(e); |
|
232 |
// } |
|
233 |
// this.listWriter = new CsvListWriter(this.fwriter,this.csvpreferences); |
|
234 |
// int n = 0; |
|
235 |
// for(int i=0; i<descriptors.length; i++ ) { |
|
236 |
// FeatureAttributeDescriptor descriptor = descriptors[i]; |
|
237 |
// if( descriptor.getEvaluator()== null ) { |
|
238 |
// n++; |
|
239 |
// } |
|
240 |
// } |
|
241 |
// |
|
242 |
// String[] header = new String[n]; |
|
243 |
// this.values = new String[n]; |
|
244 |
// n = 0; |
|
245 |
// for(int i=0; i<descriptors.length; i++ ) { |
|
246 |
// FeatureAttributeDescriptor descriptor = descriptors[i]; |
|
247 |
// if( descriptor.getEvaluator()== null ) { |
|
248 |
// String name = descriptor.getName(); |
|
249 |
// String typeName = descriptor.getDataTypeName(); |
|
250 |
// if( descriptor.getDataType().getType() == DataTypes.STRING ) { |
|
251 |
// header[n++] = name + "__" + typeName + "__" + descriptor.getSize(); |
|
252 |
// } else { |
|
253 |
// header[n++] = name + "__" + typeName; |
|
254 |
// } |
|
255 |
// } |
|
256 |
// } |
|
257 |
// try { |
|
258 |
// listWriter.writeHeader(header); |
|
259 |
// } catch (Exception e) { |
|
260 |
// logger.warn("Can't write header '"+header.toString()+"' file for write ("+file.getAbsolutePath()+").",e); |
|
261 |
// throw new RuntimeException(e); |
|
262 |
// } |
|
263 |
// } |
|
264 |
// |
|
265 |
// public void add(FeatureProvider feature) { |
|
266 |
// if (this.calculate_envelope) { |
|
267 |
// Geometry geom = feature.getDefaultGeometry(); |
|
268 |
// if (geom != null) { |
|
269 |
// if (envelope == null) { |
|
270 |
// try { |
|
271 |
// envelope = (Envelope) geom.getEnvelope().clone(); |
|
272 |
// } catch (CloneNotSupportedException e) { |
|
273 |
// logger.warn("Este error no deberia pasar, siempre se puede hacer un clone de un envelope.",e); |
|
274 |
// } |
|
275 |
// } else { |
|
276 |
// envelope.add(geom.getEnvelope()); |
|
277 |
// } |
|
278 |
// } |
|
279 |
// } |
|
280 |
// int n = 0; |
|
281 |
// for(int i=0; i<descriptors.length; i++ ) { |
|
282 |
// FeatureAttributeDescriptor descriptor = descriptors[i]; |
|
283 |
// if( descriptor.getEvaluator()== null ) { |
|
284 |
// Object value = feature.get(i); |
|
285 |
// try { |
|
286 |
// n++; |
|
287 |
// if( this.convert!=null && this.convert instanceof CoercionWithLocale ) { |
|
288 |
// values[n] = (String) ((CoercionWithLocale)this.convert).coerce(value,this.locale); |
|
289 |
// } else { |
|
290 |
// values[n] = (String) this.convert.coerce(value); |
|
291 |
// } |
|
292 |
// } catch (CoercionException e) { |
|
293 |
// try { |
|
294 |
// values[n] = value.toString(); |
|
295 |
// } catch(Exception ex) { |
|
296 |
// values[n] = ""; |
|
297 |
// } |
|
298 |
// if( errorcounts++ <= 10 ) { |
|
299 |
// this.lasterror = e; |
|
300 |
// logger.warn("Can't convert value of field "+i+" to string in CVS file '"+getFullFileName()+"'.",e); |
|
301 |
// if( errorcounts == 10 ) { |
|
302 |
// logger.warn("Too many error writing CVS file '"+getFullFileName()+"', don't output more."); |
|
303 |
// } |
|
304 |
// } |
|
305 |
// } |
|
306 |
// } |
|
307 |
// } |
|
308 |
// try { |
|
309 |
// this.listWriter.writeHeader(values); |
|
310 |
// } catch (IOException e) { |
|
311 |
// if( errorcounts++ <= 10 ) { |
|
312 |
// this.lasterror = e; |
|
313 |
// logger.warn("Can't write values to CVS file '"+getFullFileName()+"'.",e); |
|
314 |
// if( errorcounts == 10 ) { |
|
315 |
// logger.warn("Too many error writing CVS file '"+getFullFileName()+"', don't output more."); |
|
316 |
// } |
|
317 |
// } |
|
318 |
// } |
|
319 |
// |
|
320 |
// } |
|
321 |
// |
|
322 |
// public void end() throws PerformEditingException { |
|
323 |
// if( this.errorcounts>0 ) { |
|
324 |
// throw new PerformEditingException(this.file.getAbsolutePath(), lasterror); |
|
325 |
// } |
|
326 |
// if( listWriter!=null ) { |
|
327 |
// try { |
|
328 |
// listWriter.close(); |
|
329 |
// } catch(Exception ex) { |
|
330 |
// // Ignore error |
|
331 |
// } |
|
332 |
// listWriter=null ; |
|
333 |
// } |
|
334 |
// if( fwriter!=null ) { |
|
335 |
// try { |
|
336 |
// fwriter.close(); |
|
337 |
// } catch(Exception ex) { |
|
338 |
// // Ignore error |
|
339 |
// } |
|
340 |
// fwriter=null ; |
|
341 |
// } |
|
342 |
// } |
|
343 |
// |
|
344 |
// public Envelope getEnvelope() { |
|
345 |
// return this.envelope; |
|
346 |
// } |
|
347 |
// } |
|
348 |
|
|
349 |
public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException { |
|
350 |
|
|
351 |
try { |
|
352 |
this.taskStatus.add(); |
|
353 |
taskStatus.message("_preparing"); |
|
354 |
getResource().execute(new ResourceAction() { |
|
355 |
public Object run() throws Exception { |
|
356 |
FeatureSet features = null; |
|
357 |
DisposableIterator it = null; |
|
358 |
try { |
|
359 |
File file = (File) resource.get(); |
|
360 |
|
|
361 |
FeatureType featType = getStoreServices().getDefaultFeatureType(); |
|
362 |
features = |
|
363 |
getStoreServices().getFeatureStore() |
|
364 |
.getFeatureSet(); |
|
365 |
List<FeatureProvider> newdata = new ArrayList<FeatureProvider>(); |
|
366 |
it = features.fastIterator(); |
|
367 |
taskStatus.setRangeOfValues(0,0); |
|
368 |
long counter=0; |
|
369 |
while (it.hasNext()) { |
|
370 |
taskStatus.setCurValue(counter++); |
|
371 |
FeatureProvider feature = getStoreServices().getFeatureProviderFromFeature( |
|
372 |
(org.gvsig.fmap.dal.feature.Feature) it.next()); |
|
373 |
if (feature.getOID() == null){ |
|
374 |
logger.warn("feature without OID"); |
|
375 |
feature.setOID(createNewOID()); |
|
376 |
} |
|
377 |
newdata.add(feature); |
|
378 |
} |
|
379 |
data = newdata; |
|
380 |
envelope = getEnvelope(); |
|
381 |
resource.notifyChanges(); |
|
382 |
} finally { |
|
383 |
if (it != null) { |
|
384 |
it.dispose(); |
|
385 |
} |
|
386 |
if (features != null) { |
|
387 |
features.dispose(); |
|
388 |
} |
|
389 |
} |
|
390 |
return null; |
|
391 |
} |
|
392 |
}); |
|
393 |
this.taskStatus.terminate(); |
|
394 |
} catch (Exception e) { |
|
395 |
this.taskStatus.abort(); |
|
396 |
throw new PerformEditingException(getResource().toString(), e); |
|
397 |
} finally { |
|
398 |
this.taskStatus.remove(); |
|
399 |
} |
|
400 |
} |
|
401 |
|
|
402 |
public boolean closeResourceRequested(ResourceProvider resource) { |
|
403 |
return true; |
|
404 |
} |
|
405 |
|
|
406 |
public int getOIDType() { |
|
407 |
return DataTypes.LONG; |
|
408 |
} |
|
409 |
|
|
410 |
public boolean supportsAppendMode() { |
|
411 |
return false; |
|
412 |
} |
|
413 |
|
|
414 |
public void append(FeatureProvider featureProvider) { |
|
415 |
throw new UnsupportedOperationException(); |
|
416 |
} |
|
417 |
|
|
418 |
public void beginAppend() { |
|
419 |
throw new UnsupportedOperationException(); |
|
420 |
} |
|
421 |
|
|
422 |
public void endAppend() { |
|
423 |
throw new UnsupportedOperationException(); |
|
424 |
} |
|
425 |
|
|
426 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
427 |
throw new NotYetImplemented(); |
|
428 |
} |
|
429 |
|
|
430 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
431 |
throw new NotYetImplemented(); |
|
432 |
} |
|
433 |
|
|
434 |
public Object createNewOID() { |
|
435 |
return new Long(counterNewsOIDs++); |
|
436 |
} |
|
437 |
|
|
438 |
protected void initializeFeatureTypes() throws InitializeException { |
|
439 |
if(!isOpenedPreviously){ |
|
440 |
try { |
|
441 |
this.open(); |
|
442 |
} catch (OpenException e) { |
|
443 |
throw new InitializeException(this.getProviderName(), e); |
|
444 |
} |
|
445 |
} |
|
446 |
} |
|
447 |
|
|
448 |
public Envelope getEnvelope() throws DataException { |
|
449 |
if(!isOpenedPreviously ) |
|
450 |
this.open(); |
|
451 |
if( this.envelope!= null ) { |
|
452 |
return this.envelope; |
|
453 |
} |
|
454 |
if( !this.need_calculate_envelope ) { |
|
455 |
return null; |
|
456 |
} |
|
457 |
FeatureStore fs = this.getFeatureStore(); |
|
458 |
long i = fs.getFeatureCount(); |
|
459 |
FeatureType ft = fs.getDefaultFeatureType(); |
|
460 |
FeatureAttributeDescriptor fad = ft.getDefaultGeometryAttribute(); |
|
461 |
|
|
462 |
try { |
|
463 |
this.envelope = GeometryLocator.getGeometryManager().createEnvelope(fad.getGeometrySubType()); |
|
464 |
fs.accept(new Visitor() { |
|
465 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
|
466 |
Feature f = (Feature) obj; |
|
467 |
Geometry geom = f.getDefaultGeometry(); |
|
468 |
envelope.add(geom.getEnvelope()); |
|
469 |
} |
|
470 |
}); |
|
471 |
} catch (BaseException e) { |
|
472 |
logger.warn("Can't calculate the envelope of Seismic file '"+this.getFullName()+"'.",e); |
|
473 |
this.envelope = null; |
|
474 |
} |
|
475 |
|
|
476 |
this.need_calculate_envelope = false; |
|
477 |
return this.envelope; |
|
478 |
} |
|
479 |
|
|
480 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
|
481 |
if( DataStore.METADATA_ENVELOPE.equalsIgnoreCase(name) ) { |
|
482 |
try { |
|
483 |
return this.getEnvelope(); |
|
484 |
} catch (DataException e) { |
|
485 |
return null; |
|
486 |
} |
|
487 |
} else { |
|
488 |
if( DataStore.METADATA_CRS.equalsIgnoreCase(name) ) { |
|
489 |
IProjection pro = this.getDriverParameters().getCRS(); |
|
490 |
if (pro != null){ |
|
491 |
return pro; |
|
492 |
} |
|
493 |
} |
|
494 |
} |
|
495 |
return super.getDynValue(name); |
|
496 |
} |
|
497 |
|
|
498 |
|
|
499 |
public void resourceChanged(ResourceProvider resource) { |
|
500 |
this.getStoreServices().notifyChange( |
|
501 |
DataStoreNotification.RESOURCE_CHANGED, |
|
502 |
resource); |
|
503 |
} |
|
504 |
|
|
505 |
|
|
506 |
public Object getSourceId() { |
|
507 |
return this.getDriverParameters().getFile(); |
|
508 |
} |
|
509 |
|
|
510 |
public String getName() { |
|
511 |
String name = this.getDriverParameters().getFile().getName(); |
|
512 |
return FilenameUtils.getBaseName(name); |
|
513 |
} |
|
514 |
|
|
515 |
public String getFullName() { |
|
516 |
return this.getDriverParameters().getFile().getAbsolutePath(); |
|
517 |
} |
|
518 |
|
|
519 |
public ResourceProvider getResource() { |
|
520 |
return resource; |
|
521 |
} |
|
522 |
|
|
523 |
private boolean isEmpty(String s) { |
|
524 |
if( s==null ) { |
|
525 |
return true; |
|
526 |
} |
|
527 |
return s.trim().length()==0; |
|
528 |
} |
|
529 |
|
|
530 |
// private Map<String, String> getDriverPreferences() { |
|
531 |
// return this.getMetadata(); |
|
532 |
// } |
|
533 |
|
|
534 |
// private EditableFeatureType getFeatureType(String headers[], int automaticTypes[]) { |
|
535 |
// EditableFeatureType fType = getStoreServices().createFeatureType(this.getName()); |
|
536 |
// fType.setHasOID(true); |
|
537 |
// DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
|
538 |
// |
|
539 |
// int[] types = new int[headers.length]; |
|
540 |
// int[] sizes = new int[headers.length]; |
|
541 |
// // |
|
542 |
// // Calculamos cuales pueden ser los tipos de datos |
|
543 |
// // |
|
544 |
// |
|
545 |
// // Por defecto todos string |
|
546 |
// for( int i=0; i<types.length ; i++) { |
|
547 |
// types[i] = DataTypes.STRING; |
|
548 |
// sizes[i] = 0; |
|
549 |
// } |
|
550 |
// |
|
551 |
// // Luego asuminos los tipos pasados por parametro, que se supone |
|
552 |
// // son los detectados automaticamente. |
|
553 |
// if (automaticTypes != null) { |
|
554 |
// for (int i = 0; i < types.length && i < automaticTypes.length; i++) { |
|
555 |
// types[i] = automaticTypes[i]; |
|
556 |
// } |
|
557 |
// } |
|
558 |
// |
|
559 |
// // Luego probamos con lo que diga las cabezeras del CVS, sobreescribiendo |
|
560 |
// // los tipos anteriores en caso de definirse en la cabezara. |
|
561 |
// // El formato de la cabecera seria: |
|
562 |
// // name[:typename[:size]] |
|
563 |
// // name[__typename[__size]] |
|
564 |
// // |
|
565 |
// for( int i=0; i<types.length; i++) { |
|
566 |
// String s = headers[i]; |
|
567 |
// String typename = null; |
|
568 |
// String[] ss = null; |
|
569 |
// if( s.contains(":") ) { |
|
570 |
// ss = s.split(":"); |
|
571 |
// } else if( s.contains("__") ) { |
|
572 |
// ss = s.split("__"); |
|
573 |
// } |
|
574 |
// if( ss!=null ) { |
|
575 |
// headers[i] = ss[0]; |
|
576 |
// typename = ss[1]; |
|
577 |
// types[i] = dataTypesManager.getType(typename); |
|
578 |
// if( types[i]==DataTypes.INVALID ) { |
|
579 |
// types[i] = DataTypes.STRING; |
|
580 |
// logger.info("Type '"+typename+"' not valid for attribute '"+s+"' in CSV file '"+this.getFullFileName()+"'."); |
|
581 |
// } |
|
582 |
// if( types[i]== DataTypes.STRING && ss.length>2 ) { |
|
583 |
// try { |
|
584 |
// sizes[i] = Integer.parseInt(ss[2]); |
|
585 |
// } catch(Exception ex) { |
|
586 |
// logger.warn("Ignore incorrect field size for field "+i+" ("+s+") in CSV header of '"+getFullFileName()+"'.",ex); |
|
587 |
// } |
|
588 |
// } |
|
589 |
// } |
|
590 |
// } |
|
591 |
// |
|
592 |
// // Y por ultimo hacemos caso a lo que se haya especificado en los parametros |
|
593 |
// // de apertura del CSV, teniendo esto prioridad sobre todo. |
|
594 |
// int[] param_types = DriverStoreParameters.getFieldTypes(this.getParameters()); |
|
595 |
// if( param_types != null ) { |
|
596 |
// for( int i=0; i<types.length && i<param_types.length; i++) { |
|
597 |
// types[i] = param_types[i]; |
|
598 |
// } |
|
599 |
// } |
|
600 |
// |
|
601 |
// // |
|
602 |
// // Una vez ya sabemos los tipos de datos rellenamos el feature-type |
|
603 |
// // |
|
604 |
// for(int i=0; i<types.length; i++) { |
|
605 |
// int fieldType = types[i]; |
|
606 |
// String fieldName = headers[i]; |
|
607 |
// EditableFeatureAttributeDescriptor fad = fType.add(fieldName, fieldType); |
|
608 |
//// if( param_sizes!=null && i<param_sizes.length && param_sizes[i]>0 ) { |
|
609 |
//// fad.setSize(param_sizes[i]); |
|
610 |
//// } else { |
|
611 |
//// fad.setSize(sizes[i]); |
|
612 |
//// } |
|
613 |
// if( fieldType == DataTypes.GEOMETRY && fType.getDefaultGeometryAttributeName() == null) { |
|
614 |
// fType.setDefaultGeometryAttributeName(fieldName); |
|
615 |
// } |
|
616 |
// } |
|
617 |
// EditableFeatureAttributeDescriptor attr = fType.add("GEOM", DataTypes.GEOMETRY); |
|
618 |
// GeometryManager geommgr = GeometryLocator.getGeometryManager(); |
|
619 |
// GeometryType gt; |
|
620 |
// try { |
|
621 |
// gt = geommgr.getGeometryType(Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM2D); |
|
622 |
// attr.setGeometryType(gt); |
|
623 |
// } catch (Exception e) { |
|
624 |
// logger.warn("Can't set geometry type for the calculated field in Driver file '"+getFullFileName()+"'.",e); |
|
625 |
// } |
|
626 |
// return fType; |
|
627 |
// } |
|
628 |
|
|
629 |
private void loadFeatures() throws DataException, |
|
630 |
CoercionException, CloneNotSupportedException { |
|
631 |
|
|
632 |
//logger.info("---------------------------------DRIVERSTOREPROVIDER: loadFeatures() -> start"); |
|
633 |
FeatureStoreProviderServices store = this.getStoreServices(); |
|
634 |
|
|
635 |
// Initiaize the parser |
|
636 |
Parser parser = driverManager.createParser(this.getDriverParameters().getParserName()); |
|
637 |
parser.setProjectId(getDriverParameters().getProjectId()); |
|
638 |
parser.setProjectName(getDriverParameters().getProjectName()); |
|
639 |
parser.setProjectYear(getDriverParameters().getProjectYear()); |
|
640 |
parser.setEstado(getDriverParameters().getEstado()); |
|
641 |
//parser.initializeParser(); |
|
642 |
File file = this.getDriverParameters().getFile(); |
|
643 |
|
|
644 |
|
|
645 |
Map<String, String> headers = parser.getMetadataInfo(file); |
|
646 |
if (headers == null) { |
|
647 |
String msg = "Can't retrieve header from Seismic file '" |
|
648 |
+ this.getDriverParameters().getFile() |
|
649 |
.getAbsolutePath() |
|
650 |
+ "' and not specified in the parameters."; |
|
651 |
logger.warn(msg); |
|
652 |
throw new RuntimeException(msg); |
|
653 |
} |
|
654 |
|
|
655 |
// Initialize the feature types |
|
656 |
DynStruct struct = parser.getDataStruct(); |
|
657 |
EditableFeatureType edftype = this.getFeatureTypeDefinition( |
|
658 |
struct, |
|
659 |
this.getDriverParameters().getCRS(), |
|
660 |
parser.getOrderedFieldNames()); |
|
661 |
FeatureType ftype = edftype.getNotEditableCopy(); |
|
662 |
List<FeatureType> ftypes = new ArrayList<FeatureType>(); |
|
663 |
ftypes.add(ftype); |
|
664 |
store.setFeatureTypes(ftypes, ftype); |
|
665 |
|
|
666 |
|
|
667 |
Coercion coercion[] = new Coercion[ftype.size()]; |
|
668 |
int sizes[] = new int[ftype.size()]; |
|
669 |
for (int i = 0; i < ftype.size(); i++) { |
|
670 |
sizes[i] = -1; |
|
671 |
FeatureAttributeDescriptor ad = ftype.getAttributeDescriptor(i); |
|
672 |
coercion[i] = ad.getDataType().getCoercion(); |
|
673 |
if( ad.getDataType().getType() == DataTypes.STRING ) { |
|
674 |
if( ad.getSize() == 0 ) { |
|
675 |
// Es un string y no tiene un size asignado. |
|
676 |
// Lo ponemos a cero para calcularlo. |
|
677 |
sizes[i] = 0; |
|
678 |
} |
|
679 |
} |
|
680 |
} |
|
681 |
if( ftype.getDefaultGeometryAttributeName() != null) { |
|
682 |
this.need_calculate_envelope = true; |
|
683 |
} |
|
684 |
|
|
685 |
//Locale locale = DriverStoreParameters.getLocale(getDriverParameters()); |
|
686 |
taskStatus.message("_loading"); |
|
687 |
int count = 0; |
|
688 |
|
|
689 |
List<DynObject> row = parser.getData(); |
|
690 |
|
|
691 |
|
|
692 |
Iterator<DynObject> features = row.iterator(); |
|
693 |
while(features.hasNext()){ |
|
694 |
//logger.info("-----------New feature:"+ count); |
|
695 |
taskStatus.setCurValue(count++); |
|
696 |
FeatureProvider feature = this.createFeatureProvider(ftype); |
|
697 |
DynObject obj = (DynObject) features.next(); |
|
698 |
for(int i=0; i<parser.getOrderedFieldNames().length; i++){ |
|
699 |
int index = getDynFieldIndex(ftype, parser.getOrderedFieldNames()[i]); |
|
700 |
if(index>= 0){ |
|
701 |
String fieldName = parser.getOrderedFieldNames()[i]; |
|
702 |
Object value = null; |
|
703 |
value = coercion[index].coerce(obj.getDynValue(fieldName)); |
|
704 |
if(obj.getDynClass().getDeclaredDynField(fieldName).getType() == DataTypes.GEOMETRY){ |
|
705 |
value = obj.getDynValue(fieldName); |
|
706 |
} |
|
707 |
feature.set(fieldName, value); |
|
708 |
if ( sizes[i] >= 0 && value != null ) { |
|
709 |
int x = ((String) value).length(); |
|
710 |
if ( sizes[i] < x ) { |
|
711 |
sizes[i] = x; |
|
712 |
} |
|
713 |
} |
|
714 |
// logger.info(" Adding value " + obj.getDynValue(fieldName) +" to field: "+fieldName); |
|
715 |
} |
|
716 |
} |
|
717 |
Geometry geom = feature.getDefaultGeometry(); |
|
718 |
if (geom != null) { |
|
719 |
if (envelope == null) { |
|
720 |
try { |
|
721 |
envelope = (Envelope) geom.getEnvelope().clone(); |
|
722 |
} catch (CloneNotSupportedException e) { |
|
723 |
logger.warn("Este error no deberia pasar, siempre se puede hacer un clone de un envelope.",e); |
|
724 |
} |
|
725 |
} else { |
|
726 |
envelope.add(geom.getEnvelope()); |
|
727 |
} |
|
728 |
} |
|
729 |
|
|
730 |
feature.setDefaultEnvelope(envelope); |
|
731 |
this.addFeatureProvider(feature); |
|
732 |
} |
|
733 |
for ( int i = 0; i < ftype.size(); i++ ) { |
|
734 |
if ( sizes[i] > 0 ) { |
|
735 |
EditableFeatureAttributeDescriptor efad = ((EditableFeatureAttributeDescriptor) edftype.getAttributeDescriptor(i)); |
|
736 |
efad.setSize(sizes[i]); |
|
737 |
} |
|
738 |
} |
|
739 |
// Volvemos a asignar al store el featuretype, ya que puede |
|
740 |
// haber cambiado. |
|
741 |
ftype = edftype.getNotEditableCopy(); |
|
742 |
ftypes = new ArrayList<FeatureType>(); |
|
743 |
ftypes.add(ftype); |
|
744 |
store.setFeatureTypes(ftypes, ftype); |
|
745 |
|
|
746 |
taskStatus.terminate(); |
|
747 |
// logger.info("---------------------------------DRIVERSTOREPROVIDER: loadFeatures() -> end"); |
|
748 |
|
|
749 |
} |
|
750 |
|
|
751 |
private int getDynFieldIndex(FeatureType ftype, String name) { |
|
752 |
for(int i = 0; i<ftype.getDynFields().length; i++){ |
|
753 |
if(ftype.getDynFields()[i].getName().equals(name)){ |
|
754 |
return i; |
|
755 |
} |
|
756 |
} |
|
757 |
return -1; |
|
758 |
} |
|
759 |
|
|
760 |
private EditableFeatureType getFeatureTypeDefinition(DynStruct struct, IProjection projection, String[] names) { |
|
761 |
EditableFeatureType editableFeatureType = getStoreServices().createFeatureType(this.getName()); |
|
762 |
|
|
763 |
// logger.info("------Set Definition"); |
|
764 |
//DynField[] fields = struct.getDynFields(); |
|
765 |
for(int i=0; i<names.length; i++){ |
|
766 |
DynField field = struct.getDynField(names[i]); |
|
767 |
if(field != null && !field.isHidden()){ |
|
768 |
editableFeatureType.add(field.getName(), field.getType()); |
|
769 |
// logger.info(" Adding field: "+field.getName() + " of Type: " + field.getType()); |
|
770 |
if(field.getType() == DataTypes.GEOMETRY){ |
|
771 |
editableFeatureType.setDefaultGeometryAttributeName(field.getName()); |
|
772 |
EditableFeatureAttributeDescriptor editableAttrDescr = |
|
773 |
((EditableFeatureAttributeDescriptor) editableFeatureType |
|
774 |
.getDefaultGeometryAttribute()); |
|
775 |
GeometryManager geommgr = GeometryLocator.getGeometryManager(); |
|
776 |
GeometryType gt; |
|
777 |
try { |
|
778 |
gt = geommgr.getGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
779 |
editableAttrDescr.setGeometryType(gt); |
|
780 |
} catch (Exception e) { |
|
781 |
logger.warn("Can't set geometry type in '"+field.getName()+"' field",e); |
|
782 |
} |
|
783 |
|
|
784 |
if(projection == null){ |
|
785 |
projection = getDriverParameters().getCRS(); |
|
786 |
} |
|
787 |
editableAttrDescr.setSRS(projection); |
|
788 |
} |
|
789 |
} |
|
790 |
} |
|
791 |
|
|
792 |
editableFeatureType.setHasOID(true); |
|
793 |
|
|
794 |
return editableFeatureType; |
|
795 |
} |
|
796 |
|
|
797 |
} |
|
0 | 798 |
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.3/org.gvsig.seismic/org.gvsig.seismic.provider/src/main/java/org/gvsig/fmap/dal/store/seismic/SeismicStoreProviderLibrary.java | ||
---|---|---|
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.seismic; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.DALFileLibrary; |
|
30 |
import org.gvsig.fmap.dal.DALFileLocator; |
|
31 |
import org.gvsig.fmap.dal.DALLibrary; |
|
32 |
import org.gvsig.fmap.dal.DALLocator; |
|
33 |
import org.gvsig.fmap.dal.FileHelper; |
|
34 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
35 |
import org.gvsig.metadata.exceptions.MetadataException; |
|
36 |
import org.gvsig.seismic.SeismicLibrary; |
|
37 |
import org.gvsig.tools.library.AbstractLibrary; |
|
38 |
import org.gvsig.tools.library.LibraryException; |
|
39 |
|
|
40 |
public class SeismicStoreProviderLibrary extends AbstractLibrary { |
|
41 |
|
|
42 |
@Override |
|
43 |
public void doRegistration() { |
|
44 |
registerAsServiceOf(SeismicLibrary.class); |
|
45 |
require(SeismicLibrary.class); |
|
46 |
require(DALLibrary.class); |
|
47 |
require(DALFileLibrary.class); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
protected void doInitialize() throws LibraryException { |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
protected void doPostInitialize() throws LibraryException { |
|
56 |
List<Throwable> exs = new ArrayList<Throwable>(); |
|
57 |
|
|
58 |
FileHelper.registerParametersDefinition( |
|
59 |
SeismicStoreParameters.PARAMETERS_DEFINITION_NAME, |
|
60 |
SeismicStoreParameters.class, "SeismicParameters.xml"); |
|
61 |
try { |
|
62 |
FileHelper.registerMetadataDefinition( |
|
63 |
SeismicStoreProvider.METADATA_DEFINITION_NAME, |
|
64 |
SeismicStoreProvider.class, "SeismicMetadata.xml"); |
|
65 |
} catch (MetadataException e) { |
|
66 |
exs.add(e); |
|
67 |
} |
|
68 |
|
|
69 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator |
|
70 |
.getDataManager(); |
|
71 |
|
|
72 |
try { |
|
73 |
if (!dataman.getStoreProviders().contains(SeismicStoreProvider.NAME)) { |
|
74 |
dataman.registerStoreProviderFactory(new SeismicStoreProviderFactory(SeismicStoreProvider.NAME, SeismicStoreProvider.DESCRIPTION)); |
|
75 |
|
|
76 |
} |
|
77 |
} catch (RuntimeException e) { |
|
78 |
exs.add(e); |
|
79 |
} |
|
80 |
|
|
81 |
try { |
|
82 |
DALFileLocator.getFilesystemServerExplorerManager() |
|
83 |
.registerProvider(SeismicStoreProvider.NAME, |
|
84 |
SeismicStoreProvider.DESCRIPTION, |
|
85 |
SeismicFilesystemServerProvider.class); |
|
86 |
} catch (RuntimeException e) { |
|
87 |
exs.add(e); |
|
88 |
} |
|
89 |
|
|
90 |
if (exs.size() > 0) { |
|
91 |
throw new LibraryException(this.getClass(), exs); |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
0 | 95 |
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.3/org.gvsig.seismic/org.gvsig.seismic.provider/src/main/java/org/gvsig/fmap/dal/store/seismic/SeismicStoreProviderFactory.java | ||
---|---|---|
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.seismic; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.DataParameters; |
|
27 |
import org.gvsig.fmap.dal.DataStoreProvider; |
|
28 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
29 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
|
30 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory; |
|
31 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
32 |
import org.gvsig.tools.dynobject.DynObject; |
|
33 |
|
|
34 |
public class SeismicStoreProviderFactory extends AbstractFeatureStoreProviderFactory implements FeatureStoreProviderFactory{ |
|
35 |
|
|
36 |
protected SeismicStoreProviderFactory(String name, String description) { |
|
37 |
super(name, description); |
|
38 |
} |
|
39 |
|
|
40 |
public DataStoreProvider createProvider(DataParameters parameters, |
|
41 |
DataStoreProviderServices providerServices) |
|
42 |
throws InitializeException { |
|
43 |
return new SeismicStoreProvider((SeismicStoreParameters) parameters, providerServices); |
|
44 |
} |
|
45 |
|
|
46 |
public DynObject createParameters() { |
|
47 |
return new SeismicStoreParameters(); |
|
48 |
} |
|
49 |
|
|
50 |
public int allowCreate() { |
|
51 |
return NO; |
|
52 |
} |
|
53 |
|
|
54 |
public int allowWrite() { |
|
55 |
return NO; |
|
56 |
} |
|
57 |
|
|
58 |
public int allowRead() { |
|
59 |
return YES; |
|
60 |
} |
|
61 |
|
|
62 |
public int hasRasterSupport() { |
|
63 |
return NO; |
|
64 |
} |
|
65 |
|
|
66 |
public int hasTabularSupport() { |
|
67 |
return YES; |
|
68 |
} |
|
69 |
|
|
70 |
public int hasVectorialSupport() { |
|
71 |
return YES; |
|
72 |
} |
|
73 |
|
|
74 |
public int allowMultipleGeometryTypes() { |
|
75 |
return YES; |
|
76 |
} |
|
77 |
|
|
78 |
public int allowEditableFeatureType() { |
|
79 |
return YES; |
|
80 |
} |
|
81 |
|
|
82 |
} |
|
0 | 83 |
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.3/org.gvsig.seismic/org.gvsig.seismic.provider/src/main/java/org/gvsig/fmap/dal/store/seismic/SeismicStoreParameters.java | ||
---|---|---|
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.seismic; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
import org.cresques.cts.IProjection; |
|
29 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
30 |
import org.gvsig.fmap.dal.FileHelper; |
|
31 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
32 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
|
33 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
34 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
35 |
import org.gvsig.tools.dynobject.DynObject; |
|
36 |
import org.slf4j.Logger; |
|
37 |
import org.slf4j.LoggerFactory; |
|
38 |
|
|
39 |
public class SeismicStoreParameters extends AbstractDataParameters implements |
|
40 |
DataStoreParameters, FilesystemStoreParameters { |
|
41 |
|
|
42 |
private static final Logger logger = LoggerFactory.getLogger(SeismicStoreParameters.class); |
|
43 |
|
|
44 |
public static final String PARAMETERS_DEFINITION_NAME = "SeismicStoreParameters"; |
|
45 |
|
|
46 |
private static final String FILE = "file"; |
|
47 |
private static final String CRS = "CRS"; |
|
48 |
private static final String PARSER = "parser"; |
|
49 |
private static final String LOCALE = "locale"; |
|
50 |
|
|
51 |
private static final String PROJECTID = "ProjectID"; |
|
52 |
private static final String PROJECTNAME = "Project"; |
|
53 |
private static final String PROJECTYEAR = "Year"; |
|
54 |
private static final String ESTADO = "State"; |
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
private DelegatedDynObject parameters; |
|
59 |
|
|
60 |
|
|
61 |
public SeismicStoreParameters() { |
|
62 |
this(PARAMETERS_DEFINITION_NAME); |
|
63 |
} |
|
64 |
|
|
65 |
protected SeismicStoreParameters(String parametersDefinitionName) { |
|
66 |
this(parametersDefinitionName, SeismicStoreProvider.NAME); |
|
67 |
} |
|
68 |
|
|
69 |
public SeismicStoreParameters(String parametersDefinitionName, String name) { |
|
70 |
super(); |
|
71 |
this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName); |
|
72 |
this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name); |
|
73 |
} |
|
74 |
|
|
75 |
public String getDataStoreName() { |
|
76 |
return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME); |
|
77 |
} |
|
78 |
|
|
79 |
public String getDescription() { |
|
80 |
return this.getDynClass().getDescription(); |
|
81 |
} |
|
82 |
|
|
83 |
protected DelegatedDynObject getDelegatedDynObject() { |
|
84 |
return parameters; |
|
85 |
} |
|
86 |
|
|
87 |
public boolean isValid() { |
|
88 |
if (getFileName() == null) { |
|
89 |
return false; |
|
90 |
} |
|
91 |
return true; |
|
92 |
} |
|
93 |
|
|
94 |
public File getFile() { |
|
95 |
return (File) this.getDynValue(FILE); |
|
96 |
} |
|
97 |
|
|
98 |
public void setFile(File file) { |
|
99 |
this.setDynValue(FILE, file); |
|
100 |
} |
|
101 |
|
|
102 |
public void setCRS(IProjection file) { |
|
103 |
this.setDynValue(CRS, file); |
|
104 |
} |
|
105 |
|
|
106 |
public void setProjectId(String projID) { |
|
107 |
this.setDynValue(PROJECTID, projID); |
|
108 |
} |
|
109 |
|
|
110 |
public void setProjectName(String projName) { |
|
111 |
this.setDynValue(PROJECTNAME, projName); |
|
112 |
} |
|
113 |
|
|
114 |
public void setEstado(String estado) { |
|
115 |
this.setDynValue(ESTADO, estado); |
|
116 |
} |
|
117 |
|
|
118 |
public void setProjectYear(int year) { |
|
119 |
this.setDynValue(PROJECTYEAR, year); |
|
120 |
} |
|
121 |
|
|
122 |
public IProjection getCRS() { |
|
123 |
return (IProjection) getDynValue(CRS); |
|
124 |
} |
|
125 |
|
|
126 |
public String getProjectId() { |
|
127 |
return (String) getDynValue(PROJECTID); |
|
128 |
} |
|
129 |
|
|
130 |
public String getProjectName() { |
|
131 |
return (String) getDynValue(PROJECTNAME); |
|
132 |
} |
|
133 |
|
|
134 |
public String getProjectYear() { |
|
135 |
return (String) getDynValue(PROJECTYEAR); |
|
136 |
} |
|
137 |
|
|
138 |
public String getEstado() { |
|
139 |
return (String) getDynValue(ESTADO); |
|
140 |
} |
|
141 |
|
|
142 |
public String getFileName() { |
|
143 |
File f = (File) getDynValue(FILE); |
|
144 |
if( f == null ) { |
|
145 |
return null; |
|
146 |
} |
|
147 |
return f.getPath(); |
|
148 |
} |
|
149 |
|
|
150 |
public String getParserName() { |
|
151 |
return (String) getDynValue(PARSER); |
|
152 |
} |
|
153 |
|
|
154 |
public String getLocale() { |
|
155 |
return (String) getDynValue(LOCALE); |
|
156 |
} |
|
157 |
|
|
158 |
|
|
159 |
} |
|
0 | 160 |
Also available in: Unified diff