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 @ 40559
History | View | Annotate | Download (4.23 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 | * AUTHORS (In addition to CIT):
|
||
26 | * 2008 IVER T.I. S.A. {{Task}}
|
||
27 | */
|
||
28 | |||
29 | package org.gvsig.fmap.dal.store.dbf; |
||
30 | |||
31 | import java.nio.charset.Charset; |
||
32 | import java.util.ArrayList; |
||
33 | import java.util.Arrays; |
||
34 | import java.util.Iterator; |
||
35 | import java.util.LinkedHashSet; |
||
36 | import java.util.List; |
||
37 | import java.util.Map; |
||
38 | import java.util.Set; |
||
39 | |||
40 | import org.gvsig.fmap.dal.DALFileLibrary; |
||
41 | import org.gvsig.fmap.dal.DALFileLocator; |
||
42 | import org.gvsig.fmap.dal.DALLibrary; |
||
43 | import org.gvsig.fmap.dal.DALLocator; |
||
44 | import org.gvsig.fmap.dal.FileHelper; |
||
45 | import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
||
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.registerStoreProvider(DBFStoreProvider.NAME, |
||
96 | DBFStoreProvider.class, DBFStoreParameters.class); |
||
97 | } |
||
98 | } catch (RuntimeException e) { |
||
99 | exs.add(e); |
||
100 | } |
||
101 | |||
102 | try {
|
||
103 | DALFileLocator.getFilesystemServerExplorerManager() |
||
104 | .registerProvider(DBFStoreProvider.NAME, |
||
105 | DBFStoreProvider.DESCRIPTION, |
||
106 | DBFFilesystemServerProvider.class); |
||
107 | } catch (RuntimeException e) { |
||
108 | exs.add(e); |
||
109 | } |
||
110 | |||
111 | if( exs.size()>0 ) { |
||
112 | throw new LibraryException(this.getClass(), exs); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | private static void updateEncodingDefinition() { |
||
117 | DynStruct parametersDefinition = ToolsLocator.getPersistenceManager().getDefinition(DBFStoreParameters.PARAMETERS_DEFINITION_NAME); |
||
118 | |||
119 | DynObjectValueItem[] values = parametersDefinition.getDynField("encoding").getAvailableValues(); |
||
120 | |||
121 | Set<DynObjectValueItem> charsetSet = new LinkedHashSet<DynObjectValueItem>(160); |
||
122 | |||
123 | charsetSet.addAll( Arrays.asList(values) );
|
||
124 | Map<String,Charset> charsets = Charset.availableCharsets(); |
||
125 | Iterator<String> iter = charsets.keySet().iterator(); |
||
126 | while (iter.hasNext()){
|
||
127 | String value = (String) iter.next(); |
||
128 | String label= value;
|
||
129 | charsetSet.add(new DynObjectValueItem(value, label));
|
||
130 | } |
||
131 | |||
132 | parametersDefinition.getDynField("Encoding")
|
||
133 | .setAvailableValues( |
||
134 | (DynObjectValueItem[]) charsetSet.toArray(new DynObjectValueItem[charsets.size()]) |
||
135 | ); |
||
136 | |||
137 | |||
138 | } |
||
139 | } |