001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.om.impl;
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Iterator;
023:
024: //TODO: import org.apache.jetspeed.exception.JetspeedRuntimeException;
025: import org.apache.jetspeed.om.common.ParameterComposite;
026: import org.apache.pluto.om.common.Parameter;
027: import org.apache.pluto.om.common.ParameterSet;
028: import org.apache.pluto.om.common.ParameterSetCtrl;
029:
030: /**
031: *
032: * ParameterSetImpl
033: *
034: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
035: * @version $Id: ParameterSetImpl.java 516448 2007-03-09 16:25:47Z ate $
036: *
037: */
038: public abstract class ParameterSetImpl implements ParameterSet,
039: ParameterSetCtrl, Serializable {
040: protected Collection innerCollection;
041:
042: /**
043: * @param wrappedSet
044: */
045: public ParameterSetImpl(Collection collection) {
046: super ();
047: this .innerCollection = collection;
048: }
049:
050: public ParameterSetImpl() {
051: super ();
052: this .innerCollection = new ArrayList();
053: }
054:
055: /**
056: * @see org.apache.pluto.om.common.ParameterSet#iterator()
057: */
058: public Iterator iterator() {
059: return innerCollection.iterator();
060: }
061:
062: /**
063: * @see org.apache.pluto.om.common.ParameterSet#get(java.lang.String)
064: */
065: public Parameter get(String name) {
066: Iterator itr = innerCollection.iterator();
067: while (itr.hasNext()) {
068: Parameter p = (Parameter) itr.next();
069: if (p.getName().equals(name)) {
070: return p;
071: }
072: }
073:
074: return null;
075: }
076:
077: /**
078: * @see org.apache.pluto.om.common.ParameterSetCtrl#add(java.lang.String, java.lang.String)
079: */
080: public Parameter add(String name, String value) {
081: ParameterComposite p = newParameterInstance();
082: p.setName(name);
083: p.setValue(value);
084: add(p);
085: return p;
086: }
087:
088: /**
089: * @see org.apache.pluto.om.common.ParameterSetCtrl#remove(java.lang.String)
090: */
091: public Parameter remove(String name) {
092: Iterator itr = innerCollection.iterator();
093: Parameter removeMe = null;
094: while (itr.hasNext()) {
095: Parameter p = (Parameter) itr.next();
096: if (p.getName().equals(name)) {
097: removeMe = p;
098: break;
099: }
100: }
101:
102: if (removeMe != null) {
103: innerCollection.remove(removeMe);
104: }
105:
106: return removeMe;
107: }
108:
109: /**
110: * @see org.apache.pluto.om.common.ParameterSetCtrl#remove(org.apache.pluto.om.common.Parameter)
111: */
112: public void remove(Parameter parameter) {
113: remove((Object) parameter);
114: }
115:
116: /**
117: * @see java.util.Collection#add(java.lang.Object)
118: * <strong>NOTE: </code>This method will effectively convert any class
119: * implementing the <code>org.apache.jetspeed.common.ParameterComposite</code>
120: * that is NOT of the type returned by the <code>getParameterClass()</code> method it is
121: * to converted to the correct Parameter implementation.
122: */
123: public boolean add(Object o) {
124: ParameterComposite p = (ParameterComposite) o;
125:
126: return innerCollection.add(p);
127: }
128:
129: /**
130: * @see java.util.Collection#remove(java.lang.Object)
131: */
132: public boolean remove(Object o) {
133: Parameter p = (Parameter) o;
134:
135: return innerCollection.remove(p);
136: }
137:
138: /**
139: * Creates a Parameter class this Collection will be working with.
140: * <br>
141: */
142: protected abstract ParameterComposite newParameterInstance();
143:
144: /**
145: * @return
146: */
147: public Collection getInnerCollection() {
148: return innerCollection;
149: }
150:
151: /**
152: * @param collection
153: */
154: public void setInnerCollection(Collection collection) {
155: innerCollection = collection;
156: }
157:
158: }
|