Example usage for org.springframework.beans.factory.config BeanDefinitionHolder getBeanName

List of usage examples for org.springframework.beans.factory.config BeanDefinitionHolder getBeanName

Introduction

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

Prototype

public String getBeanName() 

Source Link

Document

Return the primary name of the bean, as specified for the bean definition.

Usage

From source file:org.jdal.aop.SerializableProxyUtils.java

public static BeanDefinitionHolder createSerializableProxy(BeanDefinitionHolder definition,
        BeanDefinitionRegistry registry, boolean proxyTargetClass) {

    String originalBeanName = definition.getBeanName();
    BeanDefinition targetDefinition = definition.getBeanDefinition();

    // Create a scoped proxy definition for the original bean name,
    // "hiding" the target bean in an internal target definition.
    RootBeanDefinition proxyDefinition = new RootBeanDefinition(SerializableProxyFactoryBean.class);
    proxyDefinition.setOriginatingBeanDefinition(definition.getBeanDefinition());
    proxyDefinition.setSource(definition.getSource());
    proxyDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

    String targetBeanName = getTargetBeanName(originalBeanName);
    proxyDefinition.getPropertyValues().add("targetBeanName", targetBeanName);

    if (proxyTargetClass) {
        targetDefinition.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);
    } else {/*  w  w w.  j  a v a 2  s  .  c  o m*/
        proxyDefinition.getPropertyValues().add("proxyTargetClass", Boolean.FALSE);
    }

    // Copy autowire settings from original bean definition.
    proxyDefinition.setAutowireCandidate(targetDefinition.isAutowireCandidate());
    proxyDefinition.setPrimary(targetDefinition.isPrimary());
    if (targetDefinition instanceof AbstractBeanDefinition) {
        proxyDefinition.copyQualifiersFrom((AbstractBeanDefinition) targetDefinition);
    }

    // Set singleton property of FactoryBean
    proxyDefinition.getPropertyValues().add("singleton", !targetDefinition.isPrototype());

    // The target bean should be ignored in favor of the scoped proxy.
    targetDefinition.setAutowireCandidate(false);
    targetDefinition.setPrimary(false);

    // Register the target bean as separate bean in the factory.
    registry.registerBeanDefinition(targetBeanName, targetDefinition);

    // Return the scoped proxy definition as primary bean definition
    // (potentially an inner bean).
    return new BeanDefinitionHolder(proxyDefinition, originalBeanName, definition.getAliases());
}

From source file:uk.org.ponder.rsac.support.BeanDefUtil.java

public static Object propertyValueToBeanName(Object value, BeanDefConverter converter) {
    Object beanspec = null;/*  w  w w .ja  va  2s  . c om*/
    if (value instanceof BeanDefinitionHolder) {
        // Resolve BeanDefinitionHolder: contains BeanDefinition with name and
        // aliases.
        BeanDefinitionHolder bdHolder = (BeanDefinitionHolder) value;
        String beanname = bdHolder.getBeanName();
        converter.convertBeanDef(bdHolder.getBeanDefinition(), beanname, true);
        beanspec = beanname;
    } else if (value instanceof BeanDefinition) {
        throw new IllegalArgumentException("No idea what to do with bean definition!");
    } else if (value instanceof RuntimeBeanReference) {
        RuntimeBeanReference ref = (RuntimeBeanReference) value;
        beanspec = ref.getBeanName();
    } else if (value instanceof ManagedList) {
        List valuelist = (List) value;
        StringList togo = new StringList();
        for (int i = 0; i < valuelist.size(); ++i) {
            String thisbeanname = (String) propertyValueToBeanName(valuelist.get(i), converter);
            togo.add(thisbeanname);
        }
        beanspec = togo;
    } else if (value instanceof String) {
        beanspec = new ValueHolder((String) value);
    } else if (value instanceof TypedStringValue) {
        beanspec = new ValueHolder(((TypedStringValue) value).getValue());
    } else {
        Logger.log.warn(
                "RSACBeanLocator Got value " + value + " of unknown type " + value.getClass() + ": ignoring");
    }
    return beanspec;
}

