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


001:        /*
002:         * $Id: GroupModel.java,v 1.4 2003/11/15 20:10:45 jonesde Exp $
003:         *
004:         *  Copyright (c) 2001, 2002 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:        package org.ofbiz.service.group;
025:
026:        import java.util.HashMap;
027:        import java.util.Iterator;
028:        import java.util.LinkedList;
029:        import java.util.List;
030:        import java.util.Map;
031:
032:        import org.ofbiz.base.util.Debug;
033:        import org.ofbiz.base.util.UtilXml;
034:        import org.ofbiz.service.GenericServiceException;
035:        import org.ofbiz.service.ModelService;
036:        import org.ofbiz.service.ServiceDispatcher;
037:        import org.w3c.dom.Element;
038:
039:        /**
040:         * GroupModel.java
041:         * 
042:         * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
043:         * @version    $Revision: 1.4 $
044:         * @since      2.0
045:         */
046:        public class GroupModel {
047:
048:            public static final String module = GroupModel.class.getName();
049:
050:            private String groupName, sendMode;
051:            private List services;
052:            private int lastServiceRan;
053:
054:            /**
055:             * Constructor using DOM Element
056:             * @param group DOM element for the group
057:             */
058:            public GroupModel(Element group) {
059:                this .lastServiceRan = -1;
060:                this .services = new LinkedList();
061:                List serviceList = UtilXml.childElementList(group, "service");
062:                Iterator i = serviceList.iterator();
063:                while (i.hasNext()) {
064:                    Element service = (Element) i.next();
065:                    services.add(new GroupServiceModel(service));
066:                }
067:                this .groupName = group.getAttribute("name");
068:                this .sendMode = group.getAttribute("send-mode");
069:                if (Debug.verboseOn())
070:                    Debug.logVerbose("Created Service Group Model --> " + this ,
071:                            module);
072:            }
073:
074:            /**
075:             * Basic Constructor
076:             * @param groupName Name of the group
077:             * @param sendMode Mode used (see DTD)
078:             * @param services List of GroupServiceModel objects
079:             */
080:            public GroupModel(String groupName, String sendMode, List services) {
081:                this .lastServiceRan = -1;
082:                this .groupName = groupName;
083:                this .sendMode = sendMode;
084:                this .services = services;
085:            }
086:
087:            /**
088:             * Getter for group name
089:             * @return String
090:             */
091:            public String getGroupName() {
092:                return this .groupName;
093:            }
094:
095:            /**
096:             * Getter for send mode
097:             * @return String
098:             */
099:            public String getSendMode() {
100:                return this .sendMode;
101:            }
102:
103:            /**
104:             * Returns a list of services in this group
105:             * @return List
106:             */
107:            public List getServices() {
108:                return this .services;
109:            }
110:
111:            /**
112:             * Invokes the group of services in order defined
113:             * @param dispatcher ServiceDispatcher used for invocation
114:             * @param localName Name of the LocalDispatcher (namespace)
115:             * @param context Full parameter context (combined for all services)
116:             * @return Map Result Map
117:             * @throws GenericServiceException
118:             */
119:            public Map run(ServiceDispatcher dispatcher, String localName,
120:                    Map context) throws GenericServiceException {
121:                if (this .getSendMode().equals("all")) {
122:                    return runAll(dispatcher, localName, context);
123:                } else if (this .getSendMode().equals("round-robin")) {
124:                    return runIndex(dispatcher, localName, context,
125:                            (++lastServiceRan % services.size()));
126:                } else if (this .getSendMode().equals("random")) {
127:                    int randomIndex = (int) (Math.random() * (double) (services
128:                            .size()));
129:                    return runIndex(dispatcher, localName, context, randomIndex);
130:                } else if (this .getSendMode().equals("first-available")) {
131:                    return runOne(dispatcher, localName, context);
132:                } else if (this .getSendMode().equals("none")) {
133:                    return new HashMap();
134:                } else {
135:                    throw new GenericServiceException(
136:                            "This mode is not currently supported");
137:                }
138:            }
139:
140:            /**     
141:             * @see java.lang.Object#toString()
142:             */
143:            public String toString() {
144:                StringBuffer str = new StringBuffer();
145:                str.append(getGroupName());
146:                str.append("::");
147:                str.append(getSendMode());
148:                str.append("::");
149:                str.append(getServices());
150:                return str.toString();
151:            }
152:
153:            private Map runAll(ServiceDispatcher dispatcher, String localName,
154:                    Map context) throws GenericServiceException {
155:                Map runContext = new HashMap(context);
156:                Map result = new HashMap();
157:                Iterator i = services.iterator();
158:                while (i.hasNext()) {
159:                    GroupServiceModel model = (GroupServiceModel) i.next();
160:                    if (Debug.verboseOn())
161:                        Debug
162:                                .logVerbose("Using Context: " + runContext,
163:                                        module);
164:                    Map this Result = model.invoke(dispatcher, localName,
165:                            runContext);
166:                    if (Debug.verboseOn())
167:                        Debug.logVerbose("Result: " + this Result, module);
168:
169:                    // make sure we didn't fail
170:                    if (((String) this Result.get(ModelService.RESPONSE_MESSAGE))
171:                            .equals(ModelService.RESPOND_ERROR)) {
172:                        Debug.logError("Grouped service [" + model.getName()
173:                                + "] failed.", module);
174:                        return this Result;
175:                    }
176:
177:                    result.putAll(this Result);
178:                    if (model.resultToContext()) {
179:                        runContext.putAll(this Result);
180:                        Debug.logVerbose("Added result(s) to context.", module);
181:                    }
182:                }
183:                return result;
184:            }
185:
186:            private Map runIndex(ServiceDispatcher dispatcher,
187:                    String localName, Map context, int index)
188:                    throws GenericServiceException {
189:                GroupServiceModel model = (GroupServiceModel) services
190:                        .get(index);
191:                return model.invoke(dispatcher, localName, context);
192:            }
193:
194:            private Map runOne(ServiceDispatcher dispatcher, String localName,
195:                    Map context) throws GenericServiceException {
196:                Map result = null;
197:                Iterator i = services.iterator();
198:                while (i.hasNext() && result != null) {
199:                    GroupServiceModel model = (GroupServiceModel) i.next();
200:                    try {
201:                        result = model.invoke(dispatcher, localName, context);
202:                    } catch (GenericServiceException e) {
203:                        Debug
204:                                .logError("Service: " + model + " failed.",
205:                                        module);
206:                    }
207:                }
208:                if (result == null) {
209:                    throw new GenericServiceException(
210:                            "All services failed to run; none available.");
211:                }
212:                return result;
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.