View Javadoc

1   package fr.ove.utils;
2   
3   import java.util.*;
4   
5   /***
6   * A repository of the main objects used by the programm.
7   * <P>
8   * It is used as a repository of the different objects created that are
9   * supposed to be used (listener registering, ...) by other objects.
10  * Provide a convenient way to give the reference of objects to an another one. 
11  * Rather than explicitly pass the reference to objects needed, pass the
12  * instance. The needed references are then obtains via a name that identifies
13  * the different objects.
14  */
15  public class ObjectsRepository {
16      /***
17      * The repository
18      */
19      private Hashtable repository;
20      
21      /***
22      * The Constructor.
23      */
24      public ObjectsRepository() {
25          repository = new Hashtable();
26      }
27      
28      /***
29      * Puts an object with the specified name idenfier in the repository.
30      * @param object the object to add.
31      * @param name the name that identifies the object.
32      */
33      public Object putObject(Object object, String name) {
34          return repository.put(name, object);
35      }
36      
37      /***
38      * Gets the object with  the specified name indentifier in the repository.
39      * @param name the name that identifies the object.
40      */
41      public Object getObject(String name) {
42          return repository.get(name);
43      }
44      
45      /***
46      * Remove the object with the specified name identifier from  the repository.
47      * @param name the name that identifies the object.
48      */
49      public Object removeObject(String name) {
50          return repository.remove(name);
51      }
52      
53      /***
54      * Gets the repository.
55      */
56      public Hashtable getRepository() {
57          return repository;
58      }
59  }