Source Code Cross Referenced for FieldReference.java in  » Web-Framework » TURBINE » org » apache » turbine » services » intake » validator » 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 » TURBINE » org.apache.turbine.services.intake.validator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.services.intake.validator;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import java.util.Iterator;
023:        import java.util.List;
024:
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:        import org.apache.turbine.services.intake.IntakeException;
028:        import org.apache.turbine.services.intake.model.Field;
029:        import org.apache.turbine.services.intake.model.Group;
030:
031:        /**
032:         * Helper Class to manage relations between fields. The following
033:         * comparisons are supported:
034:         * 
035:         * <table>
036:         * <tr>
037:         *   <th>Name</th><th>Valid Values</th><th>Default Value</th>
038:         * </tr>
039:         * <tr>
040:         *   <td>less-than</td>
041:         *   <td>&lt;name of other field&gt;</td>
042:         *   <td>&nbsp;</td>
043:         * </tr>
044:         * <tr>
045:         *   <td>greater-than</td>
046:         *   <td>&lt;name of other field&gt;</td>
047:         *   <td>&nbsp;</td>
048:         * </tr>
049:         * <tr>
050:         *   <td>less-than-or-equal</td>
051:         *   <td>&lt;name of other field&gt;</td>
052:         *   <td>&nbsp;</td>
053:         * </tr>
054:         * <tr>
055:         *   <td>greater-than-or-equal</td>
056:         *   <td>&lt;name of other field&gt;</td>
057:         *   <td>&nbsp;</td>
058:         * </tr>
059:         * </table>
060:         *
061:         * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
062:         * @version $Id: DateStringValidator.java 534527 2007-05-02 16:10:59Z tv $
063:         */
064:        public class FieldReference {
065:            /** a local logger */
066:            protected static final Log log = LogFactory
067:                    .getLog(FieldReference.class);
068:
069:            /** Rule name for "&lt;" comparison */
070:            public static final String RANGE_LT = "less-than";
071:
072:            /** Rule name for "&gt;" comparison */
073:            public static final String RANGE_GT = "greater-than";
074:
075:            /** Rule name for "&lt;=" comparison */
076:            public static final String RANGE_LTE = "less-than-or-equal";
077:
078:            /** Rule name for "&gt;=" comparison */
079:            public static final String RANGE_GTE = "greater-than-or-equal";
080:
081:            /** Integer value for "&lt;" comparison */
082:            public static final int COMPARE_LT = 1;
083:
084:            /** Integer value for "&gt;" comparison */
085:            public static final int COMPARE_GT = 2;
086:
087:            /** Integer value for "&lt;=" comparison */
088:            public static final int COMPARE_LTE = 3;
089:
090:            /** Integer value for "&gt;=" comparison */
091:            public static final int COMPARE_GTE = 4;
092:
093:            /** Numeric comparison */
094:            private int compare = 0;
095:
096:            /** Name of referenced field */
097:            private String fieldName = null;
098:
099:            /** Error message */
100:            private String message = null;
101:
102:            /**
103:             *  Constructor
104:             */
105:            public FieldReference() {
106:            }
107:
108:            /**
109:             * @return the comparison type
110:             */
111:            public int getCompare() {
112:                return compare;
113:            }
114:
115:            /**
116:             * @param compare the comparison type to set
117:             */
118:            public void setCompare(int compare) {
119:                this .compare = compare;
120:            }
121:
122:            /**
123:             * @return the field name
124:             */
125:            public String getFieldName() {
126:                return fieldName;
127:            }
128:
129:            /**
130:             * @param fieldName the field name to set
131:             */
132:            public void setFieldName(String fieldName) {
133:                this .fieldName = fieldName;
134:            }
135:
136:            /**
137:             * @return the message
138:             */
139:            public String getMessage() {
140:                return message;
141:            }
142:
143:            /**
144:             * @param message the message to set
145:             */
146:            public void setMessage(String message) {
147:                this .message = message;
148:            }
149:
150:            /**
151:             * Map the comparison strings to their numeric counterparts
152:             * 
153:             * @param key the 
154:             * @return
155:             */
156:            public static int getCompareType(String key) {
157:                int compareType = 0;
158:
159:                if (key.equals(RANGE_LT)) {
160:                    compareType = COMPARE_LT;
161:                } else if (key.equals(RANGE_LTE)) {
162:                    compareType = COMPARE_LTE;
163:                } else if (key.equals(RANGE_GT)) {
164:                    compareType = COMPARE_GT;
165:                } else if (key.equals(RANGE_GTE)) {
166:                    compareType = COMPARE_GTE;
167:                }
168:
169:                return compareType;
170:            }
171:
172:            /**
173:             * Check the parsed value against the referenced fields
174:             * 
175:             * @param fieldReferences List of field references to check
176:             * @param compareCallback Callback to the actual compare operation
177:             * @param value the parsed value of the related field
178:             * @param group the group the related field belongs to
179:             * 
180:             * @throws ValidationException
181:             */
182:            public static void checkReferences(List fieldReferences,
183:                    CompareCallback compareCallback, Object value, Group group)
184:                    throws ValidationException {
185:                for (Iterator i = fieldReferences.iterator(); i.hasNext();) {
186:                    FieldReference ref = (FieldReference) i.next();
187:                    boolean comp_true = true;
188:
189:                    try {
190:                        Field refField = group.get(ref.getFieldName());
191:
192:                        if (refField.isSet()) {
193:                            /*
194:                             * Fields are processed in sequence so that our
195:                             * reference field might have been set but not
196:                             * yet validated. We check this here.
197:                             */
198:                            if (!refField.isValidated()) {
199:                                refField.validate();
200:                            }
201:
202:                            if (refField.isValid()) {
203:                                try {
204:                                    comp_true = compareCallback.compareValues(
205:                                            ref.getCompare(), value, refField
206:                                                    .getValue());
207:                                } catch (ClassCastException e) {
208:                                    throw new IntakeException(
209:                                            "Type mismatch comparing " + value
210:                                                    + " with "
211:                                                    + refField.getValue(), e);
212:                                }
213:                            }
214:                        }
215:                    } catch (IntakeException e) {
216:                        log.error("Validate operation failed.", e);
217:                        throw new ValidationException(ref.getMessage());
218:                    }
219:
220:                    if (comp_true == false) {
221:                        throw new ValidationException(ref.getMessage());
222:                    }
223:                }
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.