KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > pluto > om > common > ParameterSetImpl


1 /*
2  * Copyright 2004,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.pluto.om.common;
17
18 import java.util.HashSet JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 import org.apache.pluto.om.common.Parameter;
22 import org.apache.pluto.om.common.ParameterSet;
23 import org.apache.pluto.om.common.ParameterSetCtrl;
24 import org.apache.pluto.util.StringUtils;
25
26 public class ParameterSetImpl extends HashSet JavaDoc
27 implements ParameterSet, ParameterSetCtrl, java.io.Serializable JavaDoc {
28
29     public ParameterSetImpl() {
30         // nothing to do
31
}
32
33     // ParameterSet implementation.
34

35     public Parameter get(String JavaDoc name) {
36         Iterator JavaDoc iterator = this.iterator();
37         while (iterator.hasNext()) {
38             Parameter parameter = (Parameter)iterator.next();
39             if (parameter.getName().equals(name)) {
40                 return parameter;
41             }
42         }
43         return null;
44     }
45
46     // ParameterSetCtrl implementation.
47

48     public Parameter add(String JavaDoc name, String JavaDoc value) {
49         ParameterImpl parameter = new ParameterImpl();
50         parameter.setName(name);
51         parameter.setValue(value);
52
53         super.add(parameter);
54
55         return parameter;
56     }
57
58     public Parameter remove(String JavaDoc name) {
59         Iterator JavaDoc iterator = this.iterator();
60         while (iterator.hasNext()) {
61             Parameter parameter = (Parameter)iterator.next();
62             if (parameter.getName().equals(name)) {
63                 super.remove(parameter);
64                 return parameter;
65             }
66         }
67         return null;
68     }
69
70     public void remove(Parameter parameter) {
71         super.remove(parameter);
72     }
73
74     // additional methods.
75

76     public String JavaDoc toString() {
77         return toString(0);
78     }
79
80     public String JavaDoc toString(int indent) {
81         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
82         StringUtils.newLine(buffer,indent);
83         buffer.append(getClass().toString());
84         buffer.append(": ");
85         Iterator JavaDoc iterator = this.iterator();
86         while (iterator.hasNext()) {
87             buffer.append(((ParameterImpl)iterator.next()).toString(indent+2));
88         }
89         return buffer.toString();
90     }
91 }
92
Popular Tags