%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.om.impl.ParameterSetImpl |
|
|
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 | package org.apache.jetspeed.om.impl; |
|
18 | ||
19 | import java.io.Serializable; |
|
20 | import java.util.ArrayList; |
|
21 | import java.util.Collection; |
|
22 | import java.util.Iterator; |
|
23 | ||
24 | //TODO: import org.apache.jetspeed.exception.JetspeedRuntimeException; |
|
25 | import org.apache.jetspeed.om.common.ParameterComposite; |
|
26 | import org.apache.pluto.om.common.Parameter; |
|
27 | import org.apache.pluto.om.common.ParameterSet; |
|
28 | import org.apache.pluto.om.common.ParameterSetCtrl; |
|
29 | ||
30 | /** |
|
31 | * |
|
32 | * ParameterSetImpl |
|
33 | * |
|
34 | * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a> |
|
35 | * @version $Id: ParameterSetImpl.java 516448 2007-03-09 16:25:47Z ate $ |
|
36 | * |
|
37 | */ |
|
38 | public abstract class ParameterSetImpl implements ParameterSet, ParameterSetCtrl, Serializable |
|
39 | { |
|
40 | protected Collection innerCollection; |
|
41 | ||
42 | /** |
|
43 | * @param wrappedSet |
|
44 | */ |
|
45 | public ParameterSetImpl(Collection collection) |
|
46 | { |
|
47 | 0 | super(); |
48 | 0 | this.innerCollection = collection; |
49 | 0 | } |
50 | ||
51 | public ParameterSetImpl() |
|
52 | { |
|
53 | 0 | super(); |
54 | 0 | this.innerCollection = new ArrayList(); |
55 | 0 | } |
56 | ||
57 | /** |
|
58 | * @see org.apache.pluto.om.common.ParameterSet#iterator() |
|
59 | */ |
|
60 | public Iterator iterator() |
|
61 | { |
|
62 | 0 | return innerCollection.iterator(); |
63 | } |
|
64 | ||
65 | /** |
|
66 | * @see org.apache.pluto.om.common.ParameterSet#get(java.lang.String) |
|
67 | */ |
|
68 | public Parameter get(String name) |
|
69 | { |
|
70 | 0 | Iterator itr = innerCollection.iterator(); |
71 | 0 | while (itr.hasNext()) |
72 | { |
|
73 | 0 | Parameter p = (Parameter) itr.next(); |
74 | 0 | if (p.getName().equals(name)) |
75 | { |
|
76 | 0 | return p; |
77 | } |
|
78 | 0 | } |
79 | ||
80 | 0 | return null; |
81 | } |
|
82 | ||
83 | /** |
|
84 | * @see org.apache.pluto.om.common.ParameterSetCtrl#add(java.lang.String, java.lang.String) |
|
85 | */ |
|
86 | public Parameter add(String name, String value) |
|
87 | { |
|
88 | 0 | ParameterComposite p = newParameterInstance(); |
89 | 0 | p.setName(name); |
90 | 0 | p.setValue(value); |
91 | 0 | add(p); |
92 | 0 | return p; |
93 | } |
|
94 | ||
95 | /** |
|
96 | * @see org.apache.pluto.om.common.ParameterSetCtrl#remove(java.lang.String) |
|
97 | */ |
|
98 | public Parameter remove(String name) |
|
99 | { |
|
100 | 0 | Iterator itr = innerCollection.iterator(); |
101 | 0 | Parameter removeMe = null; |
102 | 0 | while (itr.hasNext()) |
103 | { |
|
104 | 0 | Parameter p = (Parameter) itr.next(); |
105 | 0 | if (p.getName().equals(name)) |
106 | { |
|
107 | 0 | removeMe = p; |
108 | 0 | break; |
109 | } |
|
110 | 0 | } |
111 | ||
112 | 0 | if (removeMe != null) |
113 | { |
|
114 | 0 | innerCollection.remove(removeMe); |
115 | } |
|
116 | ||
117 | 0 | return removeMe; |
118 | } |
|
119 | ||
120 | /** |
|
121 | * @see org.apache.pluto.om.common.ParameterSetCtrl#remove(org.apache.pluto.om.common.Parameter) |
|
122 | */ |
|
123 | public void remove(Parameter parameter) |
|
124 | { |
|
125 | 0 | remove((Object) parameter); |
126 | 0 | } |
127 | ||
128 | /** |
|
129 | * @see java.util.Collection#add(java.lang.Object) |
|
130 | * <strong>NOTE: </code>This method will effectively convert any class |
|
131 | * implementing the <code>org.apache.jetspeed.common.ParameterComposite</code> |
|
132 | * that is NOT of the type returned by the <code>getParameterClass()</code> method it is |
|
133 | * to converted to the correct Parameter implementation. |
|
134 | */ |
|
135 | public boolean add(Object o) |
|
136 | { |
|
137 | 0 | ParameterComposite p = (ParameterComposite) o; |
138 | ||
139 | 0 | return innerCollection.add(p); |
140 | } |
|
141 | ||
142 | /** |
|
143 | * @see java.util.Collection#remove(java.lang.Object) |
|
144 | */ |
|
145 | public boolean remove(Object o) |
|
146 | { |
|
147 | 0 | Parameter p = (Parameter) o; |
148 | ||
149 | 0 | return innerCollection.remove(p); |
150 | } |
|
151 | ||
152 | /** |
|
153 | * Creates a Parameter class this Collection will be working with. |
|
154 | * <br> |
|
155 | */ |
|
156 | protected abstract ParameterComposite newParameterInstance(); |
|
157 | ||
158 | /** |
|
159 | * @return |
|
160 | */ |
|
161 | public Collection getInnerCollection() |
|
162 | { |
|
163 | 0 | return innerCollection; |
164 | } |
|
165 | ||
166 | /** |
|
167 | * @param collection |
|
168 | */ |
|
169 | public void setInnerCollection(Collection collection) |
|
170 | { |
|
171 | 0 | innerCollection = collection; |
172 | 0 | } |
173 | ||
174 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |