1 package net.sourceforge.formview; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import org.apache.commons.lang.StringUtils; 7 8 13 public class RoleDefinition { 14 15 16 private String name; 17 private String behaviours; 18 private String overloadedBy; 19 private boolean defaultRoleDefintion; 20 21 private String [] behavioursArray = null; 22 private Map behavioursArrayMap = null; 24 27 public String getBehaviours() { 28 return behaviours; 29 } 30 33 public void setBehaviours(String behaviours) { 34 this.behaviours = behaviours; 35 this.behavioursArray = null; 36 this.behavioursArrayMap = null; 37 } 38 41 public boolean isDefaultRoleDefintion() { 42 return defaultRoleDefintion; 43 } 44 47 public void setDefaultRoleDefintion(boolean defaultRoleDefintion) { 48 this.defaultRoleDefintion = defaultRoleDefintion; 49 } 50 53 public String getName() { 54 return name; 55 } 56 59 public void setName(String name) { 60 this.name = name; 61 } 62 65 public String getOverloadedBy() { 66 return overloadedBy; 67 } 68 71 public void setOverloadedBy(String overloadedBy) { 72 this.overloadedBy = overloadedBy; 73 } 74 75 public String [] getBehavioursArray() { 76 if (behavioursArray == null && 77 behaviours != null && behaviours.length() > 0) { 78 this.behavioursArray = StringUtils.split(behaviours, ","); 80 } 81 return behavioursArray; 82 } 83 84 public Map getBehavioursMap() { 85 if (behavioursArrayMap == null) { 86 String [] behavioursArray = getBehavioursArray(); 87 if (behavioursArray != null) { 88 this.behavioursArrayMap = new HashMap (); 90 for (int i = 0; i < behavioursArray.length; i++) { 91 String behaviour = behavioursArray[i]; 92 this.behavioursArrayMap.put(behaviour, new Integer (i)); 93 } 94 } 95 } 96 return behavioursArrayMap; 97 } 98 99 public int getBehaviourLevel(String behaviour) { 100 Map behavioursArrayMap = getBehavioursMap(); 101 if (behavioursArrayMap != null) { 102 Integer level = (Integer )behavioursArrayMap.get(behaviour); 103 if (level != null) 104 return level.intValue(); 105 } 106 107 return -1; 108 } 109 110 113 public String toString() { 114 StringBuffer results = new StringBuffer (); 115 116 results.append("RoleDefinition: "); 117 results.append(name); 118 results.append("\n"); 119 results.append("\tbehaviours = " + behaviours); 120 results.append("\n"); 121 results.append("\toverloaded by = " + overloadedBy); 122 results.append("\n"); 123 results.append("\tdefault = " + defaultRoleDefintion); 124 results.append("\n"); 125 return results.toString(); 126 } 127 128 public static RoleDefinition getDefaultRoleDefinition() { 129 RoleDefinition defaultRoleDefinition = new RoleDefinition(); 130 defaultRoleDefinition.setName(FormViewConstants.ROLEDEF_DEFAULT_NAME); 131 String behaviours = FormViewConstants.BEHAVIOUR_READWRITE + "," + 132 FormViewConstants.BEHAVIOUR_READONLY + "," + 133 FormViewConstants.BEHAVIOUR_INVISIBLE; 134 defaultRoleDefinition.setOverloadedBy(FormViewConstants.ROLEDEF_OVERLOADED_BY_FIELD); 135 defaultRoleDefinition.setBehaviours(behaviours); 136 return defaultRoleDefinition; 137 } 138 139 } 140 | Popular Tags |