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  // Java imports
20  import java.util.Vector;
21  import java.util.Iterator;
22  
23  // Jetspeed imports
24  import org.apache.jetspeed.om.registry.SecurityAccess;
25  import org.apache.jetspeed.om.registry.SecurityAllow;
26  
27  /***
28   * Interface for manipulatin the Security Access on the registry entries
29   *
30   * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>
31   * @version $Id: BaseSecurityAccess.java,v 1.11 2004/02/23 03:08:26 jford Exp $
32   */
33  public class BaseSecurityAccess implements SecurityAccess, java.io.Serializable
34  {
35  
36      /*** Holds value of property action. */
37      private String action;
38  
39      /*** Holds value of property allows. */
40      private Vector allows = new Vector();
41  
42      /*** Holds value of property ownerAllows. */
43      private Vector ownerAllows = new Vector();
44  
45      /*** Holds the combination of allows and ownerAllows. */
46      private transient Vector allAllows = new Vector();
47  
48      /*** Creates new BaseSecurityAccess */
49      public BaseSecurityAccess()
50      {
51      }
52  
53      /***
54       * Implements the equals operation so that 2 elements are equal if
55       * all their member values are equal.
56       */
57      public boolean equals(Object object)
58      {
59          if (object == null || !(object instanceof SecurityAccess))
60          {
61              return false;
62          }
63  
64          SecurityAccess obj = (SecurityAccess) object;
65  
66          if (action != null)
67          {
68              if (!action.equals(obj.getAction()))
69              {
70                  return false;
71              }
72          }
73          else
74          {
75              if (obj.getAction() != null)
76              {
77                  return false;
78              }
79          }
80  
81          Iterator i = allows.iterator();
82          Iterator i2 = obj.getAllows().iterator();
83          while (i.hasNext())
84          {
85              SecurityAllow c1 = (SecurityAllow) i.next();
86              SecurityAllow c2 = null;
87  
88              if (i2.hasNext())
89              {
90                  c2 = (SecurityAllow) i2.next();
91              }
92              else
93              {
94                  return false;
95              }
96  
97              if (!c1.equals(c2))
98              {
99                  return false;
100             }
101         }
102 
103         if (i2.hasNext())
104         {
105             return false;
106         }
107 
108         i = ownerAllows.iterator();
109         i2 = obj.getOwnerAllows().iterator();
110         while (i.hasNext())
111         {
112             BaseSecurityAllowOwner c1 = (BaseSecurityAllowOwner) i.next();
113             BaseSecurityAllowOwner c2 = null;
114 
115             if (i2.hasNext())
116             {
117                 c2 = (BaseSecurityAllowOwner) i2.next();
118             }
119             else
120             {
121                 return false;
122             }
123 
124             if (!c1.equals(c2))
125             {
126                 return false;
127             }
128         }
129 
130         if (i2.hasNext())
131         {
132             return false;
133         }
134 
135         return true;
136     }
137 
138     /*** Getter for property action.
139      * @return Value of property action.
140      */
141     public String getAction()
142     {
143         return action;
144     }
145 
146     /*** Setter for property action.
147      * @param action New value of property action.
148      */
149     public void setAction(String action)
150     {
151         this.action = action;
152     }
153 
154     /*** Getter for property allows.
155      * @return Value of property allows.
156      */
157     public Vector getAllows()
158     {
159         if (allows == null)
160         {
161             allows = new Vector();
162         }
163         return allows;
164     }
165 
166     /*** Setter for property allows.
167      * @param allows New value of property allows.
168      */
169     public void setAllows(Vector allows)
170     {
171         this.allows = allows;
172         if (this.allAllows != null)
173         {
174             allAllows.removeAllElements();
175         }
176     }
177 
178     /*** Getter for property ownerAllows.
179      * @return Value of property ownerAllows.
180      */
181     public Vector getOwnerAllows()
182     {
183         if (ownerAllows == null)
184         {
185             ownerAllows = new Vector();
186         }
187         return this.ownerAllows;
188     }
189 
190     /*** Setter for property ownerAllows.
191      * @param ownerAllows New value of property ownerAllows.
192      */
193     public void setOwnerAllows(Vector ownerAllows)
194     {
195         this.ownerAllows = ownerAllows;
196         if (this.allAllows != null)
197         {
198             allAllows.removeAllElements();
199         }
200     }
201 
202     /***
203      * Return a vector contain all allows elements.  If the vector is null
204      * or empty, then create and populate it with elements from the allows
205      * and ownerAllows vectors.
206      *
207      * @return vector containing all allows
208      */
209     public Vector getAllAllows()
210     {
211         int elementCount = 0;
212         if (this.allAllows == null)
213         {
214             allAllows = new Vector();
215         }
216 
217         if (allAllows.isEmpty() == true)
218         {
219             if (this.allows != null)
220             {
221                 elementCount += this.allows.size();
222                 allAllows.ensureCapacity(elementCount);
223                 allAllows.addAll(this.allows);
224             }
225 
226             if (this.ownerAllows != null)
227             {
228                 elementCount += this.ownerAllows.size();
229                 allAllows.ensureCapacity(elementCount);
230                 allAllows.addAll(this.ownerAllows);
231             }
232         }
233         return this.allAllows;
234     }
235 }