KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > rebind > rpc > ServiceInterfaceProxyGenerator


1 /*
2  * Copyright 2007 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.user.rebind.rpc;
17
18 import com.google.gwt.core.ext.Generator;
19 import com.google.gwt.core.ext.GeneratorContext;
20 import com.google.gwt.core.ext.TreeLogger;
21 import com.google.gwt.core.ext.UnableToCompleteException;
22 import com.google.gwt.core.ext.typeinfo.JClassType;
23 import com.google.gwt.core.ext.typeinfo.TypeOracle;
24
25 /**
26  * Generator for producing the asynchronous version of a
27  * {@link com.google.gwt.user.client.rpc.RemoteService RemoteService} interface.
28  */

29 public class ServiceInterfaceProxyGenerator extends Generator {
30
31   public String JavaDoc generate(TreeLogger logger, GeneratorContext ctx,
32       String JavaDoc requestedClass) throws UnableToCompleteException {
33
34     TypeOracle typeOracle = ctx.getTypeOracle();
35     assert (typeOracle != null);
36
37     JClassType remoteService = typeOracle.findType(requestedClass);
38     if (remoteService == null) {
39       logger.log(TreeLogger.ERROR, "Unable to find metadata for type '"
40           + requestedClass + "'", null);
41       throw new UnableToCompleteException();
42     }
43
44     if (remoteService.isInterface() == null) {
45       logger.log(TreeLogger.ERROR, remoteService.getQualifiedSourceName()
46           + " is not an interface", null);
47       throw new UnableToCompleteException();
48     }
49
50     ProxyCreator proxyCreator = new ProxyCreator(remoteService);
51
52     TreeLogger proxyLogger = logger.branch(TreeLogger.DEBUG,
53         "Generating client proxy for remote service interface '"
54             + remoteService.getQualifiedSourceName() + "'", null);
55
56     return proxyCreator.create(proxyLogger, ctx);
57   }
58 }
59
Popular Tags