Example usage for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference

List of usage examples for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference.

Prototype

public RuntimeBeanReference(Class<?> beanType) 

Source Link

Document

Create a new RuntimeBeanReference to a bean of the given type.

Usage

From source file:org.smf4j.spring.RegistryNodeTemplateDefinitionParser.java

protected ManagedList<RuntimeBeanReference> createGroupings(ParserContext context, Element element,
        String ranges, String suffixes) {
    ManagedList<RuntimeBeanReference> groupings = new ManagedList<RuntimeBeanReference>();
    String[] rangeArray = StringUtils.commaDelimitedListToStringArray(ranges);
    String[] suffixArray = StringUtils.commaDelimitedListToStringArray(suffixes);

    if (rangeArray.length != suffixArray.length) {
        context.getReaderContext().error("'ranges' and 'suffixes' must have the same number of " + "elements",
                context.extractSource(element));
        return null;
    }/*  w w w  . j a va2s. c  o  m*/

    for (int i = 0; i < rangeArray.length; i++) {
        String range = rangeArray[i];
        String suffix = suffixArray[i];
        BeanDefinitionBuilder bdb = getBdb(RANGEGROUP_GROUPING_CLASS);
        bdb.addPropertyValue(RANGE_ATTR, range);
        bdb.addPropertyValue(SUFFIX_ATTR, suffix);
        String groupId = context.getReaderContext().registerWithGeneratedName(bdb.getBeanDefinition());
        groupings.add(new RuntimeBeanReference(groupId));
    }
    return groupings;
}

From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java

private RootBeanDefinition createJsfValidatorHelper(Element element, Object source) {

    RootBeanDefinition bean = new RootBeanDefinition(JsfValidatorHelper.class);
    bean.setSource(source);//from  w  ww  . j a v  a  2  s  .c om
    bean.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    bean.setInitMethodName("init");
    bean.getPropertyValues().addPropertyValue("logger", new RuntimeBeanReference("logger"));
    bean.getPropertyValues().addPropertyValue("stateUtil", new RuntimeBeanReference("stateUtil"));
    bean.getPropertyValues().addPropertyValue("hdivConfig", new RuntimeBeanReference("config"));
    bean.getPropertyValues().addPropertyValue("session", new RuntimeBeanReference("sessionHDIV"));
    bean.getPropertyValues().addPropertyValue("dataValidatorFactory",
            new RuntimeBeanReference("dataValidatorFactory"));
    bean.getPropertyValues().addPropertyValue("dataComposerFactory",
            new RuntimeBeanReference("dataComposerFactory"));
    return bean;
}

From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java

private RootBeanDefinition createRequestParameterValidator(Element element, Object source) {
    RootBeanDefinition bean = new RootBeanDefinition(RequestParameterValidator.class);
    bean.setSource(source);//from   w  w w  . ja  va 2  s  . c  om
    bean.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    bean.getPropertyValues().addPropertyValue("hdivConfig", new RuntimeBeanReference("config"));
    return bean;
}

From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java

private RootBeanDefinition createEditableValidator(Element element, Object source) {
    RootBeanDefinition bean = new RootBeanDefinition(EditableValidator.class);
    bean.setSource(source);/*from  w  w w . ja va 2 s.c  o m*/
    bean.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    bean.getPropertyValues().addPropertyValue("hdivConfig", new RuntimeBeanReference("config"));
    return bean;
}

From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java

private RootBeanDefinition createRedirectHelper(Element element, Object source) {
    RootBeanDefinition bean = new RootBeanDefinition(RedirectHelper.class);
    bean.setSource(source);//w w  w  . j  ava 2  s .  c  om
    bean.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    bean.getPropertyValues().addPropertyValue("linkUrlProcessor", new RuntimeBeanReference("linkUrlProcessor"));
    return bean;
}

From source file:de.acosix.alfresco.utility.common.spring.BeanDefinitionFromPropertiesPostProcessor.java

