01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * 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 and
15: * limitations under the License.
16: */
17: /**
18: * Created on Jan 13, 2004
19: *
20: *
21: * @author
22: */package org.apache.jetspeed.deployment.simpleregistry.impl;
23:
24: import java.util.Collection;
25: import java.util.HashMap;
26: import java.util.Map;
27:
28: import org.apache.jetspeed.deployment.simpleregistry.Entry;
29: import org.apache.jetspeed.deployment.simpleregistry.SimpleRegistry;
30: import org.apache.jetspeed.deployment.simpleregistry.SimpleRegistryException;
31:
32: /**
33: * <p>
34: * InMemoryRegistryImpl
35: * </p>
36: *
37: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
38: * @version $Id: InMemoryRegistryImpl.java 516881 2007-03-11 10:34:21Z ate $
39: *
40: */
41: public class InMemoryRegistryImpl implements SimpleRegistry {
42: protected Map registry;
43:
44: public InMemoryRegistryImpl() {
45: super ();
46: registry = new HashMap();
47: }
48:
49: /**
50: * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#register(org.apache.jetspeed.cps.simpleregistry.Entry)
51: */
52: public void register(Entry entry) throws SimpleRegistryException {
53: checkArguments(entry);
54: if (!isRegistered(entry)) {
55: registry.put(entry.getId(), entry);
56: } else {
57: throw new SimpleRegistryException(entry.getId()
58: + " is already registered.");
59: }
60:
61: }
62:
63: /**
64: * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#deRegister(org.apache.jetspeed.cps.simpleregistry.Entry)
65: */
66: public void deRegister(Entry entry) {
67: checkArguments(entry);
68: registry.remove(entry.getId());
69:
70: }
71:
72: /**
73: * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#isRegistered(org.apache.jetspeed.cps.simpleregistry.Entry)
74: */
75: public boolean isRegistered(Entry entry) {
76: checkArguments(entry);
77: return registry.containsKey(entry.getId());
78: }
79:
80: /**
81: * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#getRegistry()
82: */
83: public Collection getRegistry() {
84: return registry.values();
85: }
86:
87: protected void checkArguments(Entry entry) {
88: if (entry == null) {
89: throw new IllegalArgumentException("Entry cannot be null.");
90: }
91:
92: if (entry.getId() == null) {
93: throw new IllegalArgumentException(
94: "Entry.getId() cannot be null.");
95: }
96: }
97:
98: }
|