Example usage for com.google.gwt.core.ext PropertyOracle getConfigurationProperty

List of usage examples for com.google.gwt.core.ext PropertyOracle getConfigurationProperty

Introduction

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

Prototype

ConfigurationProperty getConfigurationProperty(String propertyName) throws BadPropertyValueException;

Source Link

Document

Attempts to get a named configuration property.

Usage

From source file:com.allen_sauer.gwt.log.rebind.LogMessageFormatterGenerator.java

License:Apache License

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

    JClassType userType;//from w  w  w.  j a va2 s . c  o m
    try {
        userType = typeOracle.getType(typeName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "OOPS", e);
        throw new UnableToCompleteException();
    }
    String packageName = userType.getPackage().getName();
    String className = userType.getName();

    JClassType remoteService = typeOracle.findType(typeName);
    if (remoteService == null) {
        logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
        throw new UnableToCompleteException();
    }

    if (remoteService.isInterface() == null) {
        logger.log(TreeLogger.ERROR, remoteService.getQualifiedSourceName() + " is not an interface", null);
        throw new UnableToCompleteException();
    }
    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName,
            className + "Impl");
    composerFactory.addImplementedInterface(remoteService.getQualifiedSourceName());

    composerFactory.addImport(Date.class.getName());
    composerFactory.addImport(GWT.class.getName());
    composerFactory.addImport(LogUtil.class.getName());
    composerFactory.addImport(Duration.class.getName());

    PrintWriter pw = context.tryCreate(logger, packageName, className + "Impl");
    if (pw != null) {
        SourceWriter sw = composerFactory.createSourceWriter(context, pw);

        PropertyOracle propertyOracle = context.getPropertyOracle();
        String logPattern;
        try {
            ConfigurationProperty logPatternProperty = propertyOracle
                    .getConfigurationProperty(PROPERTY_LOG_PATTERN);
            List<String> values = logPatternProperty.getValues();
            logPattern = values.get(0);
        } catch (BadPropertyValueException e) {
            logger.log(TreeLogger.ERROR, "Unable to find value for '" + PROPERTY_LOG_PATTERN + "'", e);
            throw new UnableToCompleteException();
        }

        sw.println();
        sw.println("private double BIG_BANG = Duration.currentTimeMillis();");

        sw.println();
        sw.println(
                "public String format(String logLevelText, String category, String message, Throwable throwable) {");
        sw.indent();
        sw.println("if (category == null) {");
        sw.indent();
        sw.println("category = \"<null category>\";");
        sw.outdent();
        sw.println("}");
        sw.println("if (message == null) {");
        sw.indent();
        sw.println("message = \"<null message>\";");
        sw.outdent();
        sw.println("}");
        sw.println(logPatternToCode(logPattern));
        sw.outdent();
        sw.println("}");

        sw.commit(logger);
    }
    return composerFactory.getCreatedClassName();
}

From source file:com.allen_sauer.gwt.log.rebind.RemoteLoggerConfigGenerator.java

License:Apache License

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

    JClassType userType;/*from   ww  w.ja v a2  s  .c  o m*/
    try {
        userType = typeOracle.getType(typeName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "OOPS", e);
        throw new UnableToCompleteException();
    }
    String packageName = userType.getPackage().getName();
    String className = userType.getName();

    JClassType remoteService = typeOracle.findType(typeName);
    if (remoteService == null) {
        logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
        throw new UnableToCompleteException();
    }

    if (remoteService.isInterface() == null) {
        logger.log(TreeLogger.ERROR, remoteService.getQualifiedSourceName() + " is not an interface", null);
        throw new UnableToCompleteException();
    }
    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName,
            className + "Impl");
    composerFactory.addImplementedInterface(remoteService.getQualifiedSourceName());

    PrintWriter pw = context.tryCreate(logger, packageName, className + "Impl");
    if (pw != null) {
        SourceWriter sw = composerFactory.createSourceWriter(context, pw);

        PropertyOracle propertyOracle = context.getPropertyOracle();
        String logUrl;
        try {
            ConfigurationProperty logPatternProperty = propertyOracle
                    .getConfigurationProperty(PROPERTY_LOG_URL);
            List<String> values = logPatternProperty.getValues();
            logUrl = values.get(0);
        } catch (BadPropertyValueException e) {
            logger.log(TreeLogger.ERROR, "Unable to find value for '" + PROPERTY_LOG_URL + "'", e);
            throw new UnableToCompleteException();
        }

        sw.println();
        sw.println("public String serviceEntryPointUrl() {");
        sw.indent();

        if (logUrl == null) {
            sw.println("return null;");
        } else {
            sw.println("return \"" + logUrl.trim() + "\";");
        }

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

        sw.commit(logger);
    }
    return composerFactory.getCreatedClassName();
}

