This project has retired. For details please refer to its Attic page.
MemoryRole xref
View Javadoc

1   package org.apache.archiva.redback.rbac.memory;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.archiva.redback.rbac.AbstractRole;
23  import org.apache.archiva.redback.rbac.Permission;
24  import org.apache.archiva.redback.rbac.Role;
25  
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  /**
30   * MemoryRole
31   *
32   * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
33   *
34   */
35  public class MemoryRole
36      extends AbstractRole
37      implements Role, java.io.Serializable
38  {
39  
40      /**
41       * Field name
42       */
43      private String name;
44  
45      /**
46       * Field description
47       */
48      private String description;
49  
50      /**
51       * Field assignable
52       */
53      private boolean assignable = false;
54  
55      /**
56       * Field childRoleNames
57       */
58      private List<String> childRoleNames = new ArrayList<String>( 0 );
59  
60      /**
61       * Field permissions
62       */
63      private List<Permission> permissions = new ArrayList<Permission>( 0 );
64  
65      /**
66       * Field permanent
67       */
68      private boolean permanent = false;
69  
70      /**
71       * Method addPermission
72       *
73       * @param memoryPermission
74       */
75      public void addPermission( Permission memoryPermission )
76      {
77          if ( !( memoryPermission instanceof MemoryPermission ) )
78          {
79              throw new ClassCastException( "MemoryRole.addPermissions(memoryPermission) parameter must be instanceof "
80                                                + MemoryPermission.class.getName() );
81          }
82          getPermissions().add( memoryPermission );
83      }
84  
85      /**
86       * Method equals
87       *
88       * @param other
89       */
90      public boolean equals( Object other )
91      {
92          if ( this == other )
93          {
94              return true;
95          }
96  
97          if ( !( other instanceof MemoryRole ) )
98          {
99              return false;
100         }
101 
102         MemoryRole that = (MemoryRole) other;
103         boolean result = true;
104         result = result && ( getName() == null ? that.getName() == null : getName().equals( that.getName() ) );
105         return result;
106     }
107 
108     /**
109      * Method getChildRoles
110      */
111     public List<String> getChildRoleNames()
112     {
113         return this.childRoleNames;
114     }
115 
116     /**
117      * Get null
118      */
119     public String getDescription()
120     {
121         return this.description;
122     }
123 
124     /**
125      * Get null
126      */
127     public String getName()
128     {
129         return this.name;
130     }
131 
132     /**
133      * Method getPermissions
134      */
135     public List<Permission> getPermissions()
136     {
137         return this.permissions;
138     }
139 
140     /**
141      * Method hashCode
142      */
143     public int hashCode()
144     {
145         int result = 17;
146         result = 37 * result + ( name != null ? name.hashCode() : 0 );
147         return result;
148     }
149 
150     /**
151      * Get
152      * true if this role is available to be assigned to
153      * a user
154      */
155     public boolean isAssignable()
156     {
157         return this.assignable;
158     }
159 
160     /**
161      * Method removePermission
162      *
163      * @param memoryPermission
164      */
165     public void removePermission( Permission memoryPermission )
166     {
167         if ( !( memoryPermission instanceof MemoryPermission ) )
168         {
169             throw new ClassCastException( "MemoryRole.removePermissions(memoryPermission) parameter must be instanceof "
170                                               + MemoryPermission.class.getName() );
171         }
172         getPermissions().remove( memoryPermission );
173     }
174 
175     /**
176      * Set
177      * true if this role is available to be assigned to
178      * a user
179      *
180      * @param assignable
181      */
182     public void setAssignable( boolean assignable )
183     {
184         this.assignable = assignable;
185     }
186 
187     /**
188      * Set null
189      *
190      * @param description
191      */
192     public void setDescription( String description )
193     {
194         this.description = description;
195     }
196 
197     /**
198      * Set null
199      *
200      * @param name
201      */
202     public void setName( String name )
203     {
204         this.name = name;
205     }
206 
207     /**
208      * Set null
209      *
210      * @param permissions
211      */
212     public void setPermissions( List<Permission> permissions )
213     {
214         this.permissions = permissions;
215     }
216 
217     /**
218      * Method toString
219      */
220     public java.lang.String toString()
221     {
222         StringBuilder buf = new StringBuilder();
223         buf.append( "name = '" );
224         buf.append( getName() + "'" );
225         return buf.toString();
226     }
227 
228     public void addChildRoleName( String name )
229     {
230         this.childRoleNames.add( name );
231     }
232 
233     public void setChildRoleNames( List<String> names )
234     {
235         if ( names == null )
236         {
237             this.childRoleNames.clear();
238         }
239         else
240         {
241             this.childRoleNames = names;
242         }
243     }
244 
245     public boolean isPermanent()
246     {
247         return permanent;
248     }
249 
250     public void setPermanent( boolean permanent )
251     {
252         this.permanent = permanent;
253     }
254 }