Source Code Cross Referenced for PushExample.java in  » IDE-Netbeans » mobility » example » http » 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 » IDE Netbeans » mobility » example.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * Copyright (c) 2007, Sun Microsystems, Inc.
004:         *
005:         * All rights reserved.
006:         *
007:         * Redistribution and use in source and binary forms, with or without
008:         * modification, are permitted provided that the following conditions
009:         * are met:
010:         *
011:         *  * Redistributions of source code must retain the above copyright
012:         *    notice, this list of conditions and the following disclaimer.
013:         *  * Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in the
015:         *    documentation and/or other materials provided with the distribution.
016:         *  * Neither the name of Sun Microsystems nor the names of its contributors
017:         *    may be used to endorse or promote products derived from this software
018:         *    without specific prior written permission.
019:         *
020:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
024:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027:         * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029:         * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031:         */
032:        package example.http;
033:
034:        import java.io.DataInputStream;
035:        import java.io.IOException;
036:        import java.io.InputStream;
037:        import java.io.OutputStream;
038:
039:        import java.lang.String;
040:
041:        import java.util.Date;
042:        import java.util.Vector;
043:
044:        import javax.microedition.io.*;
045:        import javax.microedition.lcdui.*;
046:        import javax.microedition.midlet.*;
047:
048:        /**
049:         * An example MIDlet to fetch a page using an HttpConnection.
050:         * Refer to the startApp, pauseApp, and destroyApp
051:         * methods so see how it handles each requested transition.
052:         */
053:        public class PushExample extends MIDlet implements  CommandListener {
054:            // Wait for 2sec
055:            static final int DefaultTimeout = 2000;
056:
057:            /** user interface command for indicating Exit request. */
058:            Command exitCommand = new Command("Exit", Command.EXIT, 2);
059:
060:            /** user interface component containing a list of URLs */
061:            List urlList;
062:
063:            /** array of current URLs */
064:            Vector urls;
065:
066:            /** user interface alert component. */
067:            Alert alert;
068:            Image newsHoundImage;
069:            boolean imageLoaded;
070:
071:            /** current display. */
072:            Display display;
073:
074:            /** current requested url. */
075:            String url;
076:
077:            /** initialize the MIDlet with the current display object. */
078:            public PushExample() {
079:                display = Display.getDisplay(this );
080:            }
081:
082:            /**
083:             * Start creates the thread to do the timing.
084:             * It should return immediately to keep the dispatcher
085:             * from hanging.
086:             */
087:            public void startApp() {
088:                try {
089:                    newsHoundImage = Image
090:                            .createImage("/example/http/images/newshound.png");
091:                    imageLoaded = true;
092:                } catch (java.io.IOException ex) {
093:                    System.err.println("Image is not loaded :" + imageLoaded);
094:                }
095:
096:                alert = new Alert("News Hound", "", newsHoundImage,
097:                        AlertType.INFO);
098:
099:                alert.setTimeout(DefaultTimeout);
100:                setupList();
101:
102:                /* Bytes read from the URL update connection. */
103:                int count;
104:
105:                /* Check for inbound async connection for sample Finger port. */
106:                String[] connections = PushRegistry.listConnections(true);
107:
108:                /* HttpView was started to handle inbound request. */
109:                String pushProperty = getAppProperty("MIDlet-Push-1");
110:
111:                if ((connections != null) && (connections.length > 0)) {
112:                    String newurl = "Pushed URL Placeholder";
113:
114:                    /* Test basic get registry information interfaces. */
115:                    try {
116:                        String midlet = PushRegistry.getMIDlet(connections[0]);
117:                        String filter = PushRegistry.getFilter(connections[0]);
118:                    } catch (Exception e) {
119:                        e.printStackTrace();
120:                    }
121:
122:                    /* Check for socket or datagram connection. */
123:                    if (connections[0].startsWith("socket://")) {
124:                        try {
125:                            /* Simple test assumes a server socket connection. */
126:                            ServerSocketConnection scn = (ServerSocketConnection) Connector
127:                                    .open(connections[0]);
128:                            SocketConnection sc = (SocketConnection) scn
129:                                    .acceptAndOpen();
130:
131:                            /* Read one line of text as a new URL to add to the list. */
132:                            DataInputStream dis = sc.openDataInputStream();
133:                            byte[] buf = new byte[256];
134:                            int endofline = 0;
135:                            count = dis.read(buf);
136:
137:                            for (int i = 0; i < count; i++) {
138:                                if (buf[i] == '\n') {
139:                                    endofline = i;
140:
141:                                    break;
142:                                }
143:                            }
144:
145:                            newurl = new String(buf, 0, endofline);
146:
147:                            dis.close();
148:
149:                            sc.close();
150:                            scn.close();
151:                        } catch (IOException e) {
152:                            System.err
153:                                    .println("******* io exception in push example");
154:                            e.printStackTrace();
155:                        }
156:                    } else {
157:                        System.err.println("Unknown connection type");
158:                    }
159:
160:                    urlList.append(newurl, null);
161:                    urls.addElement(newurl);
162:                } else {
163:                    connections = PushRegistry.listConnections(false);
164:                }
165:
166:                display.setCurrent(alert, urlList);
167:            }
168:
169:            /**
170:             * Pause signals the thread to stop by clearing the thread field.
171:             * If stopped before done with the iterations it will
172:             * be restarted from scratch later.
173:             */
174:            public void pauseApp() {
175:            }
176:
177:            /**
178:             * Destroy must cleanup everything.  The thread is signaled
179:             * to stop and no result is produced.
180:             * @param unconditional true if a forced shutdown was requested
181:             */
182:            public void destroyApp(boolean unconditional) {
183:            }
184:
185:            /**
186:             * Check the attributes in the descriptor that identify
187:             * url's and titles and initialize the lists of urls
188:             * and urlList.
189:             * <P>
190:             * The attributes are named "ViewTitle-n" and "ViewURL-n".
191:             * The value "n" must start at "1" and increment by 1.
192:             */
193:            void setupList() {
194:                urls = new Vector();
195:                urlList = new List("News Headlines", List.IMPLICIT);
196:                urlList.setFitPolicy(Choice.TEXT_WRAP_OFF);
197:                urlList.addCommand(exitCommand);
198:                urlList.setCommandListener(this );
199:
200:                for (int n = 1; n < 100; n++) {
201:                    String nthURL = "ViewURL-" + n;
202:                    String url = getAppProperty(nthURL);
203:
204:                    if ((url == null) || (url.length() == 0)) {
205:                        break;
206:                    }
207:
208:                    String nthTitle = "ViewTitle-" + n;
209:                    String title = getAppProperty(nthTitle);
210:
211:                    if ((title == null) || (title.length() == 0)) {
212:                        title = url;
213:                    }
214:
215:                    urls.addElement(url);
216:                    urlList.append(title, null);
217:                }
218:
219:                urlList.append("Next InComing News: ", null);
220:            }
221:
222:            /**
223:             * Respond to commands, including exit
224:             * @param c user interface command requested
225:             * @param s screen object initiating the request
226:             */
227:            public void commandAction(Command c, Displayable s) {
228:                try {
229:                    if (c == exitCommand) {
230:                        destroyApp(false);
231:                        notifyDestroyed();
232:                    }
233:                } catch (Exception ex) {
234:                    ex.printStackTrace();
235:                }
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.