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


001:        package org.drools.eclipse.wizard.rule;
002:
003:        import java.io.BufferedReader;
004:        import java.io.ByteArrayInputStream;
005:        import java.io.IOException;
006:        import java.io.InputStream;
007:        import java.io.InputStreamReader;
008:        import java.io.UnsupportedEncodingException;
009:        import java.text.DateFormat;
010:        import java.util.Date;
011:        import java.util.regex.Pattern;
012:
013:        /**
014:         * This will generate DRL bits and bobs based on various templates.
015:         * For use by the wizards only. 
016:         * TODO: move this to string template (as it is being used elsewhere in drools)
017:         * @author Michael Neale
018:         */
019:        public class DRLGenerator {
020:
021:            private static final Pattern packageDec = Pattern
022:                    .compile("\\$package\\$");
023:            private static final Pattern dateDec = Pattern
024:                    .compile("\\$date\\$");
025:            private static final Pattern functionsDec = Pattern
026:                    .compile("\\$functions\\$");
027:            private static final Pattern expanderDec = Pattern
028:                    .compile("\\$expander\\$");
029:
030:            public InputStream generateRule(String packageName,
031:                    InputStream template) throws IOException {
032:
033:                String temp = readTemplate(template);
034:                temp = doHeader(packageName, temp);
035:
036:                return toStream(temp);
037:
038:            }
039:
040:            public InputStream generatePackage(String packageName,
041:                    boolean functions, boolean expander, InputStream template)
042:                    throws IOException {
043:                String temp = readTemplate(template);
044:                temp = doHeader(packageName, temp);
045:                if (functions) {
046:                    temp = functionsDec
047:                            .matcher(temp)
048:                            .replaceFirst(
049:                                    "function myFunction( ... ) "
050:                                            + System
051:                                                    .getProperty("line.separator")
052:                                            + "    #function content (can have multiple functions) "
053:                                            + System
054:                                                    .getProperty("line.separator")
055:                                            + "end"
056:                                            + System
057:                                                    .getProperty("line.separator"));
058:                } else {
059:                    temp = functionsDec.matcher(temp).replaceFirst("");
060:                }
061:                if (expander) {
062:                    temp = expanderDec
063:                            .matcher(temp)
064:                            .replaceFirst(
065:                                    "expander customLanguage.dsl"
066:                                            + System
067:                                                    .getProperty("line.separator")
068:                                            + "");
069:                } else {
070:                    temp = expanderDec.matcher(temp).replaceFirst("");
071:                }
072:                return toStream(temp);
073:
074:            }
075:
076:            private ByteArrayInputStream toStream(String temp)
077:                    throws UnsupportedEncodingException {
078:                ByteArrayInputStream stream = new ByteArrayInputStream(temp
079:                        .getBytes("UTF-8"));
080:                return stream;
081:            }
082:
083:            private String doHeader(String packageName, String temp) {
084:                temp = packageDec.matcher(temp).replaceFirst(
085:                        "package " + packageName
086:                                + System.getProperty("line.separator"));
087:                temp = dateDec.matcher(temp).replaceFirst(
088:                        DateFormat.getDateInstance().format(new Date()));
089:                return temp;
090:            }
091:
092:            private String readTemplate(InputStream template)
093:                    throws IOException {
094:                BufferedReader reader = new BufferedReader(
095:                        new InputStreamReader(template));
096:                String line = null;
097:                StringBuffer buf = new StringBuffer();
098:                while ((line = reader.readLine()) != null) {
099:                    buf.append(line + System.getProperty("line.separator"));
100:                }
101:                String temp = buf.toString();
102:                return temp;
103:            }
104:
105:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.