Example usage for org.springframework.beans.factory.config BeanDefinition getPropertyValues

List of usage examples for org.springframework.beans.factory.config BeanDefinition getPropertyValues

Introduction

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

Prototype

MutablePropertyValues getPropertyValues();

Source Link

Document

Return the property values to be applied to a new instance of the bean.

Usage

From source file:com.developmentsprint.spring.breaker.config.AnnotationDrivenBreakerBeanDefinitionParser.java

private static void parseCircuitManagerProperty(Element element, BeanDefinition def) {
    def.getPropertyValues().add("circuitManager",
            new RuntimeBeanReference(BreakerNamespaceHandler.extractCircuitManager(element)));
}

From source file:com.mtgi.analytics.aop.config.v11.SchedulerActivationPostProcessor.java

public static BeanDefinition unwrapInnerBean(BeanDefinition parent, String property) {
    Object value = parent.getPropertyValues().getPropertyValue(property).getValue();
    if (value == null)
        return null;
    if (value instanceof BeanDefinition)
        return (BeanDefinition) value;
    if (value instanceof BeanDefinitionHolder)
        return ((BeanDefinitionHolder) value).getBeanDefinition();
    throw new IllegalArgumentException("Don't know how to convert " + value.getClass()
            + " into a BeanDefinition for property " + property);
}

From source file:com.mtgi.analytics.aop.config.v11.SchedulerActivationPostProcessor.java

/**
 * Convenience method to override a CronTrigger bean definition with the given cron expression
 * and base name.// w w  w. java 2 s .com
 */
public static void configureTriggerDefinition(BeanDefinition trigger, String cronExpression, String name) {
    MutablePropertyValues props = trigger.getPropertyValues();
    if (cronExpression != null) {
        props.removePropertyValue("cronExpression");
        props.addPropertyValue("cronExpression", cronExpression);
    }
    props.addPropertyValue("name", name + "_trigger");

    unwrapInnerBean(trigger, "jobDetail").getPropertyValues().addPropertyValue("name", name + "_job");
}

From source file:org.springmodules.cache.config.ConfigAssert.java

/**
 * Asserts that the given bean definition contains a property value equal to
 * the given one./*from ww  w  .jav a2s.co  m*/
 * 
 * @param beanDefinition
 *          the given bean definition
 * @param expectedPropertyValue
 *          the expected property value
 */
public static void assertBeanDefinitionHasProperty(BeanDefinition beanDefinition,
        PropertyValue expectedPropertyValue) {

    assertPropertyIsPresent(beanDefinition.getPropertyValues(), expectedPropertyValue);
}

From source file:eap.config.AnnotationDrivenCacheBeanDefinitionParser.java

private static void parseCacheManagerProperty(Element element, BeanDefinition def) {
    //      def.getPropertyValues().add("cacheManager",
    //            new RuntimeBeanReference(CacheNamespaceHandler.extractCacheManager(element)));
    def.getPropertyValues().add("cacheManager",
            new RuntimeBeanReference((String) ReflectUtil.invokeMethod(CacheNamespaceHandler.class,
                    "extractCacheManager", new Class<?>[] { Element.class }, new Object[] { element })));
}

From source file:com.mtgi.analytics.aop.config.v11.BtManagerBeanDefinitionParser.java

/** 
 * called by nested tags to push inner beans into the enclosing {@link BehaviorTrackingManagerImpl}.
 * @return <span>true if the inner bean was added to an enclosing {@link BehaviorTrackingManagerImpl}.  Otherwise, the bean definition
 * is not nested inside a &lt;bt:manager&gt; tag and therefore will have to be registered as a global bean in the application
 * context.</span>//w w w .  j  av  a 2  s  .c om
 */
