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


001:        package org.drools.jsr94.rules;
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:        import java.util.Iterator;
019:        import java.util.List;
020:        import java.util.Map;
021:
022:        import javax.rules.InvalidRuleSessionException;
023:        import javax.rules.ObjectFilter;
024:        import javax.rules.RuleExecutionSetNotFoundException;
025:        import javax.rules.RuleRuntime;
026:        import javax.rules.StatelessRuleSession;
027:
028:        import org.drools.FactException;
029:        import org.drools.StatelessSession;
030:        import org.drools.StatelessSessionResult;
031:        import org.drools.WorkingMemory;
032:        import org.drools.jsr94.rules.admin.RuleExecutionSetImpl;
033:        import org.drools.jsr94.rules.admin.RuleExecutionSetRepository;
034:
035:        /**
036:         * The Drools implementation of the <code>StatelessRuleSession</code>
037:         * interface which is a representation of a stateless rules engine session. A
038:         * stateless rules engine session exposes a stateless rule execution API to an
039:         * underlying rules engine.
040:         * 
041:         * @see StatelessRuleSession
042:         * 
043:         * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler </a>
044:         */
045:        public class StatelessRuleSessionImpl extends AbstractRuleSessionImpl
046:                implements  StatelessRuleSession {
047:            /**
048:             * Gets the <code>RuleExecutionSet</code> for this URI and associates it
049:             * with a RuleBase.
050:             * 
051:             * @param bindUri
052:             *            the URI the <code>RuleExecutionSet</code> has been bound to
053:             * @param properties
054:             *            additional properties used to create the
055:             *            <code>RuleSession</code> implementation.
056:             * 
057:             * @throws RuleExecutionSetNotFoundException
058:             *             if there is no rule set under the given URI
059:             */
060:            StatelessRuleSessionImpl(final String bindUri,
061:                    final Map properties,
062:                    final RuleExecutionSetRepository repository)
063:                    throws RuleExecutionSetNotFoundException {
064:                super (repository);
065:                setProperties(properties);
066:
067:                final RuleExecutionSetImpl ruleSet = (RuleExecutionSetImpl) repository
068:                        .getRuleExecutionSet(bindUri);
069:
070:                if (ruleSet == null) {
071:                    throw new RuleExecutionSetNotFoundException(
072:                            "RuleExecutionSet unbound: " + bindUri);
073:                }
074:
075:                setRuleExecutionSet(ruleSet);
076:            }
077:
078:            /**
079:             * Initialize this <code>RuleSession</code>
080:             * with a new <code>WorkingMemory</code>.
081:             */
082:            protected StatelessSession newStatelessSession() {
083:                final StatelessSession session = this .getRuleExecutionSet()
084:                        .newStatelessSession();
085:
086:                final Map props = this .getProperties();
087:                if (props != null) {
088:                    for (final Iterator iterator = props.entrySet().iterator(); iterator
089:                            .hasNext();) {
090:                        final Map.Entry entry = (Map.Entry) iterator.next();
091:                        session.setGlobal((String) entry.getKey(), entry
092:                                .getValue());
093:                    }
094:                }
095:                return session;
096:            }
097:
098:            /**
099:             * Executes the rules in the bound rule execution set using the supplied
100:             * list of objects. A <code>List</code> is returned containing the objects
101:             * created by (or passed into the rule session) the executed rules that pass
102:             * the filter test of the default <code>RuleExecutionSet</code>
103:             * <code>ObjectFilter</code>
104:             * (if present). <p/> The returned list may not neccessarily include all
105:             * objects passed, and may include <code>Object</code>s created by
106:             * side-effects. The execution of a <code>RuleExecutionSet</code> can add,
107:             * remove and update objects. Therefore the returned object list is
108:             * dependent on the rules that are part of the executed
109:             * <code>RuleExecutionSet</code> as well as Drools specific rule engine
110:             * behavior.
111:             * 
112:             * @param objects
113:             *            the objects used to execute rules.
114:             * 
115:             * @return a <code>List</code> containing the objects as a result of
116:             *         executing the rules.
117:             * 
118:             * @throws InvalidRuleSessionException
119:             *             on illegal rule session state.
120:             */
121:            public List executeRules(final List objects)
122:                    throws InvalidRuleSessionException {
123:                return executeRules(objects, this .getRuleExecutionSet()
124:                        .getObjectFilter());
125:            }
126:
127:            /**
128:             * Executes the rules in the bound rule execution set using the supplied
129:             * list of objects. A <code>List</code> is returned containing the objects
130:             * created by (or passed into the rule engine) the executed rules and
131:             * filtered with the supplied object filter. <p/> The returned list may not
132:             * neccessarily include all objects passed, and may include
133:             * <code>Object</code>s created by side-effects. The execution of a
134:             * <code>RuleExecutionSet</code> can add, remove and update objects.
135:             * Therefore the returned object list is dependent on the rules that are
136:             * part of the executed <code>RuleExecutionSet</code> as well as Drools
137:             * specific rule engine behavior.
138:             * 
139:             * @param objects
140:             *            the objects used to execute rules.
141:             * @param filter
142:             *            the object filter.
143:             * 
144:             * @return a <code>List</code> containing the objects as a result of
145:             *         executing rules, after passing through the supplied object
146:             *         filter.
147:             * 
148:             * @throws InvalidRuleSessionException
149:             *             on illegal rule session state.
150:             */
151:            public List executeRules(final List objects,
152:                    final ObjectFilter filter)
153:                    throws InvalidRuleSessionException {
154:                StatelessSession session = newStatelessSession();
155:                StatelessSessionResult results = session
156:                        .executeWithResults(objects);
157:
158:                return IteratorToList.convert(results
159:                        .iterateObjects(new ObjectFilterAdapter(filter)));
160:            }
161:
162:            public int getType() throws InvalidRuleSessionException {
163:                return RuleRuntime.STATELESS_SESSION_TYPE;
164:            }
165:
166:            /**
167:             * Ensures this <code>RuleSession</code> is not
168:             * in an illegal rule session state.
169:             *
170:             * @throws InvalidRuleSessionException on illegal rule session state.
171:             */
172:            protected void checkRuleSessionValidity()
173:                    throws InvalidRuleSessionException {
174:                if (getRuleExecutionSet() == null) {
175:                    throw new InvalidRuleSessionException(
176:                            "invalid rule session");
177:                }
178:            }
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.