Package com.google.gwt.core.ext

Examples of com.google.gwt.core.ext.UnableToCompleteException


    final JClassType sourceType = typeOracle.findType(typeName);

    // Ensure that the requested type exists
    if (sourceType == null) {
      logger.log(TreeLogger.ERROR, "Could not find requested typeName", null);
      throw new UnableToCompleteException();
    }

    String locale;
    try {
      locale = context.getPropertyOracle().getPropertyValue(logger, "locale");
    } catch (BadPropertyValueException e) {
      // Don't care, likely the user isn't using localization.
      locale = "";
    }

    // Pick a name for the generated class to not conflict. Enclosing class
    // names must be preserved.
    final String generatedSimpleSourceName = generateSimpleSourceName(sourceType.getName())
        + locale;

    // Begin writing the generated source.
    final ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(
        sourceType.getPackage().getName(), generatedSimpleSourceName);

    // The generated class needs to be able to determine the module base URL
    f.addImport(GWT.class.getName());
    f.addImport(ResourcePrototype.class.getName());

    // Determine the interface to implement
    if (sourceType.isInterface() != null) {
      f.addImplementedInterface(sourceType.getQualifiedSourceName());

    } else {
      // The incoming type wasn't a plain interface, we don't support
      // abstract base classes
      logger.log(TreeLogger.ERROR, sourceType.getQualifiedSourceName()
          + " is not an interface.", null);
      throw new UnableToCompleteException();
    }

    // All source gets written through this Writer
    final PrintWriter out = context.tryCreate(logger,
        sourceType.getPackage().getName(), generatedSimpleSourceName);

    // Aggregates the field names of the resources for use with
    // ResourceBundle.getResources()
    List<String> fieldNames = new ArrayList<String>();

    // If an implementation already exists, we don't need to do any work
    if (out != null) {

      // We really use a SourceWriter since it's convenient
      final SourceWriter sw = f.createSourceWriter(context, out);

      JMethod[] methods = sourceType.getMethods();

      Map<Class<? extends ResourceGenerator>, List<JMethod>> resourceGenerators = new HashMap<Class<? extends ResourceGenerator>, List<JMethod>>();

      ResourceContext resourceContext = createResourceContext(logger, context,
          sourceType, sw);

      // First assemble all of the ResourceGenerators that we may need for the
      // type
      for (JMethod m : methods) {
        JClassType returnType = m.getReturnType().isClassOrInterface();
        if (returnType == null) {
          logger.log(TreeLogger.ERROR, "Cannot implement " + m.getName()
              + ": not a class or interface.", null);
          throw new UnableToCompleteException();
        }

        Class<? extends ResourceGenerator> clazz = findResourceGenerator(
            logger, typeOracle, m);
        List<JMethod> generatorMethods;
        if (resourceGenerators.containsKey(clazz)) {
          generatorMethods = resourceGenerators.get(clazz);
        } else {
          generatorMethods = new ArrayList<JMethod>();
          resourceGenerators.put(clazz, generatorMethods);
        }

        generatorMethods.add(m);
      }

      // Run the ResourceGenerator code
      for (Map.Entry<Class<? extends ResourceGenerator>, List<JMethod>> entry : resourceGenerators.entrySet()) {
        Class<? extends ResourceGenerator> generatorClass = entry.getKey();
        List<JMethod> generatorMethods = entry.getValue();

        // Create the ResourceGenerator
        ResourceGenerator rg;
        try {
          rg = generatorClass.newInstance();
          rg.init(logger.branch(TreeLogger.DEBUG,
              "Initializing ResourceGenerator", null), resourceContext);
        } catch (InstantiationException e) {
          logger.log(TreeLogger.ERROR,
              "Unable to initialize ResourceGenerator", e);
          throw new UnableToCompleteException();
        } catch (IllegalAccessException e) {
          logger.log(TreeLogger.ERROR,
              "Unable to instantiate ResourceGenerator. "
                  + "Does it have a public default constructor?", e);
          throw new UnableToCompleteException();
        }

        // Prepare the ResourceGenerator by telling it all methods that it is
        // expected to produce.
        for (JMethod m : generatorMethods) {
View Full Code Here


    if (generatorType == null) {
      logger.log(TreeLogger.ERROR, "No @"
          + ResourceGeneratorType.class.getName()
          + " was specifed for resource type "
          + resourceType.getQualifiedSourceName());
      throw new UnableToCompleteException();
    }
    String className = generatorType.value();

    try {
      return Class.forName(className).asSubclass(ResourceGenerator.class);
    } catch (ClassCastException e) {
      logger.log(TreeLogger.ERROR, className + " is not a "
          + ResourceGenerator.class.getName());
    } catch (ClassNotFoundException e) {
      logger.log(TreeLogger.ERROR, "Could not load " + className, e);
    }

    throw new UnableToCompleteException();
  }
View Full Code Here

      }

      sounds.put(name, def);
    } catch (IOException e) {
      logger.log(TreeLogger.ERROR, "Unable to open resource", e);
      throw new UnableToCompleteException();
    } catch (UnsupportedAudioFileException e) {
      logger.log(TreeLogger.ERROR, "Unsupported audio format", e);
      throw new UnableToCompleteException();
    }
  }
