KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > formview > permission > AbstractRolesPermissionsAdapter


1 package net.sourceforge.formview.permission;
2
3 import net.sourceforge.formview.FieldView;
4 import net.sourceforge.formview.FormViewConstants;
5 import net.sourceforge.formview.RoleDefinition;
6
7 /**
8  * Description : abstract role persmission adapater.
9  *
10  * @version 1.0.0
11  * @author <a HREF="mailto:angelo.zerr@gmail.com">Angelo ZERR</a>
12  *
13  */

14 public abstract class AbstractRolesPermissionsAdapter implements IPermissionsAdapter {
15
16    
17     public String JavaDoc getBehaviour(FieldView field, String JavaDoc defaultBehaviour, RoleDefinition roleDefinition) {
18         if (field == null || roleDefinition == null)
19             return null;
20         String JavaDoc roleBehaviour = null;
21         String JavaDoc[] fieldRoles = field.getRolesArray();
22         String JavaDoc[] roleDefinitionBehaviours = roleDefinition.getBehavioursArray();
23         if (fieldRoles != null && roleDefinitionBehaviours != null) {
24             // Loop for roles definition
25
int roleDeflength = roleDefinitionBehaviours.length;
26             int fieldRolelength = fieldRoles.length;
27             String JavaDoc role = null;
28             for(int i=0; i< roleDeflength; i++) {
29                 roleBehaviour = roleDefinitionBehaviours[i];
30                 if (fieldRolelength > i) {
31                     role = fieldRoles[i];
32                     // Test if user has role
33
if (hasRole(role)) {
34                         // User has role
35
// Test overloadedBy type (field or role)
36
String JavaDoc overloadedBy = roleDefinition.getOverloadedBy();
37                         if (FormViewConstants.ROLEDEF_OVERLOADED_BY_FIELD.equalsIgnoreCase(overloadedBy)) {
38                             // Test if level of field >= level of role
39
// Level of role behaviour
40
int levelRoleBehaviour = roleDefinition.getBehaviourLevel(roleBehaviour);
41                             // Level of field behaviour
42
String JavaDoc fieldBehaviour = field.getBehaviour();
43                             if (fieldBehaviour == null)
44                                 fieldBehaviour = defaultBehaviour;
45                             int levelFieldBehaviour = roleDefinition.getBehaviourLevel(fieldBehaviour);
46                             if (levelRoleBehaviour <= levelFieldBehaviour) {
47                                 return fieldBehaviour;
48                             }
49                         }
50                         return roleBehaviour;
51                     }
52                 }
53                 else {
54                     break;
55                 }
56             }
57         }
58         return roleBehaviour;
59     }
60     
61     public abstract boolean hasRole(String JavaDoc role);
62     
63     
64 }
65
Popular Tags