protected Object getAsValue(final String beanName, final String propertyName, final String definitionKey,
        final String value) {
    final Object result;
    if (SUFFIX_PROPERTY_REF.equals(definitionKey)) {
        LOGGER.trace("[{}] Treating value of property {} on {} as reference to bean {}", this.beanName,
                beanName, propertyName, value);
        result = new RuntimeBeanReference(value);
    } else if (SUFFIX_PROPERTY_NULL.equals(definitionKey) && Boolean.parseBoolean(value)) {
        LOGGER.trace("[{}] Treating value of property {} on {} as null", this.beanName, beanName, propertyName);
        result = null;//from  w ww  . jav  a2  s .  c  om
    } else if (definitionKey.isEmpty()) {
        LOGGER.trace("[{}] Treating value of property {} on {} as literal value {}", this.beanName, beanName,
                propertyName, value);
        result = value;
    } else {
        final StringBuilder msgBuilder = new StringBuilder();
        msgBuilder.append("Cannot handle remaining value key ");
        msgBuilder.append(definitionKey);
        msgBuilder.append(" for property ");
        msgBuilder.append(propertyName);
        msgBuilder.append(" on bean ");
        msgBuilder.append(beanName);
        throw new UnsupportedOperationException(msgBuilder.toString());
    }

    return result;
}

From source file:ome.client.utests.Preferences3Test.java

@Test
public void test_makeOurOwnDefault() throws Exception {
    // Others://from   www.jav a 2s. c om
    // new ManagedMap();
    // BeanWrapper bw = new BeanWrapperImpl( defaultMap );

    Map defaultMap = new HashMap();
    defaultMap.put("omero.user", "foo");
    ConstructorArgumentValues cav = new ConstructorArgumentValues();
    cav.addGenericArgumentValue(defaultMap);
    BeanDefinition def = new RootBeanDefinition(HashMap.class, cav, null);
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerBeanDefinition("map", def);
    ac.refresh();

    ConstructorArgumentValues testCav = new ConstructorArgumentValues();
    testCav.addGenericArgumentValue(new RuntimeBeanReference("map"));
    BeanDefinition testDef = new RootBeanDefinition(HashMap.class, testCav, null);
    StaticApplicationContext defaultTest = new StaticApplicationContext(ac);
    defaultTest.registerBeanDefinition("test", testDef);
    defaultTest.refresh();
    assertTrue("foo".equals(((Map) defaultTest.getBean("test")).get("omero.user")));

}

From source file:ome.client.utests.Preferences3Test.java

@Test
public void test_makeOurOwnRuntime() throws Exception {

    // use properties
    // if no Properties given, then is static (global)

    Map runtimeMap = new HashMap();
    runtimeMap.put("omero.user", "bar");
    ConstructorArgumentValues cav2 = new ConstructorArgumentValues();
    cav2.addGenericArgumentValue(runtimeMap);
    BeanDefinition def2 = new RootBeanDefinition(HashMap.class, cav2, null);
    StaticApplicationContext ac2 = new StaticApplicationContext();
    ac2.registerBeanDefinition("map", def2);
    ac2.refresh();/*from  w ww  .jav  a 2s  . c o  m*/

    ConstructorArgumentValues testCav2 = new ConstructorArgumentValues();
    testCav2.addGenericArgumentValue(new RuntimeBeanReference("map"));
    BeanDefinition testDef2 = new RootBeanDefinition(HashMap.class, testCav2, null);
    StaticApplicationContext defaultTest2 = new StaticApplicationContext(ac2);
    defaultTest2.registerBeanDefinition("test", testDef2);
    defaultTest2.refresh();
    assertTrue("bar".equals(((Map) defaultTest2.getBean("test")).get("omero.user")));

}

From source file:ome.client.utests.Preferences3Test.java

