Example usage for org.apache.commons.configuration2.tree DefaultExpressionEngine DefaultExpressionEngine

List of usage examples for org.apache.commons.configuration2.tree DefaultExpressionEngine DefaultExpressionEngine

Introduction

In this page you can find the example usage for org.apache.commons.configuration2.tree DefaultExpressionEngine DefaultExpressionEngine.

Prototype

public DefaultExpressionEngine(final DefaultExpressionEngineSymbols syms) 

Source Link

Document

Creates a new instance of DefaultExpressionEngine and initializes its symbols.

Usage

From source file:com.gs.obevo.api.factory.XmlFileConfigReader.java

@Override
public HierarchicalConfiguration getConfig(FileObject checkoutFolder) {
    try {/*from ww  w . j  a  va2  s  .  co  m*/
        FileObject envFileToRead = getEnvFileToRead(checkoutFolder);
        if (envFileToRead.getName().getExtension().equals("xml")) {
            // For the XML lookup, we want all access to fall to attribute queries if we choose. To do that, we override
            // the expression engine.
            DefaultExpressionEngine engine = new DefaultExpressionEngine(
                    DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS) {
                @Override
                public <T> List<QueryResult<T>> query(T root, String key, NodeHandler<T> handler) {
                    List<QueryResult<T>> results = super.query(root, key, handler);
                    if (!results.isEmpty()) {
                        return results;
                    }

                    // If we find no results, fall back to the query that specifies the attribute handler
                    return super.query(root, this.attributeKey(null, key), handler);
                }
            };

            XMLConfiguration configuration = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
                    .configure(new Parameters().hierarchical().setURL(envFileToRead.getURLDa())
                            .setListDelimiterHandler(new DisabledListDelimiterHandler())
                            .setExpressionEngine(engine))
                    .getConfiguration();
            postProcess(configuration);
            return configuration;
        } else {
            return new FileBasedConfigurationBuilder<>(FixedYAMLConfiguration.class)
                    .configure(new Parameters().hierarchical().setURL(envFileToRead.getURLDa())
                            .setListDelimiterHandler(new DisabledListDelimiterHandler()))
                    .getConfiguration();
        }
    } catch (ConfigurationException e) {
        throw new DeployerRuntimeException(e);
    }
}