1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 /***
18 * Created on Jan 13, 2004
19 *
20 *
21 * @author
22 */
23 package org.apache.jetspeed.deployment.simpleregistry.impl;
24
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import org.apache.jetspeed.deployment.simpleregistry.Entry;
30 import org.apache.jetspeed.deployment.simpleregistry.SimpleRegistry;
31 import org.apache.jetspeed.deployment.simpleregistry.SimpleRegistryException;
32
33 /***
34 * <p>
35 * InMemoryRegistryImpl
36 * </p>
37 *
38 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
39 * @version $Id: InMemoryRegistryImpl.java 516881 2007-03-11 10:34:21Z ate $
40 *
41 */
42 public class InMemoryRegistryImpl implements SimpleRegistry
43 {
44 protected Map registry;
45
46 public InMemoryRegistryImpl()
47 {
48 super();
49 registry = new HashMap();
50 }
51
52 /***
53 * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#register(org.apache.jetspeed.cps.simpleregistry.Entry)
54 */
55 public void register(Entry entry) throws SimpleRegistryException
56 {
57 checkArguments(entry);
58 if(!isRegistered(entry))
59 {
60 registry.put(entry.getId(), entry);
61 }
62 else
63 {
64 throw new SimpleRegistryException(entry.getId()+" is already registered.");
65 }
66
67 }
68
69 /***
70 * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#deRegister(org.apache.jetspeed.cps.simpleregistry.Entry)
71 */
72 public void deRegister(Entry entry)
73 {
74 checkArguments(entry);
75 registry.remove(entry.getId());
76
77 }
78
79 /***
80 * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#isRegistered(org.apache.jetspeed.cps.simpleregistry.Entry)
81 */
82 public boolean isRegistered(Entry entry)
83 {
84 checkArguments(entry);
85 return registry.containsKey(entry.getId());
86 }
87
88 /***
89 * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#getRegistry()
90 */
91 public Collection getRegistry()
92 {
93 return registry.values();
94 }
95
96 protected void checkArguments(Entry entry)
97 {
98 if(entry == null )
99 {
100 throw new IllegalArgumentException("Entry cannot be null.");
101 }
102
103 if(entry.getId() == null )
104 {
105 throw new IllegalArgumentException("Entry.getId() cannot be null.");
106 }
107 }
108
109 }