@Test(groups = "ticket:1058")
public void testOmeroUserIsProperlySetWithSpring2_5_5Manual() {

    Server s = new Server("localhost", 1099);
    Login l = new Login("me", "password");
    Properties p = s.asProperties();
    p.putAll(l.asProperties());/*from   w ww  .  ja v  a2  s.c  om*/

    // This is copied from OmeroContext. This is the parent context which
    // should contain the properties;
    Properties copy = new Properties(p);
    ConstructorArgumentValues ctorArg1 = new ConstructorArgumentValues();
    ctorArg1.addGenericArgumentValue(copy);
    BeanDefinition definition1 = new RootBeanDefinition(Properties.class, ctorArg1, null);
    StaticApplicationContext staticContext = new StaticApplicationContext();
    staticContext.registerBeanDefinition("properties", definition1);
    staticContext.refresh();

    // This is the child context and contains a definition of a
    // PlaceHolderConfigurer
    // as well as a user of
    StaticApplicationContext childContext = new StaticApplicationContext();

    MutablePropertyValues mpv2 = new MutablePropertyValues();
    mpv2.addPropertyValue("properties", new RuntimeBeanReference("properties"));
    mpv2.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_FALLBACK");
    mpv2.addPropertyValue("localOverride", "true");
    BeanDefinition definitionConfigurer = new RootBeanDefinition(PreferencesPlaceholderConfigurer.class, null,
            mpv2);
    childContext.registerBeanDefinition("propertiesPlaceholderConfigurer", definitionConfigurer);

    ConstructorArgumentValues cav2 = new ConstructorArgumentValues();
    cav2.addGenericArgumentValue("${omero.user}");
    BeanDefinition definitionTest = new RootBeanDefinition(String.class, cav2, null);
    childContext.registerBeanDefinition("test", definitionTest);

    childContext.setParent(staticContext);
    childContext.refresh();

    String test = (String) childContext.getBean("test");
    assertEquals(test, "me");

}

From source file:org.alfresco.repo.management.subsystems.LegacyConfigPostProcessor.java

/**
 * Given a bean name (assumed to implement {@link org.springframework.core.io.support.PropertiesLoaderSupport})
 * checks whether it already references the <code>global-properties</code> bean. If not, 'upgrades' the bean by
 * appending all additional resources it mentions in its <code>locations</code> property to
 * <code>globalPropertyLocations</code>, except for those resources mentioned in <code>newLocations</code>. A
 * reference to <code>global-properties</code> will then be added and the resource list in
 * <code>newLocations<code> will then become the new <code>locations</code> list for the bean.
 * // www  .j a v  a2  s.  c om
 * @param beanFactory
 *            the bean factory
 * @param globalPropertyLocations
 *            the list of global property locations to be appended to
 * @param beanName
 *            the bean name
 * @param newLocations
 *            the new locations to be set on the bean
 * @return the mutable property values
 */
@SuppressWarnings("unchecked")
private MutablePropertyValues processLocations(ConfigurableListableBeanFactory beanFactory,
        Collection<Object> globalPropertyLocations, String beanName, String[] newLocations) {
    // Get the bean an check its existing properties value
    MutablePropertyValues beanProperties = beanFactory.getBeanDefinition(beanName).getPropertyValues();
    PropertyValue pv = beanProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_PROPERTIES);
    Object value;

    // If the properties value already references the global-properties bean, we have nothing else to do. Otherwise,
    // we have to 'upgrade' the bean definition.
    if (pv == null || (value = pv.getValue()) == null || !(value instanceof BeanReference)
            || ((BeanReference) value).getBeanName()
                    .equals(LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES)) {
        // Convert the array of new locations to a managed list of type string values, so that it is
        // compatible with a bean definition
        Collection<Object> newLocationList = new ManagedList(newLocations.length);
        if (newLocations != null && newLocations.length > 0) {
            for (String preserveLocation : newLocations) {
                newLocationList.add(new TypedStringValue(preserveLocation));
            }
        }

        // If there is currently a locations list, process it
        pv = beanProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
        if (pv != null && (value = pv.getValue()) != null && value instanceof Collection) {
            Collection<Object> locations = (Collection<Object>) value;

            // Compute the set of locations that need to be added to globalPropertyLocations (preserving order) and
            // warn about each
            Set<Object> addedLocations = new LinkedHashSet<Object>(locations);
            addedLocations.removeAll(globalPropertyLocations);
            addedLocations.removeAll(newLocationList);

            for (Object location : addedLocations) {
                LegacyConfigPostProcessor.logger.warn("Legacy configuration detected: adding "
                        + (location instanceof TypedStringValue ? ((TypedStringValue) location).getValue()
                                : location.toString())
                        + " to global-properties definition");
                globalPropertyLocations.add(location);
            }

        }
        // Ensure the bean now references global-properties
        beanProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_PROPERTIES,
                new RuntimeBeanReference(LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES));

        // Ensure the new location list is now set on the bean
        if (newLocationList.size() > 0) {
            beanProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS, newLocationList);
        } else {
            beanProperties.removePropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS);
        }
    }
    return beanProperties;
}