Example usage for org.springframework.context.support GenericApplicationContext getResource

List of usage examples for org.springframework.context.support GenericApplicationContext getResource

Introduction

In this page you can find the example usage for org.springframework.context.support GenericApplicationContext getResource.

Prototype

@Override
public Resource getResource(String location) 

Source Link

Document

This implementation delegates to this context's ResourceLoader if set, falling back to the default superclass behavior else.

Usage

From source file:org.openadaptor.spring.SpringAdaptor.java

/**
 * Configure the default PropertyPlaceholderConfigurer.
 * <br>/*from ww  w . j  a v  a 2s.  c  o m*/
 * Unless suppressAutomaticPropsConfig is set true by supplying -noprops as a command line arg then
 * this method creates and installs a PropertyPlaceholderConfigurer which allows access to System Properties
 * and optionally add all -props defined urls as property resource locations.<br>
 * With one exception all urls are passed through to the context in order to locate the resource. The exception
 * is a url that is not prefixed with a protocol is assumed to be a file and arbitratily prefixed with "file:"<br>
 * NB the arbitrary name given to the generated PropertyPlaceholderConfigurer is "openadaptorAutoGeneratedSystemPropertyConfigurer".
 *
 * @param context Spring Context being used.
 * @param propsUrlList Supplied List or Property URLS.
 */
protected void configureProperties(GenericApplicationContext context, ArrayList propsUrlList) {
    // System properties

    if (!suppressAutomaticPropsConfig) {

        if (isPropertyPlaceholderPresent(context)) {
            log.warn(
                    "Spring configuration file already has PropertyPlaceholderConfigurers defined. Please ensure any conflicts are resolved satisfactorily.");
        }

        MutablePropertyValues systemPropertiesModeProperties = new MutablePropertyValues();
        systemPropertiesModeProperties.addPropertyValue("staticField",
                "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK");

        RootBeanDefinition systemPropertiesMode = new RootBeanDefinition(FieldRetrievingFactoryBean.class);
        systemPropertiesMode.setPropertyValues(systemPropertiesModeProperties);

        MutablePropertyValues properties = new MutablePropertyValues();
        properties.addPropertyValue("ignoreResourceNotFound", "false"); // Will cause an eror if a resource url is bogus
        Iterator propsUrlIter = propsUrlList.iterator();
        ArrayList resourceList = new ArrayList();
        while (propsUrlIter.hasNext()) {
            resourceList.add(context.getResource(ensureProtocol((String) propsUrlIter.next())));
        }
        properties.addPropertyValue("locations", resourceList);
        properties.addPropertyValue("systemPropertiesMode", systemPropertiesMode);
        RootBeanDefinition propertyHolder = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
        propertyHolder.setPropertyValues(properties);

        context.registerBeanDefinition("openadaptorAutoGeneratedSystemPropertyConfigurer", propertyHolder);
    }
}