Source Code Cross Referenced for ServiceEcaUtil.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » service » eca » 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 » ERP CRM Financial » SourceTap CRM » org.ofbiz.service.eca 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ServiceEcaUtil.java,v 1.3 2003/09/02 04:29:28 jonesde Exp $
003:         *
004:         * Copyright (c) 2002-2003 The Open For Business Project - www.ofbiz.org
005:         *
006:         * Permission is hereby granted, free of charge, to any person obtaining a
007:         * copy of this software and associated documentation files (the "Software"),
008:         * to deal in the Software without restriction, including without limitation
009:         * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         * and/or sell copies of the Software, and to permit persons to whom the
011:         * Software is furnished to do so, subject to the following conditions:
012:         *
013:         * The above copyright notice and this permission notice shall be included
014:         * in all copies or substantial portions of the Software.
015:         *
016:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         *
024:         */
025:        package org.ofbiz.service.eca;
026:
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:        import java.util.LinkedList;
030:        import java.util.List;
031:        import java.util.Map;
032:        import java.util.Set;
033:        import java.util.TreeSet;
034:
035:        import org.ofbiz.base.component.ComponentConfig;
036:        import org.ofbiz.base.config.GenericConfigException;
037:        import org.ofbiz.base.config.MainResourceHandler;
038:        import org.ofbiz.base.config.ResourceHandler;
039:        import org.ofbiz.service.DispatchContext;
040:        import org.ofbiz.service.GenericServiceException;
041:        import org.ofbiz.service.config.ServiceConfigUtil;
042:        import org.ofbiz.base.util.Debug;
043:        import org.ofbiz.base.util.UtilXml;
044:        import org.w3c.dom.Element;
045:
046:        /**
047:         * ServiceEcaUtil
048:         *
049:         * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
050:         * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
051:         * @version    $Revision: 1.3 $
052:         * @since      2.0
053:         */
054:        public class ServiceEcaUtil {
055:
056:            public static final String module = ServiceEcaUtil.class.getName();
057:
058:            //NOTE: the Service ECA cache is a Map instead of a UtilCache because there is no way to 
059:            // reload ecas for inidividual services if their cache line is cleared, leading to potential 
060:            // problems; the symantics of UtilCaches dictate that the user of the cache should know how
061:            // to reload ANY cleared cache line because a user could muck up the system pretty bad otherwise 
062:            public static Map ecaCache = null;
063:
064:            //public static UtilCache ecaCache = new UtilCache("service.ServiceECAs", 0, 0, false);
065:
066:            public static void reloadConfig() {
067:                ServiceEcaUtil.ecaCache = null;
068:                readConfig();
069:            }
070:
071:            public static void readConfig() {
072:                ServiceEcaUtil.ecaCache = new HashMap();
073:
074:                Element rootElement = null;
075:                try {
076:                    rootElement = ServiceConfigUtil.getXmlRootElement();
077:                } catch (GenericConfigException e) {
078:                    Debug.logError(e,
079:                            "Error getting Service Engine XML root element",
080:                            module);
081:                    return;
082:                }
083:
084:                List serviceEcasElements = UtilXml.childElementList(
085:                        rootElement, "service-ecas");
086:                Iterator secasIter = serviceEcasElements.iterator();
087:                while (secasIter.hasNext()) {
088:                    Element serviceEcasElement = (Element) secasIter.next();
089:                    ResourceHandler handler = new MainResourceHandler(
090:                            ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME,
091:                            serviceEcasElement);
092:                    addEcaDefinitions(handler);
093:                }
094:
095:                // get all of the component resource eca stuff, ie specified in each ofbiz-component.xml file
096:                List componentResourceInfos = ComponentConfig
097:                        .getAllServiceResourceInfos("eca");
098:                Iterator componentResourceInfoIter = componentResourceInfos
099:                        .iterator();
100:                while (componentResourceInfoIter.hasNext()) {
101:                    ComponentConfig.ServiceResourceInfo componentResourceInfo = (ComponentConfig.ServiceResourceInfo) componentResourceInfoIter
102:                            .next();
103:                    addEcaDefinitions(componentResourceInfo
104:                            .createResourceHandler());
105:                }
106:            }
107:
108:            public static void addEcaDefinitions(ResourceHandler handler) {
109:                Element rootElement = null;
110:                try {
111:                    rootElement = handler.getDocument().getDocumentElement();
112:                } catch (GenericConfigException e) {
113:                    Debug.logError(e, module);
114:                    return;
115:                }
116:
117:                List ecaList = UtilXml.childElementList(rootElement, "eca");
118:                Iterator ecaIt = ecaList.iterator();
119:                int numDefs = 0;
120:                while (ecaIt.hasNext()) {
121:                    Element e = (Element) ecaIt.next();
122:                    String serviceName = e.getAttribute("service");
123:                    String eventName = e.getAttribute("event");
124:                    Map eventMap = (Map) ecaCache.get(serviceName);
125:                    List rules = null;
126:
127:                    if (eventMap == null) {
128:                        eventMap = new HashMap();
129:                        rules = new LinkedList();
130:                        ecaCache.put(serviceName, eventMap);
131:                        eventMap.put(eventName, rules);
132:                    } else {
133:                        rules = (List) eventMap.get(eventName);
134:                        if (rules == null) {
135:                            rules = new LinkedList();
136:                            eventMap.put(eventName, rules);
137:                        }
138:                    }
139:                    rules.add(new ServiceEcaRule(e));
140:                    numDefs++;
141:                }
142:                if (Debug.importantOn()) {
143:                    String resourceLocation = handler.getLocation();
144:                    try {
145:                        resourceLocation = handler.getURL().toExternalForm();
146:                    } catch (GenericConfigException e) {
147:                        Debug.logError(e, "Could not get resource URL", module);
148:                    }
149:                    Debug.logImportant("Loaded " + numDefs
150:                            + " Service ECA definitions from "
151:                            + resourceLocation, module);
152:                }
153:            }
154:
155:            public static Map getServiceEventMap(String serviceName) {
156:                if (ServiceEcaUtil.ecaCache == null)
157:                    ServiceEcaUtil.readConfig();
158:                return (Map) ServiceEcaUtil.ecaCache.get(serviceName);
159:            }
160:
161:            public static void evalRules(String serviceName, Map eventMap,
162:                    String event, DispatchContext dctx, Map context,
163:                    Map result, boolean isError) throws GenericServiceException {
164:                // if the eventMap is passed we save a HashMap lookup, but if not that's okay we'll just look it up now
165:                if (eventMap == null)
166:                    eventMap = getServiceEventMap(serviceName);
167:                if (eventMap == null || eventMap.size() == 0) {
168:                    return;
169:                }
170:
171:                List rules = (List) eventMap.get(event);
172:                if (rules == null || rules.size() == 0) {
173:                    return;
174:                }
175:
176:                Iterator i = rules.iterator();
177:                if (i.hasNext() && Debug.verboseOn())
178:                    Debug.logVerbose("Running ECA (" + event + ").", module);
179:                Set actionsRun = new TreeSet();
180:                while (i.hasNext()) {
181:                    ServiceEcaRule eca = (ServiceEcaRule) i.next();
182:                    eca.eval(serviceName, dctx, context, result, isError,
183:                            actionsRun);
184:                }
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.