1/*2* Licensed to the Apache Software Foundation (ASF) under one or more3* contributor license agreements. See the NOTICE file distributed with4* this work for additional information regarding copyright ownership.5* The ASF licenses this file to You under the Apache License, Version 2.06* (the "License"); you may not use this file except in compliance with7* the License. You may obtain a copy of the License at8*9* http://www.apache.org/licenses/LICENSE-2.010*11* Unless required by applicable law or agreed to in writing, software12* distributed under the License is distributed on an "AS IS" BASIS,13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14* See the License for the specific language governing permissions and15* limitations under the License.16*/17/***18 * Created on Jan 13, 200419 *20 * 21 * @author22 */23packageorg.apache.jetspeed.deployment.simpleregistry.impl;
2425import java.util.Collection;
26import java.util.HashMap;
27import java.util.Map;
2829import org.apache.jetspeed.deployment.simpleregistry.Entry;
30import org.apache.jetspeed.deployment.simpleregistry.SimpleRegistry;
31import org.apache.jetspeed.deployment.simpleregistry.SimpleRegistryException;
3233/***34 * <p>35 * InMemoryRegistryImpl36 * </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 */42publicclassInMemoryRegistryImpl implements SimpleRegistry43 {
44protected Map registry;
4546publicInMemoryRegistryImpl()
47 {
48super();
49 registry = new HashMap();
50 }
5152/***53 * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#register(org.apache.jetspeed.cps.simpleregistry.Entry)54 */55publicvoid register(Entry entry) throws SimpleRegistryException
56 {
57 checkArguments(entry);
58if(!isRegistered(entry))
59 {
60 registry.put(entry.getId(), entry);
61 }
62else63 {
64thrownewSimpleRegistryException(entry.getId()+" is already registered.");
65 }
6667 }
6869/***70 * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#deRegister(org.apache.jetspeed.cps.simpleregistry.Entry)71 */72publicvoid deRegister(Entry entry)
73 {
74 checkArguments(entry);
75 registry.remove(entry.getId());
7677 }
7879/***80 * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#isRegistered(org.apache.jetspeed.cps.simpleregistry.Entry)81 */82publicboolean isRegistered(Entry entry)
83 {
84 checkArguments(entry);
85return registry.containsKey(entry.getId());
86 }
8788/***89 * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#getRegistry()90 */91public Collection getRegistry()
92 {
93return registry.values();
94 }
9596protectedvoid checkArguments(Entry entry)
97 {
98if(entry == null )
99 {
100thrownew IllegalArgumentException("Entry cannot be null.");
101 }
102103if(entry.getId() == null )
104 {
105thrownew IllegalArgumentException("Entry.getId() cannot be null.");
106 }
107 }
108109 }