KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > shell > PlatformSpecific


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

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 JavaDoc;
25 import java.lang.reflect.InvocationTargetException JavaDoc;
26
27 /**
28  * Performs platform-specific class selection.
29  */

30 public class PlatformSpecific {
31
32   private static final String JavaDoc[] browserClassNames = new String JavaDoc[] {
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 JavaDoc[] updaterClassNames = new String JavaDoc[] {
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 JavaDoc caught = null;
46     try {
47       for (int i = 0; i < browserClassNames.length; i++) {
48         Class JavaDoc clazz = null;
49         try {
50           clazz = Class.forName(browserClassNames[i]);
51           Constructor JavaDoc ctor = clazz.getDeclaredConstructor(new Class JavaDoc[] {
52               Shell.class, BrowserWidgetHost.class});
53           BrowserWidget bw = (BrowserWidget) ctor.newInstance(new Object JavaDoc[] {
54               parent, host});
55           return bw;
56         } catch (ClassNotFoundException JavaDoc 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 JavaDoc e) {
64       caught = e;
65     } catch (NoSuchMethodException JavaDoc e) {
66       caught = e;
67     } catch (IllegalArgumentException JavaDoc e) {
68       caught = e;
69     } catch (InstantiationException JavaDoc e) {
70       caught = e;
71     } catch (IllegalAccessException JavaDoc e) {
72       caught = e;
73     } catch (InvocationTargetException JavaDoc e) {
74       caught = e.getTargetException();
75     } catch (ClassCastException JavaDoc 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 JavaDoc clazz = Class.forName(updaterClassNames[i]);
88           Constructor JavaDoc ctor = clazz.getDeclaredConstructor(new Class JavaDoc[] {});
89           CheckForUpdates checker = (CheckForUpdates) ctor.newInstance(new Object JavaDoc[] {});
90           return checker;
91         } catch (ClassNotFoundException JavaDoc e) {
92           // keep trying
93
}
94       }
95     } catch (Throwable JavaDoc e) {
96       // silently ignore any errors
97
}
98     return null;
99   }
100 }
101
Popular Tags