1/*2 * Copyright 2000-2001,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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.om.registry.base;
1819import org.apache.jetspeed.om.registry.CapabilityMap;
20import java.util.Vector;
21import java.util.Iterator;
2223/***24 * Simple bean-like implementation of the CapabilityMap25 *26 * @author <a href="shesmer@raleigh.ibm.com">Stephan Hesmer</a>27 * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>28 * @version $Id: BaseCapabilityMap.java,v 1.3 2004/02/23 03:08:26 jford Exp $29 */30publicclassBaseCapabilityMap implements CapabilityMap, java.io.Serializable
31 {
32private Vector caps = new Vector();
3334publicBaseCapabilityMap()
35 {
36 }
3738/***39 * Implements the equals operation so that 2 elements are equal if40 * all their member values are equal.41 */42publicboolean equals(Object object)
43 {
44if (object==null)
45 {
46return false;
47 }
4849BaseCapabilityMap obj = (BaseCapabilityMap)object;
5051 Iterator i = caps.iterator();
52 Iterator i2 = obj.caps.iterator();
53while(i.hasNext())
54 {
55 String c1 = (String)i.next();
56 String c2 = null;
5758if (i2.hasNext())
59 {
60 c2 = (String)i2.next();
61 }
62else63 {
64return false;
65 }
6667if (!c1.equals(c2))
68 {
69return false;
70 }
71 }
7273if (i2.hasNext())
74 {
75return false;
76 }
7778returntrue;
79 }
8081public Iterator getCapabilities()
82 {
83return caps.iterator();
84 }
8586publicvoid addCapability(String name)
87 {
88if (!caps.contains(name))
89 {
90 caps.add(name);
91 }
92 }
9394publicvoid removeCapability(String name)
95 {
96 caps.remove(name);
97 }
9899/***100 * Checks if the argument capability is included in this map101 *102 * @param capabiltiy a capability descriptor103 * @return true if the capability is supported104 */105publicboolean contains(String capability)
106 {
107return caps.contains(capability);
108 }
109110/***111 * Checks if the all the elements of argument capability map112 * are included in the current one113 *114 * @param map a CapabilityMap implementation to test115 * @return true is all the elements the argument map are included in the116 * current map.117 */118publicboolean containsAll(CapabilityMap map)
119 {
120 Iterator i = map.getCapabilities();
121122while(i.hasNext())
123 {
124 String capability = (String)i.next();
125if (!contains(capability))
126 {
127return false;
128 }
129 }
130131returntrue;
132 }
133134// castor related method definitions135136public Vector getCaps()
137 {
138return caps;
139 }
140141 }