From source file:me.springframework.di.spring.SpringConfigurationLoader.java

/**
 * Constructs a {@link MutableSource} from a source providing an anonymous
 * bean.//ww w  .j a va  2s. c o m
 * 
 * @param sink
 *            The {@link Sink} configured to receive the value produced by
 *            the source.
 * @param value
 *            The actually value constructed.
 * @return The {@link Source} representation of the object producing that
 *         anonymous bean.
 */
private static MutableSource load(Sink sink, BeanDefinitionHolder value, MutableContext context) {
    MutableInstance instance = new MutableInstance(sink, value.getBeanName());
    load(instance, value.getBeanDefinition(), context);
    return instance;
}

From source file:org.fishwife.jrugged.spring.config.PerformanceMonitorBeanDefinitionDecorator.java

/**
 * Registers a BeanNameAutoProxyCreator class that wraps the bean being
 * monitored. The proxy is associated with the PerformanceMonitorInterceptor
 * for the bean, which is created when parsing the methods attribute from
 * the springconfiguration xml file./* w  w w  .  ja v a 2s  .  co m*/
 * 
 * @param source An Attribute node from the spring configuration
 * @param holder A container for the beans I will create
 * @param context the context currently parsing my spring config
 */
private void registerProxyCreator(Node source, BeanDefinitionHolder holder, ParserContext context) {

    String beanName = holder.getBeanName();
    String proxyName = beanName + "Proxy";
    String interceptorName = beanName + "PerformanceMonitorInterceptor";

    BeanDefinitionBuilder initializer = BeanDefinitionBuilder
            .rootBeanDefinition(BeanNameAutoProxyCreator.class);

    initializer.addPropertyValue("beanNames", beanName);
    initializer.addPropertyValue("interceptorNames", interceptorName);

    BeanDefinitionRegistry registry = context.getRegistry();
    registry.registerBeanDefinition(proxyName, initializer.getBeanDefinition());
}

From source file:org.xeustechnologies.jcl.spring.JclBeanDefinitionParser.java

public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(element);

    String beanName = holder.getBeanName();

    BeanDefinition bd = holder.getBeanDefinition();
    bd.setBeanClassName(JarClassLoader.class.getName());

    logger.info("Registering JarClassLoader bean: " + beanName);

    parserContext.getRegistry().registerBeanDefinition(beanName, bd);

    return bd;//from   w  w  w  . java2  s  .co m
}

From source file:org.fishwife.jrugged.spring.config.MonitorMethodInterceptorDefinitionDecorator.java

/**
 * Method called by Spring when it encounters the custom jrugged:methods
 * attribute. Registers the performance monitor and interceptor.
 *///  w w  w.  j  av a 2s. co m
public BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder holder, ParserContext context) {

    String beanName = holder.getBeanName();
    BeanDefinitionRegistry registry = context.getRegistry();
    registerPerformanceMonitor(beanName, registry);
    registerInterceptor(source, beanName, registry);

    return holder;
}

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

/**
 * @see BeanReferenceParser#parse(Element,ParserContext,boolean)
 *///from   w ww . j a  v a 2s. co  m
public Object parse(Element element, ParserContext parserContext, boolean registerInnerBean) {

    String refId = element.getAttribute("refId");
    if (StringUtils.hasText(refId)) {
        return new RuntimeBeanReference(refId);
    }

    Element beanElement = null;
    List beanElements = DomUtils.getChildElementsByTagName(element, "bean");
    if (!CollectionUtils.isEmpty(beanElements)) {
        beanElement = (Element) beanElements.get(0);
    }
    if (beanElement == null) {
        throw new IllegalStateException("The XML element " + StringUtils.quote(element.getNodeName())
                + " should either have a " + "reference to an already registered bean definition or contain a "
                + "bean definition");
    }

    BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(beanElement);

    String beanName = holder.getBeanName();

    if (registerInnerBean && StringUtils.hasText(beanName)) {
        BeanDefinitionRegistry registry = parserContext.getRegistry();
        BeanDefinition beanDefinition = holder.getBeanDefinition();
        registry.registerBeanDefinition(beanName, beanDefinition);

        return new RuntimeBeanReference(beanName);
    }

    return holder;
}

