Revision 4676
trunk/libraries/libIverUtiles/src/com/iver/utiles/extensionPoints/package.html | ||
---|---|---|
1 | 1 |
<html> |
2 | 2 |
<body> |
3 | 3 |
|
4 |
Este paquete expone un mecanismos para registro de clases.
|
|
4 |
Este paquete expone un mecanismo para registro de clases. |
|
5 | 5 |
<br> |
6 | 6 |
Permite registrar clases o factorias de clases que luego pueden ser |
7 | 7 |
recuperadas para construir instancias. |
... | ... | |
39 | 39 |
<br> |
40 | 40 |
<code> |
41 | 41 |
ExtensionPoint infoByPoint = (ExtensionPoint)extensionPoints.get("InfoByPoint"); |
42 |
Object ext = infoByPoint.create("Tipo1");
|
|
42 |
Object ext = infoByPoint.create("MiLayer");
|
|
43 | 43 |
</code> |
44 | 44 |
Y para poder recorrer las distintas extensiones de ese punto: |
45 | 45 |
<br> |
trunk/libraries/libIverUtiles/src/com/iver/utiles/extensionPoints/ExtensionBuilder.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.lang.reflect.Constructor; |
4 | 4 |
import java.lang.reflect.InvocationTargetException; |
5 |
import java.util.Map; |
|
5 | 6 |
|
6 | 7 |
/** |
7 | 8 |
* Clase de utilidad usada para crear las extensiones. |
... | ... | |
66 | 67 |
obj = create.newInstance(args); |
67 | 68 |
return obj; |
68 | 69 |
} |
70 |
/** |
|
71 |
* Crea un objeto de la clase indicada. |
|
72 |
* |
|
73 |
* Crea un objeto de la clase indicada pasandole al constructor |
|
74 |
* un como argumento un Map.. |
|
75 |
* <br> |
|
76 |
* @param cls Clase de la que crear la instancia |
|
77 |
* @param args Map a pasar como argumento al constructor. |
|
78 |
* @return |
|
79 |
* |
|
80 |
* @throws SecurityException |
|
81 |
* @throws NoSuchMethodException |
|
82 |
* @throws IllegalArgumentException |
|
83 |
* @throws InstantiationException |
|
84 |
* @throws IllegalAccessException |
|
85 |
* @throws InvocationTargetException |
|
86 |
*/ |
|
87 |
public static Object create(Class cls, Map args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
|
88 |
Object obj = null; |
|
89 |
Constructor create = null; |
|
90 |
Class [] types = new Class[1]; |
|
91 |
Object [] argsx = new Object[1]; |
|
92 |
|
|
93 |
if( cls == null ) { |
|
94 |
return null; |
|
95 |
} |
|
96 |
types[0] = Map.class; |
|
97 |
argsx[0] = args; |
|
98 |
create = cls.getConstructor(types); |
|
99 |
obj = create.newInstance(argsx); |
|
100 |
return obj; |
|
101 |
} |
|
69 | 102 |
} |
trunk/libraries/libIverUtiles/src/com/iver/utiles/extensionPoints/ExtensionPoint.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.lang.reflect.InvocationTargetException; |
4 | 4 |
import java.util.LinkedHashMap; |
5 |
import java.util.Map; |
|
5 | 6 |
|
6 | 7 |
|
7 | 8 |
/** |
... | ... | |
37 | 38 |
* <br> |
38 | 39 |
* @param extensionPointName Nombre del punto de extension. |
39 | 40 |
*/ |
40 |
ExtensionPoint(String extensionPointName) { |
|
41 |
public ExtensionPoint(String extensionPointName) {
|
|
41 | 42 |
this.name = extensionPointName; |
42 | 43 |
} |
43 | 44 |
|
... | ... | |
47 | 48 |
* @param extensionPointName Nombre del punto de extension |
48 | 49 |
* @param description Descripcion del punto de extension |
49 | 50 |
*/ |
50 |
ExtensionPoint(String extensionPointName, String description) { |
|
51 |
public ExtensionPoint(String extensionPointName, String description) {
|
|
51 | 52 |
this.name = extensionPointName; |
52 | 53 |
this.description = description; |
53 | 54 |
} |
... | ... | |
140 | 141 |
return ((IExtensionBuilder)extension).create(args); |
141 | 142 |
} |
142 | 143 |
return ExtensionBuilder.create((Class) extension, args); |
144 |
} |
|
145 |
|
|
146 |
public Object create(String name, Map args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
|
147 |
Object extension = this.get(name); |
|
148 |
|
|
149 |
if( extension instanceof IExtensionBuilder ) { |
|
150 |
return ((IExtensionBuilder)extension).create(args); |
|
151 |
} |
|
152 |
return ExtensionBuilder.create((Class) extension, args); |
|
143 | 153 |
} |
144 | 154 |
} |
trunk/libraries/libIverUtiles/src/com/iver/utiles/extensionPoints/IExtensionBuilder.java | ||
---|---|---|
1 | 1 |
package com.iver.utiles.extensionPoints; |
2 | 2 |
|
3 |
import java.util.Map; |
|
4 |
|
|
3 | 5 |
/** |
4 | 6 |
* Interface utilizado para indicar al registro de extensiones |
5 | 7 |
* que no se trata de una clase lo que hey registrado, si no |
... | ... | |
27 | 29 |
* @return |
28 | 30 |
*/ |
29 | 31 |
public Object create(Object [] args); |
32 |
|
|
33 |
public Object create(Map args); |
|
30 | 34 |
} |
Also available in: Unified diff