Revision 31246
tags/tmp_build/libraries/libTools/.project | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>libTools</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
</buildSpec> |
|
14 |
<natures> |
|
15 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
16 |
</natures> |
|
17 |
</projectDescription> |
|
0 | 18 |
tags/tmp_build/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 |
// Remove previous registered extension points, so other tests |
|
36 |
// don't affect the test validations. |
|
37 |
ExtensionPointsSingleton.getInstance().clear(); |
|
38 |
super.setUp(); |
|
39 |
} |
|
40 |
|
|
41 |
protected void tearDown() throws Exception { |
|
42 |
super.tearDown(); |
|
43 |
} |
|
44 |
|
|
45 |
public void test() { |
|
46 |
ExtensionPoints extensionPoints = new ExtensionPoints(); |
|
47 |
|
|
48 |
extensionPoints.add("LayerWizars","WMS",UnaExtensionDePrueba1.class); |
|
49 |
extensionPoints.add("LayerWizars","WCS",UnaExtensionDePrueba2.class); |
|
50 |
extensionPoints.add("OtherWizars","uno",UnaExtensionDePrueba1.class); |
|
51 |
extensionPoints.add("OtherWizars","dos",UnaExtensionDePrueba2.class); |
|
52 |
|
|
53 |
// Comprobamos que el orden de las extensiones es el que hemos fijado. |
|
54 |
ExtensionPoint x = (ExtensionPoint)extensionPoints.get("LayerWizars"); |
|
55 |
Iterator i =x.keySet().iterator(); |
|
56 |
String[] nombres = {"WMS", "WCS" }; |
|
57 |
int n = 0; |
|
58 |
while( i.hasNext() ) { |
|
59 |
String nombre = (String)i.next(); |
|
60 |
assertTrue(nombres[n].equals(nombre)); |
|
61 |
n++; |
|
62 |
} |
|
63 |
|
|
64 |
|
|
65 |
ExtensionPoint extensionPointLayerWizars; |
|
66 |
extensionPointLayerWizars = (ExtensionPoint)extensionPoints.get("LayerWizars"); |
|
67 |
assertTrue(extensionPointLayerWizars.containsKey("WMS")); |
|
68 |
assertTrue(extensionPointLayerWizars.containsKey("WCS")); |
|
69 |
|
|
70 |
assertEquals(extensionPoints.size(),2); |
|
71 |
assertEquals(extensionPointLayerWizars.size(),2); |
|
72 |
|
|
73 |
ExtensionPoint extensionPointLayerWizars2 = new ExtensionPoint("LayerWizars"); |
|
74 |
|
|
75 |
|
|
76 |
extensionPointLayerWizars2.put("File",UnaExtensionDePrueba3.class); |
|
77 |
extensionPointLayerWizars2.put("JDBC",UnaExtensionDePrueba4.class); |
|
78 |
|
|
79 |
extensionPoints.put("LayerWizars",extensionPointLayerWizars2); |
|
80 |
|
|
81 |
extensionPointLayerWizars = (ExtensionPoint)extensionPoints.get("LayerWizars"); |
|
82 |
assertEquals(extensionPoints.size(),2); |
|
83 |
assertEquals(extensionPointLayerWizars.size(),4); |
|
84 |
assertEquals(((ExtensionPoint)extensionPoints.get("OtherWizars")).size(),2); |
|
85 |
|
|
86 |
assertTrue(extensionPointLayerWizars.containsKey("WMS")); |
|
87 |
assertTrue(extensionPointLayerWizars.containsKey("WCS")); |
|
88 |
assertTrue(extensionPointLayerWizars.containsKey("File")); |
|
89 |
assertTrue(extensionPointLayerWizars.containsKey("JDBC")); |
|
90 |
|
|
91 |
assertEquals((extensionPointLayerWizars.get("JDBC")),UnaExtensionDePrueba4.class); |
|
92 |
assertEquals((extensionPointLayerWizars.get("WMS")),UnaExtensionDePrueba1.class); |
|
93 |
|
|
94 |
assertEquals(((ExtensionPoint)extensionPoints.get("OtherWizars")).get("uno"),UnaExtensionDePrueba1.class); |
|
95 |
|
|
96 |
ExtensionPoint extensionPointOther2 = new ExtensionPoint("OtherWizars"); |
|
97 |
extensionPointOther2.put("tres",UnaExtensionDePrueba3.class); |
|
98 |
extensionPointOther2.put("cuatro",UnaExtensionDePrueba4.class); |
|
99 |
|
|
100 |
extensionPoints.put(extensionPointOther2); |
|
101 |
|
|
102 |
ExtensionPoint extensionPointOther = (ExtensionPoint)extensionPoints.get("OtherWizars"); |
|
103 |
assertEquals(extensionPoints.size(),2); |
|
104 |
assertEquals(extensionPointLayerWizars.size(),4); |
|
105 |
assertEquals(extensionPointOther.size(),4); |
|
106 |
|
|
107 |
assertTrue(extensionPointOther.containsKey("uno")); |
|
108 |
assertTrue(extensionPointOther.containsKey("dos")); |
|
109 |
assertTrue(extensionPointOther.containsKey("tres")); |
|
110 |
assertTrue(extensionPointOther.containsKey("cuatro")); |
|
111 |
|
|
112 |
assertEquals((extensionPointOther.get("tres")),UnaExtensionDePrueba3.class); |
|
113 |
assertEquals((extensionPointOther.get("dos")),UnaExtensionDePrueba2.class); |
|
114 |
|
|
115 |
assertEquals(extensionPoints.get("Ninguno"),null); |
|
116 |
} |
|
117 |
|
|
118 |
public void testSingleton() { |
|
119 |
ExtensionPoints extensionPoints1 = ExtensionPointsSingleton.getInstance(); |
|
120 |
|
|
121 |
extensionPoints1.add("LayerWizars","WMS",UnaExtensionDePrueba1.class); |
|
122 |
extensionPoints1.add("LayerWizars","WCS",UnaExtensionDePrueba2.class); |
|
123 |
extensionPoints1.add("OtherWizars","uno",UnaExtensionDePrueba1.class); |
|
124 |
extensionPoints1.add("OtherWizars","dos",UnaExtensionDePrueba2.class); |
|
125 |
|
|
126 |
ExtensionPoints extensionPoints2 = ExtensionPointsSingleton.getInstance(); |
|
127 |
assertEquals(2, extensionPoints2.size()); |
|
128 |
|
|
129 |
ExtensionPoint extensionPointLayerWizars; |
|
130 |
extensionPointLayerWizars = (ExtensionPoint)extensionPoints2.get("LayerWizars"); |
|
131 |
assertTrue(extensionPointLayerWizars.containsKey("WMS")); |
|
132 |
assertTrue(extensionPointLayerWizars.containsKey("WCS")); |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
class UnaExtensionDePrueba1 { |
|
137 |
public UnaExtensionDePrueba1() { |
|
138 |
; |
|
139 |
} |
|
140 |
} |
|
141 |
class UnaExtensionDePrueba2 { |
|
142 |
public UnaExtensionDePrueba2() { |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
class UnaExtensionDePrueba3 { |
|
147 |
public UnaExtensionDePrueba3() { |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
class UnaExtensionDePrueba4 { |
|
152 |
public UnaExtensionDePrueba4() { |
|
153 |
} |
|
154 |
} |
|
0 | 155 |
tags/tmp_build/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 |
tags/tmp_build/libraries/libTools/src-test/org/gvsig/tools/exception/ListBaseExceptionTest.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.exception; |
|
27 |
|
|
28 |
import junit.framework.TestCase; |
|
29 |
|
|
30 |
public class ListBaseExceptionTest extends TestCase { |
|
31 |
|
|
32 |
protected void setUp() throws Exception { |
|
33 |
super.setUp(); |
|
34 |
} |
|
35 |
|
|
36 |
protected void tearDown() throws Exception { |
|
37 |
super.tearDown(); |
|
38 |
} |
|
39 |
|
|
40 |
public void testSimple(){ |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 |
} |
tags/tmp_build/libraries/libTools/src-test/org/gvsig/tools/exception/BaseExceptionTest.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.exception; |
|
27 |
|
|
28 |
import junit.framework.TestCase; |
|
29 |
|
|
30 |
public class BaseExceptionTest extends TestCase { |
|
31 |
|
|
32 |
protected void setUp() throws Exception { |
|
33 |
super.setUp(); |
|
34 |
} |
|
35 |
|
|
36 |
protected void tearDown() throws Exception { |
|
37 |
super.tearDown(); |
|
38 |
} |
|
39 |
|
|
40 |
public void testSimple(){ |
|
41 |
try { |
|
42 |
throw new NullPointerException("Excepcion de puntero nulo"); |
|
43 |
} catch (NullPointerException e){ |
|
44 |
IBaseException de = createDriverException("SimpleDriver", e); |
|
45 |
assertEquals("Error in the driver SimpleDrivers", de.getMessage()); |
|
46 |
assertEquals( |
|
47 |
"Error in the driver SimpleDrivers\nExcepcion de puntero nulo", |
|
48 |
de.getMessageStack()); |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
public void testSimpleLocalized(){ |
|
53 |
class MyTranslator implements IExceptionTranslator { |
|
54 |
public String getText(String clave) { |
|
55 |
return clave.toUpperCase(); |
|
56 |
} |
|
57 |
} |
|
58 |
BaseException.setTranslator(new MyTranslator()); |
|
59 |
try { |
|
60 |
throw new NullPointerException("Excepcion de puntero nulo"); |
|
61 |
} catch (NullPointerException e){ |
|
62 |
IBaseException de = createDriverException("SimpleDriver", e); |
|
63 |
assertEquals("ERROR_IN_THE_DRIVER_%(DRIVERNAME)S",de.getLocalizedMessage()); |
|
64 |
assertEquals( |
|
65 |
"ERROR_IN_THE_DRIVER_%(DRIVERNAME)S\nExcepcion de puntero nulo", |
|
66 |
de.getLocalizedMessageStack()); |
|
67 |
} |
|
68 |
BaseException.setTranslator(null); |
|
69 |
} |
|
70 |
|
|
71 |
public void testSimple2(){ |
|
72 |
try { |
|
73 |
throw new NullPointerException("Excepcion de puntero nulo"); |
|
74 |
} catch (NullPointerException e){ |
|
75 |
IBaseException de = createBadDateException("SimpleDriver", e); |
|
76 |
assertEquals("Driver SimpleDrivers: Formato de fecha incorrecto", |
|
77 |
de.getMessage()); |
|
78 |
assertEquals( |
|
79 |
"Driver SimpleDrivers: Formato de fecha incorrecto\nExcepcion de puntero nulo", |
|
80 |
de.getMessageStack()); |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
public void testSimpleLocalized2(){ |
|
85 |
class MyTranslator implements IExceptionTranslator { |
|
86 |
public String getText(String clave) { |
|
87 |
return clave.toUpperCase(); |
|
88 |
} |
|
89 |
} |
|
90 |
BaseException.setTranslator(new MyTranslator()); |
|
91 |
try { |
|
92 |
throw new NullPointerException("Excepcion de puntero nulo"); |
|
93 |
} catch (NullPointerException e){ |
|
94 |
IBaseException de = createBadDateException("SimpleDriver", e); |
|
95 |
assertEquals("DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO",de.getLocalizedMessage()); |
|
96 |
assertEquals( |
|
97 |
"DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO\nExcepcion de puntero nulo", |
|
98 |
de.getLocalizedMessageStack()); |
|
99 |
} |
|
100 |
BaseException.setTranslator(null); |
|
101 |
} |
|
102 |
|
|
103 |
public void testTranslatorWithoutInterface() { |
|
104 |
class MyTranslator { |
|
105 |
public String getText(String clave) { |
|
106 |
return clave.toUpperCase(); |
|
107 |
} |
|
108 |
} |
|
109 |
BaseException.setTranslator(new MyTranslator()); |
|
110 |
try { |
|
111 |
throw new NullPointerException("Excepcion de puntero nulo"); |
|
112 |
} catch (NullPointerException e){ |
|
113 |
IBaseException de = createBadDateException("SimpleDriver", e); |
|
114 |
assertEquals("DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO",de.getLocalizedMessage()); |
|
115 |
assertEquals( |
|
116 |
"DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO\nExcepcion de puntero nulo", |
|
117 |
de.getLocalizedMessageStack()); |
|
118 |
} |
|
119 |
BaseException.setTranslator(null); |
|
120 |
|
|
121 |
} |
|
122 |
|
|
123 |
public void testInsertBlanksAtStart() { |
|
124 |
String src = "test"; |
|
125 |
|
|
126 |
assertEquals("test", BaseException.insertBlanksAtStart(src, 0)); |
|
127 |
|
|
128 |
assertEquals("test", BaseException.insertBlanksAtStart(src, -5)); |
|
129 |
|
|
130 |
assertEquals(" test", BaseException.insertBlanksAtStart(src, 2)); |
|
131 |
|
|
132 |
assertEquals(" test", BaseException.insertBlanksAtStart(src, 6)); |
|
133 |
} |
|
134 |
|
|
135 |
protected IBaseException createDriverException(String driver, |
|
136 |
Throwable throwable) { |
|
137 |
return new DriverException(driver, throwable); |
|
138 |
} |
|
139 |
|
|
140 |
protected IBaseException createBadDateException(String driver, |
|
141 |
Throwable throwable) { |
|
142 |
return new BadDateException(driver, throwable); |
|
143 |
} |
|
144 |
|
|
145 |
class BadDateException extends DriverException { |
|
146 |
private static final long serialVersionUID = -8985920349210629998L; |
|
147 |
private static final String KEY = "Driver_%(driverName)s_Formato_de_fecha_incorrecto"; |
|
148 |
|
|
149 |
private static final String MESSAGE = "Driver %(driverName)s: Formato de fecha incorrecto"; |
|
150 |
|
|
151 |
public BadDateException(String driverName, Throwable cause) { |
|
152 |
super(driverName, MESSAGE, cause, KEY, serialVersionUID); |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
} |
tags/tmp_build/libraries/libTools/src-test/org/gvsig/tools/exception/DriverException.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.exception; |
|
27 |
|
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.Map; |
|
30 |
|
|
31 |
public class DriverException extends BaseException { |
|
32 |
|
|
33 |
private static final long serialVersionUID = -8985920349210629999L; |
|
34 |
|
|
35 |
private static final String KEY = "Error_in_the_driver_%(driverName)s"; |
|
36 |
|
|
37 |
private static final String MESSAGE = "Error in the driver %(driverName)s"; |
|
38 |
|
|
39 |
private String driverName; |
|
40 |
|
|
41 |
public DriverException(String driverName) { |
|
42 |
super(MESSAGE, KEY, serialVersionUID); |
|
43 |
this.driverName = driverName; |
|
44 |
} |
|
45 |
|
|
46 |
public DriverException(String driverName, Throwable cause) { |
|
47 |
super(MESSAGE, cause, KEY, serialVersionUID); |
|
48 |
this.driverName = driverName; |
|
49 |
} |
|
50 |
|
|
51 |
public DriverException(String driverName, String message, Throwable cause, |
|
52 |
String key, long code) { |
|
53 |
super(message, cause, key, code); |
|
54 |
this.driverName = driverName; |
|
55 |
} |
|
56 |
|
|
57 |
public String getDriverName() { |
|
58 |
return driverName; |
|
59 |
} |
|
60 |
|
|
61 |
protected Map values() { |
|
62 |
HashMap values = new HashMap(); |
|
63 |
values.put("driverName",this.driverName); |
|
64 |
return values; |
|
65 |
} |
|
66 |
} |
tags/tmp_build/libraries/libTools/src-test/org/gvsig/tools/exception/AllTests.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.exception; |
|
27 |
|
|
28 |
import junit.framework.Test; |
|
29 |
import junit.framework.TestSuite; |
|
30 |
|
|
31 |
public class AllTests { |
|
32 |
|
|
33 |
public static Test suite() { |
|
34 |
TestSuite suite = new TestSuite("Test for org.gvsig.tools.exceptions"); |
|
35 |
//$JUnit-BEGIN$ |
|
36 |
suite.addTestSuite(ListBaseExceptionTest.class); |
|
37 |
suite.addTestSuite(BaseExceptionTest.class); |
|
38 |
//$JUnit-END$ |
|
39 |
return suite; |
|
40 |
} |
|
41 |
|
|
42 |
} |
tags/tmp_build/libraries/libTools/src-test/org/gvsig/tools/exception/BaseRuntimeExceptionTest.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.exception; |
|
27 |
|
|
28 |
import java.util.Map; |
|
29 |
|
|
30 |
public class BaseRuntimeExceptionTest extends BaseExceptionTest { |
|
31 |
|
|
32 |
public void testRuntimeExceptionNature() { |
|
33 |
Object test = new Object() { |
|
34 |
|
|
35 |
public String toString() { |
|
36 |
throw new BaseRuntimeException("ERROR", "ERROR", 1) { |
|
37 |
protected Map values() { |
|
38 |
return null; |
|
39 |
} |
|
40 |
}; |
|
41 |
} |
|
42 |
|
|
43 |
}; |
|
44 |
|
|
45 |
try { |
|
46 |
test.toString(); |
|
47 |
fail("RuntimeException not generated"); |
|
48 |
} catch (RuntimeException rex) { |
|
49 |
// success |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
protected IBaseException createBadDateException(String driver, |
|
54 |
Throwable throwable) { |
|
55 |
return new BadDateException(driver, throwable); |
|
56 |
} |
|
57 |
|
|
58 |
protected IBaseException createDriverException(String driver, |
|
59 |
Throwable throwable) { |
|
60 |
return new DriverRuntimeException(driver, throwable); |
|
61 |
} |
|
62 |
|
|
63 |
class BadDateException extends DriverRuntimeException { |
|
64 |
private static final long serialVersionUID = -8985920349210629998L; |
|
65 |
private static final String KEY = "Driver_%(driverName)s_Formato_de_fecha_incorrecto"; |
|
66 |
|
|
67 |
private static final String MESSAGE = "Driver %(driverName)s: Formato de fecha incorrecto"; |
|
68 |
|
|
69 |
public BadDateException(String driverName, Throwable cause) { |
|
70 |
super(driverName, MESSAGE, cause, KEY, serialVersionUID); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
} |
tags/tmp_build/libraries/libTools/src-test/org/gvsig/tools/exception/DriverRuntimeException.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.exception; |
|
27 |
|
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.Map; |
|
30 |
|
|
31 |
public class DriverRuntimeException extends BaseRuntimeException { |
|
32 |
|
|
33 |
private static final long serialVersionUID = -8985920349210629999L; |
|
34 |
|
|
35 |
private static final String KEY = "Error_in_the_driver_%(driverName)s"; |
|
36 |
|
|
37 |
private static final String MESSAGE = "Error in the driver %(driverName)s"; |
|
38 |
|
|
39 |
private String driverName; |
|
40 |
|
|
41 |
public DriverRuntimeException(String driverName) { |
|
42 |
super(MESSAGE, KEY, serialVersionUID); |
|
43 |
this.driverName = driverName; |
|
44 |
} |
|
45 |
|
|
46 |
public DriverRuntimeException(String driverName, Throwable cause) { |
|
47 |
super(MESSAGE, cause, KEY, serialVersionUID); |
|
48 |
this.driverName = driverName; |
|
49 |
} |
|
50 |
|
|
51 |
public DriverRuntimeException(String driverName, String message, Throwable cause, |
|
52 |
String key, long code) { |
|
53 |
super(message, cause, key, code); |
|
54 |
this.driverName = driverName; |
|
55 |
} |
|
56 |
|
|
57 |
public String getDriverName() { |
|
58 |
return driverName; |
|
59 |
} |
|
60 |
|
|
61 |
protected Map values() { |
|
62 |
HashMap values = new HashMap(); |
|
63 |
values.put("driverName",this.driverName); |
|
64 |
return values; |
|
65 |
} |
|
66 |
} |
tags/tmp_build/libraries/libTools/src-test/org/gvsig/tools/locator/AbstractLocatorTest.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 |
* 2008 {{Company}} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.tools.locator; |
|
28 |
|
|
29 |
import java.util.Arrays; |
|
30 |
import java.util.Collection; |
|
31 |
import java.util.Map; |
|
32 |
|
|
33 |
import junit.framework.TestCase; |
|
34 |
|
|
35 |
import org.gvsig.tools.locator.AbstractLocator; |
|
36 |
import org.gvsig.tools.locator.LocatorObjectFactory; |
|
37 |
|
|
38 |
/** |
|
39 |
* Unit tests for the AbstractLocator class. |
|
40 |
* |
|
41 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
42 |
*/ |
|
43 |
public class AbstractLocatorTest extends TestCase { |
|
44 |
|
|
45 |
private TestLocator locator; |
|
46 |
|
|
47 |
protected void setUp() throws Exception { |
|
48 |
super.setUp(); |
|
49 |
locator = new TestLocator(); |
|
50 |
} |
|
51 |
|
|
52 |
protected void tearDown() throws Exception { |
|
53 |
super.tearDown(); |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* Test method for {@link org.gvsig.tools.locator.AbstractLocator#getNames()}. |
|
58 |
*/ |
|
59 |
public void testGetNames() { |
|
60 |
assertNull("Empty locator must not return any names", locator |
|
61 |
.getNames()); |
|
62 |
|
|
63 |
String name1 = "test1"; |
|
64 |
String name2 = "test2"; |
|
65 |
|
|
66 |
locator.register(name1, String.class); |
|
67 |
locator.register(name2, String.class); |
|
68 |
|
|
69 |
String[] names = locator.getNames(); |
|
70 |
|
|
71 |
assertEquals("Number of registered names incorrect, must be 2", 2, |
|
72 |
names.length); |
|
73 |
|
|
74 |
Collection namesColl = Arrays.asList(names); |
|
75 |
assertTrue("The list of names does not contain the registered name: " |
|
76 |
+ name1, namesColl.contains(name1)); |
|
77 |
assertTrue("The list of names does not contain the registered name: " |
|
78 |
+ name2, namesColl.contains(name2)); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Test method for |
|
83 |
* {@link org.gvsig.tools.locator.AbstractLocator#get(java.lang.String)} and |
|
84 |
* {@link org.gvsig.tools.locator.AbstractLocator#register(java.lang.String, java.lang.Class)} |
|
85 |
*/ |
|
86 |
public void testGetAndRegisterClass() { |
|
87 |
Class clazz = String.class; |
|
88 |
String name = "test"; |
|
89 |
|
|
90 |
locator.register(name, clazz); |
|
91 |
|
|
92 |
Object ref = locator.get(name); |
|
93 |
|
|
94 |
assertEquals(clazz, ref.getClass()); |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* Test method for |
|
99 |
* {@link org.gvsig.tools.locator.AbstractLocator#get(java.lang.String)} and |
|
100 |
* {@link org.gvsig.tools.locator.AbstractLocator#register(String, LocatorObjectFactory) |
|
101 |
|
|
102 |
*/ |
|
103 |
public void testGetAndRegisterFactory() { |
|
104 |
final Object ref = new Object(); |
|
105 |
LocatorObjectFactory factory = new LocatorObjectFactory() { |
|
106 |
|
|
107 |
public Object create() { |
|
108 |
return ref; |
|
109 |
} |
|
110 |
|
|
111 |
public Object create(Object[] args) { |
|
112 |
return ref; |
|
113 |
} |
|
114 |
|
|
115 |
public Object create(Map args) { |
|
116 |
return ref; |
|
117 |
} |
|
118 |
}; |
|
119 |
|
|
120 |
String name = "test"; |
|
121 |
|
|
122 |
locator.register(name, factory); |
|
123 |
|
|
124 |
Object locatorRef = locator.get(name); |
|
125 |
|
|
126 |
assertEquals(ref, locatorRef); |
|
127 |
} |
|
128 |
|
|
129 |
public class TestLocator extends AbstractLocator { |
|
130 |
public String getLocatorName() { |
|
131 |
return "TestLocator"; |
|
132 |
} |
|
133 |
} |
|
134 |
|
|
135 |
} |
tags/tmp_build/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 |
tags/tmp_build/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 |
tags/tmp_build/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 |
tags/tmp_build/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 |
tags/tmp_build/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; |
Also available in: Unified diff