Source Code Cross Referenced for StatusUtils.java in  » ERP-CRM-Financial » sakai » edu » indiana » lib » twinpeaks » 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 » ERP CRM Financial » sakai » edu.indiana.lib.twinpeaks.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package edu.indiana.lib.twinpeaks.util;
002:
003:        import java.lang.*;
004:        import java.util.*;
005:
006:        import org.w3c.dom.*;
007:        import org.xml.sax.*;
008:
009:        public class StatusUtils {
010:
011:            private static org.apache.commons.logging.Log _log = LogUtils
012:                    .getLog(StatusUtils.class);
013:
014:            /**
015:             * Set up initial status information (done before LOGON)
016:             */
017:            public static void initialize(SessionContext sessionContext,
018:                    String targets) {
019:                StringTokenizer parser = new StringTokenizer(targets);
020:                ArrayList dbList = new ArrayList();
021:                HashMap targetMap = getNewStatusMap(sessionContext);
022:
023:                /*
024:                 * Establish the DB list and initial (pre-LOGON) status
025:                 */
026:                while (parser.hasMoreTokens()) {
027:                    String db = parser.nextToken();
028:                    HashMap emptyMap = new HashMap();
029:
030:                    /*
031:                     * Empty status entry
032:                     */
033:                    emptyMap.put("STATUS", "INACTIVE");
034:                    emptyMap.put("STATUS_MESSAGE", "<none>");
035:
036:                    emptyMap.put("HITS", "0");
037:                    emptyMap.put("ESTIMATE", "0");
038:                    emptyMap.put("MERGED", "0");
039:                    /*
040:                     * Save
041:                     */
042:                    dbList.add(db);
043:                    targetMap.put(db, emptyMap);
044:                }
045:
046:                sessionContext.put("TARGETS", dbList);
047:                sessionContext.putInt("active", 0);
048:
049:                sessionContext.put("STATUS", "INACTIVE");
050:                sessionContext.put("STATUS_MESSAGE", "<none>");
051:            }
052:
053:            /**
054:             * Get an iterator into the system status map
055:             * @param sessionContext Active SessionContext
056:             * @return Status map Iterator
057:             */
058:            public static Iterator getStatusMapEntrySetIterator(
059:                    SessionContext sessionContext) {
060:                HashMap statusMap = (HashMap) sessionContext
061:                        .get("searchStatus");
062:                Set entrySet = Collections.EMPTY_SET;
063:
064:                if (statusMap != null) {
065:                    entrySet = statusMap.entrySet();
066:                }
067:                return entrySet.iterator();
068:            }
069:
070:            /**
071:             * Get the status entry for a specified target database
072:             * @param sessionContext Active SessionContext
073:             * @param target Database name
074:             * @return Status Map for this target (null if none)
075:             */
076:            public static HashMap getStatusMapForTarget(
077:                    SessionContext sessionContext, String target) {
078:                HashMap statusMap = (HashMap) sessionContext
079:                        .get("searchStatus");
080:
081:                _log.debug("Map for target " + target + " is "
082:                        + statusMap.get(target));
083:                return (statusMap == null) ? null : (HashMap) statusMap
084:                        .get(target);
085:            }
086:
087:            /**
088:             * Create a new status map
089:             * @param sessionContext Active SessionContext
090:             * @return Status Map for this target
091:             */
092:            public static HashMap getNewStatusMap(SessionContext sessionContext) {
093:                HashMap statusMap = new HashMap();
094:
095:                sessionContext.remove("searchStatus");
096:                sessionContext.put("searchStatus", statusMap);
097:
098:                return statusMap;
099:            }
100:
101:            /**
102:             * Set global status (effects all target databases)
103:             * @param sessionContext Active SessionContext
104:             * @param status One of ERROR | DONE
105:             * @param message Status text
106:             */
107:            public static void setGlobalStatus(SessionContext sessionContext,
108:                    String status, String message) {
109:                /*
110:                 * Set global status
111:                 */
112:                sessionContext.put("STATUS", status);
113:                sessionContext.put("STATUS_MESSAGE", message);
114:                /*
115:                 * Per-target status
116:                 */
117:                for (Iterator iterator = StatusUtils
118:                        .getStatusMapEntrySetIterator(sessionContext); iterator
119:                        .hasNext();) {
120:                    Map.Entry entry = (Map.Entry) iterator.next();
121:                    HashMap targetMap = (HashMap) entry.getValue();
122:
123:                    targetMap.put("STATUS", status);
124:                    targetMap.put("STATUS_MESSAGE", message);
125:                }
126:            }
127:
128:            /**
129:             * Set global error status (effects all target databases)
130:             * @param sessionContext Active SessionContext
131:             * @param error Error number
132:             * @param message Expanded error text (null to omit expanded message)
133:             */
134:            public static void setGlobalError(SessionContext sessionContext,
135:                    String error, String message) {
136:                String statusMessage = "Error " + error;
137:
138:                if (!StringUtils.isNull(message)) {
139:                    statusMessage += ": " + message;
140:                }
141:                setGlobalStatus(sessionContext, "ERROR", statusMessage);
142:            }
143:
144:            /**
145:             * Set all status value to "search complete" (effects all target databases)
146:             * @param sessionContext Active SessionContext
147:             */
148:            public static void setAllComplete(SessionContext sessionContext) {
149:                setGlobalStatus(sessionContext, "DONE", "Search complete");
150:            }
151:
152:            /**
153:             * Update the hit count for this target (database)
154:             * @param sessionContext Active SessionContext
155:             * @param target Database name
156:             * @return Updated hit count
157:             */
158:            public static int updateHits(SessionContext sessionContext,
159:                    String target) {
160:                Map targetMap;
161:                String hits;
162:                int total, estimate;
163:
164:                if (StringUtils.isNull(target)) {
165:                    throw new SearchException("No target database to update");
166:                }
167:
168:                if ((targetMap = getStatusMapForTarget(sessionContext, target)) == null) {
169:                    throw new SearchException(
170:                            "No status map for target database " + target);
171:                }
172:                /*
173:                 * Update total hits from this search source
174:                 */
175:                hits = (String) targetMap.get("HITS");
176:                total = Integer.parseInt(hits) + 1;
177:
178:                targetMap.put("HITS", String.valueOf(total));
179:                /*
180:                 * Have we collected all available results?
181:                 */
182:                estimate = Integer.parseInt((String) targetMap.get("ESTIMATE"));
183:                if (estimate == total) {
184:                    int active = sessionContext.getInt("active");
185:                    /*
186:                     * If this is the last active source, mark everything DONE
187:                     */
188:                    if (--active <= 0) {
189:                        setAllComplete(sessionContext);
190:                    } else { /*
191:                     * Just this source is finished
192:                     */
193:                        targetMap.put("STATUS", "DONE");
194:                        targetMap.put("STATUS_MESSAGE", "Search complete");
195:                    }
196:                    sessionContext.putInt("active", active);
197:                }
198:                return total;
199:            }
200:
201:            /**
202:             * Fetch the estimated hiots for a specified target (database)
203:             * @param sessionContext Active SessionContext
204:             * @param target Database name
205:             * @return Updated hit count
206:             */
207:            public static int getEstimatedHits(SessionContext sessionContext,
208:                    String target) {
209:                Map targetMap;
210:                String estimate;
211:
212:                if ((targetMap = getStatusMapForTarget(sessionContext, target)) == null) {
213:                    throw new SearchException(
214:                            "No status map for target database " + target);
215:                }
216:
217:                estimate = (String) targetMap.get("ESTIMATE");
218:                return Integer.parseInt(estimate);
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.