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 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
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 | 42517 | dmartinezizquierdo | 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 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
45 | 42517 | dmartinezizquierdo | import org.gvsig.fmap.dal.store.dbf.utils.DbaseFile; |
46 | 40435 | jjdelcerro | 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 | 42517 | dmartinezizquierdo | DBFStoreParameters.PARAMETERS_DEFINITION_NAME, |
71 | 40435 | jjdelcerro | DBFStoreParameters.class, |
72 | "DBFParameters.xml"
|
||
73 | ); |
||
74 | updateEncodingDefinition(); |
||
75 | FileHelper.registerParametersDefinition( |
||
76 | 42517 | dmartinezizquierdo | DBFNewStoreParameters.PARAMETERS_DEFINITION_NAME, |
77 | 40435 | jjdelcerro | DBFNewStoreParameters.class, |
78 | "DBFParameters.xml"
|
||
79 | ); |
||
80 | try {
|
||
81 | FileHelper.registerMetadataDefinition( |
||
82 | 42517 | dmartinezizquierdo | DBFStoreProvider.METADATA_DEFINITION_NAME, |
83 | 40435 | jjdelcerro | 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 | 42533 | dmartinezizquierdo | dataman.registerStoreProviderFactory(new DBFStoreProviderFactory(DBFStoreProvider.NAME, DBFStoreProvider.DESCRIPTION));
|
96 | 40435 | jjdelcerro | } |
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 | 42517 | dmartinezizquierdo | |
115 | 40435 | jjdelcerro | private static void updateEncodingDefinition() { |
116 | DynStruct parametersDefinition = ToolsLocator.getPersistenceManager().getDefinition(DBFStoreParameters.PARAMETERS_DEFINITION_NAME); |
||
117 | 42517 | dmartinezizquierdo | |
118 | 40435 | jjdelcerro | DynObjectValueItem[] values = parametersDefinition.getDynField("encoding").getAvailableValues(); |
119 | 42517 | dmartinezizquierdo | |
120 | 40435 | jjdelcerro | 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 | 42517 | dmartinezizquierdo | |
137 | 40435 | jjdelcerro | } |
138 | 40596 | jjdelcerro | } |