001 /**
002 * Copyright (C) 2009-2011 the original author or authors.
003 * See the notice.md file distributed with this work for additional
004 * information regarding copyright ownership.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package org.fusesource.restygwt.rebind;
020
021 import com.google.gwt.core.ext.Generator;
022 import com.google.gwt.core.ext.GeneratorContext;
023 import com.google.gwt.core.ext.TreeLogger;
024 import com.google.gwt.core.ext.UnableToCompleteException;
025 import com.google.gwt.core.ext.typeinfo.JClassType;
026
027 /**
028 *
029 * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
030 */
031 public class RestServiceGenerator extends Generator {
032
033 @Override
034 public String generate(TreeLogger logger, GeneratorContext context, String source) throws UnableToCompleteException {
035 try {
036 JClassType restService = find(logger, context, source);
037 RestServiceClassCreator generator = new RestServiceClassCreator(logger, context, restService);
038
039 String generated = generator.create();
040 return generated;
041 } finally {
042 BaseSourceCreator.clearGeneratedClasses();
043 }
044 }
045
046 static JClassType find(TreeLogger logger, GeneratorContext context, String type) throws UnableToCompleteException {
047 JClassType rc = context.getTypeOracle().findType(type);
048 if (rc == null) {
049 logger.log(TreeLogger.ERROR, "TypeOracle could not find " + type);
050 throw new UnableToCompleteException();
051 }
052 return rc;
053 }
054
055 }