Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BasePropertyHolder |
|
| 3.25;3.25 |
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.util; | |
16 | ||
17 | import java.util.*; | |
18 | ||
19 | /** | |
20 | * Base class implementation for the {@link IPropertyHolder} interface. | |
21 | * | |
22 | * | |
23 | * @author Howard Lewis Ship | |
24 | * | |
25 | */ | |
26 | ||
27 | 0 | public class BasePropertyHolder implements IPropertyHolder |
28 | { | |
29 | private static final int MAP_SIZE = 7; | |
30 | private Map properties; | |
31 | ||
32 | public String getProperty(String name) | |
33 | { | |
34 | 0 | if (properties == null) |
35 | 0 | return null; |
36 | ||
37 | 0 | return (String) properties.get(name); |
38 | } | |
39 | ||
40 | public void setProperty(String name, String value) | |
41 | { | |
42 | 0 | if (value == null) |
43 | { | |
44 | 0 | removeProperty(name); |
45 | 0 | return; |
46 | } | |
47 | ||
48 | 0 | if (properties == null) |
49 | 0 | properties = new HashMap(MAP_SIZE); |
50 | ||
51 | 0 | properties.put(name, value); |
52 | 0 | } |
53 | ||
54 | public void removeProperty(String name) | |
55 | { | |
56 | 0 | if (properties == null) |
57 | 0 | return; |
58 | ||
59 | 0 | properties.remove(name); |
60 | 0 | } |
61 | ||
62 | public List getPropertyNames() | |
63 | { | |
64 | 0 | if (properties == null) |
65 | 0 | return Collections.EMPTY_LIST; |
66 | ||
67 | 0 | List result = new ArrayList(properties.keySet()); |
68 | ||
69 | 0 | Collections.sort(result); |
70 | ||
71 | 0 | return result; |
72 | } | |
73 | ||
74 | } |