1 package org.apache.log4j.chainsaw.favourites;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.List;
7
8 /***
9 * A singleton class that is used as a Registry of instances of JavaBeans
10 * that are in a state that a user prefers.
11 *
12 * @author Paul Smith <psmith@apache.org>
13 *
14 */
15 public class FavouritesRegistry{
16
17 private final List favourites = new ArrayList();
18
19 /***
20 * Returns a Collection of Favourite instances whose getPrototype() method
21 * returns an object whose class is assignable from clazz, or more formally, such that
22 * clazz.isAssignableFrom(favourite.getPrototype().getClass())
23 * @param clazz
24 * @return favourites
25 */
26 public synchronized Collection getFavouritesByClass(Class clazz) {
27 throw new UnsupportedOperationException("Work In Progress");
28 }
29
30 /***
31 * Adds a favourite to this Registry
32 * @param favourite
33 */
34
35 public synchronized void addFavourite(Favourite favourite) {
36 throw new UnsupportedOperationException("Work In Progress");
37 }
38
39 /***
40 * Returns an unmodifiable List of all the known Favourite instances
41 * @return favourites
42 */
43 public List getFavourites() {
44 return Collections.unmodifiableList(favourites);
45 }
46
47 /***
48 * Creates a new Favourite instance after running throught some
49 * suitability checks to make sure the object class is ok to be used
50 * as a prototype.
51 *
52 * @param name The name to use for the favourite
53 * @param prototype The object to register
54 * @throws IllegalArgumentException if the prototype does not conform
55 * to the necessary rules to be used as a prototype (see the package documentation).
56 *
57 */
58 public void addFavourite(String name, Object prototype) {
59 favourites.add(createFavourite(name, prototype));
60 }
61
62 private Favourite createFavourite(String name, Object prototype) {
63 checkSuitability(prototype);
64 return new Favourite(name, prototype);
65 }
66
67 /***
68 * Checks the suitability of an object to make sure it conforms to all the rules
69 * for being a prototype,
70 * @param prototype
71 * @throws IllegalArgumentException if the prototype is not suitable
72 */
73 private void checkSuitability(Object prototype) throws IllegalArgumentException{
74
75 throw new UnsupportedOperationException("Work in Progress");
76 }
77
78 private FavouritesRegistry() {
79
80 }
81 }