Source Code Cross Referenced for ConstrainedUtils.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » site » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.site 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         *
004:         * $Id: ConstrainedUtils.java 3750 2007-05-12 15:05:53Z gbevin $
005:         */
006:        package com.uwyn.rife.site;
007:
008:        import com.uwyn.rife.tools.BeanUtils;
009:        import com.uwyn.rife.tools.ClassUtils;
010:        import com.uwyn.rife.tools.exceptions.BeanUtilsException;
011:        import java.util.Iterator;
012:
013:        public class ConstrainedUtils {
014:            public static Constrained getConstrainedInstance(Class beanClass) {
015:                if (null == beanClass) {
016:                    return null;
017:                }
018:
019:                Constrained constrained = null;
020:                if (Constrained.class.isAssignableFrom(beanClass)) {
021:                    try {
022:                        constrained = (Constrained) beanClass.newInstance();
023:                    } catch (Throwable e) {
024:                        return null;
025:                    }
026:                }
027:
028:                return constrained;
029:            }
030:
031:            public static Constrained makeConstrainedInstance(Object bean) {
032:                if (null == bean) {
033:                    return null;
034:                }
035:
036:                Constrained constrained = null;
037:                if (bean instanceof  Constrained) {
038:                    constrained = (Constrained) bean;
039:                }
040:
041:                return constrained;
042:            }
043:
044:            public static ConstrainedProperty getConstrainedProperty(
045:                    Object bean, String name) {
046:                if (null == bean) {
047:                    return null;
048:                }
049:
050:                Constrained constrained = ConstrainedUtils
051:                        .makeConstrainedInstance(bean);
052:                ConstrainedProperty contrained_property = null;
053:                if (constrained != null) {
054:                    contrained_property = constrained
055:                            .getConstrainedProperty(name);
056:                }
057:
058:                return contrained_property;
059:            }
060:
061:            public static String getIdentityProperty(Class beanClass) {
062:                String identity_property = null;
063:
064:                Constrained constrained_bean = getConstrainedInstance(beanClass);
065:                if (constrained_bean != null) {
066:                    Iterator<ConstrainedProperty> properties_it = constrained_bean
067:                            .getConstrainedProperties().iterator();
068:                    ConstrainedProperty property;
069:                    while (properties_it.hasNext()) {
070:                        property = properties_it.next();
071:                        if (property.isIdentifier()) {
072:                            identity_property = property.getPropertyName();
073:                            break;
074:                        }
075:                    }
076:                }
077:
078:                if (null == identity_property) {
079:                    identity_property = "id";
080:                }
081:
082:                return identity_property;
083:            }
084:
085:            public static boolean editConstrainedProperty(Constrained bean,
086:                    String propertyName, String prefix) {
087:                if (null == bean) {
088:                    return true;
089:                }
090:
091:                if (prefix != null && propertyName.startsWith(prefix)) {
092:                    propertyName = propertyName.substring(prefix.length());
093:                }
094:
095:                ConstrainedProperty constrained_property = bean
096:                        .getConstrainedProperty(propertyName);
097:
098:                return !(constrained_property != null && !constrained_property
099:                        .isEditable());
100:            }
101:
102:            public static boolean persistConstrainedProperty(Constrained bean,
103:                    String propertyName, String prefix) {
104:                if (null == bean) {
105:                    return true;
106:                }
107:
108:                if (prefix != null && propertyName.startsWith(prefix)) {
109:                    propertyName = propertyName.substring(prefix.length());
110:                }
111:
112:                ConstrainedProperty constrained_property = bean
113:                        .getConstrainedProperty(propertyName);
114:                if (constrained_property != null) {
115:                    if (!constrained_property.isPersistent()
116:                            || constrained_property.isSameAs()
117:                            || constrained_property.hasManyToOneAssociation()
118:                            || constrained_property.hasManyToMany()
119:                            || constrained_property.hasManyToManyAssociation()) {
120:                        return false;
121:                    }
122:
123:                    if (constrained_property.hasManyToOne()
124:                            && !isManyToOneJoinProperty(bean.getClass(),
125:                                    propertyName)) {
126:                        return false;
127:                    }
128:                }
129:
130:                return true;
131:            }
132:
133:            private static boolean isManyToOneJoinProperty(Class beanClass,
134:                    String propertyName) {
135:                try {
136:                    Class property_type = BeanUtils.getPropertyType(beanClass,
137:                            propertyName);
138:                    if (ClassUtils.isBasic(property_type)) {
139:                        return true;
140:                    }
141:                } catch (BeanUtilsException e) {
142:                    return true;
143:                }
144:
145:                return false;
146:            }
147:
148:            public static boolean saveConstrainedProperty(Constrained bean,
149:                    String propertyName, String prefix) {
150:                if (null == bean) {
151:                    return true;
152:                }
153:
154:                if (prefix != null && propertyName.startsWith(prefix)) {
155:                    propertyName = propertyName.substring(prefix.length());
156:                }
157:
158:                ConstrainedProperty constrained_property = bean
159:                        .getConstrainedProperty(propertyName);
160:                if (constrained_property != null) {
161:                    if (!constrained_property.isPersistent()
162:                            || !constrained_property.isSaved()
163:                            || constrained_property.isSameAs()
164:                            || constrained_property.hasManyToOneAssociation()
165:                            || constrained_property.hasManyToMany()
166:                            || constrained_property.hasManyToManyAssociation()) {
167:                        return false;
168:                    }
169:
170:                    if (constrained_property.hasManyToOne()
171:                            && !isManyToOneJoinProperty(bean.getClass(),
172:                                    propertyName)) {
173:                        return false;
174:                    }
175:                }
176:
177:                return true;
178:            }
179:
180:            public static boolean fileConstrainedProperty(Constrained bean,
181:                    String propertyName, String prefix) {
182:                if (null == bean) {
183:                    return false;
184:                }
185:
186:                if (prefix != null && propertyName.startsWith(prefix)) {
187:                    propertyName = propertyName.substring(prefix.length());
188:                }
189:
190:                ConstrainedProperty constrained_property = bean
191:                        .getConstrainedProperty(propertyName);
192:
193:                return constrained_property != null
194:                        && constrained_property.isFile();
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.