Example usage for com.google.gwt.core.ext RebindMode USE_PARTIAL_CACHED

List of usage examples for com.google.gwt.core.ext RebindMode USE_PARTIAL_CACHED

Introduction

In this page you can find the example usage for com.google.gwt.core.ext RebindMode USE_PARTIAL_CACHED.

Prototype

RebindMode USE_PARTIAL_CACHED

To view the source code for com.google.gwt.core.ext RebindMode USE_PARTIAL_CACHED.

Click Source Link

Document

Indicates that a mixture of newly generated and previously cached output should be used.

Usage

From source file:com.guit.rebind.gin.GinInjectorGenerator.java

License:Apache License

@Override
public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    saveVariables(logger, context, typeName);
    if (typeOracle.findType(GinOracle.packageName, GinOracle.className) != null) {
        return new RebindResult(RebindMode.USE_EXISTING, GinOracle.packageName + "." + GinOracle.className);
    }//from w  w w .java  2 s.com

    // Clear
    injectedClasses.clear();
    providedClasses.clear();
    asyncProvidedClasses.clear();
    gmodules.clear();

    // Call gin contributors
    List<String> contributors = getConfigurationProperty("app.gin.contributor").getValues();
    for (String c : contributors) {
        GinContributor contributor = instantiateContributor(c);
        contributor.collaborate(this, logger, context);
    }

    // Generate the modules string
    StringBuilder sb = new StringBuilder();
    sb.append("({");
    for (Class<?> m : gmodules) {
        if (sb.length() > 2) {
            sb.append(", ");
        }
        sb.append(m.getCanonicalName() + ".class");
    }
    sb.append("})");

    GinOracle.setModules(gmodules);

    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(GinOracle.packageName,
            GinOracle.className);
    composer.makeInterface();
    composer.addImplementedInterface(Ginjector.class.getCanonicalName());
    composer.addAnnotationDeclaration("@" + GinModules.class.getCanonicalName() + sb.toString());
    PrintWriter printWriter = context.tryCreate(logger, GinOracle.packageName, GinOracle.className);

    // Convert to linked to remove possible duplicated entries
    injectedClasses = findClassOrLinkedInjectionKey(injectedClasses);
    providedClasses = findClassOrLinkedInjectionKey(providedClasses);
    asyncProvidedClasses = findClassOrLinkedInjectionKey(asyncProvidedClasses);

    if (printWriter != null) {
        SourceWriter writer = composer.createSourceWriter(context, printWriter);

        writer.println(SINGLETON_DECLARATION);

        for (String classType : injectedClasses) {
            load(classType);
            writer.println(classType + " " + GinOracle.getGetterMethodName(classType) + "();");
        }

        for (String classType : providedClasses) {
            load(classType);
            writer.println(Provider.class.getCanonicalName() + "<" + classType + "> "
                    + GinOracle.getProviderGetterMethodName(classType) + "();");
        }

        for (String classType : asyncProvidedClasses) {
            load(classType);
            writer.println(AsyncProvider.class.getCanonicalName() + "<" + classType + "> "
                    + GinOracle.getAsyncProviderGetterMethodName(classType) + "();");
        }

        writer.commit(logger);
    }

    return new RebindResult(RebindMode.USE_PARTIAL_CACHED, GinOracle.packageName + "." + GinOracle.className);
}

From source file:com.seanchenxi.gwt.storage.rebind.StorageTypeSerializerGenerator.java

License:Apache License

@Override
public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();

    JClassType serializerType = typeOracle.findType(typeName);
    if (serializerType == null || serializerType.isInterface() == null)
        throw new UnableToCompleteException();

    final Set<JType> serializables = StorageTypeFinder.getInstance(context, logger).findStorageTypes();

    String typeSerializerClassName = serializerType.getQualifiedSourceName() + TYPE_SERIALIZER_SUFFIX;
    String typeSerializerSimpleName = serializerType.getSimpleSourceName() + TYPE_SERIALIZER_SUFFIX;
    JClassType typeSerializer = typeOracle.findType(typeSerializerClassName);

    SerializableTypeOracle serializationOracle = buildSerializableTypeOracle(logger, context, serializables);

    if (typeSerializer != null && typeSerializer.isClass() != null
            && isNothingChanged(logger, context, serializables, serializationOracle)) {
        return new RebindResult(RebindMode.USE_EXISTING, typeSerializerClassName);
    }//from  w w w .j  a v  a  2s .c  o  m

    TypeSerializerCreator tsc = new TypeSerializerCreator(logger, serializationOracle, serializationOracle,
            context, typeSerializerClassName, typeSerializerSimpleName);
    tsc.realize(logger);

    if (context.isGeneratorResultCachingEnabled()) {
        RebindResult result = new RebindResult(RebindMode.USE_PARTIAL_CACHED, typeSerializerClassName);
        CachedRpcTypeInformation cti = new CachedRpcTypeInformation(serializationOracle, serializationOracle,
                serializables, new HashSet<JType>());
        result.putClientData(ProxyCreator.CACHED_TYPE_INFO_KEY, cti);
        return result;
    } else {
        return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, typeSerializerClassName);
    }
}

From source file:net.zschech.gwt.comet.rebind.CometSerializerGenerator.java

License:Apache License