protected static boolean registerNestedBean(BeanDefinitionHolder nested, String parentProperty,
        ParserContext parserContext) {
    //add parsed inner bean element to containing manager definition; e.g. persister or SessionContext impls.
    CompositeComponentDefinition parent = parserContext.getContainingComponent();
    if (parent instanceof ManagerComponentDefinition) {
        //we are nested; add to enclosing bean def.
        ManagerComponentDefinition mcd = (ManagerComponentDefinition) parent;
        BeanDefinition managerDef = parserContext.getContainingBeanDefinition();

        MutablePropertyValues props = managerDef.getPropertyValues();
        PropertyValue current = props.getPropertyValue(parentProperty);
        boolean innerBean = true;

        if (current != null) {
            //if the original value is a reference, replace it with an alias to the nested bean definition.
            //this means the nested bean takes the place of the default definition
            //in other places where it might be referenced, as well as during mbean export
            Object value = current.getValue();
            DefaultListableBeanFactory factory = mcd.getTemplateFactory();
            if (value instanceof RuntimeBeanReference) {
                String ref = ((RuntimeBeanReference) value).getBeanName();

                if (factory.getBeanDefinition(ref) == nested.getBeanDefinition()) {
                    //the nested definition is the same as the default definition
                    //by reference, so we don't need to make it an inner bean definition.
                    innerBean = false;
                }
            }
        }
        if (innerBean)
            props.addPropertyValue(parentProperty, nested);
        mcd.addNestedProperty(parentProperty);
        return true;
    }
    //bean is not nested inside bt:manager
    return false;
}

From source file:org.orderofthebee.addons.support.tools.repo.caches.CacheLookupUtils.java

/**
 * Resolves the {@link CacheStatistics cache statistics} of the {@link TransactionalCache transactional cache} instance that facades a
 * specific {@link SimpleCache shared//from   w  w  w  .  ja v  a 2s .c  om
 * cache} and provides it in a more script-friendly representation.
 *
 * @param sharedCacheName
 *            the name of the shared cache
 * @return a facade to a snapshot of the cache statistics
 */
public static AlfrescoCacheStatsFacade resolveStatisticsViaTransactional(final String sharedCacheName) {
    ParameterCheck.mandatoryString("sharedCacheName", sharedCacheName);

    LOGGER.debug("Trying to resolve transactional cache for shared cache {}", sharedCacheName);

    String txnCacheName = null;

    final WebApplicationContext applicationContext = ContextLoader.getCurrentWebApplicationContext();

    if (applicationContext instanceof ConfigurableApplicationContext) {
        final ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext)
                .getBeanFactory();
        final String[] txnCacheBeanNames = applicationContext.getBeanNamesForType(TransactionalCache.class,
                false, false);

        // this is a rather ugly reference lookup, but so far I see no other way
        for (final String txnCacheBeanName : txnCacheBeanNames) {
            final BeanDefinition txnCacheDefinition = beanFactory.getBeanDefinition(txnCacheBeanName);

            final PropertyValue sharedCacheValue = txnCacheDefinition.getPropertyValues()
                    .getPropertyValue("sharedCache");
            final PropertyValue nameValue = txnCacheDefinition.getPropertyValues().getPropertyValue("name");
            if (nameValue != null && sharedCacheValue != null) {
                final Object sharedCacheRef = sharedCacheValue.getValue();
                if (sharedCacheRef instanceof RuntimeBeanReference) {
                    final String sharedCacheBeanName = ((RuntimeBeanReference) sharedCacheRef).getBeanName();

                    Object nameValueObj = nameValue.getValue();
                    if (nameValueObj instanceof TypedStringValue) {
                        nameValueObj = ((TypedStringValue) nameValueObj).getValue();
                    }

                    if (EqualsHelper.nullSafeEquals(sharedCacheBeanName, sharedCacheName)) {
                        if (txnCacheName != null) {
                            LOGGER.info("Shared cache {} is referenced by multiple transactional caches",
                                    sharedCacheName);
                            txnCacheName = null;
                            break;
                        }
                        txnCacheName = String.valueOf(nameValueObj);
                        LOGGER.debug("Resolved transactional cache {} for shared cache {}", txnCacheName,
                                sharedCacheName);
                    } else {
                        try {
                            final DefaultSimpleCache<?, ?> defaultSimpleCache = applicationContext
                                    .getBean(sharedCacheBeanName, DefaultSimpleCache.class);
                            if (EqualsHelper.nullSafeEquals(defaultSimpleCache.getCacheName(),
                                    sharedCacheName)) {
                                if (txnCacheName != null) {
                                    LOGGER.info(
                                            "Shared cache {} is referenced by multiple transactional caches",
                                            sharedCacheName);
                                    txnCacheName = null;
                                    break;
                                }
                                txnCacheName = String.valueOf(nameValueObj);
                                LOGGER.debug("Resolved transactional cache {} for shared cache {}",
                                        txnCacheName, sharedCacheName);
                            }
                            continue;
                        } catch (final BeansException be) {
                            // ignore - can be expected e.g. in EE or with alternative cache implementations
                        }
                    }
                }
            }
        }

        if (txnCacheName == null) {
            LOGGER.debug("Unable to resolve unique transactional cache for shared cache {}", sharedCacheName);
        }
    } else {
        LOGGER.debug(
                "Application context is not a configurable application context - unable to resolve transactional cache");
    }

    AlfrescoCacheStatsFacade facade = null;
    if (txnCacheName != null) {
        final CacheStatistics cacheStatistics = applicationContext.getBean("cacheStatistics",
                CacheStatistics.class);
        try {
            final Map<OpType, OperationStats> allStats = cacheStatistics.allStats(txnCacheName);
            facade = new AlfrescoCacheStatsFacade(allStats);
        } catch (final NoStatsForCache e) {
            facade = new AlfrescoCacheStatsFacade(Collections.emptyMap());
        }
    }

    return facade;
}

