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 14 public abstract class AbstractRolesPermissionsAdapter implements IPermissionsAdapter { 15 16 17 public String getBehaviour(FieldView field, String defaultBehaviour, RoleDefinition roleDefinition) { 18 if (field == null || roleDefinition == null) 19 return null; 20 String roleBehaviour = null; 21 String [] fieldRoles = field.getRolesArray(); 22 String [] roleDefinitionBehaviours = roleDefinition.getBehavioursArray(); 23 if (fieldRoles != null && roleDefinitionBehaviours != null) { 24 int roleDeflength = roleDefinitionBehaviours.length; 26 int fieldRolelength = fieldRoles.length; 27 String role = null; 28 for(int i=0; i< roleDeflength; i++) { 29 roleBehaviour = roleDefinitionBehaviours[i]; 30 if (fieldRolelength > i) { 31 role = fieldRoles[i]; 32 if (hasRole(role)) { 34 String overloadedBy = roleDefinition.getOverloadedBy(); 37 if (FormViewConstants.ROLEDEF_OVERLOADED_BY_FIELD.equalsIgnoreCase(overloadedBy)) { 38 int levelRoleBehaviour = roleDefinition.getBehaviourLevel(roleBehaviour); 41 String 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 role); 62 63 64 } 65 | Popular Tags |