1 package ch.odi.justblog.api;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 /***
7 * This is a blog entry as featured by JustBlog. Blog APIs can extend this entry
8 * by adding extensions (see Extension Object pattern).
9 *
10 * @author oglueck
11 */
12 public class Entry {
13 private String text;
14 private Map extensions = new HashMap();
15
16 /***
17 * Gets the extension that implements a certain interface.
18 * @param clazz meta object of an interface.
19 * @return an object implementing <code>clazz</code> or <code>null</code>.
20 */
21 public Object getExtension(Class clazz) {
22 if (!clazz.isInterface()) throw new IllegalArgumentException("clazz must be an interface");
23 return extensions.get(clazz);
24 }
25
26 /***
27 * Registers an extension under all the interfaces
28 * the extension implements.
29 * @param extension
30 */
31 public void addExtension(Object extension) {
32 Class c = extension.getClass();
33 Class[] ifs = c.getInterfaces();
34 for (int i = 0; i < ifs.length; i++) {
35 extensions.put(ifs[i], extension);
36 }
37 }
38
39 /***
40 * @return Returns the text.
41 */
42 public String getText() {
43 return text;
44 }
45
46 /***
47 * @param text The text to set.
48 */
49 public void setText(String text) {
50 this.text = text;
51 }
52 }