@Override
public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {

    TypeOracle typeOracle = context.getTypeOracle();

    // Create the CometSerializer impl
    String packageName = "comet";
    String className = typeName.replace('.', '_') + "Impl";
    PrintWriter printWriter = context.tryCreate(logger, packageName, className);

    if (printWriter != null) {

        try {/*from  w  w  w  .  ja  v a2s  . co  m*/
            JClassType type = typeOracle.getType(typeName);
            SerialTypes annotation = type.getAnnotation(SerialTypes.class);
            if (annotation == null) {
                logger.log(TreeLogger.ERROR, "No SerialTypes annotation on CometSerializer type: " + typeName);
                throw new UnableToCompleteException();
            }

            SerializableTypeOracleBuilder typesSentToBrowserBuilder = new SerializableTypeOracleBuilder(logger,
                    context.getPropertyOracle(), context);
            SerializableTypeOracleBuilder typesSentFromBrowserBuilder = new SerializableTypeOracleBuilder(
                    logger, context.getPropertyOracle(), context);

            for (Class<? extends Serializable> serializable : annotation.value()) {
                int rank = 0;
                if (serializable.isArray()) {
                    while (serializable.isArray()) {
                        serializable = (Class<? extends Serializable>) serializable.getComponentType();
                        rank++;
                    }
                }

                JType resolvedType = typeOracle.getType(serializable.getCanonicalName());
                while (rank > 0) {
                    resolvedType = typeOracle.getArrayType(resolvedType);
                    rank--;
                }

                typesSentToBrowserBuilder.addRootType(logger, resolvedType);
            }

            OutputStream pathInfo = context.tryCreateResource(logger, typeName + ".rpc.log");
            PrintWriter writer = new PrintWriter(new OutputStreamWriter(pathInfo));
            writer.write("====================================\n");
            writer.write("Types potentially sent from browser:\n");
            writer.write("====================================\n\n");
            writer.flush();

            typesSentToBrowserBuilder.setLogOutputWriter(writer);
            SerializableTypeOracle typesSentFromBrowser = typesSentFromBrowserBuilder.build(logger);

            writer.write("===================================\n");
            writer.write("Types potentially sent from server:\n");
            writer.write("===================================\n\n");
            writer.flush();
            typesSentFromBrowserBuilder.setLogOutputWriter(writer);
            SerializableTypeOracle typesSentToBrowser = typesSentToBrowserBuilder.build(logger);

            writer.close();

            if (pathInfo != null) {
                context.commitResource(logger, pathInfo).setPrivate(true);
            }

            // Create the serializer
            String modifiedTypeName = typeName.replace('.', '_') + "Serializer";
            TypeSerializerCreator tsc = new TypeSerializerCreator(logger, typesSentFromBrowser,
                    typesSentToBrowser, context, "comet." + modifiedTypeName, modifiedTypeName);
            String realize = tsc.realize(logger);

            // Create the CometSerializer impl
            ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName,
                    className);

            composerFactory.addImport(Serializer.class.getName());
            composerFactory.addImport(SerialMode.class.getName());

            composerFactory.setSuperclass(typeName);
            // TODO is the SERIALIZER required for DE RPC?
            SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);
            sourceWriter.print("private Serializer SERIALIZER = new " + realize + "();");
            sourceWriter.print("protected Serializer getSerializer() {return SERIALIZER;}");
            sourceWriter
                    .print("public SerialMode getMode() {return SerialMode." + annotation.mode().name() + ";}");
            sourceWriter.commit(logger);

            if (annotation.mode() == SerialMode.DE_RPC) {
                RpcDataArtifact data = new RpcDataArtifact(type.getQualifiedSourceName());
                for (JType t : typesSentToBrowser.getSerializableTypes()) {
                    if (!(t instanceof JClassType)) {
                        continue;
                    }
                    JField[] serializableFields = SerializationUtils
                            .getSerializableFields(context.getTypeOracle(), (JClassType) t);

                    List<String> names = Lists.create();
                    for (int i = 0, j = serializableFields.length; i < j; i++) {
                        names = Lists.add(names, serializableFields[i].getName());
                    }

                    data.setFields(SerializationUtils.getRpcTypeName(t), names);
                }

                context.commitArtifact(logger, data);
            }
        } catch (NotFoundException e) {
            logger.log(TreeLogger.ERROR, "", e);
            throw new UnableToCompleteException();
        }
    }

    return new RebindResult(RebindMode.USE_PARTIAL_CACHED, packageName + '.' + className);
}

From source file:org.cruxframework.crux.core.rebind.AbstractGenerator.java

License:Apache License

@Override
public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();
    assert (typeOracle != null);

    JClassType baseIntf = typeOracle.findType(typeName);
    if (baseIntf == null) {
        logger.log(TreeLogger.ERROR, "Unable to find source for type [" + typeName + "]", null);
        throw new UnableToCompleteException();
    }/*from   w ww  .java2s .  c  o m*/

    AbstractProxyCreator proxy = createProxy(logger, context, baseIntf);
    String returnType = proxy.create();
    if (returnType == null) {
        return new RebindResult(RebindMode.USE_EXISTING, typeName);
    } else if (proxy.isCacheable()) {
        return new RebindResult(RebindMode.USE_PARTIAL_CACHED, returnType);
    } else {
        return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, returnType);
    }
}