View Javadoc

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;
21  import java.util.Iterator;
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
31  {
32      private Vector caps = new Vector();
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 object)
43      {
44          if (object==null)
45          {
46              return false;
47          }
48  
49          BaseCapabilityMap obj = (BaseCapabilityMap)object;
50  
51          Iterator i = caps.iterator();
52          Iterator i2 = obj.caps.iterator();
53          while(i.hasNext())
54          {
55              String c1 = (String)i.next();
56              String c2 = null;
57  
58              if (i2.hasNext())
59              {
60                  c2 = (String)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 getCapabilities()
82      {
83          return caps.iterator();
84      }
85  
86      public void addCapability(String name)
87      {
88          if (!caps.contains(name))
89          {
90              caps.add(name);
91          }
92      }
93  
94      public void removeCapability(String 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 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 i = map.getCapabilities();
121 
122         while(i.hasNext())
123         {
124             String capability = (String)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 getCaps()
137     {
138         return caps;
139     }
140 
141 }