1 16 package com.google.gwt.dev.shell; 17 18 import com.google.gwt.core.ext.TreeLogger; 19 import com.google.gwt.core.ext.UnableToCompleteException; 20 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Shell; 23 24 import java.lang.reflect.Constructor ; 25 import java.lang.reflect.InvocationTargetException ; 26 27 30 public class PlatformSpecific { 31 32 private static final String [] browserClassNames = new String [] { 33 "com.google.gwt.dev.shell.ie.BrowserWidgetIE6", 34 "com.google.gwt.dev.shell.moz.BrowserWidgetMoz", 35 "com.google.gwt.dev.shell.mac.BrowserWidgetSaf"}; 36 37 private static final String [] updaterClassNames = new String [] { 38 "com.google.gwt.dev.shell.ie.CheckForUpdatesIE6", 39 "com.google.gwt.dev.shell.moz.CheckForUpdatesMoz", 40 "com.google.gwt.dev.shell.mac.CheckForUpdatesSaf"}; 41 42 public static BrowserWidget createBrowserWidget(TreeLogger logger, 43 Composite parent, BrowserWidgetHost host) 44 throws UnableToCompleteException { 45 Throwable caught = null; 46 try { 47 for (int i = 0; i < browserClassNames.length; i++) { 48 Class clazz = null; 49 try { 50 clazz = Class.forName(browserClassNames[i]); 51 Constructor ctor = clazz.getDeclaredConstructor(new Class [] { 52 Shell.class, BrowserWidgetHost.class}); 53 BrowserWidget bw = (BrowserWidget) ctor.newInstance(new Object [] { 54 parent, host}); 55 return bw; 56 } catch (ClassNotFoundException e) { 57 caught = e; 58 } 59 } 60 logger.log(TreeLogger.ERROR, 61 "No instantiable browser widget class could be found", caught); 62 throw new UnableToCompleteException(); 63 } catch (SecurityException e) { 64 caught = e; 65 } catch (NoSuchMethodException e) { 66 caught = e; 67 } catch (IllegalArgumentException e) { 68 caught = e; 69 } catch (InstantiationException e) { 70 caught = e; 71 } catch (IllegalAccessException e) { 72 caught = e; 73 } catch (InvocationTargetException e) { 74 caught = e.getTargetException(); 75 } catch (ClassCastException e) { 76 caught = e; 77 } 78 logger.log(TreeLogger.ERROR, 79 "The browser widget class could not be instantiated", caught); 80 throw new UnableToCompleteException(); 81 } 82 83 public static CheckForUpdates createUpdateChecker() { 84 try { 85 for (int i = 0; i < updaterClassNames.length; i++) { 86 try { 87 Class clazz = Class.forName(updaterClassNames[i]); 88 Constructor ctor = clazz.getDeclaredConstructor(new Class [] {}); 89 CheckForUpdates checker = (CheckForUpdates) ctor.newInstance(new Object [] {}); 90 return checker; 91 } catch (ClassNotFoundException e) { 92 } 94 } 95 } catch (Throwable e) { 96 } 98 return null; 99 } 100 } 101 | Popular Tags |