Source Code Cross Referenced for RuleExecutionSetProviderImpl.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.Serializable;
024:        import java.net.URL;
025:        import java.util.Map;
026:
027:        import javax.rules.admin.RuleExecutionSet;
028:        import javax.rules.admin.RuleExecutionSetCreateException;
029:        import javax.rules.admin.RuleExecutionSetProvider;
030:        import javax.xml.transform.Source;
031:        import javax.xml.transform.Transformer;
032:        import javax.xml.transform.TransformerException;
033:        import javax.xml.transform.TransformerFactory;
034:        import javax.xml.transform.dom.DOMSource;
035:        import javax.xml.transform.sax.SAXResult;
036:
037:        import org.drools.compiler.PackageBuilder;
038:        import org.drools.lang.descr.PackageDescr;
039:        import org.drools.rule.Package;
040:        import org.drools.xml.XmlPackageReader;
041:        import org.w3c.dom.Element;
042:
043:        /**
044:         * The Drools implementation of the <code>RuleExecutionSetProvider</code>
045:         * interface which defines <code>RuleExecutionSet</code> creation methods for
046:         * defining <code>RuleExecutionSet</code>s from potentially serializable
047:         * resources.
048:         *
049:         * @see RuleExecutionSetProvider
050:         *
051:         * @author N. Alex Rupp (n_alex <at>codehaus.org)
052:         * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler </a>
053:         * @author <a href="mailto:michael.frandsen@syngenio.de">michael frandsen </a>
054:         */
055:        public class RuleExecutionSetProviderImpl implements 
056:                RuleExecutionSetProvider {
057:            /**
058:             * Creates a <code>RuleExecutionSet</code> implementation from an XML
059:             * Document and additional Drools-specific properties. A Drools-specific
060:             * rule execution set is read from the supplied XML Document.
061:             *
062:             * @param ruleExecutionSetElement the XML element that is the source of the
063:             *        rule execution set
064:             * @param properties additional properties used to create the
065:             *        <code>RuleExecutionSet</code> implementation.
066:             *        May be <code>null</code>.
067:             *
068:             * @throws RuleExecutionSetCreateException on rule execution set creation
069:             *         error.
070:             *
071:             * @return The created <code>RuleExecutionSet</code>.
072:             */
073:            public RuleExecutionSet createRuleExecutionSet(
074:                    final Element ruleExecutionSetElement, final Map properties)
075:                    throws RuleExecutionSetCreateException {
076:                try {
077:                    //    		 Prepare the DOM source
078:                    final Source source = new DOMSource(ruleExecutionSetElement);
079:
080:                    final XmlPackageReader xmlPackageReader = new XmlPackageReader();
081:                    // Prepare the result
082:                    final SAXResult result = new SAXResult(xmlPackageReader);
083:
084:                    // Create a transformer
085:                    final Transformer xformer = TransformerFactory
086:                            .newInstance().newTransformer();
087:
088:                    // Traverse the DOM tree
089:                    xformer.transform(source, result);
090:
091:                    final PackageDescr packageDescr = xmlPackageReader
092:                            .getPackageDescr();
093:
094:                    //          pre build the package
095:                    final PackageBuilder builder = new PackageBuilder();
096:                    builder.addPackage(packageDescr);
097:                    final Package pkg = builder.getPackage();
098:
099:                    final LocalRuleExecutionSetProviderImpl localRuleExecutionSetProvider = new LocalRuleExecutionSetProviderImpl();
100:                    return localRuleExecutionSetProvider
101:                            .createRuleExecutionSet(pkg, properties);
102:                } catch (final TransformerException e) {
103:                    throw new RuleExecutionSetCreateException(
104:                            "could not create RuleExecutionSet: " + e);
105:                }
106:
107:            }
108:
109:            /**
110:             * Creates a <code>RuleExecutionSet</code> implementation from a
111:             * Drools-specific Abstract Syntax Tree (AST) representation and
112:             * Drools-specific properties.
113:             * <p/>
114:             * This method accepts a <code>org.drools.RuleBase</code> object as its
115:             * vendor-specific AST representation.
116:             *
117:             * @param ruleExecutionSetAst the Drools representation of a
118:             *        rule execution set
119:             * @param properties additional properties used to create the
120:             *        <code>RuleExecutionSet</code> implementation.
121:             *        May be <code>null</code>.
122:             *
123:             * @throws RuleExecutionSetCreateException on rule execution set creation
124:             *         error.
125:             *
126:             * @return The created <code>RuleExecutionSet</code>.
127:             */
128:            public RuleExecutionSet createRuleExecutionSet(
129:                    final Serializable ruleExecutionSetAst, final Map properties)
130:                    throws RuleExecutionSetCreateException {
131:                if (ruleExecutionSetAst instanceof  Package) {
132:                    final LocalRuleExecutionSetProviderImpl localRuleExecutionSetProvider = new LocalRuleExecutionSetProviderImpl();
133:                    return localRuleExecutionSetProvider
134:                            .createRuleExecutionSet(ruleExecutionSetAst,
135:                                    properties);
136:                } else {
137:                    throw new IllegalArgumentException(
138:                            "Serializable object must be "
139:                                    + "an instance of org.drools.rule.RuleSet.  It was "
140:                                    + ruleExecutionSetAst.getClass().getName());
141:                }
142:            }
143:
144:            /**
145:             * Creates a <code>RuleExecutionSet</code> implementation from a URI.
146:             * The URI is opaque to the specification and may be used to refer to the
147:             * file system, a database, or Drools-specific datasource.
148:             *
149:             * @param ruleExecutionSetUri the URI to load the rule execution set from
150:             * @param properties additional properties used to create the
151:             *        <code>RuleExecutionSet</code> implementation.
152:             *        May be <code>null</code>.
153:             *
154:             * @throws RuleExecutionSetCreateException on rule execution set creation
155:             *         error.
156:             * @throws IOException if an I/O error occurs while accessing the URI
157:             *
158:             * @return The created <code>RuleExecutionSet</code>.
159:             */
160:            public RuleExecutionSet createRuleExecutionSet(
161:                    final String ruleExecutionSetUri, final Map properties)
162:                    throws RuleExecutionSetCreateException, IOException {
163:                InputStream in = null;
164:                try {
165:                    final LocalRuleExecutionSetProviderImpl localRuleExecutionSetProvider = new LocalRuleExecutionSetProviderImpl();
166:                    in = new URL(ruleExecutionSetUri).openStream();
167:                    final Reader reader = new InputStreamReader(in);
168:                    return localRuleExecutionSetProvider
169:                            .createRuleExecutionSet(reader, properties);
170:                } catch (final IOException ex) {
171:                    throw ex;
172:                } finally {
173:                    if (in != null) {
174:                        in.close();
175:                    }
176:                }
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.