KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > i18n > rebind > MessagesImplCreator


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.i18n.rebind;
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.JClassType;
21 import com.google.gwt.core.ext.typeinfo.JMethod;
22 import com.google.gwt.core.ext.typeinfo.NotFoundException;
23 import com.google.gwt.core.ext.typeinfo.TypeOracle;
24 import com.google.gwt.i18n.rebind.util.AbstractResource;
25 import com.google.gwt.user.rebind.SourceWriter;
26
27 /**
28  * Creates the class implementation for a given resource bundle using the
29  * standard <code>AbstractGeneratorClassCreator</code>.
30  */

31 class MessagesImplCreator extends AbstractLocalizableImplCreator {
32   /**
33    * Constructor for <code>ConstantsImplCreator</code>.
34    *
35    * @param writer <code>Writer</code> to print to
36    * @param localizableClass Class/Interface to conform to
37    * @param messageBindings resource bundle used to generate the class
38    * @param oracle types
39    * @param logger logger to print errors
40    * @throws UnableToCompleteException
41    */

42   public MessagesImplCreator(TreeLogger logger, SourceWriter writer,
43       JClassType localizableClass, AbstractResource messageBindings,
44       TypeOracle oracle) throws UnableToCompleteException {
45     super(writer, localizableClass, messageBindings);
46     try {
47       JClassType stringClass = oracle.getType(String JavaDoc.class.getName());
48       register(stringClass, new MessagesMethodCreator(this));
49     } catch (NotFoundException e) {
50       // never expect this error in practice
51
throw error(logger, e);
52     }
53   }
54
55   /**
56    * Checks that the method has the right structure to implement
57    * <code>Messages</code>.
58    *
59    * @param method
60    * @throws UnableToCompleteException
61    */

62   private void checkMessagesMethod(TreeLogger logger, JMethod method)
63       throws UnableToCompleteException {
64     if (!method.getReturnType().getQualifiedSourceName().equals(
65       "java.lang.String")) {
66       throw error(
67         logger,
68         "All methods in interfaces extending Messages must have a return type of String.");
69     }
70   }
71
72   /**
73    * Create the method body associated with the given method. Arguments are
74    * arg0...argN.
75    *
76    * @param m method to emit
77    * @throws UnableToCompleteException
78    */

79   protected void emitMethodBody(TreeLogger logger, JMethod m)
80       throws UnableToCompleteException {
81     checkMessagesMethod(logger, m);
82     delegateToCreator(logger, m);
83   }
84 }
85
Popular Tags