Source Code Cross Referenced for FieldAuthorization.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » core » authorization » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » org.kuali.core.authorization 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007 The Kuali Foundation.
003:         * 
004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         * http://www.opensource.org/licenses/ecl1.php
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.kuali.core.authorization;
017:
018:        import org.apache.commons.lang.StringUtils;
019:        import org.kuali.core.web.ui.Field;
020:
021:        /**
022:         * This class represents the authorization restrictions (or lack of) for a given field.
023:         * 
024:         * 
025:         */
026:        public class FieldAuthorization {
027:
028:            private String fieldName;
029:            private boolean editable;
030:            private boolean viewable;
031:
032:            /**
033:             * Constructs a FieldAuthorization.java.
034:             */
035:            public FieldAuthorization() {
036:                editable = true;
037:                viewable = true;
038:            }
039:
040:            /**
041:             * 
042:             * Constructs a FieldAuthorization.java.
043:             * 
044:             * @param fieldName - name of field to represent
045:             * @param canEdit - true if the field is editable in this context, false otherwise
046:             * @param canView - true if thie field is viewable in this context, false otherwise
047:             * 
048:             */
049:            public FieldAuthorization(String fieldName, boolean canEdit,
050:                    boolean canView) {
051:                this .fieldName = fieldName;
052:                setEditable(canEdit); // using setters here to run impossible combinations check
053:                setViewable(canView);
054:            }
055:
056:            /**
057:             * 
058:             * Constructs a FieldAuthorization.java.
059:             * 
060:             * @param fieldName - name of the field to represent
061:             * @param fieldAuthorizationFlag - Field.HIDDEN, Field.READONLY, or Field.EDITABLE
062:             * 
063:             */
064:            public FieldAuthorization(String fieldName,
065:                    String fieldAuthorizationFlag) {
066:
067:                // if an invalid flag is passed in, the choke on it
068:                if (!fieldAuthorizationFlag.equals(Field.EDITABLE)
069:                        && !fieldAuthorizationFlag.equals(Field.READONLY)
070:                        && !fieldAuthorizationFlag.equals(Field.HIDDEN)) {
071:                    throw new IllegalArgumentException(
072:                            "The only allowable values are Field.HIDDEN, Field.READONLY, and Field.EDITABLE");
073:                }
074:
075:                this .fieldName = fieldName;
076:
077:                if (fieldAuthorizationFlag.equals(Field.EDITABLE)) {
078:                    this .editable = true;
079:                    this .viewable = true;
080:                }
081:
082:                if (fieldAuthorizationFlag.equals(Field.READONLY)) {
083:                    this .editable = false;
084:                    this .viewable = true;
085:                }
086:
087:                if (fieldAuthorizationFlag.equals(Field.HIDDEN)) {
088:                    this .editable = false;
089:                    this .viewable = false;
090:                }
091:
092:            }
093:
094:            /**
095:             * 
096:             * This method returns the correct flag from the Kuali Field object, that corresponds to the particular combination of editable
097:             * and viewable set on this object.
098:             * 
099:             * @return Field.HIDDEN, Field.READONLY, or Field.EDITABLE
100:             * 
101:             */
102:            public String getKualiFieldDisplayFlag() {
103:
104:                if (!editable && !viewable) {
105:                    return Field.HIDDEN;
106:                }
107:                if (!editable && viewable) {
108:                    return Field.READONLY;
109:                } else {
110:                    return Field.EDITABLE;
111:                }
112:
113:            }
114:
115:            /**
116:             * 
117:             * This method returns true if the FieldAuthorization is some kind of restriction, and returns false if it is an editable field.
118:             * 
119:             * @return boolean
120:             * 
121:             */
122:            public boolean isRestricted() {
123:                if (!editable || !viewable) {
124:                    return true;
125:                } else {
126:                    return false;
127:                }
128:            }
129:
130:            /**
131:             * 
132:             * This method returns true if this authorization prohibits Viewing and Editing, resulting in a hidden field.
133:             * 
134:             * @return boolean
135:             * 
136:             */
137:            public boolean isHidden() {
138:                if (!editable && !viewable) {
139:                    return true;
140:                } else {
141:                    return false;
142:                }
143:            }
144:
145:            /**
146:             * 
147:             * This method returns true if this authorization prohibits Editing but not Viewing, resulting in a ReadOnly field.
148:             * 
149:             * @return boolean
150:             * 
151:             */
152:            public boolean isReadOnly() {
153:                if (!editable && viewable) {
154:                    return true;
155:                } else {
156:                    return false;
157:                }
158:            }
159:
160:            /**
161:             * Gets the editable attribute.
162:             * 
163:             * @return Returns the editable.
164:             */
165:            public boolean isEditable() {
166:                return editable;
167:            }
168:
169:            /**
170:             * Sets the editable attribute value.
171:             * 
172:             * Note that if editable is being set to true, and the internal value of viewable is false, viewable will be flipped to true, to
173:             * avoid impossible combinations of flags.
174:             * 
175:             * @param editable The editable to set.
176:             */
177:            public void setEditable(boolean editable) {
178:                if (editable && !this .viewable) {
179:                    this .viewable = true;
180:                }
181:                this .editable = editable;
182:            }
183:
184:            /**
185:             * Gets the fieldName attribute.
186:             * 
187:             * @return Returns the fieldName.
188:             */
189:            public String getFieldName() {
190:                return fieldName;
191:            }
192:
193:            /**
194:             * Sets the fieldName attribute value.
195:             * 
196:             * @param fieldName The fieldName to set.
197:             */
198:            public void setFieldName(String fieldName) {
199:                this .fieldName = fieldName;
200:            }
201:
202:            /**
203:             * Gets the viewable attribute.
204:             * 
205:             * @return Returns the viewable.
206:             */
207:            public boolean isViewable() {
208:                return viewable;
209:            }
210:
211:            /**
212:             * Sets the viewable attribute value.
213:             * 
214:             * Note that if viewable is being set to false, and the internal value of editable is true, then editable will be silently
215:             * flipped to false. This is done to avoid impossible combinations of authorization flags.
216:             * 
217:             * @param viewable The viewable to set.
218:             */
219:            public void setViewable(boolean viewable) {
220:                if (!viewable && this .editable) {
221:                    this .editable = false;
222:                }
223:                this .viewable = viewable;
224:            }
225:
226:            /**
227:             * @see java.lang.Object#toString()
228:             */
229:            public String toString() {
230:                StringBuffer sb = new StringBuffer();
231:                sb.append(this .fieldName);
232:                sb.append(" [");
233:                if (this .editable) {
234:                    sb.append("editable");
235:                } else {
236:                    sb.append("not editable");
237:                }
238:                sb.append(",");
239:                if (this .viewable) {
240:                    sb.append("viewable");
241:                } else {
242:                    sb.append("not viewable");
243:                }
244:                sb.append("]");
245:                return sb.toString();
246:            }
247:
248:            /**
249:             * @see java.lang.Object#equals(java.lang.Object)
250:             */
251:            public boolean equals(Object obj) {
252:                boolean equal = false;
253:
254:                if (obj != null) {
255:                    if (this .getClass().equals(obj.getClass())) {
256:                        FieldAuthorization other = (FieldAuthorization) obj;
257:
258:                        if (StringUtils.equals(this .fieldName, other
259:                                .getFieldName())) {
260:                            if (this .editable == other.isEditable()
261:                                    && this .viewable == other.isViewable()) {
262:                                equal = true;
263:                            }
264:                        }
265:                    }
266:                }
267:
268:                return equal;
269:            }
270:
271:            /**
272:             * @see java.lang.Object#hashCode()
273:             */
274:            public int hashCode() {
275:                return toString().hashCode();
276:            }
277:
278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.