Source Code Cross Referenced for ApplicationManager.java in  » XML-UI » xui32 » com » xoetrope » xbb » appmgr » 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 » XML UI » xui32 » com.xoetrope.xbb.appmgr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.xbb.appmgr;
002:
003:        import com.xoetrope.service.http.XHttpRequestProxy;
004:        import com.xoetrope.swing.painter.XFlarePainter;
005:
006:        import java.awt.Color;
007:        import java.awt.SystemColor;
008:        import java.io.IOException;
009:        import java.io.StringReader;
010:        import java.text.SimpleDateFormat;
011:        import java.util.Calendar;
012:        import java.util.Date;
013:        import java.util.Properties;
014:        import javax.swing.JPanel;
015:        import javax.swing.SwingUtilities;
016:        import net.xoetrope.debug.DebugLogger;
017:        import net.xoetrope.optional.data.XOptionalDataSource;
018:        import net.xoetrope.optional.http.XHttpResponse;
019:        import net.xoetrope.optional.http.XHttpResponseHandler;
020:        import net.xoetrope.optional.http.XHttpServer;
021:        import net.xoetrope.optional.service.ServiceContext;
022:        import net.xoetrope.optional.service.ServiceProxyArgs;
023:        import net.xoetrope.optional.service.XServiceModelNode;
024:        import net.xoetrope.swing.deploy.XSystemTrayManager;
025:        import net.xoetrope.swing.painter.XGradientBackground;
026:        import net.xoetrope.swing.app.XDockingApp;
027:        import net.xoetrope.xml.XmlElement;
028:        import net.xoetrope.xml.nanoxml.NanoXmlParser;
029:        import net.xoetrope.xui.PageSupport;
030:        import net.xoetrope.xui.XLifeCycleListener;
031:        import net.xoetrope.xui.XProject;
032:        import net.xoetrope.xui.data.XBaseModel;
033:        import net.xoetrope.xui.data.XModel;
034:
035:        import sun.misc.BASE64Encoder;
036:
037:        /**
038:         * Initialize the project's connection
039:         * <p> Copyright (c) Xoetrope Ltd., 2001-2007, This software is licensed under
040:         * the GNU Public License (GPL), please see license.txt for more details. If
041:         * you make commercial use of this software you must purchase a commercial
042:         * license from Xoetrope.</p>
043:         */
044:        public class ApplicationManager implements  XLifeCycleListener {
045:            //  public static final int MAIN_CLASS = 0;
046:            public static final int STARTUP_PROPERTIES = 0;
047:            public static final int WIDGE_SET = 1;
048:            public static final int URL = 2;
049:            //  public static final int USER_NAME = 3;
050:            //  public static final int PASSWORD = 4;
051:            //  public static final int SESSION_ID = 5;
052:            //  public static final int EVENT_TYPE_ARG = 6;
053:            //  public static final int EVENT_TYPE_ID = 7;
054:            public static final int SESSION_ID = 3;
055:            public static final int EVENT_TYPE_ARG = 4;
056:            public static final int EVENT_TYPE_ID = 5;
057:
058:            public static String userName = null;//"admin";
059:            public static String password = null;//"admin";
060:            public static String sessionId = "";
061:            public static String url = "http://localhost:8080/jobs/";
062:            public static String jobRequestPage = "jobs.html";
063:            private static Logger logger;
064:            private static int queryCount = 0;
065:
066:            private static XSystemTrayManager sysTray;
067:            private static XHttpServer httpServer;
068:
069:            private static Date nextStartDate, nextEndDate;
070:
071:            /**
072:             * Called when the application/applet has been created and initialized.
073:             * @param project the owner project
074:             */
075:            public void initialize(XProject proj) {
076:                final XProject project = proj;
077:                if (sysTray == null) {
078:                    try {
079:                        sysTray = XSystemTrayManager.getInstance(project);
080:                        sysTray.setStripSplashArgument(true);
081:
082:                        httpServer = new XHttpServer(12190,
083:                                new XHttpResponseHandler() {
084:                                    public XHttpResponse getResponse(
085:                                            String uri, String method,
086:                                            Properties headers,
087:                                            Properties params) {
088:                                        if (params.get("action") != null) {
089:                                            sysTray.actionPerformed(null);
090:
091:                                            // If the startup properties/event has changed invoke the activation object
092:                                            // sysTray.showActivationEvent();
093:                                        }
094:                                        return new XHttpResponse();
095:                                    }
096:                                });
097:                    } catch (Throwable ex) {
098:                        DebugLogger
099:                                .logError("Unable to start the internal http server");
100:                        DebugLogger.logError(ex.getMessage());
101:                    }
102:
103:                    XBaseModel jobModel = (XBaseModel) proj.getModel().get(
104:                            "requests/job");
105:                    jobRequestPage = jobModel
106:                            .getAttribValueAsString(XBaseModel.VALUE_ATTRIBUTE);
107:
108:                    XDockingApp app = (XDockingApp) project.getAppWindow();
109:                    XGradientBackground gp = new XFlarePainter();
110:                    JPanel p = (JPanel) app.getContentPaneEx();
111:                    p.setForeground(new Color(255, 251, 200));
112:                    p.setBackground(SystemColor.control);
113:                    app.setBackgroundPainter(gp);
114:
115:                    String[] args = (String[]) project.getObject("StartupArgs");
116:                    if (args.length > URL) {
117:                        url = args[URL];
118:                        //    userName = args[ USER_NAME ];
119:                        //    password = args[ PASSWORD ];    
120:                        if (args.length > SESSION_ID)
121:                            sessionId = args[SESSION_ID];
122:
123:                        final String startupEventType = args.length > EVENT_TYPE_ARG ? args[EVENT_TYPE_ARG]
124:                                : null;
125:                        //final String startupEventID = args.length > EVENT_TYPE_ID ? args[ EVENT_TYPE_ID ] : null;    
126:
127:                        project.getPageManager().mapPageName("START_PAGE",
128:                                startupEventType);
129:
130:                        Thread t = new Thread() {
131:                            public void run() {
132:                                queryEvents(project, null, null);
133:                            }
134:                        };
135:                        t.start();
136:                    }
137:                }
138:            }
139:
140:            public static int queryEvents(XProject proj,
141:                    String startupEventType, String startupEventID) {
142:                final XProject project = proj;
143:                final XModel rootModel = project.getModel();
144:                XBaseModel model = (XBaseModel) rootModel.get("jobs");
145:                XServiceModelNode node = (XServiceModelNode) model.get();
146:                ((XHttpRequestProxy) node.getServiceProxy()).setupSession(
147:                        false, "__ac", sessionId);
148:
149:                ServiceContext context = new ServiceContext();
150:                ServiceProxyArgs args = context.getArgs();
151:                if (userName != null) {
152:                    String token = userName + ":" + password;
153:                    String authorization = new BASE64Encoder().encode(token
154:                            .getBytes());
155:                    args.setConfigParam(XHttpRequestProxy.PARAM_AUTHORIZATION,
156:                            authorization);
157:                }
158:                if ((url == null) || (url.length() == 0))
159:                    return -1;
160:
161:                boolean singleEventQuery = false;
162:                String queryUrl = url;
163:                if ((startupEventID != null) && (startupEventID.length() > 0)) {
164:                    queryUrl += "/" + startupEventID + "/xmlcalendar.html";
165:                    singleEventQuery = true;
166:                } else if (queryUrl.indexOf(".htm") < 0)
167:                    queryUrl += "/" + jobRequestPage;
168:
169:                args.setConfigParam("url", queryUrl);
170:
171:                if (!singleEventQuery) {
172:                    if (nextStartDate == null)
173:                        nextStartDate = new Date();
174:                    SimpleDateFormat df = new SimpleDateFormat("yyyy/M/d");
175:                    args.setPassParam("begindate", df.format(nextStartDate));
176:
177:                    Calendar endDate = Calendar.getInstance();
178:                    if (nextEndDate != null)
179:                        endDate.setTime(nextEndDate);
180:                    if (endDate.get(Calendar.MONTH) == 11)
181:                        endDate.roll(Calendar.YEAR, true);
182:                    endDate.roll(Calendar.MONTH, true);
183:                    args.setPassParam("enddate", df.format(endDate.getTime()));
184:                }
185:
186:                // Clear the search data
187:                nextStartDate = nextEndDate = null;
188:
189:                String result = (String) node.get(context);
190:                if (node.getStatus() >= 300)
191:                    return -1;
192:
193:                //System.out.println( result );
194:                StringReader sr = new StringReader(result);
195:                NanoXmlParser parser = new NanoXmlParser();
196:                XmlElement httpElement = parser.parse(sr);
197:                XOptionalDataSource modelDataSource = (XOptionalDataSource) project
198:                        .getObject("ModelDataSource");
199:                httpElement.setAttribute("id", "job");
200:
201:                XBaseModel jobsModel = (XBaseModel) rootModel.get("job");
202:                if (queryCount == 0)
203:                    jobsModel.removeChildren();
204:
205:                queryCount++;
206:                //    if ( singleEventQuery ) {
207:                //      // Add the enclosing events node!
208:                //      XmlElement httpParent = new NanoXmlElement( "Events" );
209:                //      XmlElement child = httpElement.getFirstChildNamed( "Data" );
210:                //      httpElement.setAttribute( "id", child.getAttribute( "id" ));
211:                //      httpParent.addChild( httpElement );
212:                //      httpElement = httpParent;
213:                //    }
214:                modelDataSource.loadTable(httpElement, jobsModel);
215:                int newPendingCount = 0;
216:
217:                // Now filter the events for pending and sent status and fill the tree's structure'
218:                XBaseModel pendingModel = (XBaseModel) rootModel
219:                        .get("myJobs/job/1");
220:                int pending = pendingModel.getNumChildren();
221:                XBaseModel issuedModel = (XBaseModel) rootModel
222:                        .get("myJobs/job/2");
223:                int issued = issuedModel.getNumChildren();
224:                int numEvents = jobsModel.getNumChildren();
225:                for (int i = 0; i < numEvents; i++) {
226:                    XModel eventModel = jobsModel.get(i);
227:                    String id = eventModel.getId();
228:
229:                    /** @todo fix this - the bindings seem to be saving to this node's parent erroneously */
230:                    String name = null;
231:                    Object titleModel = ((XModel) eventModel.get("title"))
232:                            .get();
233:                    if (titleModel != null)
234:                        name = titleModel.toString();
235:                    else
236:                        continue;
237:
238:                    XModel sentModel = (XModel) eventModel.get("letterSent");
239:                    if (sentModel != null) {
240:                        String sentStr = sentModel.get().toString()
241:                                .toLowerCase();
242:                        if ("true".equals(sentStr) || "tes".equals(sentStr))
243:                            issuedModel.set(id, name);
244:                        else {
245:                            pendingModel.set(id, name);
246:                            newPendingCount++;
247:                        }
248:                    } else
249:                        pendingModel.set(id, name);
250:                }
251:
252:                if (!singleEventQuery) {
253:                    SwingUtilities.invokeLater(new Runnable() {
254:                        public void run() {
255:                            PageSupport leftPage = project.getPageManager()
256:                                    .getPage("left");
257:                            if (leftPage != null) {
258:                                Object tree = leftPage
259:                                        .findComponent("taskList");
260:                                leftPage.getBinding(tree).get();
261:                            }
262:
263:                            if (logger == null)
264:                                logger = (Logger) ((XBaseModel) rootModel
265:                                        .get("Logger")).get();
266:                            if (logger != null)
267:                                logger
268:                                        .addMessage("Event list retrieved from server");
269:                        }
270:                    });
271:                }
272:
273:                return newPendingCount;
274:            }
275:
276:            /**
277:             * Called when the application/applet has been shutdown and is about to exit
278:             */
279:            public void shutdown() {
280:            }
281:
282:            /**
283:             * Can the current project close?
284:             * @param project the project initiating the shutdown
285:             * @return true if the application can close
286:             */
287:            public boolean canClose(XProject project) {
288:                return true;
289:            }
290:
291:            public static void setNextStartDate(Date d) {
292:                nextStartDate = d;
293:            }
294:
295:            public static void setNextEndDate(Date d) {
296:                nextEndDate = d;
297:            }
298:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.