KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.google.gwt.core.ext.typeinfo.CompilationUnitProvider;
21 import com.google.gwt.core.ext.typeinfo.TypeOracle;
22 import com.google.gwt.dev.jdt.StandardSourceOracle;
23 import com.google.gwt.dev.jdt.StaticCompilationUnitProvider;
24 import com.google.gwt.util.tools.Utility;
25
26 import java.io.IOException JavaDoc;
27
28 /**
29  * Does a little extra magic to handle hosted mode JSNI and
30  * <code>GWT.create()</code>.
31  */

32 public class HostedModeSourceOracle extends StandardSourceOracle {
33
34   private final JsniInjector injector;
35
36   public HostedModeSourceOracle(TypeOracle typeOracle) {
37     super(typeOracle);
38     this.injector = new JsniInjector(typeOracle);
39   }
40
41   protected CompilationUnitProvider doFilterCompilationUnit(TreeLogger logger,
42       String JavaDoc typeName, CompilationUnitProvider existing)
43       throws UnableToCompleteException {
44
45     /*
46      * MAGIC: The implementation of GWT can be very different between hosted
47      * mode and web mode. The compiler has special knowledge of GWT for web
48      * mode. The source for hosted mode is in GWT.java-hosted.
49      */

50     if (typeName.equals("com.google.gwt.core.client.GWT")) {
51       try {
52         String JavaDoc source = Utility.getFileFromClassPath("com/google/gwt/core/client/GWT.java-hosted");
53         return new StaticCompilationUnitProvider("com.google.gwt.core.client",
54             "GWT", source.toCharArray());
55       } catch (IOException JavaDoc e) {
56         logger.log(
57             TreeLogger.ERROR,
58             "Unable to load 'com/google/gwt/core/client/GWT.java-hosted' from class path; is your installation corrupt?",
59             e);
60         throw new UnableToCompleteException();
61       }
62     }
63
64     // Otherwise, it's a regular translatable type, but we want to make sure
65
// its JSNI stuff, if any, gets handled.
66
//
67
CompilationUnitProvider jsnified = injector.inject(logger, existing);
68     return jsnified;
69   }
70 }
71
Popular Tags