01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: @Override
32: public String generate(TreeLogger logger, GeneratorContext ctx,
33: String requestedClass) throws UnableToCompleteException {
34:
35: TypeOracle typeOracle = ctx.getTypeOracle();
36: assert (typeOracle != null);
37:
38: JClassType remoteService = typeOracle.findType(requestedClass);
39: if (remoteService == null) {
40: logger.log(TreeLogger.ERROR,
41: "Unable to find metadata for type '"
42: + requestedClass + "'", null);
43: throw new UnableToCompleteException();
44: }
45:
46: if (remoteService.isInterface() == null) {
47: logger.log(TreeLogger.ERROR, remoteService
48: .getQualifiedSourceName()
49: + " is not an interface", null);
50: throw new UnableToCompleteException();
51: }
52:
53: ProxyCreator proxyCreator = new ProxyCreator(remoteService);
54:
55: TreeLogger proxyLogger = logger.branch(TreeLogger.DEBUG,
56: "Generating client proxy for remote service interface '"
57: + remoteService.getQualifiedSourceName() + "'",
58: null);
59:
60: return proxyCreator.create(proxyLogger, ctx);
61: }
62: }
|