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


001:        package org.drools.jsr94.rules.admin;
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 java.io.IOException;
020:        import java.io.InputStream;
021:        import java.io.InputStreamReader;
022:        import java.io.Reader;
023:        import java.io.StringReader;
024:        import java.util.Map;
025:
026:        import javax.rules.admin.LocalRuleExecutionSetProvider;
027:        import javax.rules.admin.RuleExecutionSet;
028:        import javax.rules.admin.RuleExecutionSetCreateException;
029:
030:        import org.drools.IntegrationException;
031:        import org.drools.compiler.DroolsParserException;
032:        import org.drools.compiler.PackageBuilder;
033:        import org.drools.compiler.PackageBuilderConfiguration;
034:        import org.drools.decisiontable.InputType;
035:        import org.drools.decisiontable.SpreadsheetCompiler;
036:        import org.drools.jsr94.rules.Constants;
037:        import org.drools.rule.Package;
038:
039:        /**
040:         * The Drools implementation of the <code>LocalRuleExecutionSetProvider</code>
041:         * interface which defines <code>RuleExecutionSet</code> creation methods for
042:         * defining <code>RuleExecutionSet</code>s from local (non-serializable)
043:         * resources.
044:         *
045:         * @see LocalRuleExecutionSetProvider
046:         *
047:         * @author N. Alex Rupp (n_alex <at>codehaus.org)
048:         * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler </a>
049:         * @author <a href="mailto:michael.frandsen@syngenio.de">michael frandsen </a>
050:         */
051:        public class LocalRuleExecutionSetProviderImpl implements 
052:                LocalRuleExecutionSetProvider {
053:            /** Default constructor. */
054:            public LocalRuleExecutionSetProviderImpl() {
055:                super ();
056:            }
057:
058:            /**
059:             * Creates a <code>RuleExecutionSet</code> implementation using a supplied
060:             * input stream and additional Drools-specific properties. A Drools-specific
061:             * rule execution set is read from the supplied InputStream. The method
062:             * <code>createRuleExecutionSet</code> taking a Reader instance should be
063:             * used if the source is a character stream and encoding conversion should
064:             * be performed.
065:             *
066:             * @param ruleExecutionSetStream
067:             *            an input stream used to read the rule execution set.
068:             * @param properties
069:             *            additional properties used to create the
070:             *            <code>RuleExecutionSet</code> implementation. May be
071:             *            <code>null</code>.
072:             *
073:             * @throws RuleExecutionSetCreateException
074:             *             on rule execution set creation error.
075:             *
076:             * @return The created <code>RuleExecutionSet</code>.
077:             */
078:            public RuleExecutionSet createRuleExecutionSet(
079:                    final InputStream ruleExecutionSetStream,
080:                    final Map properties)
081:                    throws RuleExecutionSetCreateException {
082:                if (properties != null) {
083:                    String source = (String) properties
084:                            .get(Constants.RES_SOURCE);
085:                    if (source == null) {
086:                        // support legacy name
087:                        source = (String) properties.get("source");
088:                    }
089:                    if (source != null
090:                            && source
091:                                    .equals(Constants.RES_SOURCE_TYPE_DECISION_TABLE)) {
092:                        final SpreadsheetCompiler converter = new SpreadsheetCompiler();
093:                        final String drl = converter.compile(
094:                                ruleExecutionSetStream, InputType.XLS);
095:                        return createRuleExecutionSet(new StringReader(drl),
096:                                properties);
097:                    } else {
098:                        return createRuleExecutionSet(new InputStreamReader(
099:                                ruleExecutionSetStream), properties);
100:                    }
101:                } else
102:                    return createRuleExecutionSet(new InputStreamReader(
103:                            ruleExecutionSetStream), properties);
104:            }
105:
106:            /**
107:             * Creates a <code>RuleExecutionSet</code> implementation using a supplied
108:             * character stream Reader and additional Drools-specific properties. A
109:             * Drools-specific rule execution set is read from the supplied Reader.
110:             *
111:             * @param ruleExecutionSetReader
112:             *            a Reader used to read the rule execution set.
113:             * @param properties
114:             *            additional properties used to create the
115:             *            <code>RuleExecutionSet</code> implementation. May be
116:             *            <code>null</code>.
117:             *
118:             * @throws RuleExecutionSetCreateException
119:             *             on rule execution set creation error.
120:             *
121:             * @return The created <code>RuleExecutionSet</code>.
122:             */
123:            public RuleExecutionSet createRuleExecutionSet(
124:                    final Reader ruleExecutionSetReader, final Map properties)
125:                    throws RuleExecutionSetCreateException {
126:                try {
127:                    PackageBuilderConfiguration config = null;
128:
129:                    if (properties != null) {
130:                        config = (PackageBuilderConfiguration) properties
131:                                .get(Constants.RES_PACKAGEBUILDER_CONFIG);
132:                    }
133:
134:                    PackageBuilder builder = null;
135:                    if (config != null) {
136:                        builder = new PackageBuilder(config);
137:                    } else {
138:                        builder = new PackageBuilder();
139:                    }
140:
141:                    Object dsrl = null;
142:                    String source = null;
143:
144:                    if (properties != null) {
145:                        dsrl = properties.get(Constants.RES_DSL);
146:                        if (dsrl == null) {
147:                            // check for old legacy name ending
148:                            dsrl = properties.get("dsl");
149:                        }
150:                        source = (String) properties.get(Constants.RES_SOURCE);
151:                        if (source == null) {
152:                            // check for old legacy name ending
153:                            source = (String) properties.get("source");
154:                        }
155:                    }
156:
157:                    if (source == null) {
158:                        source = "drl";
159:                    }
160:
161:                    if (dsrl == null) {
162:                        if (source.equals(Constants.RES_SOURCE_TYPE_XML)
163:                                || source.equals("xml")) {
164:                            builder.addPackageFromXml(ruleExecutionSetReader);
165:                        } else {
166:                            builder.addPackageFromDrl(ruleExecutionSetReader);
167:                        }
168:                    } else {
169:                        if (source.equals(Constants.RES_SOURCE_TYPE_XML)
170:                                || source.equals("xml")) {
171:                            // xml cannot specify a dsl
172:                            builder.addPackageFromXml(ruleExecutionSetReader);
173:                        } else {
174:                            if (dsrl instanceof  Reader) {
175:                                builder.addPackageFromDrl(
176:                                        ruleExecutionSetReader, (Reader) dsrl);
177:                            } else {
178:                                builder.addPackageFromDrl(
179:                                        ruleExecutionSetReader,
180:                                        new StringReader((String) dsrl));
181:                            }
182:                        }
183:                    }
184:
185:                    final Package pkg = builder.getPackage();
186:                    return createRuleExecutionSet(pkg, properties);
187:                } catch (final IOException e) {
188:                    throw new RuleExecutionSetCreateException(
189:                            "cannot create rule execution set", e);
190:                } catch (final DroolsParserException e) {
191:                    throw new RuleExecutionSetCreateException(
192:                            "cannot create rule execution set", e);
193:                }
194:            }
195:
196:            /**
197:             * Creates a <code>RuleExecutionSet</code> implementation from a
198:             * Drools-specific AST representation and Drools-specific properties.
199:             *
200:             * @param ruleExecutionSetAst
201:             *            the vendor representation of a rule execution set
202:             * @param properties
203:             *            additional properties used to create the
204:             *            <code>RuleExecutionSet</code> implementation. May be
205:             *            <code>null</code>.
206:             *
207:             * @throws RuleExecutionSetCreateException
208:             *             on rule execution set creation error.
209:             *
210:             * @return The created <code>RuleExecutionSet</code>.
211:             */
212:            public RuleExecutionSet createRuleExecutionSet(
213:                    final Object ruleExecutionSetAst, final Map properties)
214:                    throws RuleExecutionSetCreateException {
215:                if (ruleExecutionSetAst instanceof  Package) {
216:                    final Package pkg = (Package) ruleExecutionSetAst;
217:                    return this .createRuleExecutionSet(pkg, properties);
218:                }
219:                throw new RuleExecutionSetCreateException(
220:                        " Incoming AST object must be an org.drools.rule.Package.  Was "
221:                                + ruleExecutionSetAst.getClass());
222:            }
223:
224:            /**
225:             * Creates a <code>RuleExecutionSet</code> implementation from a
226:             * <code>RuleSet</code> and Drools-specific properties.
227:             *
228:             * @param pkg
229:             *            a Drools <code>org.drools.rule.Package</code> representation
230:             *            of a rule execution set.
231:             * @param properties
232:             *            additional properties used to create the RuleExecutionSet
233:             *            implementation. May be <code>null</code>.
234:             *
235:             * @throws RuleExecutionSetCreateException
236:             *             on rule execution set creation error.
237:             *
238:             * @return The created <code>RuleExecutionSet</code>.
239:             */
240:            private RuleExecutionSet createRuleExecutionSet(final Package pkg,
241:                    final Map properties)
242:                    throws RuleExecutionSetCreateException {
243:                try {
244:                    return new RuleExecutionSetImpl(pkg, properties);
245:                } catch (final IntegrationException e) {
246:                    throw new RuleExecutionSetCreateException(
247:                            "Failed to create RuleExecutionSet", e);
248:                }
249:            }
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.