svn-gvsig-desktop / trunk / frameworks / _fwAndami / src / com / iver / andami / PluginServices.java @ 1119
History | View | Annotate | Download (6.62 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.andami; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.event.ActionListener; |
45 |
import java.util.Iterator; |
46 |
import java.io.File; |
47 |
import java.util.Locale; |
48 |
import java.util.MissingResourceException; |
49 |
import java.util.PropertyResourceBundle; |
50 |
import java.util.ResourceBundle; |
51 |
|
52 |
import org.apache.log4j.Logger; |
53 |
|
54 |
import com.iver.andami.plugins.Extension; |
55 |
import com.iver.andami.plugins.PluginClassLoader; |
56 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
57 |
import com.iver.andami.ui.mdiFrame.MainFrame; |
58 |
import com.iver.andami.ui.mdiManager.MDIManager; |
59 |
import com.iver.utiles.XMLEntity; |
60 |
|
61 |
|
62 |
/**
|
63 |
* DOCUMENT ME!
|
64 |
*
|
65 |
* @author $author$
|
66 |
* @version $Revision: 1119 $
|
67 |
*/
|
68 |
public class PluginServices { |
69 |
private static Logger logger = Logger.getLogger(PluginServices.class.getName()); |
70 |
private PluginClassLoader loader;
|
71 |
private PropertyResourceBundle resourceBundle; |
72 |
private XMLEntity persistentXML;
|
73 |
|
74 |
/**
|
75 |
* Crea un nuevo PluginServices
|
76 |
*
|
77 |
* @param loader DOCUMENT ME!
|
78 |
*/
|
79 |
public PluginServices(PluginClassLoader loader) {
|
80 |
this.loader = loader;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Devuelve el mensaje en el idioma del locale actual del texto
|
85 |
* correspondiente a la clave que se pasa como par?metro
|
86 |
*
|
87 |
* @param key Clave del texto que se quiere obtener
|
88 |
*
|
89 |
* @return Texto en el idioma que toca o la propia clave si no se encuentra
|
90 |
* en el fichero
|
91 |
*/
|
92 |
public String getText(String key) { |
93 |
if (resourceBundle == null) { |
94 |
return key;
|
95 |
} |
96 |
if (key == null) |
97 |
return null; |
98 |
try {
|
99 |
return resourceBundle.getString(key);
|
100 |
} catch (MissingResourceException e) { |
101 |
logger.warn("No se encontr? la traducci?n para " + key);
|
102 |
|
103 |
return key;
|
104 |
} |
105 |
} |
106 |
|
107 |
/**
|
108 |
* Obtiene el classloader del plugin
|
109 |
*
|
110 |
* @return Returns the loader.
|
111 |
*/
|
112 |
public PluginClassLoader getClassLoader() {
|
113 |
return loader;
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Obtiene el nombre del plugin
|
118 |
*
|
119 |
* @return DOCUMENT ME!
|
120 |
*/
|
121 |
String getPluginName() {
|
122 |
return loader.getPluginName();
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* DOCUMENT ME!
|
127 |
*
|
128 |
* @param name
|
129 |
* @param locale
|
130 |
*/
|
131 |
void setResourceBundle(String name, Locale locale) { |
132 |
try{
|
133 |
resourceBundle = (PropertyResourceBundle) ResourceBundle.getBundle(name, locale, loader); |
134 |
}catch (MissingResourceException e) { |
135 |
logger.error("No se encontr? el recurso de traducciones " + name, e);
|
136 |
} |
137 |
} |
138 |
|
139 |
/**
|
140 |
* Obtienen una referencia al PluginServices del plugin cuyo nombre se pasa
|
141 |
* como par?metro
|
142 |
*
|
143 |
* @param pluginClassInstance Instancia de una clase propia del plugin a cuyos
|
144 |
* servicios se quiere acceder
|
145 |
*
|
146 |
* @return DOCUMENT ME!
|
147 |
*/
|
148 |
public static PluginServices getPluginServices(Object pluginClassInstance) { |
149 |
try{
|
150 |
PluginClassLoader loader = (PluginClassLoader) pluginClassInstance.getClass().getClassLoader(); |
151 |
return Launcher.getPluginServices(loader.getPluginName());
|
152 |
}catch (ClassCastException e) { |
153 |
throw new RuntimeException("Parameter is not a plugin class instance"); |
154 |
} |
155 |
} |
156 |
|
157 |
/**
|
158 |
* Obtienen una referencia al PluginServices del plugin cuyo nombre se pasa
|
159 |
* como par?metro
|
160 |
*
|
161 |
* @param pluginClassInstance Instancia de una clase propia del plugin a cuyos
|
162 |
* servicios se quiere acceder
|
163 |
*
|
164 |
* @return DOCUMENT ME!
|
165 |
*/
|
166 |
public static PluginServices getPluginServices(String pluginName) { |
167 |
return Launcher.getPluginServices(pluginName);
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* Obtiene una referencia al gestor de ventanas
|
172 |
*
|
173 |
* @return DOCUMENT ME!
|
174 |
*/
|
175 |
public static MDIManager getMDIManager() { |
176 |
return Launcher.getFrame().getMDIManager();
|
177 |
} |
178 |
|
179 |
public static MainFrame getMainFrame() { |
180 |
return Launcher.getFrame();
|
181 |
} |
182 |
|
183 |
public static Extension getExtension(Class extensionClass){ |
184 |
return (Extension) Launcher.getClassesExtensions().get(extensionClass);
|
185 |
} |
186 |
public static Iterator getExtensions(){ |
187 |
return Launcher.getClassesExtensions().values().iterator();
|
188 |
} |
189 |
|
190 |
public static String getText(Object pluginObject, String key){ |
191 |
try
|
192 |
{ |
193 |
PluginServices ps = getPluginServices(pluginObject); |
194 |
return ps.getText(key);
|
195 |
} |
196 |
catch(RuntimeException e) |
197 |
{ |
198 |
logger.error("GetText: Clave = " + key + ". ", e); |
199 |
return key;
|
200 |
} |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Establece los datos del plugin que deber?n persistir entre ejecuciones
|
205 |
* en formato xml
|
206 |
*
|
207 |
* @param entity DOCUMENT ME!
|
208 |
*/
|
209 |
public void setPresistentXML(XMLEntity entity) { |
210 |
persistentXML = entity; |
211 |
} |
212 |
|
213 |
/**
|
214 |
* Obtiene un objeto que representa la persistencia del plugin en formato
|
215 |
* xml
|
216 |
*
|
217 |
* @return DOCUMENT ME!
|
218 |
*/
|
219 |
public XMLEntity getPersistentXML() {
|
220 |
return persistentXML;
|
221 |
} |
222 |
|
223 |
/**
|
224 |
* DOCUMENT ME!
|
225 |
*
|
226 |
* @param name DOCUMENT ME!
|
227 |
* @param c DOCUMENT ME!
|
228 |
* @param listener DOCUMENT ME!
|
229 |
*
|
230 |
* @throws RuntimeException DOCUMENT ME!
|
231 |
*/
|
232 |
public void addPopupMenuListener(String name, Component c, |
233 |
ActionListener listener) {
|
234 |
MDIFrame frame = Launcher.getFrame(); |
235 |
|
236 |
if (frame == null) { |
237 |
throw new RuntimeException("MDIFrame not loaded yet"); |
238 |
} |
239 |
|
240 |
frame.addPopupMenuListener(name, c, listener, loader); |
241 |
} |
242 |
|
243 |
public File getPluginDirectory(){ |
244 |
return new File(Launcher.getPluginsDir() + File.separator + getPluginName()); |
245 |
} |
246 |
} |