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: package org.apache.cocoon.portal.pluto.om.common;
18:
19: import java.util.HashSet;
20: import java.util.Iterator;
21:
22: import org.apache.pluto.om.common.Parameter;
23: import org.apache.pluto.om.common.ParameterSet;
24: import org.apache.pluto.om.common.ParameterSetCtrl;
25: import org.apache.pluto.util.StringUtils;
26:
27: public class ParameterSetImpl extends HashSet implements ParameterSet,
28: ParameterSetCtrl, java.io.Serializable {
29:
30: public ParameterSetImpl() {
31: // nothing to do
32: }
33:
34: // ParameterSet implementation.
35:
36: public Parameter get(String name) {
37: Iterator iterator = this .iterator();
38: while (iterator.hasNext()) {
39: Parameter parameter = (Parameter) iterator.next();
40: if (parameter.getName().equals(name)) {
41: return parameter;
42: }
43: }
44: return null;
45: }
46:
47: // ParameterSetCtrl implementation.
48:
49: public Parameter add(String name, String value) {
50: ParameterImpl parameter = new ParameterImpl();
51: parameter.setName(name);
52: parameter.setValue(value);
53:
54: super .add(parameter);
55:
56: return parameter;
57: }
58:
59: public Parameter remove(String name) {
60: Iterator iterator = this .iterator();
61: while (iterator.hasNext()) {
62: Parameter parameter = (Parameter) iterator.next();
63: if (parameter.getName().equals(name)) {
64: super .remove(parameter);
65: return parameter;
66: }
67: }
68: return null;
69: }
70:
71: public void remove(Parameter parameter) {
72: super .remove(parameter);
73: }
74:
75: // additional methods.
76:
77: public String toString() {
78: return toString(0);
79: }
80:
81: public String toString(int indent) {
82: StringBuffer buffer = new StringBuffer(50);
83: StringUtils.newLine(buffer, indent);
84: buffer.append(getClass().toString());
85: buffer.append(": ");
86: Iterator iterator = this .iterator();
87: while (iterator.hasNext()) {
88: buffer.append(((ParameterImpl) iterator.next())
89: .toString(indent + 2));
90: }
91: return buffer.toString();
92: }
93: }
|