From source file:com.mtgi.analytics.aop.config.TemplateBeanDefinitionParser.java

/**
 * Convenience method to update a template bean definition from overriding XML data.  
 * If <code>overrides</code> contains attribute <code>attribute</code> or a child element
 * with name <code>attribute</code>, transfer that
 * attribute as a bean property onto <code>template</code>, overwriting the default value.
 * @param reference if true, the value of the attribute is to be interpreted as a runtime bean name reference; otherwise it is interpreted as a literal value
 *//*from   www.  ja  v  a  2 s . com*/
public static boolean overrideProperty(String attribute, BeanDefinition template, Element overrides,
        boolean reference) {
    Object value = null;
    if (overrides.hasAttribute(attribute)) {
        value = overrides.getAttribute(attribute);
    } else {
        NodeList children = overrides.getElementsByTagNameNS("*", attribute);
        if (children.getLength() == 1) {
            Element child = (Element) children.item(0);
            value = child.getTextContent();
        }
    }

    if (value != null) {
        if (reference)
            value = new RuntimeBeanReference(value.toString());

        String propName = Conventions.attributeNameToPropertyName(attribute);
        MutablePropertyValues props = template.getPropertyValues();
        props.removePropertyValue(propName);
        props.addPropertyValue(propName, value);
        return true;
    }

    return false;
}

From source file:pl.chilldev.web.spring.config.MetaHttpEquivBeanDefinitionParser.java

/**
 * Initializes bean parser.//from w w  w .  j av a2  s  .  co m
 *
 * @param pageMetaModelFactoryBean Page model factory.
 * @since 0.0.2
 */
public MetaHttpEquivBeanDefinitionParser(BeanDefinition pageMetaModelFactoryBean) {
    pageMetaModelFactoryBean.getPropertyValues()
            .addPropertyValue(MetaHttpEquivBeanDefinitionParser.PROPERTY_METAHTTPEQUIV, this.meta);
}

From source file:pl.chilldev.web.spring.config.MetaNameBeanDefinitionParser.java

/**
 * Initializes bean parser./*from ww  w .  jav a  2s .co m*/
 *
 * @param pageMetaModelFactoryBean Page model factory.
 * @since 0.0.2
 */
public MetaNameBeanDefinitionParser(BeanDefinition pageMetaModelFactoryBean) {
    pageMetaModelFactoryBean.getPropertyValues()
            .addPropertyValue(MetaNameBeanDefinitionParser.PROPERTY_METANAMES, this.meta);
}