Source Code Cross Referenced for DeviceAnywhereUploadTask.java in  » IDE-Netbeans » debugger » org » netbeans » modules » deployment » deviceanywhere » 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 » debugger » org.netbeans.modules.deployment.deviceanywhere 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        /*
043:         * DeviceAnywhereUploadTask.java
044:         *
045:         * Created on April 27, 2007, 6:01 PM
046:         */
047:
048:        package org.netbeans.modules.deployment.deviceanywhere;
049:
050:        import java.io.BufferedInputStream;
051:        import java.io.BufferedReader;
052:        import java.io.ByteArrayInputStream;
053:        import java.io.DataInputStream;
054:        import java.io.File;
055:        import java.io.FileInputStream;
056:        import java.io.IOException;
057:        import java.io.InputStreamReader;
058:        import java.util.List;
059:        import java.util.ResourceBundle;
060:        import org.apache.tools.ant.*;
061:        import org.apache.tools.ant.types.*;
062:
063:        import org.netbeans.modules.deployment.deviceanywhere.service.ApplicationAPIDeviceWrapper;
064:        import org.netbeans.modules.deployment.deviceanywhere.service.ApplicationAPIGetLockedDevicesReturn;
065:        import org.netbeans.modules.deployment.deviceanywhere.service.ApplicationAPIStartDownloadScriptReturn;
066:        import org.netbeans.modules.deployment.deviceanywhere.service.ApplicationAPIUploadApplicationReturn;
067:        import org.netbeans.modules.deployment.deviceanywhere.service.ReturnCodes;
068:
069:        /**
070:         * @author suchys
071:         */
072:        public class DeviceAnywhereUploadTask extends Task {
073:            private ResourceBundle bundle;
074:
075:            private String user;
076:            private String password;
077:            private int deviceId;
078:            private File jadFile;
079:            private File jarFile;
080:            private String career;
081:
082:            @Override
083:            public void execute() throws BuildException {
084:                bundle = ResourceBundle
085:                        .getBundle("org/netbeans/modules/deployment/deviceanywhere/messages"); //NOI18N
086:
087:                ClassLoader oldClassLoader = Thread.currentThread()
088:                        .getContextClassLoader();
089:                Thread.currentThread().setContextClassLoader(
090:                        DeviceAnywhereUploadTask.class.getClassLoader());
091:
092:                System.setProperty("javax.xml.stream.XMLInputFactory",
093:                        "com.sun.xml.stream.ZephyrParserFactory"); //NOI18N
094:                System.setProperty("javax.xml.stream.XMLOutputFactory",
095:                        "com.sun.xml.stream.ZephyrWriterFactory"); //NOI18N        
096:                try {
097:                    org.netbeans.modules.deployment.deviceanywhere.service.ApplicationAPIService serviceApi = new org.netbeans.modules.deployment.deviceanywhere.service.ApplicationAPIService();
098:                    org.netbeans.modules.deployment.deviceanywhere.service.ApplicationAPI port = serviceApi
099:                            .getApplicationAPI();
100:                    boolean deviceLockedOK = false;
101:                    try {
102:                        ApplicationAPIGetLockedDevicesReturn lockedDevices = port
103:                                .getLockedDevices(user, password);
104:                        handleReturnCode(lockedDevices.getReturnCode());
105:                        List<ApplicationAPIDeviceWrapper> result = lockedDevices
106:                                .getDeviceWrappers().getDeviceWrappers();
107:                        log("Found following devices:", Project.MSG_VERBOSE); //NOI18N
108:                        for (ApplicationAPIDeviceWrapper elem : result) {
109:                            log("Device: " + String.valueOf(elem.getId()),
110:                                    Project.MSG_VERBOSE);
111:                            if (deviceId == elem.getId()) {
112:                                deviceLockedOK = true;
113:                                log("Device " + deviceId + " found",
114:                                        Project.MSG_VERBOSE); //NOI18N
115:                            }
116:                        }
117:                    } catch (Exception ex) {
118:                        if (ex instanceof  ClassNotFoundException) {
119:                            throw new BuildException(ex);
120:                        }
121:                        throw new BuildException(bundle
122:                                .getString("can_not_connect"));
123:                    }
124:                    if (!deviceLockedOK) {
125:                        throw new BuildException(bundle
126:                                .getString("device_not_locked"));
127:                    }
128:
129:                    byte[] jadData = null;
130:                    byte[] jarData = null;
131:                    DataInputStream jad = null;
132:                    DataInputStream jar = null;
133:                    try {
134:                        jad = new DataInputStream(new BufferedInputStream(
135:                                new FileInputStream(jadFile)));
136:                        jadData = new byte[jad.available()];
137:                        jad.read(jadData);
138:                        //hack for Sprint
139:                        StringBuffer filtered = new StringBuffer();
140:                        BufferedReader br = new BufferedReader(
141:                                new InputStreamReader(new ByteArrayInputStream(
142:                                        jadData)));
143:                        String line;
144:                        while ((line = br.readLine()) != null) {
145:                            if (line.startsWith("MicroEdition-")) //NOI18N
146:                                continue;
147:                            filtered.append(line).append("\r\n");
148:                        }
149:                        jadData = filtered.toString().getBytes();
150:                        //end hack for Sprint
151:                        log("JAD file read", Project.MSG_VERBOSE);
152:                    } catch (Exception ex) {
153:                        throw new BuildException(bundle
154:                                .getString("error_reading_jad"));
155:                    } finally {
156:                        if (jad != null) {
157:                            try {
158:                                jad.close();
159:                            } catch (IOException ex) {
160:                            }
161:                        }
162:                    }
163:
164:                    try {
165:                        jar = new DataInputStream(new BufferedInputStream(
166:                                new FileInputStream(jarFile)));
167:                        jarData = new byte[jar.available()];
168:                        jar.read(jarData);
169:                        log("JAR file read", Project.MSG_VERBOSE);
170:                    } catch (Exception ex) {
171:                        throw new BuildException(bundle
172:                                .getString("error_reading_jar"));
173:                    } finally {
174:                        if (jar != null) {
175:                            try {
176:                                jar.close();
177:                            } catch (IOException ex) {
178:                            }
179:                        }
180:                    }
181:
182:                    String name = jadFile.getName();
183:                    int index = name.indexOf('.');
184:                    name = name.substring(0, index != -1 ? index : name
185:                            .length() - 1);
186:                    int applicationId = -1;
187:                    try {
188:                        log("Starting upload", Project.MSG_VERBOSE); //NOI18N
189:                        //System.out.println(new String(jadData));
190:                        ApplicationAPIUploadApplicationReturn uploadReturn = port
191:                                .uploadApplication(user, password, name,
192:                                        jarData, jadData);
193:                        handleReturnCode(uploadReturn.getReturnCode());
194:                        applicationId = uploadReturn.getApplicationId();
195:                        log("Application id: " + applicationId,
196:                                Project.MSG_VERBOSE); //NOI18N
197:                    } catch (Exception e) {
198:                        throw new BuildException(bundle
199:                                .getString("error_uploading_data"));
200:                    }
201:
202:                    try {
203:                        log("Starting script", Project.MSG_VERBOSE); //NOI18N
204:                        ApplicationAPIStartDownloadScriptReturn scriptReturn = port
205:                                .startDownloadScript(user, password, deviceId,
206:                                        applicationId);
207:                        handleReturnCode(scriptReturn.getReturnCode());
208:                        log("Script executed", Project.MSG_VERBOSE); //NOI18N
209:                    } catch (Exception e) {
210:                        throw new BuildException(bundle
211:                                .getString("error_running_remote_script"));
212:                    }
213:                } catch (IOException ioEx) {
214:                    throw new BuildException(ioEx);
215:                } finally {
216:                    System.setProperty("javax.xml.stream.XMLInputFactory", ""); //NOI18N
217:                    System.setProperty("javax.xml.stream.XMLOutputFactory", ""); //NOI18N
218:                    Thread.currentThread()
219:                            .setContextClassLoader(oldClassLoader);
220:                }
221:                log("Done!", Project.MSG_VERBOSE); //NOI18N
222:            }
223:
224:            public void setUser(String user) {
225:                this .user = user;
226:            }
227:
228:            public void setPassword(String password) {
229:                this .password = password;
230:            }
231:
232:            public void setDeviceId(int deviceId) {
233:                this .deviceId = deviceId;
234:            }
235:
236:            public void setJadFile(File jadFile) {
237:                this .jadFile = jadFile;
238:            }
239:
240:            public void setJarFile(File jarFile) {
241:                this .jarFile = jarFile;
242:            }
243:
244:            public String getCareer() {
245:                return career;
246:            }
247:
248:            public void setCareer(String career) {
249:                this .career = career;
250:            }
251:
252:            private void handleReturnCode(int returnCode) {
253:                if (returnCode == ReturnCodes.INTERNAL_ERROR) {
254:                    throw new BuildException(bundle.getString("intenal_error"));
255:                }
256:                if (returnCode == ReturnCodes.LOGIN_FAILED) {
257:                    throw new BuildException(bundle.getString("wrong_login"));
258:                }
259:                if (returnCode == ReturnCodes.INVALID_APPLICATION_NAME) {
260:                    throw new BuildException(bundle
261:                            .getString("invalid_application_name"));
262:                }
263:                if (returnCode == ReturnCodes.JAD_FILE_PARSE_ERROR) {
264:                    throw new BuildException(bundle
265:                            .getString("jad_file_cant_parse"));
266:                }
267:                if (returnCode == ReturnCodes.DEVICE_NOT_FOUND) {
268:                    throw new BuildException(bundle
269:                            .getString("device_not_found"));
270:                }
271:                if (returnCode == ReturnCodes.APPLICATION_NOT_FOUND) {
272:                    throw new BuildException(bundle
273:                            .getString("application_not_found"));
274:                }
275:            }
276:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.