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.dbf / src / main / java / org / gvsig / fmap / dal / store / dbf / DBFLibrary.java @ 42533
History | View | Annotate | Download (4.4 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 |
|
25 |
package org.gvsig.fmap.dal.store.dbf; |
26 |
|
27 |
import java.nio.charset.Charset; |
28 |
import java.util.ArrayList; |
29 |
import java.util.Arrays; |
30 |
import java.util.Iterator; |
31 |
import java.util.LinkedHashSet; |
32 |
import java.util.List; |
33 |
import java.util.Map; |
34 |
import java.util.Set; |
35 |
|
36 |
import org.gvsig.fmap.dal.DALFileLibrary; |
37 |
import org.gvsig.fmap.dal.DALFileLocator; |
38 |
import org.gvsig.fmap.dal.DALLibrary; |
39 |
import org.gvsig.fmap.dal.DALLocator; |
40 |
import org.gvsig.fmap.dal.FileHelper; |
41 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
42 |
import org.gvsig.fmap.dal.resource.file.FileResourceParameters; |
43 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
44 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
45 |
import org.gvsig.fmap.dal.store.dbf.utils.DbaseFile; |
46 |
import org.gvsig.metadata.exceptions.MetadataException; |
47 |
import org.gvsig.tools.ToolsLocator; |
48 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
49 |
import org.gvsig.tools.dynobject.DynStruct; |
50 |
import org.gvsig.tools.library.AbstractLibrary; |
51 |
import org.gvsig.tools.library.LibraryException; |
52 |
|
53 |
public class DBFLibrary extends AbstractLibrary { |
54 |
|
55 |
@Override
|
56 |
public void doRegistration() { |
57 |
registerAsServiceOf(DALLibrary.class); |
58 |
require(DALFileLibrary.class); |
59 |
} |
60 |
|
61 |
@Override
|
62 |
protected void doInitialize() throws LibraryException { |
63 |
} |
64 |
|
65 |
@Override
|
66 |
protected void doPostInitialize() throws LibraryException { |
67 |
List<Throwable> exs = new ArrayList<Throwable>(); |
68 |
|
69 |
FileHelper.registerParametersDefinition( |
70 |
DBFStoreParameters.PARAMETERS_DEFINITION_NAME, |
71 |
DBFStoreParameters.class, |
72 |
"DBFParameters.xml"
|
73 |
); |
74 |
updateEncodingDefinition(); |
75 |
FileHelper.registerParametersDefinition( |
76 |
DBFNewStoreParameters.PARAMETERS_DEFINITION_NAME, |
77 |
DBFNewStoreParameters.class, |
78 |
"DBFParameters.xml"
|
79 |
); |
80 |
try {
|
81 |
FileHelper.registerMetadataDefinition( |
82 |
DBFStoreProvider.METADATA_DEFINITION_NAME, |
83 |
DBFStoreProvider.class, |
84 |
"DBFMetadata.xml"
|
85 |
); |
86 |
} catch (MetadataException e) {
|
87 |
exs.add(e); |
88 |
} |
89 |
|
90 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator |
91 |
.getDataManager(); |
92 |
|
93 |
try {
|
94 |
if (!dataman.getStoreProviders().contains(DBFStoreProvider.NAME)) {
|
95 |
dataman.registerStoreProviderFactory(new DBFStoreProviderFactory(DBFStoreProvider.NAME, DBFStoreProvider.DESCRIPTION));
|
96 |
} |
97 |
} catch (RuntimeException e) { |
98 |
exs.add(e); |
99 |
} |
100 |
|
101 |
try {
|
102 |
DALFileLocator.getFilesystemServerExplorerManager() |
103 |
.registerProvider(DBFStoreProvider.NAME, |
104 |
DBFStoreProvider.DESCRIPTION, |
105 |
DBFFilesystemServerProvider.class); |
106 |
} catch (RuntimeException e) { |
107 |
exs.add(e); |
108 |
} |
109 |
|
110 |
if( exs.size()>0 ) { |
111 |
throw new LibraryException(this.getClass(), exs); |
112 |
} |
113 |
} |
114 |
|
115 |
private static void updateEncodingDefinition() { |
116 |
DynStruct parametersDefinition = ToolsLocator.getPersistenceManager().getDefinition(DBFStoreParameters.PARAMETERS_DEFINITION_NAME); |
117 |
|
118 |
DynObjectValueItem[] values = parametersDefinition.getDynField("encoding").getAvailableValues(); |
119 |
|
120 |
Set<DynObjectValueItem> charsetSet = new LinkedHashSet<DynObjectValueItem>(160); |
121 |
|
122 |
charsetSet.addAll( Arrays.asList(values) );
|
123 |
Map<String,Charset> charsets = Charset.availableCharsets(); |
124 |
Iterator<String> iter = charsets.keySet().iterator(); |
125 |
while (iter.hasNext()){
|
126 |
String value = (String) iter.next(); |
127 |
String label= value;
|
128 |
charsetSet.add(new DynObjectValueItem(value, label));
|
129 |
} |
130 |
|
131 |
parametersDefinition.getDynField("Encoding")
|
132 |
.setAvailableValues( |
133 |
(DynObjectValueItem[]) charsetSet.toArray(new DynObjectValueItem[charsets.size()]) |
134 |
); |
135 |
|
136 |
|
137 |
} |
138 |
} |