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


001:        package org.drools.spi;
002:
003:        import java.util.HashMap;
004:        import java.util.Map;
005:        import java.util.Stack;
006:
007:        import org.drools.rule.Pattern;
008:        import org.drools.rule.Declaration;
009:        import org.drools.rule.GroupElement;
010:        import org.drools.rule.RuleConditionElement;
011:
012:        /**
013:         * A class capable of resolving a declaration in the current build context
014:         * 
015:         * @author etirelli
016:         */
017:        public class DeclarationScopeResolver {
018:            private static final Stack EMPTY_STACK = new Stack();
019:            private Map[] maps;
020:            private Stack buildStack;
021:
022:            public DeclarationScopeResolver(final Map[] maps) {
023:                this (maps, EMPTY_STACK);
024:            }
025:
026:            public DeclarationScopeResolver(final Map[] maps,
027:                    final Stack buildStack) {
028:                this .maps = maps;
029:                if (buildStack == null) {
030:                    this .buildStack = EMPTY_STACK;
031:                } else {
032:                    this .buildStack = buildStack;
033:                }
034:            }
035:
036:            public Class getType(final String name) {
037:                for (int i = this .buildStack.size() - 1; i >= 0; i--) {
038:                    final Declaration declaration = (Declaration) ((RuleConditionElement) this .buildStack
039:                            .get(i)).getInnerDeclarations().get(name);
040:                    if (declaration != null) {
041:                        return declaration.getExtractor().getExtractToClass();
042:                    }
043:                }
044:                for (int i = 0, length = this .maps.length; i < length; i++) {
045:                    final Object object = this .maps[i].get(name);
046:                    if (object != null) {
047:                        if (object instanceof  Declaration) {
048:                            return ((Declaration) object).getExtractor()
049:                                    .getExtractToClass();
050:                        } else {
051:                            return (Class) object;
052:                        }
053:                    }
054:                }
055:                return null;
056:            }
057:
058:            public Declaration getDeclaration(final String name) {
059:                // it may be a local bound variable
060:                for (int i = this .buildStack.size() - 1; i >= 0; i--) {
061:                    final Declaration declaration = (Declaration) ((RuleConditionElement) this .buildStack
062:                            .get(i)).getInnerDeclarations().get(name);
063:                    if (declaration != null) {
064:                        return declaration;
065:                    }
066:                }
067:                // it may be a global or something
068:                for (int i = 0, length = this .maps.length; i < length; i++) {
069:                    if (this .maps[i].containsKey((name))) {
070:                        final GlobalExtractor global = new GlobalExtractor(
071:                                name, this .maps[i]);
072:                        final Pattern dummy = new Pattern(0, global
073:                                .getObjectType());
074:                        final Declaration declaration = new Declaration(name,
075:                                global, dummy);
076:                        return declaration;
077:                    }
078:                }
079:                return null;
080:            }
081:
082:            public boolean available(final String name) {
083:                for (int i = this .buildStack.size() - 1; i >= 0; i--) {
084:                    final Declaration declaration = (Declaration) ((RuleConditionElement) this .buildStack
085:                            .get(i)).getInnerDeclarations().get(name);
086:                    if (declaration != null) {
087:                        return true;
088:                    }
089:                }
090:                for (int i = 0, length = this .maps.length; i < length; i++) {
091:                    if (this .maps[i].containsKey((name))) {
092:                        return true;
093:                    }
094:                }
095:                return false;
096:            }
097:
098:            public boolean isDuplicated(final String name) {
099:                for (int i = 0, length = this .maps.length; i < length; i++) {
100:                    if (this .maps[i].containsKey((name))) {
101:                        return true;
102:                    }
103:                }
104:                for (int i = this .buildStack.size() - 1; i >= 0; i--) {
105:                    final RuleConditionElement rce = (RuleConditionElement) this .buildStack
106:                            .get(i);
107:                    final Declaration declaration = (Declaration) rce
108:                            .getInnerDeclarations().get(name);
109:                    if (declaration != null) {
110:                        if ((rce instanceof  GroupElement)
111:                                && ((GroupElement) rce).isOr()) {
112:                            // if it is an OR and it is duplicated, we can stop looking for duplication now
113:                            // as it is a separate logical branch
114:                            return false;
115:                        }
116:                        return true;
117:                    }
118:                }
119:                return false;
120:            }
121:
122:            /**
123:             * Return all declarations scoped to the current
124:             * RuleConditionElement in the build stack
125:             * 
126:             * @return
127:             */
128:            public Map getDeclarations() {
129:                final Map declarations = new HashMap();
130:                for (int i = 0; i < this .buildStack.size(); i++) {
131:                    // this may be optimized in the future to only re-add elements at 
132:                    // scope breaks, like "NOT" and "EXISTS"
133:                    declarations.putAll(((RuleConditionElement) this.buildStack
134:                            .get(i)).getInnerDeclarations());
135:                }
136:                return declarations;
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.