Source Code Cross Referenced for ValueCountValidationRule.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » woody » datatype » validationruleimpl » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.woody.datatype.validationruleimpl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.cocoon.woody.datatype.validationruleimpl;
018:
019:        import org.apache.cocoon.woody.datatype.ValidationError;
020:        import org.apache.cocoon.woody.formmodel.CannotYetResolveWarning;
021:        import org.apache.cocoon.woody.util.I18nMessage;
022:        import org.apache.cocoon.woody.Constants;
023:        import org.outerj.expression.ExpressionContext;
024:        import org.outerj.expression.Expression;
025:
026:        import java.math.BigDecimal;
027:
028:        /**
029:         * Checks the number of values (i.e. the size of the array). This only works for Datatypes
030:         * for which {@link org.apache.cocoon.woody.datatype.Datatype#isArrayType()} returns
031:         * true.
032:         *
033:         * <p>This validation rule can perform 4 different checks:
034:         * <ul>
035:         *  <li>check exact array size
036:         *  <li>check minimum array size
037:         *  <li>check maximum array size
038:         *  <li>check min and max array size
039:         * </ul>
040:         * 
041:         * @version $Id: ValueCountValidationRule.java 433543 2006-08-22 06:22:54Z crossley $
042:         */
043:        public class ValueCountValidationRule extends AbstractValidationRule {
044:            private Expression exactExpr;
045:            private Expression minExpr;
046:            private Expression maxExpr;
047:
048:            public void setExactExpr(Expression exactExpr) {
049:                this .exactExpr = exactExpr;
050:            }
051:
052:            public void setMinExpr(Expression minExpr) {
053:                this .minExpr = minExpr;
054:            }
055:
056:            public void setMaxExpr(Expression maxExpr) {
057:                this .maxExpr = maxExpr;
058:            }
059:
060:            public ValidationError validate(Object value,
061:                    ExpressionContext expressionContext) {
062:                Object[] array = (Object[]) value;
063:
064:                if (exactExpr != null) {
065:                    Object result = evaluateNumeric(exactExpr,
066:                            expressionContext, "exact", "value-count");
067:                    if (result instanceof  ValidationError)
068:                        return (ValidationError) result;
069:                    else if (result instanceof  CannotYetResolveWarning)
070:                        return null;
071:                    int length = ((BigDecimal) result).intValue();
072:                    if (array.length != length)
073:                        return hasFailMessage() ? getFailMessage()
074:                                : new ValidationError(
075:                                        new I18nMessage(
076:                                                "validation.array.exact-valuecount",
077:                                                new String[] { String
078:                                                        .valueOf(length) },
079:                                                Constants.I18N_CATALOGUE));
080:                    return null;
081:                } else if (minExpr != null && maxExpr != null) {
082:                    Object result = evaluateNumeric(minExpr, expressionContext,
083:                            "min", "value-count");
084:                    if (result instanceof  ValidationError)
085:                        return (ValidationError) result;
086:                    else if (result instanceof  CannotYetResolveWarning)
087:                        return null;
088:                    int minLength = ((BigDecimal) result).intValue();
089:
090:                    result = evaluateNumeric(maxExpr, expressionContext, "max",
091:                            "value-count");
092:                    if (result instanceof  ValidationError)
093:                        return (ValidationError) result;
094:                    else if (result instanceof  CannotYetResolveWarning)
095:                        return null;
096:                    int maxLength = ((BigDecimal) result).intValue();
097:
098:                    if (array.length < minLength || array.length > maxLength)
099:                        return hasFailMessage() ? getFailMessage()
100:                                : new ValidationError(new I18nMessage(
101:                                        "validation.array.range-valuecount",
102:                                        new String[] {
103:                                                String.valueOf(minLength),
104:                                                String.valueOf(maxLength) },
105:                                        Constants.I18N_CATALOGUE));
106:                    return null;
107:                } else if (minExpr != null) {
108:                    Object result = evaluateNumeric(minExpr, expressionContext,
109:                            "min", "value-count");
110:                    if (result instanceof  ValidationError)
111:                        return (ValidationError) result;
112:                    else if (result instanceof  CannotYetResolveWarning)
113:                        return null;
114:                    int length = ((BigDecimal) result).intValue();
115:                    if (array.length < length)
116:                        return hasFailMessage() ? getFailMessage()
117:                                : new ValidationError(
118:                                        new I18nMessage(
119:                                                "validation.array.min-valuecount",
120:                                                new String[] { String
121:                                                        .valueOf(length) },
122:                                                Constants.I18N_CATALOGUE));
123:                    return null;
124:                } else if (maxExpr != null) {
125:                    Object result = evaluateNumeric(maxExpr, expressionContext,
126:                            "max", "value-count");
127:                    if (result instanceof  ValidationError)
128:                        return (ValidationError) result;
129:                    else if (result instanceof  CannotYetResolveWarning)
130:                        return null;
131:                    int length = ((BigDecimal) result).intValue();
132:                    if (array.length > length)
133:                        return hasFailMessage() ? getFailMessage()
134:                                : new ValidationError(
135:                                        new I18nMessage(
136:                                                "validation.array.max-valuecount",
137:                                                new String[] { String
138:                                                        .valueOf(length) },
139:                                                Constants.I18N_CATALOGUE));
140:                    return null;
141:                }
142:                return null;
143:            }
144:
145:            public boolean supportsType(Class clazz, boolean arrayType) {
146:                return arrayType;
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.