View Full Code Here

    // Get a handle to the SoundKernel app
    InputStream in = getClass().getClassLoader().getResourceAsStream(
        "com/google/gwt/libideas/resources/rg/SoundKernel.swf");
    if (in == null) {
      logger.log(TreeLogger.ERROR, "Could not load SoundKernel.swf", null);
      throw new UnableToCompleteException();
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    // Set up the processing chain
View Full Code Here

    URL[] urls = ResourceGeneratorUtil.findResources(logger, context, method);

    if (urls.length != 1) {
      logger.log(TreeLogger.ERROR, "Exactly one resource must be specified",
          null);
      throw new UnableToCompleteException();
    }

    URL resource = urls[0];

    TreeLogger transformLogger = logger.branch(TreeLogger.DEBUG,
View Full Code Here

    } catch (InstantiationException e) {
      logger.log(TreeLogger.ERROR,
          "TextTransformers must have public, no-arg constructors", e);
    }

    throw new UnableToCompleteException();
  }
View Full Code Here

      if (md.length == 0) {
        logger.log(TreeLogger.ERROR,
            "Method " + method.getName() + " does not have a @"
                + Resource.class.getName() + " annotations.", null);
        throw new UnableToCompleteException();
      }

      // Emit a deprecation warning about metadata:
      logger.log(TreeLogger.WARN, "Method " + method.getName() + " uses a "
          + "deprecated @gwt.resources metadata annotation.  Convert to @"
          + Resource.class.getName(), null);

      resources = new String[md.length];
      for (int tagIndex = 0; tagIndex < md.length; tagIndex++) {
        int lastIndex = md[tagIndex].length - 1;
        resources[tagIndex] = md[tagIndex][lastIndex];
      }
    }

    String locale;
    try {
      PropertyOracle oracle = context.getGeneratorContext().getPropertyOracle();
      locale = oracle.getPropertyValue(logger, "locale");
    } catch (BadPropertyValueException e) {
      locale = null;
    }

    URL[] toReturn = new URL[resources.length];

    boolean error = false;
    int tagIndex = 0;
    for (String resource : resources) {

      // Make sure the name is either absolute or package-relative.
      if (resource.indexOf("/") == -1) {
        String pkgName = method.getEnclosingType().getPackage().getName();

        // This construction handles the default package correctly, too.
        resource = pkgName.replace('.', '/') + "/" + resource;
      }

      URL resourceURL = tryFindResource(resource, locale);

      if (resourceURL == null) {
        logger.log(TreeLogger.ERROR, "Resource " + resource
            + " not found on classpath. Is the name specified as "
            + "Class.getResource() would expect?", null);
        error = true;
      }

      toReturn[tagIndex++] = resourceURL;
    }

    if (error) {
      throw new UnableToCompleteException();
    }

    // In the future, it would be desirable to be able to automatically
    // determine the resource name to use from the method declaration. We're
    // currently limited by the inability to list the contents of the classpath
View Full Code Here

    try {
      soundEnabled = Boolean.parseBoolean(po.getPropertyValue(logger,
          "ResourceBundle.enableSound"));
    } catch (BadPropertyValueException e) {
      logger.log(TreeLogger.ERROR, "Bad property", e);
      throw new UnableToCompleteException();
    }
  }
View Full Code Here

    URL[] urls = ResourceGeneratorUtil.findResources(logger, context, method);
    if (urls.length != 1) {
      logger.log(TreeLogger.ERROR, "Exactly one resource must be specified",
          null);
      throw new UnableToCompleteException();
    }

    builder.assimilate(logger, method.getName(), urls[0]);
  }
View Full Code Here

        ResourceGeneratorUtil.findResources(logger, context, method);

    if (resources.length != 1) {
      logger.log(TreeLogger.ERROR, "Exactly one "
          + ResourceGeneratorUtil.METADATA_TAG + " must be specified", null);
      throw new UnableToCompleteException();
    }

    URL resource = resources[0];
    String outputUrlExpression = context.addToOutput(resource, false);
View Full Code Here

TOP

Related Classes of com.google.gwt.core.ext.UnableToCompleteException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.