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


001:        /*******************************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         *******************************************************************************/package org.ofbiz.minilang.method.ifops;
019:
020:        import java.util.*;
021:
022:        import org.w3c.dom.*;
023:        import org.ofbiz.base.util.*;
024:        import org.ofbiz.minilang.*;
025:        import org.ofbiz.minilang.method.*;
026:
027:        import org.ofbiz.minilang.operation.*;
028:
029:        /**
030:         * Iff the comparison between the specified field and the other field is true process sub-operations
031:         */
032:        public class IfCompareField extends MethodOperation {
033:
034:            public static final String module = IfCompareField.class.getName();
035:
036:            List subOps = new LinkedList();
037:            List elseSubOps = null;
038:
039:            ContextAccessor mapAcsr;
040:            ContextAccessor fieldAcsr;
041:            ContextAccessor toMapAcsr;
042:            ContextAccessor toFieldAcsr;
043:
044:            String operator;
045:            String type;
046:            String format;
047:
048:            public IfCompareField(Element element, SimpleMethod simpleMethod) {
049:                super (element, simpleMethod);
050:                this .mapAcsr = new ContextAccessor(element
051:                        .getAttribute("map-name"));
052:                this .fieldAcsr = new ContextAccessor(element
053:                        .getAttribute("field-name"));
054:
055:                this .toMapAcsr = new ContextAccessor(element
056:                        .getAttribute("to-map-name"));
057:                // set fieldAcsr to their defualt value of fieldAcsr if empty
058:                this .toFieldAcsr = new ContextAccessor(element
059:                        .getAttribute("to-field-name"), element
060:                        .getAttribute("field-name"));
061:
062:                // do NOT default the to-map-name to the map-name because that
063:                //would make it impossible to compare from a map field to an 
064:                //environment field
065:
066:                this .operator = element.getAttribute("operator");
067:                this .type = element.getAttribute("type");
068:                this .format = element.getAttribute("format");
069:
070:                SimpleMethod.readOperations(element, subOps, simpleMethod);
071:                Element elseElement = UtilXml
072:                        .firstChildElement(element, "else");
073:                if (elseElement != null) {
074:                    elseSubOps = new LinkedList();
075:                    SimpleMethod.readOperations(elseElement, elseSubOps,
076:                            simpleMethod);
077:                }
078:            }
079:
080:            public boolean exec(MethodContext methodContext) {
081:                // if conditions fails, always return true; if a sub-op returns false 
082:                // return false and stop, otherwise return true
083:
084:                String operator = methodContext.expandString(this .operator);
085:                String type = methodContext.expandString(this .type);
086:                String format = methodContext.expandString(this .format);
087:
088:                Object fieldVal1 = null;
089:                Object fieldVal2 = null;
090:
091:                if (!mapAcsr.isEmpty()) {
092:                    Map fromMap = (Map) mapAcsr.get(methodContext);
093:                    if (fromMap == null) {
094:                        if (Debug.infoOn())
095:                            Debug.logInfo("Map not found with name " + mapAcsr
096:                                    + ", using null for comparison", module);
097:                    } else {
098:                        fieldVal1 = fieldAcsr.get(fromMap, methodContext);
099:                    }
100:                } else {
101:                    // no map name, try the env
102:                    fieldVal1 = fieldAcsr.get(methodContext);
103:                }
104:
105:                if (!toMapAcsr.isEmpty()) {
106:                    Map toMap = (Map) toMapAcsr.get(methodContext);
107:                    if (toMap == null) {
108:                        if (Debug.infoOn())
109:                            Debug.logInfo(
110:                                    "To Map not found with name " + toMapAcsr
111:                                            + ", using null for comparison",
112:                                    module);
113:                    } else {
114:                        fieldVal2 = toFieldAcsr.get(toMap, methodContext);
115:                    }
116:                } else {
117:                    // no map name, try the env
118:                    fieldVal2 = toFieldAcsr.get(methodContext);
119:                }
120:
121:                List messages = new LinkedList();
122:                Boolean resultBool = BaseCompare.doRealCompare(fieldVal1,
123:                        fieldVal2, operator, type, format, messages, null,
124:                        methodContext.getLoader(), false);
125:
126:                if (messages.size() > 0) {
127:                    messages.add(0,
128:                            "Error with comparison in if-compare-field between fields ["
129:                                    + mapAcsr.toString() + "."
130:                                    + fieldAcsr.toString() + "] with value ["
131:                                    + fieldVal1 + "] and ["
132:                                    + toMapAcsr.toString() + "."
133:                                    + toFieldAcsr.toString() + "] with value ["
134:                                    + fieldVal2 + "] with operator ["
135:                                    + operator + "] and type [" + type + "]: ");
136:                    if (methodContext.getMethodType() == MethodContext.EVENT) {
137:                        StringBuffer fullString = new StringBuffer();
138:
139:                        Iterator miter = messages.iterator();
140:                        while (miter.hasNext()) {
141:                            fullString.append((String) miter.next());
142:                        }
143:                        Debug.logWarning(fullString.toString(), module);
144:
145:                        methodContext.putEnv(simpleMethod
146:                                .getEventErrorMessageName(), fullString
147:                                .toString());
148:                        methodContext.putEnv(simpleMethod
149:                                .getEventResponseCodeName(), simpleMethod
150:                                .getDefaultErrorCode());
151:                    } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
152:                        methodContext.putEnv(simpleMethod
153:                                .getServiceErrorMessageListName(), messages);
154:                        methodContext.putEnv(simpleMethod
155:                                .getServiceResponseMessageName(), simpleMethod
156:                                .getDefaultErrorCode());
157:                    }
158:                    return false;
159:                }
160:
161:                if (resultBool != null && resultBool.booleanValue()) {
162:                    return SimpleMethod.runSubOps(subOps, methodContext);
163:                } else {
164:                    if (elseSubOps != null) {
165:                        return SimpleMethod
166:                                .runSubOps(elseSubOps, methodContext);
167:                    } else {
168:                        return true;
169:                    }
170:                }
171:            }
172:
173:            public String rawString() {
174:                // TODO: add all attributes and other info
175:                return "<if-compare-field field-name=\"" + this .fieldAcsr
176:                        + "\" map-name=\"" + this .mapAcsr + "\"/>";
177:            }
178:
179:            public String expandedString(MethodContext methodContext) {
180:                // TODO: something more than a stub/dummy
181:                return this.rawString();
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.