gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.base / src / main / java / org / gvsig / geoprocess / algorithm / base / core / AlgorithmAbstractLibrary.java @ 245
History | View | Annotate | Download (3.84 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 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 2
|
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.geoprocess.algorithm.base.core; |
25 |
|
26 |
import java.util.Enumeration; |
27 |
import java.util.HashMap; |
28 |
import java.util.Locale; |
29 |
import java.util.Map; |
30 |
import java.util.MissingResourceException; |
31 |
import java.util.ResourceBundle; |
32 |
|
33 |
import org.gvsig.geoprocess.lib.api.GeoProcess; |
34 |
import org.gvsig.geoprocess.lib.api.GeoProcessLibrary; |
35 |
import org.gvsig.geoprocess.lib.api.GeoProcessLocator; |
36 |
import org.gvsig.tools.library.AbstractLibrary; |
37 |
|
38 |
/**
|
39 |
* Base class for the entry point of an algorithm
|
40 |
*
|
41 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
42 |
* @author gvSIG team
|
43 |
*/
|
44 |
public abstract class AlgorithmAbstractLibrary extends AbstractLibrary { |
45 |
|
46 |
/**
|
47 |
* @deprecated Use {@link #getLanguageStrings(String)} instead.
|
48 |
*/
|
49 |
protected HashMap<String, String> text = new HashMap<String, String>(); |
50 |
|
51 |
@Override
|
52 |
public void doRegistration() { |
53 |
registerAsServiceOf(GeoProcessLibrary.class); |
54 |
} |
55 |
|
56 |
/**
|
57 |
* @deprecated Use {@link #getLanguageStrings(String)} instead.
|
58 |
*/
|
59 |
protected void setLanguageStrings(String algorithmName) { |
60 |
this.text =
|
61 |
new HashMap<String, String>(getLanguageStrings(algorithmName)); |
62 |
} |
63 |
|
64 |
/**
|
65 |
* Returns the translations.
|
66 |
*
|
67 |
* @param algorithmName
|
68 |
*/
|
69 |
protected Map<String, String> getLanguageStrings(String algorithmName) { |
70 |
Map<String, String> text = new HashMap<String, String>(); |
71 |
String defaultFile = algorithmName;
|
72 |
String file = algorithmName + "_" + Locale.getDefault().getLanguage(); |
73 |
ResourceBundle labels = null; |
74 |
|
75 |
try {
|
76 |
labels = ResourceBundle.getBundle(file, Locale.getDefault()); |
77 |
} catch (final MissingResourceException e) { |
78 |
file = defaultFile; |
79 |
} |
80 |
|
81 |
try {
|
82 |
if (labels == null) { |
83 |
labels = ResourceBundle.getBundle(file, Locale.getDefault()); |
84 |
} |
85 |
Enumeration<String> bundleKeys = labels.getKeys(); |
86 |
|
87 |
while (bundleKeys.hasMoreElements()) {
|
88 |
final String key = bundleKeys.nextElement(); |
89 |
final String value = labels.getString(key); |
90 |
text.put(key, value); |
91 |
} |
92 |
} catch (final MissingResourceException e) { |
93 |
file = defaultFile; |
94 |
} |
95 |
|
96 |
return text;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Registers a new {@link GeoProcess}.
|
101 |
*
|
102 |
* @param geoProcessClazz
|
103 |
* implementation of the {@link GeoProcess} to register
|
104 |
*/
|
105 |
protected void registerGeoProcess(GeoProcess geoProcess) { |
106 |
GeoProcessLocator.getGeoProcessManager().registerGeoProcess(geoProcess); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* @deprecated use {@link #registerGeoProcess(Class)} instead
|
111 |
*/
|
112 |
protected void registerGeoProcess( |
113 |
Class<? extends GeoProcess> geoProcessClazz, |
114 |
Map<String, String> localeStrings) { |
115 |
GeoProcessLocator.getGeoProcessManager().registerGeoProcess( |
116 |
geoProcessClazz, localeStrings); |
117 |
} |
118 |
|
119 |
} |