Source Code Cross Referenced for SwingWebClient.java in  » Web-Framework » swingweb » org » onemind » swingweb » client » awt » 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 » Web Framework » swingweb » org.onemind.swingweb.client.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2004 TiongHiang Lee
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not,  write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         *
018:         * Email: thlee@onemindsoft.org
019:         */
020:
021:        package org.onemind.swingweb.client.awt;
022:
023:        import java.awt.Component;
024:        import java.io.ByteArrayInputStream;
025:        import java.io.IOException;
026:        import java.util.*;
027:        import javax.xml.parsers.DocumentBuilder;
028:        import javax.xml.parsers.DocumentBuilderFactory;
029:        import org.apache.commons.httpclient.*;
030:        import org.apache.commons.httpclient.methods.GetMethod;
031:        import org.onemind.swingweb.client.awt.ui.ComponentUIHandler;
032:        import org.onemind.swingweb.client.core.AbstractClient;
033:        import org.onemind.swingweb.client.core.ui.UIHandler;
034:        import org.onemind.swingweb.client.dom.DomNode;
035:        import org.w3c.dom.*;
036:
037:        public class SwingWebClient extends AbstractClient implements  Logger {
038:
039:            private Console _console;
040:
041:            private HttpClient _client;
042:
043:            private Logger _logger;
044:
045:            private UIHandler _defaultHandler = new ComponentUIHandler(this );
046:
047:            int _requestId = 0;
048:
049:            public SwingWebClient(String url) {
050:                super (url);
051:                _client = new HttpClient();
052:                _console = new Console(url, this );
053:                _console.pack();
054:                _console.setSize(600, 300);
055:                _console.setVisible(true);
056:            }
057:
058:            public void setLogger(Logger logger) {
059:                _logger = logger;
060:            }
061:
062:            public Document sendRequest(HttpMethod request) throws IOException {
063:                try {
064:                    int statusCode = _client.executeMethod(request);
065:                    if (statusCode != HttpStatus.SC_OK) {
066:                        System.err.println("Method failed: "
067:                                + request.getStatusLine());
068:                        return null;
069:                    } else {
070:                        byte[] responseBody = request.getResponseBody();
071:                        log(_requestId, new String(responseBody));
072:                        DocumentBuilderFactory factory = DocumentBuilderFactory
073:                                .newInstance();
074:                        try {
075:                            DocumentBuilder builder = factory
076:                                    .newDocumentBuilder();
077:                            Document document = builder
078:                                    .parse(new ByteArrayInputStream(
079:                                            responseBody));
080:                            return document;
081:                        } catch (Exception spe) {
082:                            spe.printStackTrace();
083:                            return null;
084:                        }
085:                    }
086:                } finally {
087:                    request.releaseConnection();
088:                }
089:            }
090:
091:            public void refreshUI() throws IOException {
092:                GetMethod method = new GetMethod(getUrl());
093:                Document doc = sendRequest(method);
094:                _handleDocument(doc);
095:            }
096:
097:            public Object handle(Object parent, DomNode element, String id) {
098:                String className = element.getAttribute("class");
099:                String handlerName = element.getAttribute("handler");
100:                UIHandler handler = (UIHandler) getHandlerByName(handlerName);
101:                if (handler == null) {
102:                    handler = _defaultHandler;
103:                    System.out.println("Unable to handle " + className);
104:                }
105:                Object com = null;
106:                if (getComponent(id) != null) {
107:                    com = handler.updateComponent(getComponent(id), element);
108:                } else {
109:                    com = handler.createComponent(parent, element);
110:                    addComponent(id, com);
111:                }
112:                return com;
113:            }
114:
115:            public void submitRequest() {
116:                try {
117:                    GetMethod method = new GetMethod(getUrl());
118:                    List nvPairs = new ArrayList();
119:                    Iterator it = getChanges().entrySet().iterator();
120:                    while (it.hasNext()) {
121:                        Map.Entry entry = (Map.Entry) it.next();
122:                        if (entry.getValue() instanceof  String[]) {
123:                            String[] nvs = (String[]) entry.getValue();
124:                            for (int i = 0; i < nvs.length; i++) {
125:                                NameValuePair pair = new NameValuePair();
126:                                pair.setName((String) entry.getKey());
127:                                pair.setValue(nvs[i]);
128:                                nvPairs.add(pair);
129:                            }
130:                        } else {
131:                            NameValuePair pair = new NameValuePair();
132:                            pair.setName((String) entry.getKey());
133:                            pair.setValue((String) entry.getValue());
134:                            nvPairs.add(pair);
135:                        }
136:                    }
137:                    method.setQueryString((NameValuePair[]) nvPairs
138:                            .toArray(new NameValuePair[0]));
139:                    Document doc = sendRequest(method);
140:                    getChanges().clear();
141:                    _handleDocument(doc);
142:                    _requestId++;
143:                } catch (Exception e) {
144:                    e.printStackTrace();
145:                }
146:            }
147:
148:            public void log(String tag, String message) {
149:                //TODO
150:            }
151:
152:            public void log(int requestId, String log) {
153:                if (_logger != null) {
154:                    _logger.log(requestId, log);
155:                } else {
156:                    System.out.println(requestId + ": " + log);
157:                }
158:            }
159:
160:            private void _handleDocument(Document doc) {
161:                NodeList nodes = doc.getChildNodes();
162:                if (nodes.getLength() > 0) {
163:                    Element element = (Element) nodes.item(0);
164:                    if (element.getNodeName().equals("thin-ui")) {
165:                        NodeList childNodes = element.getChildNodes();
166:                        for (int i = 0; i < childNodes.getLength(); i++) {
167:                            if (childNodes.item(i) instanceof  Element) {
168:                                Element child = (Element) childNodes.item(i);
169:                                Component com = (Component) handle(null,
170:                                        new W3CDomNode(child, null));
171:                            }
172:                        }
173:                    }
174:                }
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.