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


001:        package org.drools.brms.server.util;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collections;
005:        import java.util.HashMap;
006:        import java.util.Iterator;
007:        import java.util.List;
008:        import java.util.Map;
009:        import java.util.StringTokenizer;
010:
011:        import org.mvel.MVEL;
012:
013:        /**
014:         * Use mvel to load up map/list of valid items for fields - used by the Guided rule editor.
015:         */
016:        public class DataEnumLoader {
017:
018:            private final List errors;
019:            private final Map data;
020:
021:            /**
022:             * This is the source of the asset, which is an MVEL map (minus the outer "[") of course.
023:             */
024:            public DataEnumLoader(String mvelSource) {
025:                errors = new ArrayList();
026:                this .data = loadEnum(mvelSource);
027:            }
028:
029:            private Map loadEnum(String mvelSource) {
030:
031:                if (mvelSource == null || (mvelSource.trim().equals(""))) {
032:                    return Collections.EMPTY_MAP;
033:                }
034:                mvelSource = addCommasForNewLines(mvelSource);
035:                final Object mvelData;
036:                try {
037:                    mvelSource = "[ " + mvelSource + " ]";
038:                    mvelData = MVEL.eval(mvelSource, new HashMap());
039:                } catch (RuntimeException e) {
040:                    addError("Unable to load enumeration data.");
041:                    addError(e.getMessage());
042:                    addError("Error type: " + e.getClass().getName());
043:                    return Collections.EMPTY_MAP;
044:                }
045:                if (!(mvelData instanceof  Map)) {
046:                    addError("The expression is not a map, it is a "
047:                            + mvelData.getClass().getName());
048:                    return Collections.EMPTY_MAP;
049:                }
050:                Map map = (Map) mvelData;
051:                Map newMap = new HashMap();
052:                for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
053:                    String key = (String) iter.next();
054:                    Object list = map.get(key);
055:                    if (!(list instanceof  List)) {
056:                        if (list == null) {
057:                            addError("The item with " + key + " is null.");
058:                        } else {
059:                            addError("The item with " + key
060:                                    + " is not a list, it is a "
061:                                    + list.getClass().getName());
062:                        }
063:                        return Collections.EMPTY_MAP;
064:                    }
065:                    List items = (List) list;
066:                    String[] newItems = new String[items.size()];
067:                    for (int i = 0; i < items.size(); i++) {
068:                        Object listItem = items.get(i);
069:                        if (!(listItem instanceof  String)) {
070:                            newItems[i] = listItem.toString();
071:                        } else {
072:                            newItems[i] = (String) listItem;
073:                        }
074:                    }
075:                    newMap.put(key, newItems);
076:                }
077:                return newMap;
078:            }
079:
080:            public static String addCommasForNewLines(String mvelSource) {
081:                StringTokenizer st = new StringTokenizer(mvelSource, "\r\n");
082:                StringBuffer buf = new StringBuffer();
083:                while (st.hasMoreTokens()) {
084:                    String line = st.nextToken().trim();
085:                    if (st.hasMoreTokens() && line.endsWith(",")) {
086:                        buf.append(line);
087:                    } else {
088:                        buf.append(line);
089:                        if (st.hasMoreTokens()) {
090:                            buf.append(",");
091:                        }
092:                    }
093:                    if (st.hasMoreTokens()) {
094:                        buf.append("\n");
095:                    }
096:                }
097:                return buf.toString();
098:            }
099:
100:            private void addError(String string) {
101:                this .errors.add(string);
102:            }
103:
104:            /**
105:             * Return a list of any errors found.
106:             */
107:            public List getErrors() {
108:                return this .errors;
109:            }
110:
111:            public boolean hasErrors() {
112:                return this .errors.size() > 0;
113:            }
114:
115:            /**
116:             * Return the map of Fact.field to List (of Strings).
117:             */
118:            public Map getData() {
119:                return this.data;
120:            }
121:
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.