From source file:org.activiti.spring.components.aop.util.Scopifier.java

@Override
protected Object resolveValue(Object value) {

    BeanDefinition definition = null;/*from w  w  w  . j  av a 2 s  . co  m*/
    String beanName = null;
    if (value instanceof BeanDefinition) {
        definition = (BeanDefinition) value;
        beanName = BeanDefinitionReaderUtils.generateBeanName(definition, registry);
    } else if (value instanceof BeanDefinitionHolder) {
        BeanDefinitionHolder holder = (BeanDefinitionHolder) value;
        definition = holder.getBeanDefinition();
        beanName = holder.getBeanName();
    }

    if (definition != null) {
        boolean nestedScoped = scope.equals(definition.getScope());
        boolean scopeChangeRequiresProxy = !scoped && nestedScoped;
        if (scopeChangeRequiresProxy) {
            // Exit here so that nested inner bean definitions are not
            // analysed
            return createScopedProxy(beanName, definition, registry, proxyTargetClass);
        }
    }

    // Nested inner bean definitions are recursively analysed here
    value = super.resolveValue(value);
    return value;
}

From source file:org.opencredo.esper.config.xml.EsperListenerParser.java

/**
 * Parses out a set of configured esper statement listeners.
 * /*  w  w w  . j  a  v a2 s  . com*/
 * @param element
 *            the esper listeners element
 * @param parserContext
 *            the parser's current context
 * @return a list of configured esper statement listeners
 */
@SuppressWarnings("unchecked")
public ManagedSet parseListeners(Element element, ParserContext parserContext) {
    ManagedSet listeners = new ManagedSet();
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element childElement = (Element) child;
            String localName = child.getLocalName();
            if ("bean".equals(localName)) {
                BeanDefinitionHolder holder = parserContext.getDelegate()
                        .parseBeanDefinitionElement(childElement);
                parserContext.registerBeanComponent(new BeanComponentDefinition(holder));
                listeners.add(new RuntimeBeanReference(holder.getBeanName()));
            } else if ("ref".equals(localName)) {
                String ref = childElement.getAttribute("bean");
                listeners.add(new RuntimeBeanReference(ref));
            }
        }
    }
    return listeners;
}

From source file:org.devefx.httpmapper.spring.mapper.ClassPathMapperScanner.java

private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
    ScannedGenericBeanDefinition definition;
    for (BeanDefinitionHolder holder : beanDefinitions) {
        definition = (ScannedGenericBeanDefinition) holder.getBeanDefinition();

        if (logger.isDebugEnabled()) {
            logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '"
                    + definition.getBeanClassName() + "' mapperInterface");
        }/*from   w w w.j  a v a 2s .  c  o  m*/
        // the mapper interface is the original class of the bean
        // but, the actual class of the bean is MapperFactoryBean
        definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName());
        definition.setBeanClass(this.factoryBeanClass);

        boolean explicitFactoryUsed = false;
        if (StringUtils.hasText(this.configBeanName)) {
            definition.getPropertyValues().add("config", new RuntimeBeanReference(this.configBeanName));
            explicitFactoryUsed = true;
        }

        if (!explicitFactoryUsed) {
            if (logger.isDebugEnabled()) {
                logger.debug("Enabling autowire by type for MapperFactoryBean with name '"
                        + holder.getBeanName() + "'.");
            }
            definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
        }
    }
}