From source file:com.arcbees.gwtpolymer.rebind.velocity.GeneratorUtil.java

License:Apache License

public ConfigurationProperty getConfigurationProperty(String name) throws UnableToCompleteException {
    try {/*w ww.  j  a  v a  2  s  .  co  m*/
        PropertyOracle propertyOracle = generatorContext.getPropertyOracle();

        ConfigurationProperty configurationProperty = propertyOracle.getConfigurationProperty(name);
        return configurationProperty;
    } catch (BadPropertyValueException e) {
        logger.log(TreeLogger.Type.ERROR, e.getMessage());
        throw new UnableToCompleteException();
    }
}

From source file:com.googlecode.mgwt.css.rebind.StyleSheetUrlHolderGenerator.java

License:Apache License

private ConfigurationProperty getConfigurationProperty(PropertyOracle propertyOracle, TreeLogger logger,
        String name) throws UnableToCompleteException {
    try {//from   w w  w  .j  av a2  s  . c  o m
        return propertyOracle.getConfigurationProperty(name);
    } catch (BadPropertyValueException e) {
        // if we can`t find it die
        logger.log(TreeLogger.ERROR, "can not resolve " + name, e);
        throw new UnableToCompleteException();
    }
}

From source file:com.googlecode.mgwt.ui.generator.SuperDevModeGenerator.java

License:Apache License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {
    // get the property oracle
    PropertyOracle propertyOracle = context.getPropertyOracle();
    ConfigurationProperty property = null;
    try {/*  w  ww  . j a  va  2 s.  co m*/
        // get mgwt.superdevmode variable
        property = propertyOracle.getConfigurationProperty("mgwt.superdevmode");
    } catch (BadPropertyValueException e) {
        // if we can`t find it die
        logger.log(TreeLogger.ERROR, "can not resolve mgwt.superdevmode variable", e);
        throw new UnableToCompleteException();
    }

    ConfigurationProperty superDevModeServer = null;
    try {
        // get mgwt.superdevmode variable
        superDevModeServer = propertyOracle.getConfigurationProperty("mgwt.superdevmode_host");
    } catch (BadPropertyValueException e) {
        // if we can`t find it die
        logger.log(TreeLogger.INFO,
                "can not resolve mgwt.superdevmode_host variable - using default - http://<server>:9876", e);
    }

    JClassType classType = null;

    try {
        // get the type we are looking for
        classType = context.getTypeOracle().getType(typeName);
    } catch (NotFoundException e) {
        // if we can`t get it die
        logger.log(TreeLogger.ERROR, "can not find type: '" + typeName + "'", e);
        throw new UnableToCompleteException();
    }

    // get value of mgwt.os
    String mgwtSuperDevmodePropertyValue = property.getValues().get(0);

    if ("on".equals(mgwtSuperDevmodePropertyValue)) {
        return buildOnImplementation(logger, context, classType, typeName, superDevModeServer);
    } else {
        return "com.googlecode.mgwt.ui.client.util.impl.SuperDevModeOffImpl";
    }

}

From source file:com.gwtplatform.dispatch.rest.rebind.DispatchRestIncrementalGenerator.java

License:Apache License

private void loadExtensionModules(List<Module> modules) {
    PropertyOracle propertyOracle = context.getPropertyOracle();

    try {//from ww  w.ja v a  2 s  .  co m
        ConfigurationProperty property = propertyOracle.getConfigurationProperty(GENERATOR_EXTENSIONS_PROPERTY);

        loadExtensionModules(property, modules);
    } catch (BadPropertyValueException e) {
        logger.log(Type.WARN, "Unable to read Dispatch-Rest generator extensions property. Extensions won't be "
                + "loaded. Make sure '" + GENERATOR_EXTENSIONS_PROPERTY + "' is defined.", e);
    }
}

From source file:com.gwtplatform.mvp.rebind.GinjectorInspector.java

License:Apache License

private void findGinjectorClassName(TreeLogger logger, PropertyOracle oracle) throws UnableToCompleteException {
    ginjectorClassName = null;//  w  w w.j a  v a  2 s  .c om
    try {
        ginjectorClassName = oracle.getConfigurationProperty("gin.ginjector").getValues().get(0);
    } catch (BadPropertyValueException e) {
        logger.log(TreeLogger.ERROR, "The required configuration property 'gin.ginjector' was not found.", e);
        throw new UnableToCompleteException();
    }
}

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

