KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > om > registry > base > BaseCapabilityMap


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 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
17 package org.apache.jetspeed.om.registry.base;
18
19 import org.apache.jetspeed.om.registry.CapabilityMap;
20 import java.util.Vector JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 /**
24  * Simple bean-like implementation of the CapabilityMap
25  *
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  */

30 public class BaseCapabilityMap implements CapabilityMap, java.io.Serializable JavaDoc
31 {
32     private Vector JavaDoc caps = new Vector JavaDoc();
33
34     public BaseCapabilityMap()
35     {
36     }
37
38     /**
39      * Implements the equals operation so that 2 elements are equal if
40      * all their member values are equal.
41      */

42     public boolean equals(Object JavaDoc object)
43     {
44         if (object==null)
45         {
46             return false;
47         }
48
49         BaseCapabilityMap obj = (BaseCapabilityMap)object;
50
51         Iterator JavaDoc i = caps.iterator();
52         Iterator JavaDoc i2 = obj.caps.iterator();
53         while(i.hasNext())
54         {
55             String JavaDoc c1 = (String JavaDoc)i.next();
56             String JavaDoc c2 = null;
57
58             if (i2.hasNext())
59             {
60                 c2 = (String JavaDoc)i2.next();
61             }
62             else
63             {
64                 return false;
65             }
66
67             if (!c1.equals(c2))
68             {
69                 return false;
70             }
71         }
72
73         if (i2.hasNext())
74         {
75             return false;
76         }
77
78         return true;
79     }
80
81     public Iterator JavaDoc getCapabilities()
82     {
83         return caps.iterator();
84     }
85
86     public void addCapability(String JavaDoc name)
87     {
88         if (!caps.contains(name))
89         {
90             caps.add(name);
91         }
92     }
93
94     public void removeCapability(String JavaDoc name)
95     {
96         caps.remove(name);
97     }
98
99     /**
100      * Checks if the argument capability is included in this map
101      *
102      * @param capabiltiy a capability descriptor
103      * @return true if the capability is supported
104      */

105     public boolean contains(String JavaDoc capability)
106     {
107         return caps.contains(capability);
108     }
109
110     /**
111      * Checks if the all the elements of argument capability map
112      * are included in the current one
113      *
114      * @param map a CapabilityMap implementation to test
115      * @return true is all the elements the argument map are included in the
116      * current map.
117      */

118     public boolean containsAll(CapabilityMap map)
119     {
120         Iterator JavaDoc i = map.getCapabilities();
121
122         while(i.hasNext())
123         {
124             String JavaDoc capability = (String JavaDoc)i.next();
125             if (!contains(capability))
126             {
127                 return false;
128             }
129         }
130
131         return true;
132     }
133
134     // castor related method definitions
135

136     public Vector JavaDoc getCaps()
137     {
138         return caps;
139     }
140
141 }
142
Popular Tags