Source Code Cross Referenced for IfCompareField.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » minilang » method » ifops » 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 » SourceTap CRM » org.ofbiz.minilang.method.ifops 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: IfCompareField.java,v 1.2 2003/09/14 05:40:41 jonesde Exp $
003:         *
004:         *  Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005:         *
006:         *  Permission is hereby granted, free of charge, to any person obtaining a
007:         *  copy of this software and associated documentation files (the "Software"),
008:         *  to deal in the Software without restriction, including without limitation
009:         *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         *  and/or sell copies of the Software, and to permit persons to whom the
011:         *  Software is furnished to do so, subject to the following conditions:
012:         *
013:         *  The above copyright notice and this permission notice shall be included
014:         *  in all copies or substantial portions of the Software.
015:         *
016:         *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         */
024:        package org.ofbiz.minilang.method.ifops;
025:
026:        import java.util.*;
027:
028:        import org.w3c.dom.*;
029:        import org.ofbiz.base.util.*;
030:        import org.ofbiz.minilang.*;
031:        import org.ofbiz.minilang.method.*;
032:
033:        import org.ofbiz.minilang.operation.*;
034:
035:        /**
036:         * Iff the comparison between the specified field and the other field is true process sub-operations
037:         *
038:         * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
039:         * @version    $Revision: 1.2 $
040:         * @since      2.0
041:         */
042:        public class IfCompareField extends MethodOperation {
043:
044:            public static final String module = IfCompareField.class.getName();
045:
046:            List subOps = new LinkedList();
047:            List elseSubOps = null;
048:
049:            ContextAccessor mapAcsr;
050:            ContextAccessor fieldAcsr;
051:            ContextAccessor toMapAcsr;
052:            ContextAccessor toFieldAcsr;
053:
054:            String operator;
055:            String type;
056:            String format;
057:
058:            public IfCompareField(Element element, SimpleMethod simpleMethod) {
059:                super (element, simpleMethod);
060:                this .mapAcsr = new ContextAccessor(element
061:                        .getAttribute("map-name"));
062:                this .fieldAcsr = new ContextAccessor(element
063:                        .getAttribute("field-name"));
064:
065:                this .toMapAcsr = new ContextAccessor(element
066:                        .getAttribute("to-map-name"));
067:                // set fieldAcsr to their defualt value of fieldAcsr if empty
068:                this .toFieldAcsr = new ContextAccessor(element
069:                        .getAttribute("to-field-name"), element
070:                        .getAttribute("field-name"));
071:
072:                // do NOT default the to-map-name to the map-name because that
073:                //would make it impossible to compare from a map field to an 
074:                //environment field
075:
076:                this .operator = element.getAttribute("operator");
077:                this .type = element.getAttribute("type");
078:                this .format = element.getAttribute("format");
079:
080:                SimpleMethod.readOperations(element, subOps, simpleMethod);
081:                Element elseElement = UtilXml
082:                        .firstChildElement(element, "else");
083:                if (elseElement != null) {
084:                    elseSubOps = new LinkedList();
085:                    SimpleMethod.readOperations(elseElement, elseSubOps,
086:                            simpleMethod);
087:                }
088:            }
089:
090:            public boolean exec(MethodContext methodContext) {
091:                // if conditions fails, always return true; if a sub-op returns false 
092:                // return false and stop, otherwise return true
093:
094:                String operator = methodContext.expandString(this .operator);
095:                String type = methodContext.expandString(this .type);
096:                String format = methodContext.expandString(this .format);
097:
098:                Object fieldVal1 = null;
099:                Object fieldVal2 = null;
100:
101:                if (!mapAcsr.isEmpty()) {
102:                    Map fromMap = (Map) mapAcsr.get(methodContext);
103:                    if (fromMap == null) {
104:                        if (Debug.infoOn())
105:                            Debug.logInfo("Map not found with name " + mapAcsr
106:                                    + ", using null for comparison", module);
107:                    } else {
108:                        fieldVal1 = fieldAcsr.get(fromMap, methodContext);
109:                    }
110:                } else {
111:                    // no map name, try the env
112:                    fieldVal1 = fieldAcsr.get(methodContext);
113:                }
114:
115:                if (!toMapAcsr.isEmpty()) {
116:                    Map toMap = (Map) toMapAcsr.get(methodContext);
117:                    if (toMap == null) {
118:                        if (Debug.infoOn())
119:                            Debug.logInfo(
120:                                    "To Map not found with name " + toMapAcsr
121:                                            + ", using null for comparison",
122:                                    module);
123:                    } else {
124:                        fieldVal2 = toFieldAcsr.get(toMap, methodContext);
125:                    }
126:                } else {
127:                    // no map name, try the env
128:                    fieldVal2 = toFieldAcsr.get(methodContext);
129:                }
130:
131:                List messages = new LinkedList();
132:                Boolean resultBool = BaseCompare.doRealCompare(fieldVal1,
133:                        fieldVal2, operator, type, format, messages, null,
134:                        methodContext.getLoader());
135:
136:                if (messages.size() > 0) {
137:                    messages.add(0,
138:                            "Error with comparison in if-compare-field between fields ["
139:                                    + mapAcsr.toString() + "."
140:                                    + fieldAcsr.toString() + "] with value ["
141:                                    + fieldVal1 + "] and ["
142:                                    + toMapAcsr.toString() + "."
143:                                    + toFieldAcsr.toString() + "] with value ["
144:                                    + fieldVal2 + "] with operator ["
145:                                    + operator + "] and type [" + type + "]: ");
146:                    if (methodContext.getMethodType() == MethodContext.EVENT) {
147:                        StringBuffer fullString = new StringBuffer();
148:
149:                        Iterator miter = messages.iterator();
150:                        while (miter.hasNext()) {
151:                            fullString.append((String) miter.next());
152:                        }
153:                        Debug.logWarning(fullString.toString(), module);
154:
155:                        methodContext.putEnv(simpleMethod
156:                                .getEventErrorMessageName(), fullString
157:                                .toString());
158:                        methodContext.putEnv(simpleMethod
159:                                .getEventResponseCodeName(), simpleMethod
160:                                .getDefaultErrorCode());
161:                    } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
162:                        methodContext.putEnv(simpleMethod
163:                                .getServiceErrorMessageListName(), messages);
164:                        methodContext.putEnv(simpleMethod
165:                                .getServiceResponseMessageName(), simpleMethod
166:                                .getDefaultErrorCode());
167:                    }
168:                    return false;
169:                }
170:
171:                if (resultBool != null && resultBool.booleanValue()) {
172:                    return SimpleMethod.runSubOps(subOps, methodContext);
173:                } else {
174:                    if (elseSubOps != null) {
175:                        return SimpleMethod
176:                                .runSubOps(elseSubOps, methodContext);
177:                    } else {
178:                        return true;
179:                    }
180:                }
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.