Example usage for com.google.gwt.user.rebind SourceWriter print

List of usage examples for com.google.gwt.user.rebind SourceWriter print

Introduction

In this page you can find the example usage for com.google.gwt.user.rebind SourceWriter print.

Prototype

void print(String s);

Source Link

Usage

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 {/*  w w w. j  a  v a  2  s  .  c o  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.atmosphere.extensions.gwtwrapper.rebind.SerializerGenerator.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 {//  w w  w  .  ja v  a2  s. co  m
            JClassType type = typeOracle.getType(typeName);
            GwtSerialTypes annotation = type.getAnnotation(GwtSerialTypes.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);

            List<Class<?>> serializableTypes = new ArrayList();
            Collections.addAll(serializableTypes, annotation.value());
            for (Class<?> serializable : serializableTypes) {
                int rank = 0;
                if (serializable.isArray()) {
                    while (serializable.isArray()) {
                        serializable = (Class<?>) serializable.getComponentType();
                        rank++;
                    }
                }

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

                typesSentToBrowserBuilder.addRootType(logger, resolvedType);
                typesSentFromBrowserBuilder.addRootType(logger, resolvedType);
            }

            // Create a resource file to receive all of the serialization information
            // computed by STOB and mark it as private so it does not end up in the
            // output.
            OutputStream pathInfo = context.tryCreateResource(logger, typeName + ".rpc.log");
            PrintWriter writer = new PrintWriter(new OutputStreamWriter(pathInfo));
            writer.write("====================================\n");
            writer.write("Types potentially sent from server:\n");
            writer.write("====================================\n\n");
            writer.flush();

            typesSentToBrowserBuilder.setLogOutputWriter(writer);
            SerializableTypeOracle typesSentToBrowser = typesSentToBrowserBuilder.build(logger);

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

            writer.close();

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

            // Create the serializer
            final String modifiedTypeName = typeName.replace('.', '_');
            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(SerializationException.class.getName());
            composerFactory.addImport(Serializable.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 getRPCSerializer() {return SERIALIZER;}");
            sourceWriter.commit(logger);

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

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

From source file:org.atmosphere.gwt.rebind.SerializerGenerator.java

License:Apache License

@Override
public RebindResult generateIncrementally(TreeLogger logger, GeneratorContextExt 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   www. j a v  a  2 s.c o  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);
                typesSentFromBrowserBuilder.addRootType(logger, resolvedType);
            }

            // Create a resource file to receive all of the serialization information
            // computed by STOB and mark it as private so it does not end up in the
            // output.
            OutputStream pathInfo = context.tryCreateResource(logger, typeName + ".rpc.log");
            PrintWriter writer = new PrintWriter(new OutputStreamWriter(pathInfo));
            writer.write("====================================\n");
            writer.write("Types potentially sent from server:\n");
            writer.write("====================================\n\n");
            writer.flush();

            typesSentToBrowserBuilder.setLogOutputWriter(writer);
            SerializableTypeOracle typesSentToBrowser = typesSentToBrowserBuilder.build(logger);

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

            writer.close();

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

            // Create the serializer
            final String modifiedTypeName = typeName.replace('.', '_');
            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.print("public SerialMode getPushMode() {return SerialMode."
                    + annotation.pushmode().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(RebindStatus.USE_PARTIAL_CACHED, packageName + '.' + className);
}

From source file:org.atmosphere.gwt20.rebind.SerializerGenerator.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 {/* ww w  . j  a  va2  s. co m*/
            JClassType type = typeOracle.getType(typeName);
            GwtRpcSerialTypes annotation = type.getAnnotation(GwtRpcSerialTypes.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);

            List<Class<?>> serializableTypes = new ArrayList();
            Collections.addAll(serializableTypes, annotation.value());
            for (Class<?> serializable : serializableTypes) {
                int rank = 0;
                if (serializable.isArray()) {
                    while (serializable.isArray()) {
                        serializable = (Class<?>) serializable.getComponentType();
                        rank++;
                    }
                }

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

                typesSentToBrowserBuilder.addRootType(logger, resolvedType);
                typesSentFromBrowserBuilder.addRootType(logger, resolvedType);
            }

            // Create a resource file to receive all of the serialization information
            // computed by STOB and mark it as private so it does not end up in the
            // output.
            OutputStream pathInfo = context.tryCreateResource(logger, typeName + ".rpc.log");
            PrintWriter writer = new PrintWriter(new OutputStreamWriter(pathInfo));
            writer.write("====================================\n");
            writer.write("Types potentially sent from server:\n");
            writer.write("====================================\n\n");
            writer.flush();

            typesSentToBrowserBuilder.setLogOutputWriter(writer);
            SerializableTypeOracle typesSentToBrowser = typesSentToBrowserBuilder.build(logger);

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

            writer.close();

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

            // Create the serializer
            final String modifiedTypeName = typeName.replace('.', '_');
            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(SerializationException.class.getName());
            composerFactory.addImport(Serializable.class.getName());

            composerFactory.setSuperclass(typeName);
            SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);
            sourceWriter.print("private Serializer SERIALIZER = new " + realize + "();");
            sourceWriter.print("protected Serializer getRPCSerializer() {return SERIALIZER;}");
            sourceWriter.commit(logger);

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

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

