KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > person > search > PersonSearchFilterItemEditorHelperRegistry


1 /*
2  * Created on Dec 16, 2004
3  * by alex
4  *
5  */

6 package com.nightlabs.ipanema.person.search;
7
8 import java.util.HashMap JavaDoc;
9 import java.util.Map JavaDoc;
10
11 /**
12  * This registry holds PersonSearchFilterItemEditorHelper
13  * linked to classes of PersonStructFields.
14  *
15  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
16  */

17 public class PersonSearchFilterItemEditorHelperRegistry {
18
19     /**
20      * key: Class AbstractPersonStructFieldClass<br/>
21      * value: PersonSearchFilterItemEditorHelper personSearchFilterItemEditorHelper<br/>
22      */

23     private Map JavaDoc itemEditorHelpers = new HashMap JavaDoc();
24     
25     /**
26      * Adds a PersonSearchFilterItemEditorHelper linked to the
27      * given class name to the registry.
28      *
29      * @param itemClassName
30      * @param itemEditor
31      */

32     public void addItemEditor(Class JavaDoc structFieldClass, PersonSearchFilterItemEditorHelper editorHelper) {
33         itemEditorHelpers.put(structFieldClass,editorHelper);
34     }
35     
36     /**
37      * Removes the PersonSearchFilterItemEditorHelper from the
38      * registry.
39      *
40      * @param itemClassName
41      */

42     public void removeItemEditor(Class JavaDoc structFieldClass) {
43         if (!itemEditorHelpers.containsKey(structFieldClass))
44             return;
45         itemEditorHelpers.remove(structFieldClass);
46     }
47     
48     
49     /**
50      * Returns a new instance of a PersonSearchFilterItemEditorHelper.
51      *
52      * @param searchFieldClass
53      * @return
54      * @throws SearchFilterItemEditorNotFoundException
55      */

56     public PersonSearchFilterItemEditorHelper getEditorHelper(Class JavaDoc structFieldClass)
57     throws PersonSearchFilterItemEditorHelperNotFoundException {
58         PersonSearchFilterItemEditorHelper editorHelper = (PersonSearchFilterItemEditorHelper)itemEditorHelpers.get(structFieldClass);
59         if (editorHelper != null)
60             return editorHelper.newInstance();
61         else
62             throw new PersonSearchFilterItemEditorHelperNotFoundException("Registry does not contain an entry for "+structFieldClass.getName());
63     }
64     
65     
66     private static PersonSearchFilterItemEditorHelperRegistry sharedInstance;
67     
68     public static PersonSearchFilterItemEditorHelperRegistry getSharedInstance() {
69         if (sharedInstance == null) {
70             sharedInstance = new PersonSearchFilterItemEditorHelperRegistry();
71         }
72         return sharedInstance;
73     }
74
75 }
76
Popular Tags