KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > formview > RoleDefinition


1 package net.sourceforge.formview;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import org.apache.commons.lang.StringUtils;
7
8 /**
9  * Description : Role defintion.
10  * @version 1.0.0
11  * @author <a HREF="mailto:angelo.zerr@gmail.com">Angelo ZERR</a>
12  */

13 public class RoleDefinition {
14
15     
16     private String JavaDoc name;
17     private String JavaDoc behaviours;
18     private String JavaDoc overloadedBy;
19     private boolean defaultRoleDefintion;
20     
21     private String JavaDoc[] behavioursArray = null;
22     private Map JavaDoc behavioursArrayMap = null; // key=behaviour value=level of Behaviour
23

24     /**
25      * @return Returns the behaviours.
26      */

27     public String JavaDoc getBehaviours() {
28         return behaviours;
29     }
30     /**
31      * @param behaviours The behaviours to set.
32      */

33     public void setBehaviours(String JavaDoc behaviours) {
34         this.behaviours = behaviours;
35         this.behavioursArray = null;
36         this.behavioursArrayMap = null;
37     }
38     /**
39      * @return Returns the defaultRoleDefintion.
40      */

41     public boolean isDefaultRoleDefintion() {
42         return defaultRoleDefintion;
43     }
44     /**
45      * @param defaultRoleDefintion The defaultRoleDefintion to set.
46      */

47     public void setDefaultRoleDefintion(boolean defaultRoleDefintion) {
48         this.defaultRoleDefintion = defaultRoleDefintion;
49     }
50     /**
51      * @return Returns the name.
52      */

53     public String JavaDoc getName() {
54         return name;
55     }
56     /**
57      * @param name The name to set.
58      */

59     public void setName(String JavaDoc name) {
60         this.name = name;
61     }
62     /**
63      * @return Returns the overloadedBy.
64      */

65     public String JavaDoc getOverloadedBy() {
66         return overloadedBy;
67     }
68     /**
69      * @param overloadedBy The overloadedBy to set.
70      */

71     public void setOverloadedBy(String JavaDoc overloadedBy) {
72         this.overloadedBy = overloadedBy;
73     }
74     
75     public String JavaDoc[] getBehavioursArray() {
76         if (behavioursArray == null &&
77             behaviours != null && behaviours.length() > 0) {
78             // Compute array of Behaviour
79
this.behavioursArray = StringUtils.split(behaviours, ",");
80         }
81         return behavioursArray;
82     }
83
84     public Map JavaDoc getBehavioursMap() {
85         if (behavioursArrayMap == null) {
86             String JavaDoc[] behavioursArray = getBehavioursArray();
87             if (behavioursArray != null) {
88                 // Compute Map of Behaviour
89
this.behavioursArrayMap = new HashMap JavaDoc();
90                 for (int i = 0; i < behavioursArray.length; i++) {
91                     String JavaDoc behaviour = behavioursArray[i];
92                     this.behavioursArrayMap.put(behaviour, new Integer JavaDoc(i));
93                 }
94             }
95         }
96         return behavioursArrayMap;
97     }
98     
99     public int getBehaviourLevel(String JavaDoc behaviour) {
100         Map JavaDoc behavioursArrayMap = getBehavioursMap();
101         if (behavioursArrayMap != null) {
102             Integer JavaDoc level = (Integer JavaDoc)behavioursArrayMap.get(behaviour);
103             if (level != null)
104                 return level.intValue();
105         }
106         
107         return -1;
108     }
109     
110     /**
111      * Returns a string representation of the object.
112      */

113     public String JavaDoc toString() {
114         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
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 JavaDoc 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