From source file:org.broadleafcommerce.openadmin.generator.i18nConstantsGenerator.java

License:Apache License

public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();

    JClassType clazz = typeOracle.findType(typeName);
    if (clazz == null) {
        logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
        throw new UnableToCompleteException();
    }/*from   w  ww.ja  v a  2  s . c o  m*/
    try {
        Map<String, String> generatedClasses = generateDynamicConstantClasses(clazz, logger, context);
        logger.log(TreeLogger.INFO, "Generating source for " + clazz.getQualifiedSourceName(), null);

        String packageName = clazz.getPackage().getName();
        String simpleName = clazz.getName() + "Wrapper";
        SourceWriter sourceWriter = getSourceWriter(packageName, simpleName, context, logger,
                new String[] { "org.broadleafcommerce.openadmin.client.i18nConstants" });
        if (sourceWriter != null) {
            sourceWriter.println(
                    "private java.util.List<String> supportedLocales = new java.util.ArrayList<String>();");
            sourceWriter.println("public " + simpleName + "() {");
            for (Map.Entry<String, String> entry : generatedClasses.entrySet()) {
                sourceWriter.print("supportedLocales.add(\"");
                sourceWriter.print(entry.getKey());
                sourceWriter.print("\");\n");
            }
            sourceWriter.println("}");
            sourceWriter.println("");
            sourceWriter.println(
                    "public void retrievei18nProperties(final org.broadleafcommerce.openadmin.client.i18nPropertiesClient i18nClient) {");
            sourceWriter.println(
                    "com.google.gwt.i18n.client.LocaleInfo localeInfo = com.google.gwt.i18n.client.LocaleInfo.getCurrentLocale();");
            sourceWriter.println("String localeName = localeInfo.getLocaleName();");
            sourceWriter.println("if (!supportedLocales.contains(localeName) && localeName.contains(\"_\")){");
            //look for a language equiv
            sourceWriter.println("localeName = localeName.substring(0, localeName.indexOf(\"_\"));");
            sourceWriter.println("if (!supportedLocales.contains(localeName)){");
            sourceWriter.println("localeName = null;");
            sourceWriter.println("}");
            sourceWriter.println("} else {");
            sourceWriter.println("localeName = null;");
            sourceWriter.println("}");
            sourceWriter.println("if (localeName == null){");
            //TODO re-introduce runAsync to optimize loading of i18n properties. This currently doesn't work because of timing problems with the module loading
            //sourceWriter.println("com.google.gwt.core.client.GWT.runAsync(new com.google.gwt.core.client.RunAsyncCallback() {");
            //sourceWriter.println("public void onFailure(Throwable err) {");
            //sourceWriter.println("asyncClient.onUnavailable(err);");
            //sourceWriter.println("}");
            //sourceWriter.println("public void onSuccess() {");
            sourceWriter.print("i18nClient.onSuccess(new ");
            sourceWriter.print(generatedClasses.values().iterator().next());
            sourceWriter.print("().getAlli18nProperties());\n");
            //sourceWriter.println("}});");
            sourceWriter.println("return;");
            sourceWriter.println("}");
            for (Map.Entry<String, String> entry : generatedClasses.entrySet()) {
                sourceWriter.println("if (localeName.equals(\"" + entry.getKey() + "\")){");
                //sourceWriter.println("com.google.gwt.core.client.GWT.runAsync(new com.google.gwt.core.client.RunAsyncCallback() {");
                //sourceWriter.println("public void onFailure(Throwable err) {");
                //sourceWriter.println("asyncClient.onUnavailable(err);");
                //sourceWriter.println("}");
                //sourceWriter.println("public void onSuccess() {");
                sourceWriter.print("i18nClient.onSuccess(new ");
                sourceWriter.print(entry.getValue());
                sourceWriter.print("().getAlli18nProperties());\n");
                //sourceWriter.println("}});");
                sourceWriter.println("return;");
                sourceWriter.println("}");
            }
            sourceWriter.println(
                    "i18nClient.onUnavailable(new RuntimeException(\"Unable to find a localized file for "
                            + packageName + "." + simpleName + "\"));");
            sourceWriter.println("}");
            sourceWriter.commit(logger);
            logger.log(TreeLogger.INFO,
                    "Done Generating source for " + clazz.getQualifiedSourceName() + "Wrapper", null);
        }

        return clazz.getQualifiedSourceName() + "Wrapper";
    } catch (NotFoundException e) {
        e.printStackTrace();
        throw new UnableToCompleteException();
    }
}

