|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| CustomPropertyEditorManager.java | 87,5% | 100% | 100% | 96% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* EJTools, the Enterprise Java Tools
|
|
| 3 |
*
|
|
| 4 |
* Distributable under LGPL license.
|
|
| 5 |
* See terms of license at www.gnu.org.
|
|
| 6 |
*/
|
|
| 7 |
package org.ejtools.beans;
|
|
| 8 |
|
|
| 9 |
import java.beans.PropertyEditor;
|
|
| 10 |
import java.beans.PropertyEditorManager;
|
|
| 11 |
import java.util.Arrays;
|
|
| 12 |
import java.util.Vector;
|
|
| 13 |
|
|
| 14 |
/**
|
|
| 15 |
* Decorator class to enhance the functionnality of the {@link PropertyEditorManager}.
|
|
| 16 |
* If a PropertyEditor is not found, a PropertyEditor matching one of the implemented interfaces
|
|
| 17 |
* is searched.
|
|
| 18 |
*
|
|
| 19 |
* @author Laurent Etiemble
|
|
| 20 |
* @version $Revision: 1.8 $
|
|
| 21 |
*/
|
|
| 22 |
public abstract class CustomPropertyEditorManager extends PropertyEditorManager |
|
| 23 |
{
|
|
| 24 |
/** Description of the Field */
|
|
| 25 |
public final static String EDITORS_PACKAGE = "org.ejtools.adwt.editor"; |
|
| 26 |
|
|
| 27 |
|
|
| 28 |
/**
|
|
| 29 |
* Add super interfaces search when finding a PropertyEditor
|
|
| 30 |
*
|
|
| 31 |
* @param clazz The class of the property
|
|
| 32 |
* @return The PropertyEditor found, null otherwise
|
|
| 33 |
*/
|
|
| 34 | 64 |
public static synchronized PropertyEditor findEditor(Class clazz) |
| 35 |
{
|
|
| 36 | 64 |
PropertyEditor result = PropertyEditorManager.findEditor(clazz); |
| 37 |
|
|
| 38 |
// If the PropertyEditor is not found in mapping, it is the first time it is required
|
|
| 39 |
// so fetch it by the PropertyEditorManager
|
|
| 40 | 64 |
if (result == null) |
| 41 |
{
|
|
| 42 |
// Search among the interfaces if there is one that has a PropertyEditor
|
|
| 43 | 32 |
Class[] interfaces = clazz.getInterfaces(); |
| 44 | 32 |
for (int i = 0; i < interfaces.length; i++) |
| 45 |
{
|
|
| 46 | 24 |
Class current = interfaces[i]; |
| 47 | 24 |
result = CustomPropertyEditorManager.findEditor(current); |
| 48 | 24 |
if (result != null) |
| 49 |
{
|
|
| 50 | 16 |
PropertyEditorManager.registerEditor(clazz, result.getClass()); |
| 51 | 16 |
break;
|
| 52 |
} |
|
| 53 |
} |
|
| 54 |
} |
|
| 55 |
|
|
| 56 | 64 |
return result;
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
/** Add a new package for the search */
|
|
| 60 |
static
|
|
| 61 |
{
|
|
| 62 | 8 |
String[] paths = PropertyEditorManager.getEditorSearchPath(); |
| 63 | 8 |
Vector newPaths = new Vector();
|
| 64 | 8 |
newPaths.addAll(Arrays.asList(paths)); |
| 65 | 8 |
if (!newPaths.contains(EDITORS_PACKAGE))
|
| 66 |
{
|
|
| 67 | 8 |
newPaths.add(EDITORS_PACKAGE); |
| 68 |
} |
|
| 69 | 8 |
PropertyEditorManager.setEditorSearchPath((String[]) newPaths.toArray(new String[0]));
|
| 70 |
} |
|
| 71 |
} |
|
| 72 |
|
|
||||||||||