Revision 22422
trunk/libraries/libRaster/src/org/gvsig/raster/util/extensionPoints/ExtensionPoints.java | ||
---|---|---|
1 |
package org.gvsig.raster.util.extensionPoints; |
|
2 |
|
|
3 |
import java.util.TreeMap; |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* Clase para registro de puntos de extension. |
|
8 |
* <br> |
|
9 |
* <br> |
|
10 |
* |
|
11 |
* @author jjdelcerro |
|
12 |
*/ |
|
13 |
public class ExtensionPoints extends TreeMap { |
|
14 |
|
|
15 |
|
|
16 |
private static final long serialVersionUID = -798417910971607414L; |
|
17 |
|
|
18 |
/** |
|
19 |
* Evita que se a?adan elementos que no son puntos de extension. |
|
20 |
* <br> |
|
21 |
* <br> |
|
22 |
* Aunque la clase se comporta como un <i>Map</i>, no esta permitido |
|
23 |
* a?adir a esta objetos que no sean de la clase <i>ExtensionPoint</i>. |
|
24 |
* Si intentamos a?adir un elemento que no sea de esta clase, se disparara |
|
25 |
* una excepcion ClassCastException. |
|
26 |
* <br> |
|
27 |
* <br> |
|
28 |
* @see java.util.Map#put(java.lang.Object, java.lang.Object) |
|
29 |
*/ |
|
30 |
public Object put(Object key, Object value) throws ClassCastException { |
|
31 |
throw new ClassCastException(); |
|
32 |
} |
|
33 |
|
|
34 |
/** |
|
35 |
* A?ade un punto de extension al registro de puntos de extension. |
|
36 |
* <br> |
|
37 |
* <br> |
|
38 |
* Mediante este metodo puede a?adir un punto de extension al registro |
|
39 |
* de puntos de extension, llevandose detras todas las extensiones que |
|
40 |
* esten registradas en el. |
|
41 |
* <br> |
|
42 |
* <br> |
|
43 |
* En caso de que ya existiese un punto de extension con el nombre dado, |
|
44 |
* a?adira a este las extensiones del punto de extension suministrado. |
|
45 |
* <br> |
|
46 |
* <br> |
|
47 |
* @param value Punto de extension a registrar |
|
48 |
* @return |
|
49 |
* |
|
50 |
*/ |
|
51 |
public Object put(ExtensionPoint value) { |
|
52 |
return put(value.getName(),value); |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* A?ade un punto de extension al registro de puntos de extension. |
|
57 |
* <br> |
|
58 |
* <br> |
|
59 |
* Mediante este metodo puede a?adir un punto de extension al registro |
|
60 |
* de puntos de extension, llevandose detras todas las extensiones que |
|
61 |
* esten registradas en el. |
|
62 |
* <br> |
|
63 |
* <br> |
|
64 |
* En caso de que ya existiese un punto de extension con el nombre dado, |
|
65 |
* a?adira a este las extensiones del punto de extension suministrado. |
|
66 |
* <br> |
|
67 |
* <br> |
|
68 |
* Cuando se a?ade un punto de extension, es imprescindible que <i>key</i> y |
|
69 |
* el nombre del punto de extension que se este a?adiendo coincidan. |
|
70 |
* <br> |
|
71 |
* <br> |
|
72 |
* @param key Nombre del punto de extension |
|
73 |
* @param value Punto de extension a registrar |
|
74 |
* @return |
|
75 |
* |
|
76 |
*/ |
|
77 |
public Object put(String key, ExtensionPoint value) { |
|
78 |
if ( !value.getName().equals(key) ) { |
|
79 |
throw new IllegalArgumentException (); |
|
80 |
} |
|
81 |
ExtensionPoint n = (ExtensionPoint)super.get(key); |
|
82 |
if( n == null ) { |
|
83 |
return super.put(key,value); |
|
84 |
} |
|
85 |
// Como estamos actualizando un punto de extension, a?adimos a este las |
|
86 |
// extensiones del que nos acaban de suministrar. |
|
87 |
n.putAll(value); |
|
88 |
return value; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Registra una extension en un punto de extension. |
|
93 |
* <br> |
|
94 |
* <br> |
|
95 |
* Mediante este metodo puede registrar sobre un punto de extension |
|
96 |
* una extension. La extension esta identificada mediante un nombre |
|
97 |
* unico, y una clase que se usara para manejar la extension o una |
|
98 |
* clase que contruira el objeto que maneje la extension. |
|
99 |
* <br> |
|
100 |
* <br> |
|
101 |
* Si ya existe en el punto de extension indicado por <i>extensionPointName</i> |
|
102 |
* una extension con el nombre <i>name</i>, esta sera sustituida por la |
|
103 |
* nueva extension. |
|
104 |
* <br> |
|
105 |
* @param extensionPointName Nombre del punto de extension |
|
106 |
* @param name Nombre o identificador de la extension |
|
107 |
* @param data Clase que implementa la extension o que la construye. |
|
108 |
* |
|
109 |
* |
|
110 |
*/ |
|
111 |
public void add(String extensionPointName, String name, Object data) { |
|
112 |
ExtensionPoint extensionPoint = (ExtensionPoint)super.get(extensionPointName); |
|
113 |
if( extensionPoint == null ) { |
|
114 |
extensionPoint = new ExtensionPoint(extensionPointName); |
|
115 |
super.put(extensionPoint.getName(), extensionPoint); |
|
116 |
} |
|
117 |
|
|
118 |
extensionPoint.put(name, data); |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Registra una extension en un punto de extension. |
|
123 |
* <br> |
|
124 |
* <br> |
|
125 |
* Mediante este metodo puede registrar sobre un punto de extension |
|
126 |
* una extension. La extension esta identificada mediante un nombre |
|
127 |
* unico, y una clase que se usara para manejar la extension o una |
|
128 |
* clase que contruira el objeto que maneje la extension. |
|
129 |
* <br> |
|
130 |
* <br> |
|
131 |
* Si ya existe en el punto de extension indicado por <i>extensionPointName</i> |
|
132 |
* una extension con el nombre <i>name</i>, esta sera sustituida por la |
|
133 |
* nueva extension. |
|
134 |
* <br> |
|
135 |
* @param extensionPointName Nombre del punto de extension |
|
136 |
* @param name Nombre o identificador de la extension |
|
137 |
* @param description descripcion de la extension. |
|
138 |
* @param data Clase que implementa la extension o que la construye. |
|
139 |
* |
|
140 |
* |
|
141 |
*/ |
|
142 |
public void add(String extensionPointName, String name, String description, Object data) { |
|
143 |
ExtensionPoint extensionPoint = (ExtensionPoint)super.get(extensionPointName); |
|
144 |
if( extensionPoint == null ) { |
|
145 |
extensionPoint = new ExtensionPoint(extensionPointName); |
|
146 |
super.put(extensionPoint.getName(), extensionPoint); |
|
147 |
} |
|
148 |
|
|
149 |
extensionPoint.put(name,description, data); |
|
150 |
} |
|
151 |
|
|
152 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/util/extensionPoints/ExtensionPointsSingleton.java | ||
---|---|---|
1 |
package org.gvsig.raster.util.extensionPoints; |
|
2 |
|
|
3 |
|
|
4 |
public class ExtensionPointsSingleton extends ExtensionPoints { |
|
5 |
|
|
6 |
private static final long serialVersionUID = -630976693542039111L; |
|
7 |
|
|
8 |
private static ExtensionPoints extensionPoints = new ExtensionPointsSingleton(); |
|
9 |
|
|
10 |
private ExtensionPointsSingleton() { |
|
11 |
super(); |
|
12 |
} |
|
13 |
|
|
14 |
public static ExtensionPoints getInstance() { |
|
15 |
return ExtensionPointsSingleton.extensionPoints; |
|
16 |
} |
|
17 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/util/extensionPoints/IExtensionBuilder.java | ||
---|---|---|
1 |
package org.gvsig.raster.util.extensionPoints; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
/** |
|
6 |
* Interface utilizado para indicar al registro de extensiones |
|
7 |
* que no se trata de una clase lo que hey registrado, si no |
|
8 |
* una instancia de un objeto a usar para crear la extension. |
|
9 |
* |
|
10 |
* |
|
11 |
* @author jjdelcerro |
|
12 |
* |
|
13 |
*/ |
|
14 |
public interface IExtensionBuilder { |
|
15 |
/** |
|
16 |
* Crea una instancia de la extension y la retorna. |
|
17 |
* <br> |
|
18 |
* @return |
|
19 |
*/ |
|
20 |
public Object create(); |
|
21 |
|
|
22 |
/** |
|
23 |
* Crea una instancia de la extension y la retorna. |
|
24 |
* <br> |
|
25 |
* En <i>args</i> recibira la lista de argumeentos a utilizar |
|
26 |
* para crear la extension. |
|
27 |
* <br> |
|
28 |
* @param args |
|
29 |
* @return |
|
30 |
*/ |
|
31 |
public Object create(Object [] args); |
|
32 |
|
|
33 |
public Object create(Map args); |
|
34 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/util/extensionPoints/package.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
<p> |
|
4 |
Este paquete expone un mecanismo para registro de clases. |
|
5 |
</p> |
|
6 |
<p> |
|
7 |
Permite registrar clases o factorias de clases que luego pueden ser |
|
8 |
recuperadas para construir instancias. |
|
9 |
</p> |
|
10 |
<p> |
|
11 |
La finalidad de este registro es el manejo de puntos de extension a una |
|
12 |
aplicacion. Una aplicacion declara o registra con un nombre los puntos de |
|
13 |
extension que va a tener. Cada punto de extension puede tener registradas una |
|
14 |
o mas extensiones. Cuando se quiere a?adir una extension a la aplicacion, se |
|
15 |
registra la clase o factoria que gestiona esa extension para el punto de extension |
|
16 |
que se desee. |
|
17 |
</p> |
|
18 |
<p> |
|
19 |
Veamos esto con un ejemplo. |
|
20 |
</p> |
|
21 |
<p> |
|
22 |
Supongamos que queremos a?adir un punto de extension a la aplicacion gvSIG, que |
|
23 |
permita asignar un mecanismo de presentacion de la informacion asociada a la |
|
24 |
herramienta de "informacion" especializada segun el tipo de tema sobre el que se |
|
25 |
esta trabajando. |
|
26 |
</p> |
|
27 |
<p> |
|
28 |
Lo primero que tendriamos que hacer es darle un nombre al punto de extension. |
|
29 |
Lo llamaremos "InfoByPoint". Para esto, la aplicacion que valla a utilizar |
|
30 |
las extensiones que se registren en este punto deberia hacer lo siguiente: |
|
31 |
</p> |
|
32 |
<pre> |
|
33 |
ExtensionPoint infoByPoint = new ExtensionPoint("InfoByPoint","Registra las distintas extensiones que se pueden a?adir al 'InfoByPoint'"); |
|
34 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
35 |
|
|
36 |
extensionPoints.put(infoByPoint); |
|
37 |
</pre> |
|
38 |
<p> |
|
39 |
Con esto creamos un punto de extension de nombre "InfoByPoint", recogemos la |
|
40 |
instancia del registro de extensiones e insertamos el nuevo punto de extenstion |
|
41 |
en el.<br> |
|
42 |
Normalmente esta operacion, en el contexto de gvSIG, se realizaria en la |
|
43 |
inicializacion de la extension de andami en la que vallamos a a?adir |
|
44 |
la herramienta de informacion. |
|
45 |
</p> |
|
46 |
<p> |
|
47 |
Las extensiones a registrar en el "InfoByPoint" podrian consistir un un |
|
48 |
JPanel que gestione la presentacion a usar para el tema. |
|
49 |
</p> |
|
50 |
<p> |
|
51 |
Luego, desde la parte de la aplicacion que necesite a?adir nueva funcionalidad |
|
52 |
en este punto de extension, se deberia a?adir la extension. Por ejemplo |
|
53 |
en la extension de andami de WMS, se podria a?adir a "InfoByPoint" la posibilidad |
|
54 |
de usar una forma especial de presentacion. Podria hacerse: |
|
55 |
</p> |
|
56 |
<pre> |
|
57 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
58 |
extensionPoints.add("InfoByPoint","WMS",PanelQueGestionaLaExtension); |
|
59 |
</pre> |
|
60 |
<p> |
|
61 |
Donde "PanelQueGestionaLaExtension" sera el JPanel que gestiona la extension para |
|
62 |
"InfoByPoint" de WMS. |
|
63 |
</p> |
|
64 |
<p> |
|
65 |
Si quieran acceder a la extension de nombre "WMS" |
|
66 |
se haria: |
|
67 |
</p> |
|
68 |
<pre> |
|
69 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
70 |
ExtensionPoint infoByPoint = (ExtensionPoint)extensionPoints.get("InfoByPoint"); |
|
71 |
Object ext = infoByPoint.create("WMS"); |
|
72 |
</pre> |
|
73 |
<p> |
|
74 |
Y esto nos devolberia un objeto JPanel que gestiona la extension "WMS" |
|
75 |
para el "InfoByPoint". |
|
76 |
</p> |
|
77 |
<p> |
|
78 |
Si quisiesemos recorrer las distintas extensiones de ese punto podriamos |
|
79 |
hacerlo asi: |
|
80 |
</p> |
|
81 |
<pre> |
|
82 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
83 |
ExtensionPoint infoByPoint = (ExtensionPoint)extensionPoints.get("InfoByPoint"); |
|
84 |
Iterator infoByPoint =infoByPoint.keySet().iterator(); |
|
85 |
while( i.hasNext() ) { |
|
86 |
String nombre = (String)i.next(); |
|
87 |
... |
|
88 |
// Y para crear los JPanel asociados a la extension... |
|
89 |
Object panel = infoByPoint.create(nombre); |
|
90 |
... |
|
91 |
} |
|
92 |
</pre> |
|
93 |
<p> |
|
94 |
Ademas de registrar clases en un punto de extension, se pueden registrar |
|
95 |
instancias que implementen el interface de IExtensionBuilder. En este caso, |
|
96 |
cuando se invoque al metodo "create" del punto de extension, en lugar |
|
97 |
de crear una instancia, como no tiene la clase, este invocara al metodo |
|
98 |
create del objeto que ha sido registrado. |
|
99 |
</p> |
|
100 |
|
|
101 |
<p> |
|
102 |
Podemos encontrar un ejemplo de esto en la extension de JDBC para el |
|
103 |
catalogo. Como no existe una capa especifica para las capas JDBC, en lugar |
|
104 |
de registrar en el punto de extension una clase "capa JDBC", se registra |
|
105 |
una clase que implementa el interface IExtensionBuilder, que en su |
|
106 |
metodo create construye una capa vectorial y la inicializa de la forma |
|
107 |
apropiada para funcionar con la fuente de datos de JDBC. |
|
108 |
</p> |
|
109 |
<p> |
|
110 |
Hay que tener en cuenta que para un punto de extension dado, deberia ser |
|
111 |
trasparente que se registren en el clases o instancias que contruyen las clases. |
|
112 |
E incluso que es posible mezclar en un punto de extension los dos |
|
113 |
mecanismos, como es el caso del catalogo. |
|
114 |
</p> |
|
115 |
</body> |
|
116 |
</html> |
trunk/libraries/libRaster/src/org/gvsig/raster/util/extensionPoints/ExtensionBuilder.java | ||
---|---|---|
1 |
package org.gvsig.raster.util.extensionPoints; |
|
2 |
|
|
3 |
import java.lang.reflect.Constructor; |
|
4 |
import java.lang.reflect.InvocationTargetException; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
|
|
8 |
/** |
|
9 |
* Clase de utilidad usada para crear las extensiones. |
|
10 |
* |
|
11 |
* Esta clase presenta un par de metodos estaticos para |
|
12 |
* permitir crear un objeto a partir de una clase. |
|
13 |
* |
|
14 |
* @author jjdelcerro |
|
15 |
* |
|
16 |
*/ |
|
17 |
public abstract class ExtensionBuilder implements IExtensionBuilder { |
|
18 |
|
|
19 |
/** |
|
20 |
* Crea un objeto de la clase indicada. |
|
21 |
* |
|
22 |
* @param cls Clase de la que crear la instancia |
|
23 |
* @return |
|
24 |
* |
|
25 |
* @throws InstantiationException |
|
26 |
* @throws IllegalAccessException |
|
27 |
*/ |
|
28 |
public static Object create(Class cls) throws InstantiationException, IllegalAccessException { |
|
29 |
Object obj = null; |
|
30 |
|
|
31 |
if( cls == null ) { |
|
32 |
return null; |
|
33 |
} |
|
34 |
obj = cls.newInstance(); |
|
35 |
return obj; |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* Crea un objeto de la clase indicada. |
|
40 |
* |
|
41 |
* Crea un objeto de la clase indicada pasandole al constructor |
|
42 |
* los argumentos indicados en <i>args</i>. |
|
43 |
* <br> |
|
44 |
* @param cls Clase de la que crear la instancia |
|
45 |
* @param args Argumentos que pasar al constructor. |
|
46 |
* @return |
|
47 |
* |
|
48 |
* @throws SecurityException |
|
49 |
* @throws NoSuchMethodException |
|
50 |
* @throws IllegalArgumentException |
|
51 |
* @throws InstantiationException |
|
52 |
* @throws IllegalAccessException |
|
53 |
* @throws InvocationTargetException |
|
54 |
*/ |
|
55 |
public static Object create(Class cls, Object [] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
|
56 |
Object obj = null; |
|
57 |
Constructor create = null; |
|
58 |
Class [] types = new Class[args.length]; |
|
59 |
|
|
60 |
if( cls == null ) { |
|
61 |
return null; |
|
62 |
} |
|
63 |
for( int n=0 ; n<args.length ; n++ ) { |
|
64 |
Object arg = args[n]; |
|
65 |
types[n] = arg.getClass(); |
|
66 |
} |
|
67 |
create = cls.getConstructor(types); |
|
68 |
obj = create.newInstance(args); |
|
69 |
return obj; |
|
70 |
} |
|
71 |
/** |
|
72 |
* Crea un objeto de la clase indicada. |
|
73 |
* |
|
74 |
* Crea un objeto de la clase indicada pasandole al constructor |
|
75 |
* un como argumento un Map.. |
|
76 |
* <br> |
|
77 |
* @param cls Clase de la que crear la instancia |
|
78 |
* @param args Map a pasar como argumento al constructor. |
|
79 |
* @return |
|
80 |
* |
|
81 |
* @throws SecurityException |
|
82 |
* @throws NoSuchMethodException |
|
83 |
* @throws IllegalArgumentException |
|
84 |
* @throws InstantiationException |
|
85 |
* @throws IllegalAccessException |
|
86 |
* @throws InvocationTargetException |
|
87 |
*/ |
|
88 |
public static Object create(Class cls, Map args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
|
89 |
Object obj = null; |
|
90 |
Constructor create = null; |
|
91 |
Class [] types = new Class[1]; |
|
92 |
Object [] argsx = new Object[1]; |
|
93 |
|
|
94 |
if( cls == null ) { |
|
95 |
return null; |
|
96 |
} |
|
97 |
types[0] = Map.class; |
|
98 |
argsx[0] = args; |
|
99 |
create = cls.getConstructor(types); |
|
100 |
obj = create.newInstance(argsx); |
|
101 |
return obj; |
|
102 |
} |
|
103 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/util/extensionPoints/ExtensionPoint.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 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 |
*/ |
|
1 | 19 |
package org.gvsig.raster.util.extensionPoints; |
2 | 20 |
|
3 |
import java.lang.reflect.InvocationTargetException; |
|
4 |
import java.security.KeyException; |
|
5 |
import java.util.Hashtable; |
|
21 |
import java.util.Iterator; |
|
6 | 22 |
import java.util.LinkedHashMap; |
7 | 23 |
import java.util.Map; |
8 |
|
|
9 |
|
|
10 |
|
|
24 |
import java.util.TreeMap; |
|
11 | 25 |
/** |
12 |
* Esta clase permite registrar extensiones para un punto de extension. |
|
13 |
* <br> |
|
14 |
* <br> |
|
15 |
* La clase se comporta como un Map que mantiene el orden de insercion |
|
16 |
* de los elementos, para que puedan ser recorridos en ese orden. |
|
17 |
* <br> |
|
18 |
* Ademas de registrar las extensiones para un punto de extension, presenta |
|
19 |
* metodos para facilitar la creacion de la extension. |
|
20 |
* <br> |
|
21 |
* A la hora de registrar una extension, mediante el petodo <i>put</i>, |
|
22 |
* podremos suministrarle una clase o una instancia que implemente el |
|
23 |
* interface IExtensionBuilder. Si le suministramos una clase, cuando |
|
24 |
* queramos crear la extension mediante el metodo <i>create</i>, se creara |
|
25 |
* una instancia de la clase y se retornara. Si lo que se suministro fue |
|
26 |
* una instancia que implementa el interface IExtensionBuilder, se invocara |
|
27 |
* al metodo <i>create</i> de esta para crear la extension. |
|
28 |
* <br> |
|
29 |
* @author jjdelcerro |
|
30 |
* |
|
26 |
* ExtensionPoint es una clase en la que se pueden registrar elementos asociados a un identificador. |
|
27 |
* <br><br> |
|
28 |
* Esta clase no posee constructores. La ?nica forma de poder obtener una instancia a dicha clase |
|
29 |
* es usando el m?todo <code>getExtensionPoint(String)</code> |
|
30 |
* |
|
31 |
* @version 21/07/2008 |
|
32 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
31 | 33 |
*/ |
32 |
public class ExtensionPoint extends LinkedHashMap { |
|
34 |
public class ExtensionPoint { |
|
35 |
static private TreeMap map = new TreeMap(); |
|
36 |
private LinkedHashMap point = new LinkedHashMap(); |
|
33 | 37 |
|
34 |
private static final long serialVersionUID = -5908427725588553371L; |
|
35 |
|
|
36 | 38 |
private String name; |
37 | 39 |
private String description; |
38 |
private Hashtable extensionDescriptions = new Hashtable(); |
|
39 |
private Hashtable aliases = new Hashtable(); |
|
40 | 40 |
|
41 | 41 |
/** |
42 | 42 |
* Construye un punto de extension. |
43 | 43 |
* <br> |
44 | 44 |
* @param extensionPointName Nombre del punto de extension. |
45 | 45 |
*/ |
46 |
public ExtensionPoint(String extensionPointName) {
|
|
46 |
private ExtensionPoint(String extensionPointName) {
|
|
47 | 47 |
this.name = extensionPointName; |
48 | 48 |
} |
49 | 49 |
|
... | ... | |
53 | 53 |
* @param extensionPointName Nombre del punto de extension |
54 | 54 |
* @param description Descripcion del punto de extension |
55 | 55 |
*/ |
56 |
public ExtensionPoint(String extensionPointName, String description) {
|
|
56 |
private ExtensionPoint(String extensionPointName, String description) {
|
|
57 | 57 |
this.name = extensionPointName; |
58 | 58 |
this.description = description; |
59 | 59 |
} |
60 |
|
|
60 |
|
|
61 | 61 |
/** |
62 |
* Retorna el nombre de punto de extension. |
|
63 |
* <br> |
|
64 |
* @return Nombre del punto de extension |
|
62 |
* Devuelve un punto de extensi?n asociado al identificador pasado por parametro. |
|
63 |
* En caso de no existir dicho punto de extensi?n, lo crea. |
|
64 |
* @param extensionPointName |
|
65 |
* @return |
|
65 | 66 |
*/ |
66 |
public String getName() { |
|
67 |
return this.name; |
|
67 |
public static ExtensionPoint getExtensionPoint(String extensionPointName) { |
|
68 |
ExtensionPoint extensionPoint = (ExtensionPoint) map.get(extensionPointName); |
|
69 |
if (extensionPoint == null) { |
|
70 |
extensionPoint = new ExtensionPoint(extensionPointName); |
|
71 |
map.put(extensionPoint.getName(), extensionPoint); |
|
72 |
} |
|
73 |
return extensionPoint; |
|
68 | 74 |
} |
69 | 75 |
|
70 | 76 |
/** |
71 |
* Retorna la descripcion asociada al punto de extension. |
|
72 |
* <br> |
|
73 |
* @return descripcion del punto de extension |
|
77 |
* Establece la descripci?n del punto de extensi?n actual. |
|
78 |
* @param description |
|
74 | 79 |
*/ |
75 |
public String getDescription() {
|
|
76 |
return this.description;
|
|
80 |
public void setDescription(String description) {
|
|
81 |
this.description = description;
|
|
77 | 82 |
} |
78 |
|
|
83 |
|
|
79 | 84 |
/** |
80 |
* Asocia una descripcion al punto de extension. |
|
81 |
* <br> |
|
82 |
* |
|
83 |
* @param description |
|
85 |
* Devuelve la descripci?n del punto de extensi?n actual |
|
86 |
* @return |
|
84 | 87 |
*/ |
85 |
public void setDescripcion(String description) {
|
|
86 |
this.description = description;
|
|
88 |
public String getDescription() {
|
|
89 |
return description;
|
|
87 | 90 |
} |
88 |
|
|
91 |
|
|
89 | 92 |
/** |
90 |
* Retorna la descripcion asociada a una extension. |
|
91 |
* <br> |
|
92 |
* @param key |
|
93 |
* <br> |
|
94 |
* @return descripcion del punto de extension |
|
93 |
* Devuelve el nombre del punto de extensi?n actual |
|
94 |
* @return |
|
95 | 95 |
*/ |
96 |
public String getExtensionDescription(String key) {
|
|
97 |
return (String)this.extensionDescriptions.get(key);
|
|
96 |
public String getName() {
|
|
97 |
return name;
|
|
98 | 98 |
} |
99 |
|
|
99 |
|
|
100 | 100 |
/** |
101 |
* Asocia una descripcion a una extension registrada. |
|
102 |
* <br> |
|
103 |
* |
|
104 |
* @param key Nombre de la extension |
|
105 |
* @param description |
|
106 |
*/ |
|
107 |
public void setExtensionDescription(String key,String description) { |
|
108 |
if (this.containsKey(key)) { |
|
109 |
this.extensionDescriptions.put(key,description); |
|
110 |
} |
|
101 |
* Registra un elemento en el punto de extensi?n actual asoci?ndolo con un key identificador. |
|
102 |
* @param key |
|
103 |
* @param value |
|
104 |
*/ |
|
105 |
public void register(String key, Object value) { |
|
106 |
point.put(key, value); |
|
111 | 107 |
} |
112 |
|
|
108 |
|
|
113 | 109 |
/** |
114 |
* A?ade una extension con su descripcion asociada |
|
115 |
* |
|
116 |
* @param key clave de la extension |
|
117 |
* @param decription descripcion de la extension |
|
118 |
* @param value extension |
|
110 |
* Devuelve un iterador para poder recorrer todos los elementos del punto de extensi?n. |
|
111 |
* @return |
|
119 | 112 |
*/ |
120 |
|
|
121 |
public Object put(String key, String description,Object value) { |
|
122 |
this.extensionDescriptions.put(key,description); |
|
123 |
return super.put(key,value); |
|
113 |
public Iterator getIterator() { |
|
114 |
return point.entrySet().iterator(); |
|
124 | 115 |
} |
125 | 116 |
|
126 |
|
|
127 | 117 |
/** |
128 |
* Crea una extension. |
|
129 |
* <br> |
|
130 |
* Dado un nombre de extension asociada a este punto de extension, crea |
|
131 |
* el objeto registrado para manejar la extension. |
|
132 |
* <br> |
|
133 |
* Si el objeto registrado para esa extension implementa el interface |
|
134 |
* <i>IExtensionBuilder</i>, se invoca al metodo create para crear la instancia |
|
135 |
* de la extension. |
|
136 |
* <br> |
|
137 |
* Si no implementa este interface, debera ser una clase, y se creara una |
|
138 |
* instancia de esa clase. |
|
139 |
* <br> |
|
140 |
* @param name Nombre de la extension a crear. |
|
141 |
* @return La instancia creada de la extension. |
|
142 |
* |
|
143 |
* @throws InstantiationException |
|
144 |
* @throws IllegalAccessException |
|
118 |
* Devuelve el n?mero de elementos que hay registrados en el punto de extensi?n |
|
119 |
* @return |
|
145 | 120 |
*/ |
146 |
public Object create(String name) throws InstantiationException, IllegalAccessException { |
|
147 |
Object extension = this.get(name); |
|
148 |
if (extension == null) { |
|
149 |
extension = this.get(this.aliases.get(name)); |
|
150 |
} |
|
151 |
|
|
152 |
if( extension instanceof IExtensionBuilder ) { |
|
153 |
return ((IExtensionBuilder)extension).create(); |
|
154 |
} |
|
155 |
return ExtensionBuilder.create((Class) extension); |
|
121 |
public int size() { |
|
122 |
return point.size(); |
|
156 | 123 |
} |
157 | 124 |
|
158 | 125 |
/** |
159 |
* Crea una extension. |
|
160 |
* <br> |
|
161 |
* Dado un nombre de extension asociada a este punto de extension, crea |
|
162 |
* el objeto registrado para manejar la extension. |
|
163 |
* <br> |
|
164 |
* A la hora de crear la instanacia de la extension, le pasara los parametros |
|
165 |
* indicados en <i>args</i>. |
|
166 |
* <br> |
|
167 |
* Debido a que los argumentos se pasan como un array de objetos, no es posible |
|
168 |
* pasar al constructor de la extension parametros de tipos basicos como <i>int</i> |
|
169 |
* o <i>long</i>. Se deberan pasar como objetos y existir un constructor de la clase |
|
170 |
* que los pueda recibir de esta manera. |
|
171 |
* <br> |
|
172 |
* @param name Nombre de la extension a crear. |
|
173 |
* @param args Array de objetos a pasar como parametros en la construccion de la instancia de la extension. |
|
174 |
* @return La instancia creada de la extension. |
|
175 |
* |
|
176 |
* @throws SecurityException |
|
177 |
* @throws NoSuchMethodException |
|
178 |
* @throws IllegalArgumentException |
|
179 |
* @throws InstantiationException |
|
180 |
* @throws IllegalAccessException |
|
181 |
* @throws InvocationTargetException |
|
126 |
* Devuelve <tt>true</tt> si el punto de extensi?n contiene un key en su lista de elementos |
|
127 |
* @param key |
|
128 |
* @return |
|
182 | 129 |
*/ |
183 |
public Object create(String name, Object [] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
|
184 |
Object extension = this.get(name); |
|
185 |
if (extension == null) { |
|
186 |
extension = this.get(this.aliases.get(name)); |
|
187 |
} |
|
188 |
|
|
189 |
if( extension instanceof IExtensionBuilder ) { |
|
190 |
return ((IExtensionBuilder)extension).create(args); |
|
191 |
} |
|
192 |
return ExtensionBuilder.create((Class) extension, args); |
|
193 |
} |
|
130 |
public boolean existKey(String key) { |
|
131 |
if (point.get(key) == null) |
|
132 |
return false; |
|
133 |
return true; |
|
134 |
} |
|
194 | 135 |
|
195 |
public Object create(String name, Map args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
|
196 |
Object extension = this.get(name); |
|
197 |
if (extension == null) { |
|
198 |
extension = this.get(this.aliases.get(name)); |
|
199 |
} |
|
200 |
|
|
201 |
if( extension instanceof IExtensionBuilder ) { |
|
202 |
return ((IExtensionBuilder)extension).create(args); |
|
203 |
} |
|
204 |
return ExtensionBuilder.create((Class) extension, args); |
|
136 |
/** |
|
137 |
* Devuelve el elemento asociado al key pasado por parametro. En caso de no existir, devolver? |
|
138 |
* <tt>null</tt>. |
|
139 |
* @param key |
|
140 |
* @return |
|
141 |
*/ |
|
142 |
public Object getValue(String key) { |
|
143 |
return point.get(key); |
|
205 | 144 |
} |
206 | 145 |
|
207 | 146 |
/** |
208 |
* Crea un alias para una extension registrada. |
|
209 |
* <br> |
|
210 |
* @param item Nombre de la extension registrada. |
|
211 |
* @param alias alias a a?adir. |
|
212 |
* |
|
213 |
**/ |
|
214 |
public void addAlias(String item, String alias) throws KeyException{ |
|
215 |
if (!this.containsKey(item)) { |
|
216 |
throw new KeyException(item); |
|
147 |
* Devuelve la lista de keys para el punto de extensi?n actual. |
|
148 |
* @param key |
|
149 |
* @return |
|
150 |
*/ |
|
151 |
public String[] getKeys() { |
|
152 |
String[] list = new String[size()]; |
|
153 |
Iterator iterator = getIterator(); |
|
154 |
int i = 0; |
|
155 |
while (iterator.hasNext()) { |
|
156 |
list[i] = (String) ((Map.Entry) iterator.next()).getKey(); |
|
157 |
i++; |
|
217 | 158 |
} |
218 |
this.aliases.put(alias,item);
|
|
159 |
return list;
|
|
219 | 160 |
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 | 161 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/datastruct/serializer/ColorTableRmfSerializer.java | ||
---|---|---|
28 | 28 |
import org.gvsig.raster.dataset.io.rmf.ParsingException; |
29 | 29 |
import org.gvsig.raster.datastruct.ColorItem; |
30 | 30 |
import org.gvsig.raster.datastruct.ColorTable; |
31 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
|
32 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
|
31 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoint; |
|
33 | 32 |
import org.kxml2.io.KXmlParser; |
34 | 33 |
import org.xmlpull.v1.XmlPullParserException; |
35 | 34 |
/** |
... | ... | |
62 | 61 |
* Registra ColorTableRmfSerializer en los puntos de extension de Serializer |
63 | 62 |
*/ |
64 | 63 |
public static void register() { |
65 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
|
|
66 |
extensionPoints.add("Serializer", "ColorTable", ColorTableRmfSerializer.class);
|
|
64 |
ExtensionPoint point = ExtensionPoint.getExtensionPoint("Serializer");
|
|
65 |
point.register("ColorTable", ColorTableRmfSerializer.class);
|
|
67 | 66 |
} |
68 | 67 |
|
69 | 68 |
/** |
trunk/libraries/libRaster/src/org/gvsig/raster/datastruct/serializer/NoDataRmfSerializer.java | ||
---|---|---|
26 | 26 |
import org.gvsig.raster.dataset.io.rmf.ClassSerializer; |
27 | 27 |
import org.gvsig.raster.dataset.io.rmf.ParsingException; |
28 | 28 |
import org.gvsig.raster.datastruct.NoData; |
29 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
|
30 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
|
29 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoint; |
|
31 | 30 |
import org.kxml2.io.KXmlParser; |
32 | 31 |
import org.xmlpull.v1.XmlPullParserException; |
33 | 32 |
/** |
... | ... | |
55 | 54 |
* Registra NoDataRmfSerializer en los puntos de extension de Serializer |
56 | 55 |
*/ |
57 | 56 |
public static void register() { |
58 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
|
|
59 |
extensionPoints.add("Serializer", "NoData", NoDataRmfSerializer.class);
|
|
57 |
ExtensionPoint point = ExtensionPoint.getExtensionPoint("Serializer");
|
|
58 |
point.register("NoData", NoDataRmfSerializer.class);
|
|
60 | 59 |
} |
61 | 60 |
|
62 | 61 |
/** |
trunk/libraries/libRaster/src/org/gvsig/raster/datastruct/serializer/HistogramRmfSerializer.java | ||
---|---|---|
26 | 26 |
import org.gvsig.raster.dataset.io.rmf.ParsingException; |
27 | 27 |
import org.gvsig.raster.datastruct.Histogram; |
28 | 28 |
import org.gvsig.raster.datastruct.HistogramClass; |
29 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
|
30 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
|
29 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoint; |
|
31 | 30 |
import org.kxml2.io.KXmlParser; |
32 | 31 |
import org.xmlpull.v1.XmlPullParserException; |
33 | 32 |
/** |
... | ... | |
77 | 76 |
* Registra HistogramRmfSerializer en los puntos de extension de Serializer |
78 | 77 |
*/ |
79 | 78 |
public static void register() { |
80 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
|
|
81 |
extensionPoints.add("Serializer", "Histogram", HistogramRmfSerializer.class);
|
|
79 |
ExtensionPoint point = ExtensionPoint.getExtensionPoint("Serializer");
|
|
80 |
point.register("Histogram", HistogramRmfSerializer.class);
|
|
82 | 81 |
} |
83 | 82 |
|
84 | 83 |
/** |
trunk/libraries/libRaster/src/org/gvsig/raster/RasterLibrary.java | ||
---|---|---|
19 | 19 |
package org.gvsig.raster; |
20 | 20 |
|
21 | 21 |
import java.io.File; |
22 |
import java.io.FileFilter; |
|
23 |
import java.io.IOException; |
|
24 |
import java.net.MalformedURLException; |
|
25 |
import java.net.URL; |
|
26 | 22 |
import java.util.ArrayList; |
27 |
import java.util.Enumeration; |
|
28 |
import java.util.Hashtable; |
|
29 |
import java.util.jar.JarException; |
|
30 |
import java.util.zip.ZipEntry; |
|
31 |
import java.util.zip.ZipException; |
|
32 |
import java.util.zip.ZipFile; |
|
33 | 23 |
|
34 |
import org.apache.log4j.Logger; |
|
35 | 24 |
import org.gvsig.raster.dataset.io.ErmapperDriver; |
36 | 25 |
import org.gvsig.raster.dataset.io.ErmapperWriter; |
37 | 26 |
import org.gvsig.raster.dataset.io.GdalDriver; |
... | ... | |
65 | 54 |
import org.gvsig.raster.util.PropertyEvent; |
66 | 55 |
import org.gvsig.raster.util.PropertyListener; |
67 | 56 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoint; |
68 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
|
69 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
|
70 | 57 |
/** |
71 | 58 |
* Clase principal de la libreria. En ella se definen variables globales con informaci?n |
72 | 59 |
* de uso general, as? como acciones a realizar al arracar la librer?a. El m?todo que |
... | ... | |
138 | 125 |
*/ |
139 | 126 |
public static String[] pathExtensions = {"." + File.separator}; |
140 | 127 |
|
141 |
private static Hashtable clasesJar = new Hashtable(); |
|
142 |
|
|
143 | 128 |
/** |
144 | 129 |
* Valor noData por defecto para la librer?a. En caso de no tener un valor asociado |
145 | 130 |
* al raster se usar? este. |
... | ... | |
162 | 147 |
return; |
163 | 148 |
|
164 | 149 |
// Punto de extensi?n para registro de drivers de lectura |
165 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
166 |
if (!extensionPoints.containsKey("RasterReader")) |
|
167 |
extensionPoints.put(new ExtensionPoint("RasterReader", "Raster Reader Classes")); |
|
168 |
|
|
169 |
// Punto de extensi?n para registro de drivers de escritura |
|
170 |
if (!extensionPoints.containsKey("RasterWriter")) |
|
171 |
extensionPoints.put(new ExtensionPoint("RasterWriter", "Raster Writer Classes")); |
|
172 |
|
|
173 |
// Ejecuta el c?digo static de la clase cada driver |
|
150 |
ExtensionPoint.getExtensionPoint("RasterReader").setDescription("Raster Reader Classes"); |
|
151 |
|
|
152 |
// Registro de los drivers de lectura |
|
174 | 153 |
GdalDriver.register(); |
175 | 154 |
ErmapperDriver.register(); |
176 | 155 |
MrSidDriver.register(); |
177 | 156 |
MemoryRasterDriver.register(); |
178 | 157 |
|
158 |
// Punto de extensi?n para registro de drivers de escritura |
|
159 |
ExtensionPoint.getExtensionPoint("RasterWriter").setDescription("Raster Writer Classes"); |
|
160 |
|
|
161 |
// Registro de los drivers de escritura |
|
179 | 162 |
GdalWriter.register(); |
180 | 163 |
ErmapperWriter.register(); |
181 | 164 |
JpegWriter.register(); |
182 | 165 |
PngWriter.register(); |
183 | 166 |
|
184 |
// Punto de extensi?n para registro de filtros |
|
185 |
if (!extensionPoints.containsKey("RasterFilter")) { |
|
186 |
extensionPoints.put(new ExtensionPoint("RasterFilter", "Raster Filter Classes")); |
|
187 |
} |
|
167 |
// Punto de extensi?n de los filtros |
|
168 |
ExtensionPoint.getExtensionPoint("RasterFilter").setDescription("Raster Filter Classes"); |
|
188 | 169 |
|
189 |
// Invoca las llamadas est?ticas de cada clase para registrarlas en los |
|
190 |
// puntos de extensi?n |
|
170 |
// Invoca las llamadas est?ticas de cada clase para registrarlas en los puntos de extensi?n |
|
191 | 171 |
BrightnessContrastListManager.register(); |
192 | 172 |
FirstDerivativeListManager.register(); |
193 | 173 |
MedianListManager.register(); |
... | ... | |
207 | 187 |
// Registrar los nuevos filtros del directorio |
208 | 188 |
// registerClasses(); |
209 | 189 |
|
190 |
// Punto de extensi?n de los serializadores |
|
191 |
ExtensionPoint.getExtensionPoint("Serializer").setDescription("Raster Serializer Classes"); |
|
192 |
|
|
210 | 193 |
// Registro de serializadores |
211 | 194 |
ColorInterpretationRmfSerializer.register(); |
212 | 195 |
GeoInfoRmfSerializer.register(); |
... | ... | |
305 | 288 |
if(propetiesListeners.get(i) == listener) |
306 | 289 |
propetiesListeners.remove(i); |
307 | 290 |
} |
308 |
|
|
291 |
|
|
309 | 292 |
//******* End: Servicio de nombres de capas ?nicos ************** |
293 |
|
|
294 |
/** |
|
295 |
* Esta funci?n crea el directorio para temporales y devuelve el manejador |
|
296 |
* del directorio |
|
297 |
* @return |
|
298 |
*/ |
|
299 |
static public File getTemporalFile() { |
|
300 |
File tempDirectory = new File(tempCacheDirectoryPath); |
|
301 |
if (!tempDirectory.exists()) |
|
302 |
tempDirectory.mkdir(); |
|
303 |
return tempDirectory; |
|
304 |
} |
|
310 | 305 |
|
311 | 306 |
/** |
307 |
* Esta funci?n crea el directorio para temporales y devuelve la ruta de este |
|
308 |
* @return |
|
309 |
*/ |
|
310 |
static public String getTemporalPath() { |
|
311 |
return getTemporalFile().getAbsolutePath(); |
|
312 |
} |
|
313 |
|
|
314 |
/* |
|
315 |
private static Hashtable clasesJar = new Hashtable(); |
|
316 |
|
|
317 |
* |
|
312 | 318 |
* Esta funci?n buscar? todos los jars en las rutas de pathExtensions y |
313 | 319 |
* registrar? todos las clases registrables. En este momento hay posibilidad |
314 | 320 |
* de registro de drivers y filtros. |
315 |
*/
|
|
321 |
* |
|
316 | 322 |
private static void registerClasses() throws Exception { |
317 | 323 |
RasterClassLoader loader = new RasterClassLoader(); |
318 | 324 |
|
... | ... | |
370 | 376 |
throw e; |
371 | 377 |
} |
372 | 378 |
} |
373 |
|
|
374 | 379 |
} |
375 |
|
|
376 |
/** |
|
377 |
* Esta funci?n crea el directorio para temporales y devuelve el manejador |
|
378 |
* del directorio |
|
379 |
* @return |
|
380 |
*/ |
|
381 |
static public File getTemporalFile() { |
|
382 |
File tempDirectory = new File(tempCacheDirectoryPath); |
|
383 |
if (!tempDirectory.exists()) |
|
384 |
tempDirectory.mkdir(); |
|
385 |
return tempDirectory; |
|
386 |
} |
|
387 |
|
|
388 |
/** |
|
389 |
* Esta funci?n crea el directorio para temporales y devuelve la ruta de este |
|
390 |
* @return |
|
391 |
*/ |
|
392 |
static public String getTemporalPath() { |
|
393 |
return getTemporalFile().getAbsolutePath(); |
|
394 |
} |
|
380 |
*/ |
|
395 | 381 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/PngWriter.java | ||
---|---|---|
34 | 34 |
import org.gvsig.raster.dataset.io.features.PngFeatures; |
35 | 35 |
import org.gvsig.raster.dataset.io.features.WriteFileFormatFeatures; |
36 | 36 |
import org.gvsig.raster.util.RasterUtilities; |
37 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
|
38 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
|
37 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoint; |
|
39 | 38 |
|
40 | 39 |
import es.gva.cit.jgdal.Gdal; |
41 | 40 |
import es.gva.cit.jgdal.GdalDriver; |
... | ... | |
54 | 53 |
@author Nacho Brodin (nachobrodin@gmail.com) |
55 | 54 |
*/ |
56 | 55 |
public class PngWriter extends GeoRasterWriter { |
57 |
|
|
58 |
//Datos de registro de drivers |
|
59 |
public static void register() { |
|
60 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
61 | 56 |
|
62 |
extensionPoints.add("RasterWriter", "png", PngWriter.class); |
|
57 |
// Datos de registro de drivers |
|
58 |
public static void register() { |
|
59 |
ExtensionPoint point = ExtensionPoint.getExtensionPoint("RasterWriter"); |
|
60 |
point.register("png", PngWriter.class); |
|
63 | 61 |
fileFeature.put("png", new PngFeatures()); |
64 |
}
|
|
62 |
}
|
|
65 | 63 |
|
66 |
private GdalWriter gdalWriter = null;
|
|
67 |
private String outTif = null;
|
|
68 |
private String outPng = null;
|
|
69 |
|
|
64 |
private GdalWriter gdalWriter = null;
|
|
65 |
private String outTif = null;
|
|
66 |
private String outPng = null;
|
|
67 |
|
|
70 | 68 |
/** |
71 | 69 |
* Carga los par?metros de este driver. |
72 | 70 |
*/ |
... | ... | |
76 | 74 |
driverParams = wfff.getParams(); |
77 | 75 |
} |
78 | 76 |
|
79 |
/**
|
|
80 |
* Constructor para la obtenci?n de par?metros del driver
|
|
81 |
* @param drvType Tipo de driver
|
|
82 |
*/
|
|
83 |
public PngWriter(String fileName) {
|
|
77 |
/**
|
|
78 |
* Constructor para la obtenci?n de par?metros del driver
|
|
79 |
* @param drvType Tipo de driver
|
|
80 |
*/
|
|
81 |
public PngWriter(String fileName) {
|
|
84 | 82 |
ident = RasterUtilities.getExtensionFromFileName(fileName); |
85 | 83 |
driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName(); |
86 |
gdalWriter = new GdalWriter(fileName);
|
|
87 |
|
|
84 |
gdalWriter = new GdalWriter(fileName);
|
|
85 |
|
|
88 | 86 |
loadParams(ident); |
89 |
}
|
|
87 |
}
|
|
90 | 88 |
|
91 |
/**
|
|
92 |
* Constructor para salvar datos servidos por el cliente
|
|
93 |
* @param dataWriter Objeto servidor de datos para el driver de escritura
|
|
94 |
* @param outSizeX N?mero de pixels en X de la imagen de salida
|
|
95 |
* @param outSizeY N?mero de pixels en Y de la imagen de salida
|
|
96 |
* @param outFilename Fichero de salida
|
|
97 |
* @param extentMaxX Posici?n en X m?xima del extent
|
|
98 |
* @param extentMinX Posici?n en X m?nima del extent
|
|
99 |
* @param extentMaxY Posici?n en Y m?xima del extent
|
|
100 |
* @param extentMinY Posici?n en Y m?nima del extent
|
|
101 |
* @param nBands N?mero de bandas
|
|
102 |
* @param drvType Tipo de driver
|
|
103 |
* @throws GdalException
|
|
104 |
* @throws IOException
|
|
105 |
*/
|
|
106 |
public PngWriter( IDataWriter dataWriter,
|
|
107 |
String outFileName,
|
|
108 |
Integer nBands,
|
|
109 |
AffineTransform at,
|
|
110 |
Integer outSizeX,
|
|
111 |
Integer outSizeY,
|
|
112 |
Integer dataType,
|
|
113 |
Params params,
|
|
114 |
IProjection proj,
|
|
115 |
Boolean geo)throws GdalException, IOException {
|
|
116 |
ident = RasterUtilities.getExtensionFromFileName(outFileName);
|
|
89 |
/**
|
|
90 |
* Constructor para salvar datos servidos por el cliente
|
|
91 |
* @param dataWriter Objeto servidor de datos para el driver de escritura
|
|
92 |
* @param outSizeX N?mero de pixels en X de la imagen de salida
|
|
93 |
* @param outSizeY N?mero de pixels en Y de la imagen de salida
|
|
94 |
* @param outFilename Fichero de salida
|
|
95 |
* @param extentMaxX Posici?n en X m?xima del extent
|
|
96 |
* @param extentMinX Posici?n en X m?nima del extent
|
|
97 |
* @param extentMaxY Posici?n en Y m?xima del extent
|
|
98 |
* @param extentMinY Posici?n en Y m?nima del extent
|
|
99 |
* @param nBands N?mero de bandas
|
|
100 |
* @param drvType Tipo de driver
|
|
101 |
* @throws GdalException
|
|
102 |
* @throws IOException
|
|
103 |
*/
|
|
104 |
public PngWriter( IDataWriter dataWriter,
|
|
105 |
String outFileName,
|
|
106 |
Integer nBands,
|
|
107 |
AffineTransform at,
|
|
108 |
Integer outSizeX,
|
|
109 |
Integer outSizeY,
|
|
110 |
Integer dataType,
|
|
111 |
Params params,
|
|
112 |
IProjection proj,
|
|
113 |
Boolean geo)throws GdalException, IOException {
|
|
114 |
ident = RasterUtilities.getExtensionFromFileName(outFileName);
|
|
117 | 115 |
driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName(); |
118 |
outPng = outFileName;
|
|
119 |
outTif = outFileName.substring(0, outFileName.lastIndexOf("."));
|
|
120 |
outTif += ".tif";
|
|
116 |
outPng = outFileName;
|
|
117 |
outTif = outFileName.substring(0, outFileName.lastIndexOf("."));
|
|
118 |
outTif += ".tif";
|
|
121 | 119 |
this.at = at; |
122 |
|
|
123 |
gdalWriter = new GdalWriter(dataWriter, outTif, nBands,
|
|
124 |
at, outSizeX, outSizeY, dataType, params, proj, geo);
|
|
120 |
|
|
121 |
gdalWriter = new GdalWriter(dataWriter, outTif, nBands,
|
|
122 |
at, outSizeX, outSizeY, dataType, params, proj, geo);
|
|
125 | 123 |
if(params == null) |
126 | 124 |
loadParams(ident); |
127 | 125 |
else |
128 | 126 |
this.driverParams = params; |
129 |
}
|
|
127 |
}
|
|
130 | 128 |
|
131 |
|
|
132 |
/**
|
|
133 |
* Asigna el tipo de driver con el que se salvar? la imagen
|
|
134 |
* @param drvType Tipo de driver
|
|
135 |
*/
|
|
136 |
public void setDriverType(String drvType) {
|
|
137 |
gdalWriter.setDriverType(drvType);
|
|
138 |
}
|
|
139 |
|
|
140 |
/**
|
|
141 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
|
142 |
* @throws IOException
|
|
143 |
*/
|
|
144 |
public void fileWrite() throws IOException, InterruptedException {
|
|
145 |
gdalWriter.fileWrite();
|
|
146 |
}
|
|
129 |
|
|
130 |
/**
|
|
131 |
* Asigna el tipo de driver con el que se salvar? la imagen
|
|
132 |
* @param drvType Tipo de driver
|
|
133 |
*/
|
|
134 |
public void setDriverType(String drvType) {
|
|
135 |
gdalWriter.setDriverType(drvType);
|
|
136 |
}
|
|
137 |
|
|
138 |
/**
|
|
139 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
|
140 |
* @throws IOException
|
|
141 |
*/
|
|
142 |
public void fileWrite() throws IOException, InterruptedException {
|
|
143 |
gdalWriter.fileWrite();
|
|
144 |
}
|
|
147 | 145 |
|
148 |
/**
|
|
149 |
* Realiza una copia en el formato especificado.
|
|
150 |
* @throws IOException
|
|
151 |
*/
|
|
152 |
public static void createCopy(GdalDriver driverDst, String dst, String src,
|
|
153 |
boolean bstrict, String[] params, IProjection proj) throws IOException, GdalException {
|
|
154 |
GdalWriter.createCopy(driverDst, dst, src, bstrict, params, proj);
|
|
155 |
}
|
|
156 |
|
|
157 |
/**
|
|
158 |
* Realiza la escritura de datos con los datos que le pasa el cliente.
|
|
159 |
* @throws IOException
|
|
160 |
*/
|
|
161 |
public void dataWrite() throws IOException, InterruptedException {
|
|
162 |
gdalWriter.setColorBandsInterpretation(colorInterp.getValues());
|
|
163 |
gdalWriter.dataWrite();
|
|
164 |
if(gdalWriter.isWrite()){
|
|
165 |
gdalWriter.writeClose();
|
|
166 |
if(outTif != null){
|
|
167 |
GdalDriver driver = null;
|
|
168 |
try{
|
|
169 |
driver = Gdal.getDriverByName("PNG");
|
|
170 |
GdalWriter.createCopy(driver, outPng, outTif, false, gdalWriter.gdalParamsFromRasterParams(driverParams), null);
|
|
171 |
}catch(GdalException exc){
|
|
172 |
throw new IOException("No se ha podido obtener el driver.");
|
|
173 |
}
|
|
174 |
File file = new File(outTif);
|
|
175 |
file.delete();
|
|
176 |
}
|
|
177 |
}
|
|
178 |
}
|
|
146 |
/**
|
|
147 |
* Realiza una copia en el formato especificado.
|
|
148 |
* @throws IOException
|
|
149 |
*/
|
|
150 |
public static void createCopy(GdalDriver driverDst, String dst, String src,
|
|
151 |
boolean bstrict, String[] params, IProjection proj) throws IOException, GdalException {
|
|
152 |
GdalWriter.createCopy(driverDst, dst, src, bstrict, params, proj);
|
|
153 |
}
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Realiza la escritura de datos con los datos que le pasa el cliente.
|
|
157 |
* @throws IOException
|
|
158 |
*/
|
|
159 |
public void dataWrite() throws IOException, InterruptedException {
|
|
160 |
gdalWriter.setColorBandsInterpretation(colorInterp.getValues());
|
|
161 |
gdalWriter.dataWrite();
|
|
162 |
if(gdalWriter.isWrite()){
|
|
163 |
gdalWriter.writeClose();
|
|
164 |
if(outTif != null){
|
|
165 |
GdalDriver driver = null;
|
|
166 |
try{
|
|
167 |
driver = Gdal.getDriverByName("PNG");
|
|
168 |
GdalWriter.createCopy(driver, outPng, outTif, false, gdalWriter.gdalParamsFromRasterParams(driverParams), null);
|
|
169 |
}catch(GdalException exc){
|
|
170 |
throw new IOException("No se ha podido obtener el driver.");
|
|
171 |
}
|
|
172 |
File file = new File(outTif);
|
|
173 |
file.delete();
|
|
174 |
}
|
|
175 |
}
|
|
176 |
}
|
|
179 | 177 |
|
180 |
/**
|
|
181 |
* Cierra el compresor ecw.
|
|
182 |
* @throws GdalException
|
|
183 |
*/
|
|
184 |
public void writeClose() {
|
|
185 |
//El close del tif se hizo en dataWrite
|
|
186 |
}
|
|
178 |
/**
|
|
179 |
* Cierra el compresor ecw.
|
|
180 |
* @throws GdalException
|
|
181 |
*/
|
|
182 |
public void writeClose() {
|
|
183 |
//El close del tif se hizo en dataWrite
|
|
184 |
}
|
|
187 | 185 |
|
188 |
/**
|
|
189 |
* Cancela el salvado de datos.
|
|
190 |
*/
|
|
191 |
public void writeCancel() {
|
|
192 |
gdalWriter.setWrite(false);
|
|
193 |
}
|
|
194 |
|
|
195 |
/*
|
|
196 |
* (non-Javadoc)
|
|
197 |
* @see org.gvsig.raster.dataset.GeoRasterWriter#setParams(org.gvsig.raster.dataset.Params)
|
|
198 |
*/
|
|
186 |
/**
|
|
187 |
* Cancela el salvado de datos.
|
|
188 |
*/
|
|
189 |
public void writeCancel() {
|
|
190 |
gdalWriter.setWrite(false);
|
|
191 |
}
|
|
192 |
|
|
193 |
/*
|
|
194 |
* (non-Javadoc)
|
|
195 |
* @see org.gvsig.raster.dataset.GeoRasterWriter#setParams(org.gvsig.raster.dataset.Params)
|
|
196 |
*/
|
|
199 | 197 |
public void setParams(Params params) { |
200 | 198 |
driverParams = params; |
201 | 199 |
if(gdalWriter != null) |
202 | 200 |
gdalWriter.setParams(params); |
203 | 201 |
} |
204 |
|
|
202 |
|
|
205 | 203 |
/* |
206 | 204 |
* (non-Javadoc) |
207 | 205 |
* @see org.gvsig.raster.dataset.GeoRasterWriter#setWkt(java.lang.String) |
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/JpegWriter.java | ||
---|---|---|
34 | 34 |
import org.gvsig.raster.dataset.io.features.JpegFeatures; |
35 | 35 |
import org.gvsig.raster.dataset.io.features.WriteFileFormatFeatures; |
36 | 36 |
import org.gvsig.raster.util.RasterUtilities; |
37 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
|
38 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
|
37 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoint; |
|
39 | 38 |
|
40 | 39 |
import es.gva.cit.jgdal.Gdal; |
41 | 40 |
import es.gva.cit.jgdal.GdalDriver; |
... | ... | |
54 | 53 |
*/ |
55 | 54 |
public class JpegWriter extends GeoRasterWriter { |
56 | 55 |
|
57 |
|
|
58 |
//Datos de registro de drivers |
|
59 |
public static void register() { |
|
60 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
61 |
|
|
62 |
extensionPoints.add("RasterWriter", "jpg", JpegWriter.class); |
|
56 |
// Datos de registro de drivers |
|
57 |
public static void register() { |
|
58 |
ExtensionPoint point = ExtensionPoint.getExtensionPoint("RasterWriter"); |
|
59 |
point.register("jpg", JpegWriter.class); |
|
63 | 60 |
fileFeature.put("jpg", new JpegFeatures()); |
64 |
}
|
|
61 |
}
|
|
65 | 62 |
|
66 |
private GdalWriter gdalWriter = null;
|
|
67 |
private String outTif = null;
|
|
68 |
private String outJpg = null;
|
|
69 |
|
|
63 |
private GdalWriter gdalWriter = null;
|
|
64 |
private String outTif = null;
|
|
65 |
private String outJpg = null;
|
|
66 |
|
|
70 | 67 |
/** |
71 | 68 |
* Carga los par?metros de este driver. |
72 | 69 |
*/ |
... | ... | |
76 | 73 |
driverParams = wfff.getParams(); |
77 | 74 |
} |
78 | 75 |
|
79 |
/**
|
|
80 |
* Constructor para la obtenci?n de par?metros del driver
|
|
81 |
* @param drvType Tipo de driver
|
|
82 |
*/
|
|
83 |
public JpegWriter(String fileName) {
|
|
76 |
/**
|
|
77 |
* Constructor para la obtenci?n de par?metros del driver
|
|
78 |
* @param drvType Tipo de driver
|
|
79 |
*/
|
|
80 |
public JpegWriter(String fileName) {
|
|
84 | 81 |
ident = RasterUtilities.getExtensionFromFileName(fileName); |
85 | 82 |
driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName(); |
86 |
gdalWriter = new GdalWriter(fileName);
|
|
87 |
|
|
83 |
gdalWriter = new GdalWriter(fileName);
|
|
84 |
|
|
88 | 85 |
loadParams(ident); |
89 |
}
|
|
86 |
}
|
|
90 | 87 |
|
91 |
/**
|
|
92 |
* Constructor para salvar datos servidos por el cliente
|
|
93 |
* @param dataWriter Objeto servidor de datos para el driver de escritura
|
|
94 |
* @param outSizeX N?mero de pixels en X de la imagen de salida
|
|
95 |
* @param outSizeY N?mero de pixels en Y de la imagen de salida
|
|
96 |
* @param outFilename Fichero de salida
|
|
97 |
* @param extentMaxX Posici?n en X m?xima del extent
|
|
98 |
* @param extentMinX Posici?n en X m?nima del extent
|
|
99 |
* @param extentMaxY Posici?n en Y m?xima del extent
|
|
100 |
* @param extentMinY Posici?n en Y m?nima del extent
|
|
101 |
* @param nBands N?mero de bandas
|
|
102 |
* @param drvType Tipo de driver
|
|
103 |
* @throws GdalException
|
|
104 |
* @throws IOException
|
|
105 |
*/
|
|
106 |
public JpegWriter( IDataWriter dataWriter,
|
|
107 |
String outFileName,
|
|
108 |
Integer nBands,
|
|
109 |
AffineTransform at,
|
|
110 |
Integer outSizeX,
|
|
111 |
Integer outSizeY,
|
|
112 |
Integer dataType,
|
|
113 |
Params params,
|
|
114 |
IProjection proj,
|
|
115 |
Boolean geo)throws GdalException, IOException {
|
|
116 |
ident = RasterUtilities.getExtensionFromFileName(outFileName);
|
|
88 |
/**
|
|
89 |
* Constructor para salvar datos servidos por el cliente
|
|
90 |
* @param dataWriter Objeto servidor de datos para el driver de escritura
|
|
91 |
* @param outSizeX N?mero de pixels en X de la imagen de salida
|
|
92 |
* @param outSizeY N?mero de pixels en Y de la imagen de salida
|
|
93 |
* @param outFilename Fichero de salida
|
|
94 |
* @param extentMaxX Posici?n en X m?xima del extent
|
|
95 |
* @param extentMinX Posici?n en X m?nima del extent
|
|
96 |
* @param extentMaxY Posici?n en Y m?xima del extent
|
|
97 |
* @param extentMinY Posici?n en Y m?nima del extent
|
|
98 |
* @param nBands N?mero de bandas
|
|
99 |
* @param drvType Tipo de driver
|
|
100 |
* @throws GdalException
|
|
101 |
* @throws IOException
|
|
102 |
*/
|
|
103 |
public JpegWriter( IDataWriter dataWriter,
|
|
104 |
String outFileName,
|
|
105 |
Integer nBands,
|
|
106 |
AffineTransform at,
|
|
107 |
Integer outSizeX,
|
|
108 |
Integer outSizeY,
|
|
109 |
Integer dataType,
|
|
110 |
Params params,
|
|
111 |
IProjection proj,
|
|
112 |
Boolean geo)throws GdalException, IOException {
|
|
113 |
ident = RasterUtilities.getExtensionFromFileName(outFileName);
|
|
117 | 114 |
driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName(); |
118 |
outJpg = outFileName;
|
|
119 |
outTif = outFileName.substring(0, outFileName.lastIndexOf("."));
|
|
120 |
outTif += ".tif";
|
|
121 |
|
|
122 |
gdalWriter = new GdalWriter(dataWriter, outTif, nBands,
|
|
123 |
at, outSizeX, outSizeY, dataType, params, proj, geo);
|
|
115 |
outJpg = outFileName;
|
|
116 |
outTif = outFileName.substring(0, outFileName.lastIndexOf("."));
|
|
117 |
outTif += ".tif";
|
|
118 |
|
|
119 |
gdalWriter = new GdalWriter(dataWriter, outTif, nBands,
|
|
120 |
at, outSizeX, outSizeY, dataType, params, proj, geo);
|
|
124 | 121 |
if(params == null) |
125 | 122 |
loadParams(ident); |
126 | 123 |
else |
127 | 124 |
this.driverParams = params; |
128 |
}
|
|
125 |
}
|
|
129 | 126 |
|
130 |
|
|
131 |
/**
|
|
132 |
* Asigna el tipo de driver con el que se salvar? la imagen
|
|
133 |
* @param drvType Tipo de driver
|
|
134 |
*/
|
|
135 |
public void setDriverType(String drvType) {
|
|
136 |
gdalWriter.setDriverType(drvType);
|
|
137 |
}
|
|
138 |
|
|
139 |
/**
|
|
140 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
|
141 |
* @throws IOException
|
|
142 |
*/
|
|
143 |
public void fileWrite() throws IOException, InterruptedException {
|
|
144 |
gdalWriter.fileWrite();
|
|
145 |
}
|
|
127 |
|
|
128 |
/**
|
|
129 |
* Asigna el tipo de driver con el que se salvar? la imagen
|
|
130 |
* @param drvType Tipo de driver
|
|
131 |
*/
|
|
132 |
public void setDriverType(String drvType) {
|
|
133 |
gdalWriter.setDriverType(drvType);
|
|
134 |
}
|
|
135 |
|
|
136 |
/**
|
|
137 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
|
138 |
* @throws IOException
|
|
139 |
*/
|
|
140 |
public void fileWrite() throws IOException, InterruptedException {
|
|
141 |
gdalWriter.fileWrite();
|
|
142 |
}
|
|
146 | 143 |
|
147 |
/** |
|
148 |
* Realiza una copia en el formato especificado. |
|
149 |
* @throws IOException |
|
150 |
*/ |
|
151 |
public static void createCopy(GdalDriver driverDst, String dst, String src, |
|
152 |
boolean bstrict, String[] params, IProjection proj) throws IOException, GdalException { |
|
153 |
GdalWriter.createCopy(driverDst, dst, src, bstrict, params, proj); |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* Realiza la escritura de datos con los datos que le pasa el cliente. |
|
158 |
* @throws IOException |
|
159 |
*/ |
|
160 |
public void dataWrite() throws IOException, InterruptedException { |
|
161 |
if(colorInterp != null) |
|
162 |
gdalWriter.setColorBandsInterpretation(colorInterp.getValues()); |
|
163 |
gdalWriter.dataWrite(); |
|
164 |
if(gdalWriter.isWrite()){ |
|
165 |
gdalWriter.writeClose(); |
|
166 |
if(outTif != null){ |
|
167 |
GdalDriver driver = null; |
|
168 |
try{ |
|
169 |
driver = Gdal.getDriverByName("JPEG"); |
|
170 |
GdalWriter.createCopy(driver, outJpg, outTif, false, gdalWriter.gdalParamsFromRasterParams(driverParams), null); |
|
171 |
}catch(GdalException exc){ |
|
172 |
throw new IOException("No se ha podido obtener el driver."); |
|
173 |
} |
|
174 |
File file = new File(outTif); |
|
175 |
file.delete(); |
|
176 |
} |
|
177 |
} |
|
178 |
} |
Also available in: Unified diff