From source file:org.broadleafcommerce.openadmin.generator.i18nConstantsGenerator.java

License:Apache License

protected Map<String, String> generateDynamicConstantClasses(JClassType clazz, TreeLogger logger,
        GeneratorContext context) throws NotFoundException {
    ResourceOracle resourceOracle = context.getResourcesOracle();
    Map<String, String> generatedClassses = new HashMap<String, String>();
    String myTypeName = clazz.getQualifiedSourceName().replace('.', '/');
    Map<String, Resource> resourceMap = resourceOracle.getResourceMap();
    for (Map.Entry<String, Resource> entry : resourceMap.entrySet()) {
        if (entry.getKey().contains(myTypeName) && entry.getKey().endsWith(".properties")) {
            String noSuffix = entry.getKey().substring(0, entry.getKey().indexOf(".properties"));
            String position1 = null;
            String position2 = null;
            if (noSuffix.contains("_")) {
                String i18nMatch = noSuffix.substring(noSuffix.lastIndexOf("_") + 1, noSuffix.length());
                if (i18nMatch != null && i18nMatch.length() == 2) {
                    position1 = i18nMatch;
                    noSuffix = noSuffix.substring(0, noSuffix.lastIndexOf("_"));
                    if (noSuffix.contains("_")) {
                        i18nMatch = noSuffix.substring(noSuffix.lastIndexOf("_") + 1, noSuffix.length());
                        if (i18nMatch != null && i18nMatch.length() == 2) {
                            position2 = i18nMatch;
                        }/* ww  w.  ja v  a2s .c om*/
                    }
                }
            }
            String packageName = clazz.getPackage().getName();
            StringBuilder suffix = new StringBuilder();
            if (position1 != null) {
                suffix.append("_");
                suffix.append(position1);
            }
            if (position2 != null) {
                suffix.append("_");
                suffix.append(position2);
            }
            if (position1 == null && position2 == null) {
                suffix.append("_default");
            }
            String simpleName = clazz.getName() + suffix.toString();
            SourceWriter sourceWriter = getSourceWriter(packageName, simpleName, context, logger,
                    new String[] {});
            if (sourceWriter != null) {
                Map<String, String> props = new HashMap<String, String>();
                InputStream is = entry.getValue().openContents();
                try {
                    BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                    boolean eof = false;
                    while (!eof) {
                        String temp = in.readLine();
                        if (temp == null) {
                            eof = true;
                        } else {
                            temp = temp.trim();
                            if (!temp.startsWith("#") && temp.length() > 0 && temp.contains("=")) {
                                String key = temp.substring(0, temp.indexOf("=")).trim();
                                String value = temp.substring(temp.indexOf("=") + 1, temp.length()).trim();
                                props.put(key, value);
                            }
                        }
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } finally {
                    try {
                        is.close();
                    } catch (Throwable ignored) {
                    }
                }

                logger.log(TreeLogger.INFO, "Emitting localized code for: " + entry.getKey(), null);
                sourceWriter.println(
                        "private java.util.Map<String, String> i18nProperties = new java.util.HashMap<String, String>();");
                sourceWriter.println("public " + simpleName + "() {");
                for (Map.Entry<String, String> prop : props.entrySet()) {
                    sourceWriter.print("i18nProperties.put(\"");
                    sourceWriter.print(prop.getKey());
                    sourceWriter.print("\",\"");
                    sourceWriter.print(prop.getValue().replace("\"", "\\\""));
                    sourceWriter.print("\");\n");
                }
                sourceWriter.println("}");
                sourceWriter.println("");
                sourceWriter.println("public java.util.Map<String, String> getAlli18nProperties() {");
                sourceWriter.println("return i18nProperties;");
                sourceWriter.println("}");
                sourceWriter.commit(logger);
                logger.log(TreeLogger.INFO, "Done Generating source for " + packageName + "." + simpleName,
                        null);

                generatedClassses.put(suffix.toString().substring(1, suffix.toString().length()),
                        packageName + "." + simpleName);
            }
        }
    }

    return generatedClassses;
}

From source file:org.cruxframework.crux.core.rebind.rpc.CruxProxyCreator.java

License:Apache License

/**
 * //from www  .j  a  va2 s.  c  om
 * @param parameter
 * @param methodDescVar 
 * @param blocksScreen 
 */
private void generateAsyncCallbackForSyncTokenMethod(SourceWriter srcWriter, JParameter parameter,
        String methodDescVar, boolean blocksScreen) {
    JParameterizedType parameterizedType = parameter.getType().isParameterized();
    String typeSourceName = parameterizedType.getParameterizedQualifiedSourceName();
    JClassType[] typeArgs = parameterizedType.getTypeArgs();

    String typeParameterSourceName = typeArgs[0].getParameterizedQualifiedSourceName();

    srcWriter.println("new " + typeSourceName + "(){");
    srcWriter.indent();

    srcWriter.println("public void onSuccess(" + typeParameterSourceName + " result){");
    srcWriter.indent();
    srcWriter.println("try{");
    srcWriter.println(parameter.getName() + ".onSuccess(result);");
    srcWriter.println("}finally{");
    srcWriter.println("__endMethodCall(" + methodDescVar + ", " + blocksScreen + ");");
    srcWriter.println("}");
    srcWriter.outdent();
    srcWriter.println("}");

    srcWriter.println("public void onFailure(Throwable caught){");
    srcWriter.indent();
    srcWriter.println("try{");
    srcWriter.println(parameter.getName() + ".onFailure(caught);");
    srcWriter.println("}finally{");
    srcWriter.println("__endMethodCall(" + methodDescVar + ", " + blocksScreen + ");");
    srcWriter.println("}");
    srcWriter.outdent();
    srcWriter.println("}");

    srcWriter.outdent();
    srcWriter.print("}");
}

From source file:org.cruxframework.crux.core.rebind.rpc.CruxProxyCreator.java

License:Apache License

/**
 * @param srcWriter/*from   w ww  .ja  va 2 s  . com*/
 * @param asyncMethod
 * @param parameters
 * @param methodDescVar
 */
private void generateProxyMethodCall(SourceWriter srcWriter, JMethod asyncMethod, List<JParameter> parameters,
        String methodDescVar, boolean blocksScreen) {

    srcWriter.print(getProxyWrapperQualifiedName() + ".super." + asyncMethod.getName() + "(");
    boolean needsComma = false;
    for (int i = 0; i < parameters.size(); ++i) {
        JParameter parameter = parameters.get(i);
        if (needsComma) {
            srcWriter.print(", ");
        }
        needsComma = true;
        if (i < (parameters.size() - 1)) {
            srcWriter.print(parameter.getName());
        } else {
            generateAsyncCallbackForSyncTokenMethod(srcWriter, parameter, methodDescVar, blocksScreen);
        }
    }
    srcWriter.println(");");
}

From source file:org.cruxframework.crux.core.rebind.rpc.CruxProxyCreator.java

License:Apache License

/**
 * @param srcWriter/*from   w w  w.  ja v a2 s  .  co  m*/
 * @param asyncMethod
 * @param asyncReturnType
 * @return
 */
private List<JParameter> generateProxyWrapperMethodDeclaration(SourceWriter srcWriter, JMethod asyncMethod,
        JType asyncReturnType) {
    srcWriter.println();
    srcWriter.print("public ");
    srcWriter.print(asyncReturnType.getQualifiedSourceName());
    srcWriter.print(" ");
    srcWriter.print(asyncMethod.getName() + "(");

    boolean needsComma = false;
    List<JParameter> parameters = new ArrayList<JParameter>();
    JParameter[] asyncParams = asyncMethod.getParameters();
    for (int i = 0; i < asyncParams.length; ++i) {
        JParameter param = asyncParams[i];

        if (needsComma) {
            srcWriter.print(", ");
        } else {
            needsComma = true;
        }

        JType paramType = param.getType();
        if (i == (asyncParams.length - 1)) {
            srcWriter.print("final ");
        }
        srcWriter.print(paramType.getQualifiedSourceName());
        srcWriter.print(" ");

        String paramName = param.getName();
        parameters.add(param);
        srcWriter.print(paramName);
    }

    srcWriter.println(") {");
    srcWriter.indent();
    return parameters;
}

From source file:org.cruxframework.crux.plugin.bootstrap.rebind.font.FontResourceGenerator.java

License:Apache License

/**
 *  Create a custom font-resource to inject at a stylesheet
 *  @param logger/*from ww  w . j  a  v  a2  s . c  om*/
 *  @param context
 *  @param method
 */
@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {
    SourceWriter sw = new StringSourceWriter();

    sw.print("new ");
    sw.print(method.getReturnType().getQualifiedSourceName());
    sw.println("() {");
    sw.indent();

    writeGetFontName(method, sw);
    writeGetName(method, sw);
    writeEnsureInjected(sw);
    writeGetText(logger, context, method, sw);

    sw.outdent();
    sw.println("}");
    return sw.toString();
}