Revision 23154
branches/v2_0_0_prep/libraries/libTools/src-test/org/gvsig/tools/extensionPoint/TestExtensionPoint.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
*/ |
|
26 |
package org.gvsig.tools.extensionPoint; |
|
27 |
|
|
28 |
import java.lang.reflect.InvocationTargetException; |
|
29 |
import java.util.Iterator; |
|
30 |
|
|
31 |
import junit.framework.TestCase; |
|
32 |
|
|
33 |
public class TestExtensionPoint extends TestCase { |
|
34 |
|
|
35 |
|
|
36 |
protected void setUp() throws Exception { |
|
37 |
super.setUp(); |
|
38 |
} |
|
39 |
|
|
40 |
protected void tearDown() throws Exception { |
|
41 |
super.tearDown(); |
|
42 |
} |
|
43 |
|
|
44 |
public void testCreacion() { |
|
45 |
String name = "LayerWizars"; |
|
46 |
String description = "Punto de extension que registra los distintos Wizars para a?adir capas."; |
|
47 |
ExtensionPoint ep = null; |
|
48 |
|
|
49 |
ep = new ExtensionPoint(name); |
|
50 |
TestExtensionPoint.assertEquals(ep.getName(),name); |
|
51 |
TestExtensionPoint.assertEquals(ep.getDescription(),null); |
|
52 |
ep.setDescripcion(description); |
|
53 |
TestExtensionPoint.assertEquals(ep.getDescription(),description); |
|
54 |
|
|
55 |
|
|
56 |
ep = new ExtensionPoint(name,description); |
|
57 |
TestExtensionPoint.assertEquals(ep.getName(),name); |
|
58 |
TestExtensionPoint.assertEquals(ep.getDescription(),description); |
|
59 |
|
|
60 |
ep.put("WMSLayer",(Object)ExtensionDePrueba2.class); |
|
61 |
ep.put("WCSLayer",(Object)ExtensionDePrueba1.class); |
|
62 |
ep.put("WFSLayer",(Object)ExtensionDePrueba1.class); |
|
63 |
|
|
64 |
TestExtensionPoint.assertEquals(ep.size(),3); |
|
65 |
|
|
66 |
// Comprobamos que la lista de extensiones |
|
67 |
// mantiene el orden de insercion. |
|
68 |
Iterator iter = ep.keySet().iterator(); |
|
69 |
TestExtensionPoint.assertEquals("WMSLayer",iter.next()); |
|
70 |
TestExtensionPoint.assertEquals("WCSLayer",iter.next()); |
|
71 |
TestExtensionPoint.assertEquals("WFSLayer",iter.next()); |
|
72 |
|
|
73 |
try { |
|
74 |
/*Object extension =*/ ep.create("WCSLayer"); |
|
75 |
} catch (InstantiationException e) { |
|
76 |
TestExtensionPoint.fail("Ha petado la creacion de WCSLayer con InstantiationException"); |
|
77 |
} catch (IllegalAccessException e) { |
|
78 |
TestExtensionPoint.fail("Ha petado la creacion de WCSLayer con IllegalAccessException"); |
|
79 |
} |
|
80 |
|
|
81 |
ExtensionDePrueba2 extension = null; |
|
82 |
try { |
|
83 |
Object args[] = {"pepe",new Integer(5)}; |
|
84 |
extension =(ExtensionDePrueba2)ep.create("WMSLayer",args); |
|
85 |
} catch (InstantiationException e) { |
|
86 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con InstantiationException"); |
|
87 |
} catch (IllegalAccessException e) { |
|
88 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con IllegalAccessException"); |
|
89 |
} catch (SecurityException e) { |
|
90 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con SecurityException"); |
|
91 |
} catch (IllegalArgumentException e) { |
|
92 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con IllegalArgumentException"); |
|
93 |
} catch (NoSuchMethodException e) { |
|
94 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con NoSuchMethodException"); |
|
95 |
} catch (InvocationTargetException e) { |
|
96 |
TestExtensionPoint.fail("Ha petado la creacion de WMSLayer con InvocationTargetException"); |
|
97 |
} |
|
98 |
|
|
99 |
TestExtensionPoint.assertEquals("pepe",extension.nombre); |
|
100 |
TestExtensionPoint.assertEquals(5,extension.ancho); |
|
101 |
|
|
102 |
} |
|
103 |
|
|
104 |
public void testInsert() { |
|
105 |
String name = "LayerWizars"; |
|
106 |
String description = "Punto de extension que registra los distintos Wizars para a?adir capas."; |
|
107 |
ExtensionPoint ep = null; |
|
108 |
|
|
109 |
ep = new ExtensionPoint(name,description); |
|
110 |
|
|
111 |
ep.put("WMSLayer",(Object)ExtensionDePrueba2.class); |
|
112 |
ep.put("WCSLayer",(Object)ExtensionDePrueba1.class); |
|
113 |
ep.put("WFSLayer",(Object)ExtensionDePrueba1.class); |
|
114 |
Iterator i=ep.keySet().iterator(); |
|
115 |
TestExtensionPoint.assertEquals("WMSLayer",(String)i.next()); |
|
116 |
TestExtensionPoint.assertEquals("WCSLayer",(String)i.next()); |
|
117 |
TestExtensionPoint.assertEquals("WFSLayer",(String)i.next()); |
|
118 |
|
|
119 |
ep.insert("WCSLayer","testA",null,(Object)ExtensionDePrueba1.class); |
|
120 |
|
|
121 |
i=ep.keySet().iterator(); |
|
122 |
TestExtensionPoint.assertEquals("WMSLayer",(String)i.next()); |
|
123 |
TestExtensionPoint.assertEquals("testA",(String)i.next()); |
|
124 |
TestExtensionPoint.assertEquals("WCSLayer",(String)i.next()); |
|
125 |
TestExtensionPoint.assertEquals("WFSLayer",(String)i.next()); |
|
126 |
|
|
127 |
ep.insert("XXXX","testB",null,(Object)ExtensionDePrueba1.class); |
|
128 |
i=ep.keySet().iterator(); |
|
129 |
TestExtensionPoint.assertEquals("WMSLayer",(String)i.next()); |
|
130 |
TestExtensionPoint.assertEquals("testA",(String)i.next()); |
|
131 |
TestExtensionPoint.assertEquals("WCSLayer",(String)i.next()); |
|
132 |
TestExtensionPoint.assertEquals("WFSLayer",(String)i.next()); |
|
133 |
TestExtensionPoint.assertEquals("testB",(String)i.next()); |
|
134 |
|
|
135 |
ep.insert("testB","testC",null,(Object)ExtensionDePrueba1.class); |
|
136 |
i=ep.keySet().iterator(); |
|
137 |
TestExtensionPoint.assertEquals("WMSLayer",(String)i.next()); |
|
138 |
TestExtensionPoint.assertEquals("testA",(String)i.next()); |
|
139 |
TestExtensionPoint.assertEquals("WCSLayer",(String)i.next()); |
|
140 |
TestExtensionPoint.assertEquals("WFSLayer",(String)i.next()); |
|
141 |
TestExtensionPoint.assertEquals("testC",(String)i.next()); |
|
142 |
TestExtensionPoint.assertEquals("testB",(String)i.next()); |
|
143 |
|
|
144 |
ep.insert("WMSLayer","testD",null,(Object)ExtensionDePrueba1.class); |
|
145 |
i=ep.keySet().iterator(); |
|
146 |
TestExtensionPoint.assertEquals("testD",(String)i.next()); |
|
147 |
TestExtensionPoint.assertEquals("WMSLayer",(String)i.next()); |
|
148 |
TestExtensionPoint.assertEquals("testA",(String)i.next()); |
|
149 |
TestExtensionPoint.assertEquals("WCSLayer",(String)i.next()); |
|
150 |
TestExtensionPoint.assertEquals("WFSLayer",(String)i.next()); |
|
151 |
TestExtensionPoint.assertEquals("testC",(String)i.next()); |
|
152 |
TestExtensionPoint.assertEquals("testB",(String)i.next()); |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
class ExtensionDePrueba1 { |
|
157 |
public ExtensionDePrueba1() { |
|
158 |
; |
|
159 |
} |
|
160 |
} |
|
161 |
class ExtensionDePrueba2 { |
|
162 |
public int ancho; |
|
163 |
public String nombre; |
|
164 |
|
|
165 |
public ExtensionDePrueba2(String nombre, Integer ancho) { |
|
166 |
this.ancho = ancho.intValue(); |
|
167 |
this.nombre = nombre; |
|
168 |
} |
|
169 |
} |
|
0 | 170 |
branches/v2_0_0_prep/libraries/libTools/src-test/org/gvsig/tools/extensionPoint/TestExtensionPoints.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
*/ |
|
26 |
package org.gvsig.tools.extensionPoint; |
|
27 |
|
|
28 |
import java.util.Iterator; |
|
29 |
|
|
30 |
import junit.framework.TestCase; |
|
31 |
|
|
32 |
public class TestExtensionPoints extends TestCase { |
|
33 |
|
|
34 |
protected void setUp() throws Exception { |
|
35 |
super.setUp(); |
|
36 |
} |
|
37 |
|
|
38 |
protected void tearDown() throws Exception { |
|
39 |
super.tearDown(); |
|
40 |
} |
|
41 |
|
|
42 |
public void test() { |
|
43 |
ExtensionPoints extensionPoints = new ExtensionPoints(); |
|
44 |
|
|
45 |
extensionPoints.add("LayerWizars","WMS",UnaExtensionDePrueba1.class); |
|
46 |
extensionPoints.add("LayerWizars","WCS",UnaExtensionDePrueba2.class); |
|
47 |
extensionPoints.add("OtherWizars","uno",UnaExtensionDePrueba1.class); |
|
48 |
extensionPoints.add("OtherWizars","dos",UnaExtensionDePrueba2.class); |
|
49 |
|
|
50 |
// Comprobamos que el orden de las extensiones es el que hemos fijado. |
|
51 |
ExtensionPoint x = (ExtensionPoint)extensionPoints.get("LayerWizars"); |
|
52 |
Iterator i =x.keySet().iterator(); |
|
53 |
String[] nombres = {"WMS", "WCS" }; |
|
54 |
int n = 0; |
|
55 |
while( i.hasNext() ) { |
|
56 |
String nombre = (String)i.next(); |
|
57 |
assertTrue(nombres[n].equals(nombre)); |
|
58 |
n++; |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
ExtensionPoint extensionPointLayerWizars; |
|
63 |
extensionPointLayerWizars = (ExtensionPoint)extensionPoints.get("LayerWizars"); |
|
64 |
assertTrue(extensionPointLayerWizars.containsKey("WMS")); |
|
65 |
assertTrue(extensionPointLayerWizars.containsKey("WCS")); |
|
66 |
|
|
67 |
assertEquals(extensionPoints.size(),2); |
|
68 |
assertEquals(extensionPointLayerWizars.size(),2); |
|
69 |
|
|
70 |
ExtensionPoint extensionPointLayerWizars2 = new ExtensionPoint("LayerWizars"); |
|
71 |
|
|
72 |
|
|
73 |
extensionPointLayerWizars2.put("File",UnaExtensionDePrueba3.class); |
|
74 |
extensionPointLayerWizars2.put("JDBC",UnaExtensionDePrueba4.class); |
|
75 |
|
|
76 |
extensionPoints.put("LayerWizars",extensionPointLayerWizars2); |
|
77 |
|
|
78 |
extensionPointLayerWizars = (ExtensionPoint)extensionPoints.get("LayerWizars"); |
|
79 |
assertEquals(extensionPoints.size(),2); |
|
80 |
assertEquals(extensionPointLayerWizars.size(),4); |
|
81 |
assertEquals(((ExtensionPoint)extensionPoints.get("OtherWizars")).size(),2); |
|
82 |
|
|
83 |
assertTrue(extensionPointLayerWizars.containsKey("WMS")); |
|
84 |
assertTrue(extensionPointLayerWizars.containsKey("WCS")); |
|
85 |
assertTrue(extensionPointLayerWizars.containsKey("File")); |
|
86 |
assertTrue(extensionPointLayerWizars.containsKey("JDBC")); |
|
87 |
|
|
88 |
assertEquals((extensionPointLayerWizars.get("JDBC")),UnaExtensionDePrueba4.class); |
|
89 |
assertEquals((extensionPointLayerWizars.get("WMS")),UnaExtensionDePrueba1.class); |
|
90 |
|
|
91 |
assertEquals(((ExtensionPoint)extensionPoints.get("OtherWizars")).get("uno"),UnaExtensionDePrueba1.class); |
|
92 |
|
|
93 |
ExtensionPoint extensionPointOther2 = new ExtensionPoint("OtherWizars"); |
|
94 |
extensionPointOther2.put("tres",UnaExtensionDePrueba3.class); |
|
95 |
extensionPointOther2.put("cuatro",UnaExtensionDePrueba4.class); |
|
96 |
|
|
97 |
extensionPoints.put(extensionPointOther2); |
|
98 |
|
|
99 |
ExtensionPoint extensionPointOther = (ExtensionPoint)extensionPoints.get("OtherWizars"); |
|
100 |
assertEquals(extensionPoints.size(),2); |
|
101 |
assertEquals(extensionPointLayerWizars.size(),4); |
|
102 |
assertEquals(extensionPointOther.size(),4); |
|
103 |
|
|
104 |
assertTrue(extensionPointOther.containsKey("uno")); |
|
105 |
assertTrue(extensionPointOther.containsKey("dos")); |
|
106 |
assertTrue(extensionPointOther.containsKey("tres")); |
|
107 |
assertTrue(extensionPointOther.containsKey("cuatro")); |
|
108 |
|
|
109 |
assertEquals((extensionPointOther.get("tres")),UnaExtensionDePrueba3.class); |
|
110 |
assertEquals((extensionPointOther.get("dos")),UnaExtensionDePrueba2.class); |
|
111 |
|
|
112 |
assertEquals(extensionPoints.get("Ninguno"),null); |
|
113 |
} |
|
114 |
|
|
115 |
public void testSingleton() { |
|
116 |
ExtensionPoints extensionPoints1 = ExtensionPointsSingleton.getInstance(); |
|
117 |
|
|
118 |
extensionPoints1.add("LayerWizars","WMS",UnaExtensionDePrueba1.class); |
|
119 |
extensionPoints1.add("LayerWizars","WCS",UnaExtensionDePrueba2.class); |
|
120 |
extensionPoints1.add("OtherWizars","uno",UnaExtensionDePrueba1.class); |
|
121 |
extensionPoints1.add("OtherWizars","dos",UnaExtensionDePrueba2.class); |
|
122 |
|
|
123 |
ExtensionPoints extensionPoints2 = ExtensionPointsSingleton.getInstance(); |
|
124 |
assertEquals(extensionPoints2.size(),2); |
|
125 |
|
|
126 |
ExtensionPoint extensionPointLayerWizars; |
|
127 |
extensionPointLayerWizars = (ExtensionPoint)extensionPoints2.get("LayerWizars"); |
|
128 |
assertTrue(extensionPointLayerWizars.containsKey("WMS")); |
|
129 |
assertTrue(extensionPointLayerWizars.containsKey("WCS")); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
class UnaExtensionDePrueba1 { |
|
134 |
public UnaExtensionDePrueba1() { |
|
135 |
; |
|
136 |
} |
|
137 |
} |
|
138 |
class UnaExtensionDePrueba2 { |
|
139 |
public UnaExtensionDePrueba2() { |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
class UnaExtensionDePrueba3 { |
|
144 |
public UnaExtensionDePrueba3() { |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
class UnaExtensionDePrueba4 { |
|
149 |
public UnaExtensionDePrueba4() { |
|
150 |
} |
|
151 |
} |
|
0 | 152 |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/extensionPoint/ExtensionPointsSingleton.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
*/ |
|
26 |
package org.gvsig.tools.extensionPoint; |
|
27 |
|
|
28 |
public class ExtensionPointsSingleton extends ExtensionPoints { |
|
29 |
|
|
30 |
private static final long serialVersionUID = -630976693542039111L; |
|
31 |
|
|
32 |
private static ExtensionPoints extensionPoints = new ExtensionPointsSingleton(); |
|
33 |
|
|
34 |
private ExtensionPointsSingleton() { |
|
35 |
super(); |
|
36 |
} |
|
37 |
|
|
38 |
public static ExtensionPoints getInstance() { |
|
39 |
return ExtensionPointsSingleton.extensionPoints; |
|
40 |
} |
|
41 |
} |
|
0 | 42 |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/extensionPoint/IExtensionBuilder.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
*/ |
|
26 |
package org.gvsig.tools.extensionPoint; |
|
27 |
|
|
28 |
import java.util.Map; |
|
29 |
|
|
30 |
/** |
|
31 |
* Interface utilizado para indicar al registro de extensiones |
|
32 |
* que no se trata de una clase lo que hey registrado, si no |
|
33 |
* una instancia de un objeto a usar para crear la extension. |
|
34 |
* |
|
35 |
* |
|
36 |
* @author jjdelcerro |
|
37 |
* |
|
38 |
*/ |
|
39 |
public interface IExtensionBuilder { |
|
40 |
/** |
|
41 |
* Crea una instancia de la extension y la retorna. |
|
42 |
* <br> |
|
43 |
* @return |
|
44 |
*/ |
|
45 |
public Object create(); |
|
46 |
|
|
47 |
/** |
|
48 |
* Crea una instancia de la extension y la retorna. |
|
49 |
* <br> |
|
50 |
* En <i>args</i> recibira la lista de argumeentos a utilizar |
|
51 |
* para crear la extension. |
|
52 |
* <br> |
|
53 |
* @param args |
|
54 |
* @return |
|
55 |
*/ |
|
56 |
public Object create(Object [] args); |
|
57 |
|
|
58 |
public Object create(Map args); |
|
59 |
} |
|
0 | 60 |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/extensionPoint/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> |
|
0 | 117 |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/extensionPoint/ExtensionBuilder.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
*/ |
|
26 |
package org.gvsig.tools.extensionPoint; |
|
27 |
|
|
28 |
import java.lang.reflect.Constructor; |
|
29 |
import java.lang.reflect.InvocationTargetException; |
|
30 |
import java.util.Map; |
|
31 |
|
|
32 |
/** |
|
33 |
* Clase de utilidad usada para crear las extensiones. |
|
34 |
* |
|
35 |
* Esta clase presenta un par de metodos estaticos para |
|
36 |
* permitir crear un objeto a partir de una clase. |
|
37 |
* |
|
38 |
* @author jjdelcerro |
|
39 |
* |
|
40 |
*/ |
|
41 |
public abstract class ExtensionBuilder implements IExtensionBuilder { |
|
42 |
|
|
43 |
/** |
|
44 |
* Crea un objeto de la clase indicada. |
|
45 |
* |
|
46 |
* @param cls Clase de la que crear la instancia |
|
47 |
* @return |
|
48 |
* |
|
49 |
* @throws InstantiationException |
|
50 |
* @throws IllegalAccessException |
|
51 |
*/ |
|
52 |
public static Object create(Class cls) throws InstantiationException, IllegalAccessException { |
|
53 |
Object obj = null; |
|
54 |
|
|
55 |
if( cls == null ) { |
|
56 |
return null; |
|
57 |
} |
|
58 |
obj = cls.newInstance(); |
|
59 |
return obj; |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Crea un objeto de la clase indicada. |
|
64 |
* |
|
65 |
* Crea un objeto de la clase indicada pasandole al constructor |
|
66 |
* los argumentos indicados en <i>args</i>. |
|
67 |
* <br> |
|
68 |
* @param cls Clase de la que crear la instancia |
|
69 |
* @param args Argumentos que pasar al constructor. |
|
70 |
* @return |
|
71 |
* |
|
72 |
* @throws SecurityException |
|
73 |
* @throws NoSuchMethodException |
|
74 |
* @throws IllegalArgumentException |
|
75 |
* @throws InstantiationException |
|
76 |
* @throws IllegalAccessException |
|
77 |
* @throws InvocationTargetException |
|
78 |
*/ |
|
79 |
public static Object create(Class cls, Object [] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
|
80 |
Object obj = null; |
|
81 |
Constructor create = null; |
|
82 |
Class [] types = new Class[args.length]; |
|
83 |
|
|
84 |
if( cls == null ) { |
|
85 |
return null; |
|
86 |
} |
|
87 |
for( int n=0 ; n<args.length ; n++ ) { |
|
88 |
Object arg = args[n]; |
|
89 |
types[n] = arg.getClass(); |
|
90 |
} |
|
91 |
create = cls.getConstructor(types); |
|
92 |
obj = create.newInstance(args); |
|
93 |
return obj; |
|
94 |
} |
|
95 |
/** |
|
96 |
* Crea un objeto de la clase indicada. |
|
97 |
* |
|
98 |
* Crea un objeto de la clase indicada pasandole al constructor |
|
99 |
* un como argumento un Map.. |
|
100 |
* <br> |
|
101 |
* @param cls Clase de la que crear la instancia |
|
102 |
* @param args Map a pasar como argumento al constructor. |
|
103 |
* @return |
|
104 |
* |
|
105 |
* @throws SecurityException |
|
106 |
* @throws NoSuchMethodException |
|
107 |
* @throws IllegalArgumentException |
|
108 |
* @throws InstantiationException |
|
109 |
* @throws IllegalAccessException |
|
110 |
* @throws InvocationTargetException |
|
111 |
*/ |
|
112 |
public static Object create(Class cls, Map args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
|
113 |
Object obj = null; |
|
114 |
Constructor create = null; |
|
115 |
Class [] types = new Class[1]; |
|
116 |
Object [] argsx = new Object[1]; |
|
117 |
|
|
118 |
if( cls == null ) { |
|
119 |
return null; |
|
120 |
} |
|
121 |
types[0] = Map.class; |
|
122 |
argsx[0] = args; |
|
123 |
create = cls.getConstructor(types); |
|
124 |
obj = create.newInstance(argsx); |
|
125 |
return obj; |
|
126 |
} |
|
127 |
} |
|
0 | 128 |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/extensionPoint/ExtensionPoint.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
*/ |
|
26 |
package org.gvsig.tools.extensionPoint; |
|
27 |
|
|
28 |
import java.lang.reflect.InvocationTargetException; |
|
29 |
import java.security.KeyException; |
|
30 |
import java.util.*; |
|
31 |
|
|
32 |
/** |
|
33 |
* Esta clase permite registrar extensiones para un punto de extension. |
|
34 |
* <br> |
|
35 |
* <br> |
|
36 |
* La clase se comporta como un Map que mantiene el orden de insercion |
|
37 |
* de los elementos, para que puedan ser recorridos en ese orden. |
|
38 |
* <br> |
|
39 |
* Ademas de registrar las extensiones para un punto de extension, presenta |
|
40 |
* metodos para facilitar la creacion de la extension. |
|
41 |
* <br> |
|
42 |
* A la hora de registrar una extension, mediante el metodo <i>put</i>, |
|
43 |
* podremos suministrarle una clase o una instancia que implemente el |
|
44 |
* interface IExtensionBuilder. Si le suministramos una clase, cuando |
|
45 |
* queramos crear la extension mediante el metodo <i>create</i>, se creara |
|
46 |
* una instancia de la clase y se retornara. Si lo que se suministro fue |
|
47 |
* una instancia que implementa el interface IExtensionBuilder, se invocara |
|
48 |
* al metodo <i>create</i> de esta para crear la extension. |
|
49 |
* <br> |
|
50 |
* @author jjdelcerro |
|
51 |
* |
|
52 |
*/ |
|
53 |
public class ExtensionPoint extends LinkedHashMap { |
|
54 |
|
|
55 |
private static final long serialVersionUID = -5908427725588553371L; |
|
56 |
|
|
57 |
private String name; |
|
58 |
private String description; |
|
59 |
private Hashtable extensionDescriptions = new Hashtable(); |
|
60 |
private Hashtable aliases = new Hashtable(); |
|
61 |
|
|
62 |
/** |
|
63 |
* Construye un punto de extension. |
|
64 |
* <br> |
|
65 |
* @param extensionPointName Nombre del punto de extension. |
|
66 |
*/ |
|
67 |
public ExtensionPoint(String extensionPointName) { |
|
68 |
this.name = extensionPointName; |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Construye un punto de extension. |
|
73 |
* <br> |
|
74 |
* @param extensionPointName Nombre del punto de extension |
|
75 |
* @param description Descripcion del punto de extension |
|
76 |
*/ |
|
77 |
public ExtensionPoint(String extensionPointName, String description) { |
|
78 |
this.name = extensionPointName; |
|
79 |
this.description = description; |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Retorna el nombre de punto de extension. |
|
84 |
* <br> |
|
85 |
* @return Nombre del punto de extension |
|
86 |
*/ |
|
87 |
public String getName() { |
|
88 |
return this.name; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Retorna la descripcion asociada al punto de extension. |
|
93 |
* <br> |
|
94 |
* @return descripcion del punto de extension |
|
95 |
*/ |
|
96 |
public String getDescription() { |
|
97 |
return this.description; |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Asocia una descripcion al punto de extension. |
|
102 |
* <br> |
|
103 |
* |
|
104 |
* @param description |
|
105 |
*/ |
|
106 |
public void setDescripcion(String description) { |
|
107 |
this.description = description; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* Retorna la descripcion asociada a una extension. |
|
112 |
* <br> |
|
113 |
* @param key |
|
114 |
* <br> |
|
115 |
* @return descripcion del punto de extension |
|
116 |
*/ |
|
117 |
public String getExtensionDescription(String key) { |
|
118 |
return (String)this.extensionDescriptions.get(key); |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Asocia una descripcion a una extension registrada. |
|
123 |
* <br> |
|
124 |
* |
|
125 |
* @param key Nombre de la extension |
|
126 |
* @param description |
|
127 |
*/ |
|
128 |
public void setExtensionDescription(String key,String description) { |
|
129 |
if (this.containsKey(key)) { |
|
130 |
this.extensionDescriptions.put(key,description); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* A?ade una extension con su descripcion asociada |
|
136 |
* |
|
137 |
* @param key clave de la extension |
|
138 |
* @param decription descripcion de la extension |
|
139 |
* @param value extension |
|
140 |
*/ |
|
141 |
|
|
142 |
public Object put(String key, String description,Object value) { |
|
143 |
this.extensionDescriptions.put(key,description); |
|
144 |
return super.put(key,value); |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* A?ade una extension antes de la indicada con beforeKey, |
|
149 |
* con su descripcion asociada |
|
150 |
* |
|
151 |
* @param key clave de la extension |
|
152 |
* @param decription descripcion de la extension |
|
153 |
* @param value extension |
|
154 |
*/ |
|
155 |
|
|
156 |
public Object insert(String beforeKey, String key, String description,Object value) { |
|
157 |
boolean mover = false; |
|
158 |
Map tmp = new LinkedHashMap(); |
|
159 |
|
|
160 |
for (Iterator i = this.entrySet().iterator(); i.hasNext(); ) { |
|
161 |
Map.Entry e = (Map.Entry)i.next(); |
|
162 |
if ( e.getKey().equals(beforeKey) ) { |
|
163 |
mover = true; |
|
164 |
} |
|
165 |
if( mover ) { |
|
166 |
tmp.put(e.getKey(), e.getValue()); |
|
167 |
} |
|
168 |
} |
|
169 |
for (Iterator i = tmp.keySet().iterator(); i.hasNext(); ) { |
|
170 |
String key1 = (String)i.next(); |
|
171 |
this.remove(key1); |
|
172 |
} |
|
173 |
if ( description!= null ) { |
|
174 |
this.extensionDescriptions.put(key,description); |
|
175 |
} |
|
176 |
Object returnValue = super.put(key,value); |
|
177 |
this.putAll(tmp); |
|
178 |
return returnValue; |
|
179 |
} |
|
180 |
|
|
181 |
/** |
|
182 |
* Crea una extension. |
|
183 |
* <br> |
|
184 |
* Dado un nombre de extension asociada a este punto de extension, crea |
|
185 |
* el objeto registrado para manejar la extension. |
|
186 |
* <br> |
|
187 |
* Si el objeto registrado para esa extension implementa el interface |
|
188 |
* <i>IExtensionBuilder</i>, se invoca al metodo create para crear la instancia |
|
189 |
* de la extension. |
|
190 |
* <br> |
|
191 |
* Si no implementa este interface, debera ser una clase, y se creara una |
|
192 |
* instancia de esa clase. |
|
193 |
* <br> |
|
194 |
* @param name Nombre de la extension a crear. |
|
195 |
* @return La instancia creada de la extension. |
|
196 |
* |
|
197 |
* @throws InstantiationException |
|
198 |
* @throws IllegalAccessException |
|
199 |
*/ |
|
200 |
public Object create(String name) throws InstantiationException, IllegalAccessException { |
|
201 |
Object extension = this.get(name); |
|
202 |
if (extension == null) { |
|
203 |
extension = this.get(this.aliases.get(name)); |
|
204 |
} |
|
205 |
|
|
206 |
if( extension instanceof IExtensionBuilder ) { |
|
207 |
return ((IExtensionBuilder)extension).create(); |
|
208 |
} |
|
209 |
return ExtensionBuilder.create((Class) extension); |
|
210 |
} |
|
211 |
|
|
212 |
/** |
|
213 |
* Crea una extension. |
|
214 |
* <br> |
|
215 |
* Dado un nombre de extension asociada a este punto de extension, crea |
|
216 |
* el objeto registrado para manejar la extension. |
|
217 |
* <br> |
|
218 |
* A la hora de crear la instancia de la extension, le pasara los parametros |
|
219 |
* indicados en <i>args</i>. |
|
220 |
* <br> |
|
221 |
* Debido a que los argumentos se pasan como un array de objetos, no es posible |
|
222 |
* pasar al constructor de la extension parametros de tipos basicos como <i>int</i> |
|
223 |
* o <i>long</i>. Se deberan pasar como objetos y existir un constructor de la clase |
|
224 |
* que los pueda recibir de esta manera. |
|
225 |
* <br> |
|
226 |
* @param name Nombre de la extension a crear. |
|
227 |
* @param args Array de objetos a pasar como parametros en la construccion de la instancia de la extension. |
|
228 |
* @return La instancia creada de la extension. |
|
229 |
* |
|
230 |
* @throws SecurityException |
|
231 |
* @throws NoSuchMethodException |
|
232 |
* @throws IllegalArgumentException |
|
233 |
* @throws InstantiationException |
|
234 |
* @throws IllegalAccessException |
|
235 |
* @throws InvocationTargetException |
|
236 |
*/ |
|
237 |
public Object create(String name, Object [] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
|
238 |
Object extension = this.get(name); |
|
239 |
if (extension == null) { |
|
240 |
extension = this.get(this.aliases.get(name)); |
|
241 |
} |
|
242 |
|
|
243 |
if( extension instanceof IExtensionBuilder ) { |
|
244 |
return ((IExtensionBuilder)extension).create(args); |
|
245 |
} |
|
246 |
return ExtensionBuilder.create((Class) extension, args); |
|
247 |
} |
|
248 |
|
|
249 |
public Object create(String name, Map args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
|
250 |
Object extension = this.get(name); |
|
251 |
if (extension == null) { |
|
252 |
extension = this.get(this.aliases.get(name)); |
|
253 |
} |
|
254 |
|
|
255 |
if( extension instanceof IExtensionBuilder ) { |
|
256 |
return ((IExtensionBuilder)extension).create(args); |
|
257 |
} |
|
258 |
return ExtensionBuilder.create((Class) extension, args); |
|
259 |
} |
|
260 |
|
|
261 |
/** |
|
262 |
* Crea un alias para una extension registrada. |
|
263 |
* <br> |
|
264 |
* @param item Nombre de la extension registrada. |
|
265 |
* @param alias alias a a?adir. |
|
266 |
* |
|
267 |
**/ |
|
268 |
public void addAlias(String item, String alias) throws KeyException{ |
|
269 |
if (!this.containsKey(item)) { |
|
270 |
throw new KeyException(item); |
|
271 |
} |
|
272 |
this.aliases.put(alias,item); |
|
273 |
} |
|
274 |
} |
|
0 | 275 |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/extensionPoint/ExtensionPoints.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
*/ |
|
26 |
package org.gvsig.tools.extensionPoint; |
|
27 |
|
|
28 |
import java.util.TreeMap; |
|
29 |
|
|
30 |
/** |
|
31 |
* Clase para registro de puntos de extension. |
|
32 |
* <br> |
|
33 |
* <br> |
|
34 |
* |
|
35 |
* @author jjdelcerro |
|
36 |
*/ |
|
37 |
public class ExtensionPoints extends TreeMap { |
|
38 |
|
|
39 |
|
|
40 |
private static final long serialVersionUID = -798417910971607414L; |
|
41 |
|
|
42 |
/** |
|
43 |
* Evita que se a?adan elementos que no son puntos de extension. |
|
44 |
* <br> |
|
45 |
* <br> |
|
46 |
* Aunque la clase se comporta como un <i>Map</i>, no esta permitido |
|
47 |
* a?adir a esta objetos que no sean de la clase <i>ExtensionPoint</i>. |
|
48 |
* Si intentamos a?adir un elemento que no sea de esta clase, se disparara |
|
49 |
* una excepcion ClassCastException. |
|
50 |
* <br> |
|
51 |
* <br> |
|
52 |
* @see java.util.Map#put(java.lang.Object, java.lang.Object) |
|
53 |
*/ |
|
54 |
public Object put(Object key, Object value) throws ClassCastException { |
|
55 |
throw new ClassCastException(); |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* A?ade un punto de extension al registro de puntos de extension. |
|
60 |
* <br> |
|
61 |
* <br> |
|
62 |
* Mediante este metodo puede a?adir un punto de extension al registro |
|
63 |
* de puntos de extension, llevandose detras todas las extensiones que |
|
64 |
* esten registradas en el. |
|
65 |
* <br> |
|
66 |
* <br> |
|
67 |
* En caso de que ya existiese un punto de extension con el nombre dado, |
|
68 |
* a?adira a este las extensiones del punto de extension suministrado. |
|
69 |
* <br> |
|
70 |
* <br> |
|
71 |
* @param value Punto de extension a registrar |
|
72 |
* @return |
|
73 |
* |
|
74 |
*/ |
|
75 |
public Object put(ExtensionPoint value) { |
|
76 |
return put(value.getName(),value); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* A?ade un punto de extension al registro de puntos de extension. |
|
81 |
* <br> |
|
82 |
* <br> |
|
83 |
* Mediante este metodo puede a?adir un punto de extension al registro |
|
84 |
* de puntos de extension, llevandose detras todas las extensiones que |
|
85 |
* esten registradas en el. |
|
86 |
* <br> |
|
87 |
* <br> |
|
88 |
* En caso de que ya existiese un punto de extension con el nombre dado, |
|
89 |
* a?adira a este las extensiones del punto de extension suministrado. |
|
90 |
* <br> |
|
91 |
* <br> |
|
92 |
* Cuando se a?ade un punto de extension, es imprescindible que <i>key</i> y |
|
93 |
* el nombre del punto de extension que se este a?adiendo coincidan. |
|
94 |
* <br> |
|
95 |
* <br> |
|
96 |
* @param key Nombre del punto de extension |
|
97 |
* @param value Punto de extension a registrar |
|
98 |
* @return |
|
99 |
* |
|
100 |
*/ |
|
101 |
public Object put(String key, ExtensionPoint value) { |
|
102 |
if ( !value.getName().equals(key) ) { |
|
103 |
throw new IllegalArgumentException (); |
|
104 |
} |
|
105 |
ExtensionPoint n = (ExtensionPoint)super.get(key); |
|
106 |
if( n == null ) { |
|
107 |
return super.put(key,value); |
|
108 |
} |
|
109 |
// Como estamos actualizando un punto de extension, a?adimos a este las |
|
110 |
// extensiones del que nos acaban de suministrar. |
|
111 |
n.putAll(value); |
|
112 |
return value; |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Registra una extension en un punto de extension. |
|
117 |
* <br> |
|
118 |
* <br> |
|
119 |
* Mediante este metodo puede registrar sobre un punto de extension |
|
120 |
* una extension. La extension esta identificada mediante un nombre |
|
121 |
* unico, y una clase que se usara para manejar la extension o una |
|
122 |
* clase que contruira el objeto que maneje la extension. |
|
123 |
* <br> |
|
124 |
* <br> |
|
125 |
* Si ya existe en el punto de extension indicado por <i>extensionPointName</i> |
|
126 |
* una extension con el nombre <i>name</i>, esta sera sustituida por la |
|
127 |
* nueva extension. |
|
128 |
* <br> |
|
129 |
* @param extensionPointName Nombre del punto de extension |
|
130 |
* @param name Nombre o identificador de la extension |
|
131 |
* @param data Clase que implementa la extension o que la construye. |
|
132 |
* |
|
133 |
* |
|
134 |
*/ |
|
135 |
public void add(String extensionPointName, String name, Object data) { |
|
136 |
ExtensionPoint extensionPoint = (ExtensionPoint)super.get(extensionPointName); |
|
137 |
if( extensionPoint == null ) { |
|
138 |
extensionPoint = new ExtensionPoint(extensionPointName); |
|
139 |
super.put(extensionPoint.getName(), extensionPoint); |
|
140 |
} |
|
141 |
|
|
142 |
extensionPoint.put(name, data); |
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
146 |
* Registra una extension en un punto de extension. |
|
147 |
* <br> |
|
148 |
* <br> |
|
149 |
* Mediante este metodo puede registrar sobre un punto de extension |
|
150 |
* una extension. La extension esta identificada mediante un nombre |
|
151 |
* unico, y una clase que se usara para manejar la extension o una |
|
152 |
* clase que contruira el objeto que maneje la extension. |
|
153 |
* <br> |
|
154 |
* <br> |
|
155 |
* Si ya existe en el punto de extension indicado por <i>extensionPointName</i> |
|
156 |
* una extension con el nombre <i>name</i>, esta sera sustituida por la |
|
157 |
* nueva extension. |
|
158 |
* <br> |
|
159 |
* @param extensionPointName Nombre del punto de extension |
|
160 |
* @param name Nombre o identificador de la extension |
|
161 |
* @param description descripcion de la extension. |
|
162 |
* @param data Clase que implementa la extension o que la construye. |
|
163 |
* |
|
164 |
* |
|
165 |
*/ |
|
166 |
public void add(String extensionPointName, String name, String description, Object data) { |
|
167 |
ExtensionPoint extensionPoint = (ExtensionPoint)super.get(extensionPointName); |
|
168 |
if( extensionPoint == null ) { |
|
169 |
extensionPoint = new ExtensionPoint(extensionPointName); |
|
170 |
super.put(extensionPoint.getName(), extensionPoint); |
|
171 |
} |
|
172 |
|
|
173 |
extensionPoint.put(name,description, data); |
|
174 |
} |
|
175 |
|
|
176 |
} |
|
0 | 177 |
branches/v2_0_0_prep/libraries/libIverUtiles/src/com/iver/utiles/extensionPoints/ExtensionPointsSingleton.java | ||
---|---|---|
1 | 1 |
package com.iver.utiles.extensionPoints; |
2 | 2 |
|
3 |
/** |
|
4 |
* @deprecated @see org.gvsig.tools.extensionPoint.ExtensionPointsSingleton |
|
5 |
*/ |
|
3 | 6 |
public class ExtensionPointsSingleton extends ExtensionPoints { |
4 | 7 |
|
5 | 8 |
private static final long serialVersionUID = -630976693542039111L; |
branches/v2_0_0_prep/libraries/libIverUtiles/src/com/iver/utiles/extensionPoints/IExtensionBuilder.java | ||
---|---|---|
3 | 3 |
import java.util.Map; |
4 | 4 |
|
5 | 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.
|
|
6 |
* Interface utilizado para indicar al registro de extensiones que no se trata
|
|
7 |
* de una clase lo que hey registrado, si no una instancia de un objeto a usar
|
|
8 |
* para crear la extension. |
|
9 | 9 |
* |
10 | 10 |
* |
11 | 11 |
* @author jjdelcerro |
12 |
* |
|
12 |
* @deprecated @see org.gvsig.tools.extensionPoint.IExtensionBuilder
|
|
13 | 13 |
*/ |
14 | 14 |
public interface IExtensionBuilder { |
15 | 15 |
/** |
branches/v2_0_0_prep/libraries/libIverUtiles/src/com/iver/utiles/extensionPoints/ExtensionBuilder.java | ||
---|---|---|
7 | 7 |
/** |
8 | 8 |
* Clase de utilidad usada para crear las extensiones. |
9 | 9 |
* |
10 |
* Esta clase presenta un par de metodos estaticos para |
|
11 |
* permitir crear un objeto a partir de una clase.
|
|
10 |
* Esta clase presenta un par de metodos estaticos para permitir crear un objeto
|
|
11 |
* a partir de una clase. |
|
12 | 12 |
* |
13 | 13 |
* @author jjdelcerro |
14 |
* |
|
14 |
* @deprecated @see org.gvsig.tools.extensionPoint.ExtensionBuilder
|
|
15 | 15 |
*/ |
16 | 16 |
public abstract class ExtensionBuilder implements IExtensionBuilder { |
17 | 17 |
|
branches/v2_0_0_prep/libraries/libIverUtiles/src/com/iver/utiles/extensionPoints/ExtensionPoint.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.lang.reflect.InvocationTargetException; |
4 | 4 |
import java.security.KeyException; |
5 |
import java.util.Hashtable; |
|
6 |
import java.util.Iterator; |
|
7 |
import java.util.LinkedHashMap; |
|
8 |
import java.util.Map; |
|
5 |
import java.util.*; |
|
9 | 6 |
|
10 |
|
|
11 | 7 |
/** |
12 |
* Esta clase permite registrar extensiones para un punto de extension. |
|
8 |
* Esta clase permite registrar extensiones para un punto de extension. <br>
|
|
13 | 9 |
* <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> |
|
10 |
* La clase se comporta como un Map que mantiene el orden de insercion de los |
|
11 |
* elementos, para que puedan ser recorridos en ese orden. <br> |
|
18 | 12 |
* 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 metodo <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> |
|
13 |
* metodos para facilitar la creacion de la extension. <br> |
|
14 |
* A la hora de registrar una extension, mediante el metodo <i>put</i>, podremos |
|
15 |
* suministrarle una clase o una instancia que implemente el interface |
|
16 |
* IExtensionBuilder. Si le suministramos una clase, cuando queramos crear la |
|
17 |
* extension mediante el metodo <i>create</i>, se creara una instancia de la |
|
18 |
* clase y se retornara. Si lo que se suministro fue una instancia que |
|
19 |
* implementa el interface IExtensionBuilder, se invocara al metodo |
|
20 |
* <i>create</i> de esta para crear la extension. <br> |
|
21 |
* |
|
29 | 22 |
* @author jjdelcerro |
30 |
* |
|
23 |
* |
|
24 |
* @deprecated @see org.gvsig.tools.extensionPoint.ExtensionPoint |
|
31 | 25 |
*/ |
32 | 26 |
public class ExtensionPoint extends LinkedHashMap { |
33 | 27 |
|
34 |
private static final long serialVersionUID = -5908427725588553371L;
|
|
28 |
private static final long serialVersionUID = -5908427725588553371L;
|
|
35 | 29 |
|
36 | 30 |
private String name; |
37 | 31 |
private String description; |
branches/v2_0_0_prep/libraries/libIverUtiles/src/com/iver/utiles/extensionPoints/ExtensionPoints.java | ||
---|---|---|
3 | 3 |
import java.util.TreeMap; |
4 | 4 |
|
5 | 5 |
/** |
6 |
* Clase para registro de puntos de extension. |
|
6 |
* Clase para registro de puntos de extension. <br>
|
|
7 | 7 |
* <br> |
8 |
* <br> |
|
9 | 8 |
* |
10 | 9 |
* @author jjdelcerro |
10 |
* @deprecated @see org.gvsig.tools.extensionPoint.ExtensionPoints |
|
11 | 11 |
*/ |
12 | 12 |
public class ExtensionPoints extends TreeMap { |
13 | 13 |
|
Also available in: Unified diff