%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.deployment.simpleregistry.impl.InMemoryRegistryImpl |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * 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 | */ |
|
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 | 0 | super(); |
49 | 0 | registry = new HashMap(); |
50 | 0 | } |
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 | 0 | checkArguments(entry); |
58 | 0 | if(!isRegistered(entry)) |
59 | { |
|
60 | 0 | registry.put(entry.getId(), entry); |
61 | } |
|
62 | else |
|
63 | { |
|
64 | 0 | throw new SimpleRegistryException(entry.getId()+" is already registered."); |
65 | } |
|
66 | ||
67 | 0 | } |
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 | 0 | checkArguments(entry); |
75 | 0 | registry.remove(entry.getId()); |
76 | ||
77 | 0 | } |
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 | 0 | checkArguments(entry); |
85 | 0 | return registry.containsKey(entry.getId()); |
86 | } |
|
87 | ||
88 | /** |
|
89 | * @see org.apache.jetspeed.cps.simpleregistry.SimpleRegistry#getRegistry() |
|
90 | */ |
|
91 | public Collection getRegistry() |
|
92 | { |
|
93 | 0 | return registry.values(); |
94 | } |
|
95 | ||
96 | protected void checkArguments(Entry entry) |
|
97 | { |
|
98 | 0 | if(entry == null ) |
99 | { |
|
100 | 0 | throw new IllegalArgumentException("Entry cannot be null."); |
101 | } |
|
102 | ||
103 | 0 | if(entry.getId() == null ) |
104 | { |
|
105 | 0 | throw new IllegalArgumentException("Entry.getId() cannot be null."); |
106 | } |
|
107 | 0 | } |
108 | ||
109 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |