Source Code Cross Referenced for FactTemplateFactory.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » base » evaluators » 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 » Rule Engine » drolls Rule Engine » org.drools.base.evaluators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.base.evaluators;
002:
003:        /*
004:         * Copyright 2005 JBoss Inc
005:         * 
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * 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, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        import org.drools.base.BaseEvaluator;
020:        import org.drools.base.ValueType;
021:        import org.drools.common.InternalWorkingMemory;
022:        import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
023:        import org.drools.rule.VariableRestriction.VariableContextEntry;
024:        import org.drools.spi.Evaluator;
025:        import org.drools.spi.Extractor;
026:        import org.drools.spi.FieldValue;
027:
028:        /**
029:         * This is the misc "bucket" evaluator factory for objects.
030:         * It is fairly limited in operations, 
031:         * and what operations are available are dependent on the exact type.
032:         * 
033:         * @author Michael Neale
034:         */
035:        public class FactTemplateFactory implements  EvaluatorFactory {
036:
037:            private static final long serialVersionUID = 400L;
038:            private static EvaluatorFactory INSTANCE = new FactTemplateFactory();
039:
040:            private FactTemplateFactory() {
041:
042:            }
043:
044:            public static EvaluatorFactory getInstance() {
045:                if (FactTemplateFactory.INSTANCE == null) {
046:                    FactTemplateFactory.INSTANCE = new FactTemplateFactory();
047:                }
048:                return FactTemplateFactory.INSTANCE;
049:            }
050:
051:            public Evaluator getEvaluator(final Operator operator) {
052:                if (operator == Operator.EQUAL) {
053:                    return FactTemplateEqualEvaluator.INSTANCE;
054:                } else if (operator == Operator.NOT_EQUAL) {
055:                    return FactTemplateNotEqualEvaluator.INSTANCE;
056:                } else {
057:                    throw new RuntimeException("Operator '" + operator
058:                            + "' does not exist for FactTemplateEvaluator");
059:                }
060:            }
061:
062:            static class FactTemplateEqualEvaluator extends BaseEvaluator {
063:                /**
064:                 * 
065:                 */
066:                private static final long serialVersionUID = 400L;
067:                public final static Evaluator INSTANCE = new FactTemplateEqualEvaluator();
068:
069:                private FactTemplateEqualEvaluator() {
070:                    super (ValueType.FACTTEMPLATE_TYPE, Operator.EQUAL);
071:                }
072:
073:                public boolean evaluate(InternalWorkingMemory workingMemory,
074:                        final Extractor extractor, final Object object1,
075:                        final FieldValue object2) {
076:                    final Object value1 = extractor.getValue(workingMemory,
077:                            object1);
078:                    final Object value2 = object2.getValue();
079:                    if (value1 == null) {
080:                        return value2 == null;
081:                    }
082:                    return value1.equals(value2);
083:                }
084:
085:                public boolean evaluateCachedRight(
086:                        InternalWorkingMemory workingMemory,
087:                        final VariableContextEntry context, final Object left) {
088:                    final Object value = context.declaration.getExtractor()
089:                            .getValue(workingMemory, left);
090:                    if (value == null) {
091:                        return ((ObjectVariableContextEntry) context).right == null;
092:                    }
093:                    return value
094:                            .equals(((ObjectVariableContextEntry) context).right);
095:                }
096:
097:                public boolean evaluateCachedLeft(
098:                        InternalWorkingMemory workingMemory,
099:                        final VariableContextEntry context, final Object right) {
100:                    final Object value = context.extractor.getValue(
101:                            workingMemory, right);
102:                    if (((ObjectVariableContextEntry) context).left == null) {
103:                        return value == null;
104:                    }
105:                    return ((ObjectVariableContextEntry) context).left
106:                            .equals(value);
107:                }
108:
109:                public boolean evaluate(InternalWorkingMemory workingMemory,
110:                        final Extractor extractor1, final Object object1,
111:                        final Extractor extractor2, final Object object2) {
112:                    final Object value1 = extractor1.getValue(workingMemory,
113:                            object1);
114:                    final Object value2 = extractor2.getValue(workingMemory,
115:                            object2);
116:                    if (value1 == null) {
117:                        return value2 == null;
118:                    }
119:                    return value1.equals(value2);
120:                }
121:
122:                public String toString() {
123:                    return "FactTemplate ==";
124:                }
125:
126:            }
127:
128:            static class FactTemplateNotEqualEvaluator extends BaseEvaluator {
129:                /**
130:                 * 
131:                 */
132:                private static final long serialVersionUID = 400L;
133:                public final static Evaluator INSTANCE = new FactTemplateNotEqualEvaluator();
134:
135:                private FactTemplateNotEqualEvaluator() {
136:                    super (ValueType.FACTTEMPLATE_TYPE, Operator.NOT_EQUAL);
137:                }
138:
139:                public boolean evaluate(InternalWorkingMemory workingMemory,
140:                        final Extractor extractor, final Object object1,
141:                        final FieldValue object2) {
142:                    final Object value1 = extractor.getValue(workingMemory,
143:                            object1);
144:                    final Object value2 = object2.getValue();
145:                    if (value1 == null) {
146:                        return value2 != null;
147:                    }
148:                    return !value1.equals(value2);
149:                }
150:
151:                public boolean evaluateCachedRight(
152:                        InternalWorkingMemory workingMemory,
153:                        final VariableContextEntry context, final Object left) {
154:                    final Object value = context.declaration.getExtractor()
155:                            .getValue(workingMemory, left);
156:                    if (value == null) {
157:                        return ((ObjectVariableContextEntry) context).right != null;
158:                    }
159:                    return !value
160:                            .equals(((ObjectVariableContextEntry) context).right);
161:                }
162:
163:                public boolean evaluateCachedLeft(
164:                        InternalWorkingMemory workingMemory,
165:                        final VariableContextEntry context, final Object right) {
166:                    final Object value = context.extractor.getValue(
167:                            workingMemory, right);
168:                    if (((ObjectVariableContextEntry) context).left == null) {
169:                        return value != null;
170:                    }
171:                    return !((ObjectVariableContextEntry) context).left
172:                            .equals(value);
173:                }
174:
175:                public boolean evaluate(InternalWorkingMemory workingMemory,
176:                        final Extractor extractor1, final Object object1,
177:                        final Extractor extractor2, final Object object2) {
178:                    final Object value1 = extractor1.getValue(workingMemory,
179:                            object1);
180:                    final Object value2 = extractor2.getValue(workingMemory,
181:                            object2);
182:                    if (value1 == null) {
183:                        return value2 != null;
184:                    }
185:                    return !value1.equals(value2);
186:                }
187:
188:                public String toString() {
189:                    return "FactTemplate !=";
190:                }
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.