Source Code Cross Referenced for InstallerFactoryImpl.java in  » 6.0-JDK-Modules » j2me » com » sun » jumpimpl » module » installer » 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 » 6.0 JDK Modules » j2me » com.sun.jumpimpl.module.installer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004:         *
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License version
007:         * 2 only, as published by the Free Software Foundation.
008:         *
009:         * This program is distributed in the hope that it will be useful, but
010:         * WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * General Public License version 2 for more details (a copy is
013:         * included at /legal/license.txt).
014:         *
015:         * You should have received a copy of the GNU General Public License
016:         * version 2 along with this work; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018:         * 02110-1301 USA
019:         *
020:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021:         * Clara, CA 95054 or visit www.sun.com if you need additional
022:         * information or have any questions.
023:         */
024:
025:        package com.sun.jumpimpl.module.installer;
026:
027:        import com.sun.jump.common.JUMPAppModel;
028:        import com.sun.jump.module.installer.JUMPInstallerModuleFactory;
029:        import com.sun.jump.module.installer.JUMPInstallerModule;
030:        import java.util.Map;
031:        import java.util.MissingResourceException;
032:        import java.util.ResourceBundle;
033:
034:        import java.io.File;
035:        import java.lang.reflect.Method;
036:        import java.util.Vector;
037:        import java.util.HashMap;
038:
039:        import sun.misc.MIDPConfig;
040:
041:        /**
042:         * Factory implementation methods for the installer module
043:         */
044:        public class InstallerFactoryImpl extends JUMPInstallerModuleFactory {
045:
046:            private JUMPInstallerModule mainInstaller;
047:            private JUMPInstallerModule xletInstaller;
048:            private JUMPInstallerModule midletInstaller;
049:            private Map configMap = new HashMap();
050:
051:            private JUMPInstallerModule getMainInstaller() {
052:                synchronized (InstallerFactoryImpl.class) {
053:                    if (mainInstaller == null) {
054:                        mainInstaller = new MAINInstallerImpl();
055:                        mainInstaller.load(configMap);
056:                    }
057:                    return mainInstaller;
058:                }
059:            }
060:
061:            private JUMPInstallerModule getXletInstaller() {
062:                synchronized (InstallerFactoryImpl.class) {
063:                    if (xletInstaller == null) {
064:                        xletInstaller = new XLETInstallerImpl();
065:                        xletInstaller.load(configMap);
066:                    }
067:                    return xletInstaller;
068:                }
069:            }
070:
071:            static boolean midletInstallerInitialized = false;
072:
073:            private JUMPInstallerModule getMidletInstaller() {
074:                synchronized (InstallerFactoryImpl.class) {
075:
076:                    if (midletInstaller == null && !midletInstallerInitialized) {
077:
078:                        /** 
079:                         * The MIDLET installer is part of the MIDP library, which
080:                         * is only accessible through the MIDPImplementationClassLoader.
081:                         * Hence the installer needs to be loaded by the midp implementation
082:                         * classloader via reflection. Otherwise, the full midp-cdc-jump
083:                         * rommization fails as well as runtime requiring midp classes to
084:                         * be in the same path as jump classes. 
085:                         **/
086:
087:                        try {
088:
089:                            ClassLoader midpImplementationClassLoader = MIDPConfig
090:                                    .getMIDPImplementationClassLoader();
091:
092:                            if (midpImplementationClassLoader == null) {
093:
094:                                /**		   
095:                                 *	Noone had a need to load midp classes yet.
096:                                 *	Create the classloader using the
097:                                 *	default location in which sun.misc.MIDPLauncher
098:                                 *	normally uses, unless jump.midp.classes.zip is set.
099:                                 **/
100:
101:                                String midpFile = (String) configMap
102:                                        .get("jump.midp.classes.zip");
103:
104:                                midpImplementationClassLoader = MIDPConfig
105:                                        .newMIDPImplementationClassLoader(new String[] { midpFile });
106:                            }
107:
108:                            midletInstaller = (JUMPInstallerModule) loadAndInstantiate(
109:                                    midpImplementationClassLoader,
110:                                    "com.sun.midp.jump.installer.MIDLETInstallerImpl");
111:                            if (midletInstaller != null) {
112:                                midletInstaller.load(configMap);
113:                            }
114:
115:                        } catch (ClassNotFoundException e) {
116:                            // MIDPConfig or MIDLETInstallerImpl not found. 
117:                            // Not a dual stack platform.
118:                            e.printStackTrace();
119:                        } catch (Exception e) {
120:                            // Other unexpected error? Let's report it.
121:                            e.printStackTrace();
122:                        }
123:                        midletInstallerInitialized = true;
124:                    }
125:
126:                    return midletInstaller;
127:                }
128:            }
129:
130:            private static Object loadAndInstantiate(ClassLoader loader,
131:                    String className) throws ClassNotFoundException {
132:
133:                try {
134:                    Class clazz = Class.forName(className, true, loader);
135:                    return clazz.newInstance();
136:                } catch (InstantiationException e) {
137:                    e.printStackTrace();
138:                } catch (IllegalAccessException e) {
139:                    e.printStackTrace();
140:                }
141:
142:                return null;
143:            }
144:
145:            /**
146:             * resource bundle for the installer module
147:             */
148:            static protected ResourceBundle bundle = null;
149:
150:            /**
151:             * load this module with the given properties
152:             * @param map properties of this module
153:             */
154:            public void load(Map map) {
155:                this .configMap = map;
156:            }
157:
158:            /**
159:             * unload the module
160:             */
161:            public void unload() {
162:            }
163:
164:            /**
165:             * Returns a <code>JUMPInstallerModule</code> for the app model specified
166:             * @param appModel the application model for which an appropriate
167:             *        installer module should be returned.
168:             * @return installer module object
169:             */
170:            public JUMPInstallerModule getModule(JUMPAppModel appModel) {
171:
172:                if (appModel == JUMPAppModel.MAIN) {
173:                    return getMainInstaller();
174:                }
175:
176:                if (appModel == JUMPAppModel.XLET) {
177:                    return getXletInstaller();
178:                }
179:
180:                if (appModel == JUMPAppModel.MIDLET) {
181:                    JUMPInstallerModule module = getMidletInstaller();
182:                    if (module == null)
183:                        throw new IllegalArgumentException(
184:                                "Can't find MIDLET installer");
185:
186:                    return module;
187:                }
188:
189:                throw new IllegalArgumentException(
190:                        "Illegal app model for installer.");
191:            }
192:
193:            /**
194:             * Returns a <code>JUMPInstallerModule</code> for the mime type
195:             * specified.
196:             *
197:             * @param mimeType mime type for which an appropriate
198:             *        installer module should be returned.
199:             *
200:             * @return This can return null if no installer module is available
201:             *
202:             */
203:            public JUMPInstallerModule getModule(String mimeType) {
204:
205:                // Note yet implemented
206:                return null;
207:            }
208:
209:            /**
210:             * Get all of the available installer modules
211:             * @return a list of all registered installers in the system for all types
212:             * of content.
213:             */
214:            public JUMPInstallerModule[] getAllInstallers() {
215:                Vector vector = new Vector();
216:                JUMPInstallerModule mainModule = getMainInstaller();
217:                if (mainModule != null) {
218:                    vector.add(mainModule);
219:                }
220:                JUMPInstallerModule xletModule = getXletInstaller();
221:                if (xletModule != null) {
222:                    vector.add(xletModule);
223:                }
224:                JUMPInstallerModule midletModule = getMidletInstaller();
225:                if (midletModule != null) {
226:                    vector.add(midletModule);
227:                }
228:                return (JUMPInstallerModule[]) vector
229:                        .toArray(new JUMPInstallerModule[] {});
230:            };
231:
232:            /*
233:             * For localization support
234:             */
235:            static ResourceBundle getResourceBundle() {
236:                if (bundle == null) {
237:                    bundle = ResourceBundle
238:                            .getBundle("com.sun.jumpimpl.module.installer.resources.installer");
239:                }
240:
241:                return bundle;
242:            }
243:
244:            static String getString(String key) {
245:                String value = null;
246:
247:                try {
248:                    value = getResourceBundle().getString(key);
249:                } catch (MissingResourceException e) {
250:                    System.out.println("Could not find key for " + key);
251:                    e.printStackTrace();
252:                }
253:
254:                return value;
255:            }
256:
257:            static int getInt(String key) {
258:                return Integer.parseInt(getString(key));
259:            }
260:
261:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.