Source Code Cross Referenced for AllocatableImpl.java in  » Development » rapla » org » rapla » entities » domain » internal » 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 » Development » rapla » org.rapla.entities.domain.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*--------------------------------------------------------------------------*
002:         | Copyright (C) 2006 Christopher Kohlhaas                                  |
003:         |                                                                          |
004:         | This program is free software; you can redistribute it and/or modify     |
005:         | it under the terms of the GNU General Public License as published by the |
006:         | Free Software Foundation. A copy of the license has been included with   |
007:         | these distribution in the COPYING file, if not go to www.fsf.org         |
008:         |                                                                          |
009:         | As a special exception, you are granted the permissions to link this     |
010:         | program with every library, which license fulfills the Open Source       |
011:         | Definition as published by the Open Source Initiative (OSI).             |
012:         *--------------------------------------------------------------------------*/
013:        package org.rapla.entities.domain.internal;
014:
015:        import java.util.ArrayList;
016:        import java.util.Date;
017:        import java.util.Iterator;
018:        import java.util.Locale;
019:
020:        import org.rapla.components.util.iterator.IteratorChain;
021:        import org.rapla.components.util.iterator.NestedIterator;
022:        import org.rapla.entities.EntityNotFoundException;
023:        import org.rapla.entities.RaplaType;
024:        import org.rapla.entities.User;
025:        import org.rapla.entities.domain.Allocatable;
026:        import org.rapla.entities.domain.Permission;
027:        import org.rapla.entities.dynamictype.Classification;
028:        import org.rapla.entities.dynamictype.DynamicType;
029:        import org.rapla.entities.dynamictype.internal.ClassificationImpl;
030:        import org.rapla.entities.storage.DynamicTypeDependant;
031:        import org.rapla.entities.storage.RefEntity;
032:        import org.rapla.entities.storage.EntityResolver;
033:        import org.rapla.entities.storage.Mementable;
034:        import org.rapla.entities.storage.internal.SimpleEntity;
035:
036:        public class AllocatableImpl extends SimpleEntity implements 
037:                Allocatable, Mementable, java.io.Serializable,
038:                DynamicTypeDependant {
039:            // Don't forget to increase the serialVersionUID when you change the fields
040:            private static final long serialVersionUID = 1;
041:
042:            private ClassificationImpl classification;
043:            private boolean holdBackConflicts;
044:            private boolean _isPerson;
045:            private ArrayList permissions = new ArrayList();
046:
047:            transient private boolean permissionArrayUpToDate = false;
048:            transient private Permission[] permissionArray;
049:
050:            public AllocatableImpl() {
051:                _isPerson = false;
052:            }
053:
054:            public void resolveEntities(EntityResolver resolver)
055:                    throws EntityNotFoundException {
056:                super .resolveEntities(resolver);
057:                classification.resolveEntities(resolver);
058:                for (Iterator it = permissions.iterator(); it.hasNext();) {
059:                    ((PermissionImpl) it.next()).resolveEntities(resolver);
060:                }
061:            }
062:
063:            public void setReadOnly(boolean enable) {
064:                super .setReadOnly(enable);
065:                classification.setReadOnly(enable);
066:                Iterator it = permissions.iterator();
067:                while (it.hasNext()) {
068:                    ((PermissionImpl) it.next()).setReadOnly(enable);
069:                }
070:            }
071:
072:            public RaplaType getRaplaType() {
073:                return TYPE;
074:            }
075:
076:            // Implementation of interface classifiable
077:            public Classification getClassification() {
078:                return classification;
079:            }
080:
081:            public void setClassification(Classification classification) {
082:                this .classification = (ClassificationImpl) classification;
083:            }
084:
085:            public void setHoldBackConflicts(boolean enable) {
086:                holdBackConflicts = enable;
087:            }
088:
089:            public boolean isHoldBackConflicts() {
090:                return holdBackConflicts;
091:            }
092:
093:            public String getName(Locale locale) {
094:                Classification c = getClassification();
095:                if (c == null)
096:                    return "";
097:                return c.getName(locale);
098:            }
099:
100:            public void setPerson(boolean isPerson) {
101:                checkWritable();
102:                _isPerson = isPerson;
103:            }
104:
105:            public boolean isPerson() {
106:                return _isPerson;
107:            }
108:
109:            private boolean hasAccess(User user, int accessLevel) {
110:                Permission[] permissions = getPermissions();
111:                if (user == null || user.isAdmin())
112:                    return true;
113:
114:                for (int i = 0; i < permissions.length; i++) {
115:                    Permission p = permissions[i];
116:                    if (p.affectsUser(user)
117:                            && (p.getAccessLevel() >= accessLevel)) {
118:                        return true;
119:                    }
120:                }
121:                return false;
122:            }
123:
124:            public boolean canCreateConflicts(User user) {
125:                return hasAccess(user, Permission.ALLOCATE_CONFLICTS);
126:            }
127:
128:            public boolean canModify(User user) {
129:                return hasAccess(user, Permission.ADMIN);
130:            }
131:
132:            public boolean canRead(User user) {
133:                return hasAccess(user, Permission.READ);
134:            }
135:
136:            public boolean canAllocate(User user, Date start, Date end,
137:                    Date today) {
138:                if (user == null)
139:                    return false;
140:
141:                Permission[] permissions = getPermissions();
142:                if (user.isAdmin())
143:                    return true;
144:
145:                for (int i = 0; i < permissions.length; i++) {
146:                    Permission p = permissions[i];
147:                    if (p.affectsUser(user)
148:                            && p.getAccessLevel() >= Permission.ALLOCATE
149:                            && (p.getAccessLevel() == Permission.ADMIN || p
150:                                    .covers(start, end, today))) {
151:                        return true;
152:                    }
153:                }
154:                return false;
155:            }
156:
157:            public void addPermission(Permission permission) {
158:                checkWritable();
159:                permissionArrayUpToDate = false;
160:                permissions.add(permission);
161:            }
162:
163:            public boolean removePermission(Permission permission) {
164:                checkWritable();
165:                permissionArrayUpToDate = false;
166:                return permissions.remove(permission);
167:            }
168:
169:            public Permission newPermission() {
170:                return new PermissionImpl();
171:            }
172:
173:            public Permission[] getPermissions() {
174:                updatePermissionArray();
175:                return permissionArray;
176:            }
177:
178:            private void updatePermissionArray() {
179:                if (permissionArrayUpToDate)
180:                    return;
181:
182:                permissionArray = (Permission[]) permissions
183:                        .toArray(Permission.PERMISSION_ARRAY);
184:                permissionArrayUpToDate = true;
185:            }
186:
187:            public Iterator getReferences() {
188:                return new IteratorChain(classification.getReferences(),
189:                        new NestedIterator(permissions.iterator()) {
190:                            public Iterator getNestedIterator(Object obj) {
191:                                return ((PermissionImpl) obj).getReferences();
192:                            }
193:                        });
194:            }
195:
196:            public boolean needsChange(DynamicType type) {
197:                return classification.needsChange(type);
198:            }
199:
200:            public void commitChange(DynamicType type) {
201:                classification.commitChange(type);
202:            }
203:
204:            public boolean isRefering(RefEntity object) {
205:                if (super .isRefering(object))
206:                    return true;
207:                if (classification.isRefering(object))
208:                    return true;
209:                Permission[] permissions = getPermissions();
210:                for (int i = 0; i < permissions.length; i++) {
211:                    if (((PermissionImpl) permissions[i]).isRefering(object))
212:                        return true;
213:                }
214:                return false;
215:            }
216:
217:            static private void copy(AllocatableImpl source,
218:                    AllocatableImpl dest) {
219:                dest.permissionArrayUpToDate = false;
220:                dest.classification = (ClassificationImpl) source.classification
221:                        .clone();
222:
223:                dest.permissions.clear();
224:                Iterator it = source.permissions.iterator();
225:                while (it.hasNext()) {
226:                    dest.permissions.add(((PermissionImpl) it.next()).clone());
227:                }
228:
229:                dest.holdBackConflicts = source.holdBackConflicts;
230:                dest._isPerson = source._isPerson;
231:            }
232:
233:            public void copy(Object obj) {
234:                super .copy((AllocatableImpl) obj);
235:                copy((AllocatableImpl) obj, this );
236:            }
237:
238:            public Object deepClone() {
239:                AllocatableImpl clone = new AllocatableImpl();
240:                super .deepClone(clone);
241:                copy(this , clone);
242:                return clone;
243:            }
244:
245:            public Object clone() {
246:                AllocatableImpl clone = new AllocatableImpl();
247:                super .clone(clone);
248:                copy(this , clone);
249:                return clone;
250:            }
251:
252:            public String toString() {
253:                StringBuffer buf = new StringBuffer();
254:                buf.append(" [");
255:                buf.append(super .toString());
256:                buf.append(",");
257:                buf.append(super .getVersion());
258:                buf.append("] ");
259:                if (getClassification() != null) {
260:                    buf.append(getClassification().toString());
261:                }
262:                return buf.toString();
263:            }
264:
265:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.