License:Apache License

protected static List<StorageTypeFinder> getStorageTypeFinders(GeneratorContext context, TreeLogger logger)
        throws UnableToCompleteException {
    final List<StorageTypeFinder> typeFinders = new ArrayList<>();

    JClassType keyProviderIntf = context.getTypeOracle().findType(StorageKeyProvider.class.getName());
    if (keyProviderIntf.getSubtypes() != null && keyProviderIntf.getSubtypes().length > 1) {
        typeFinders.add(new TypeProviderFinder(context, logger));
    }//from  w  w w .  j a  va 2 s.c  om

    PropertyOracle propertyOracle = context.getPropertyOracle();
    try {
        ConfigurationProperty property = propertyOracle.getConfigurationProperty(PROP_TYPE_FINDER);
        String value = property == null ? TYPE_FINDER_VALUES.get(0) : property.getValues().get(0).toLowerCase();
        switch (TYPE_FINDER_VALUES.indexOf(value)) {
        case 0:
            typeFinders.add(new TypeRpcFinder(context, logger));
            break;
        case 1:
            typeFinders.add(new TypeXmlFinder(context, logger));
            break;
        case 2:
            typeFinders.add(new TypeRpcFinder(context, logger));
            typeFinders.add(new TypeXmlFinder(context, logger));
            break;
        default:
            break;
        }
    } catch (BadPropertyValueException e) {
        logger.branch(TreeLogger.DEBUG, "Could not find property " + PROP_TYPE_FINDER, e);
    }
    return typeFinders;
}

From source file:fr.onevu.gwt.uibinder.rebind.UiBinderGenerator.java

License:Apache License

private Boolean extractConfigProperty(MortalLogger logger, PropertyOracle propertyOracle, String configProperty,
        boolean defaultValue) {
    List<String> values;
    try {/*from w  w  w .  j av a 2  s.  c  om*/
        values = propertyOracle.getConfigurationProperty(configProperty).getValues();
    } catch (BadPropertyValueException e) {
        logger.warn("No value found for configuration property %s.", configProperty);
        return defaultValue;
    }

    String value = values.get(0);
    if (!value.equals(Boolean.FALSE.toString()) && !value.equals(Boolean.TRUE.toString())) {
        logger.warn("Unparseable value \"%s\" found for configuration property %s", value, configProperty);
        return defaultValue;
    }

    return Boolean.valueOf(value);
}

From source file:org.jboss.as.console.rebind.ProductConfigGenerator.java

License:Open Source License

private void generateMethods(SourceWriter sourceWriter, GeneratorContext context) throws Throwable {

    PropertyOracle propertyOracle = context.getPropertyOracle();
    String consoleProfileProperty = propertyOracle.getConfigurationProperty("console.profile").getValues()
            .get(0);//from  ww  w  .j av  a 2s .c om

    if (null == consoleProfileProperty)
        throw new BadPropertyValueException("Missing configuration property 'console.profile'!");

    String prodVersionProperty = propertyOracle.getConfigurationProperty("console.product.version").getValues()
            .get(0);

    String consoleProductVersion = (prodVersionProperty != null) ? prodVersionProperty : "";

    String devHostProperty = propertyOracle.getConfigurationProperty("console.dev.host").getValues().get(0);

    String consoleDevHost = (devHostProperty != null) ? devHostProperty : "127.0.0.1";

    // most of the config attributes are by default empty
    // they need be overriden by custom gwt.xml descriptor on a project/product level

    sourceWriter.println("public String getProductTitle() { ");
    sourceWriter.indent();
    sourceWriter.println("return \"\";");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println("public String getProductVersion() { ");
    sourceWriter.indent();
    sourceWriter.println("return \"" + consoleProductVersion + "\";");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println("public String getCoreVersion() { ");
    sourceWriter.indent();
    sourceWriter.println("return org.jboss.as.console.client.Build.VERSION;");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println("public String getDevHost() { ");
    sourceWriter.indent();
    sourceWriter.println("return \"" + devHostProperty + "\";");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println("public ProductConfig.Profile getProfile() { ");
    sourceWriter.indent();
    if ("eap".equals(consoleProfileProperty))
        sourceWriter.println("return ProductConfig.Profile.EAP;");
    else
        sourceWriter.println("return ProductConfig.Profile.JBOSS;");
    sourceWriter.outdent();
    sourceWriter.println("}");

}