Example usage for org.springframework.beans.factory.support RootBeanDefinition getPropertyValues

List of usage examples for org.springframework.beans.factory.support RootBeanDefinition getPropertyValues

Introduction

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

Prototype

@Override
public MutablePropertyValues getPropertyValues() 

Source Link

Document

Return property values for this bean (never null ).

Usage

From source file:com.inspiresoftware.lib.dto.geda.config.AnnotationDrivenGeDABeanDefinitionParser.java

protected RuntimeBeanReference setupDtoSupport(final Element element, final String dtoSupportBeanName,
        final BeanDefinitionRegistry registry, final Object elementSource,
        final RuntimeBeanReference dtoFactoryRef, final RuntimeBeanReference dtoVcrRef,
        final RuntimeBeanReference dtoDslRef) {

    final RootBeanDefinition dtoSupportDef = new RootBeanDefinition(DTOSupportImpl.class);
    dtoSupportDef.setSource(elementSource);
    dtoSupportDef.setRole(BeanDefinition.ROLE_APPLICATION);

    final MutablePropertyValues valuesArgs = dtoSupportDef.getPropertyValues();
    valuesArgs.addPropertyValue("beanFactory", dtoFactoryRef);
    if (dtoVcrRef != null) {
        valuesArgs.addPropertyValue("adaptersRegistrar", dtoVcrRef);
    }/*from w w w . ja  va 2s .c o  m*/
    if (dtoDslRef != null) {
        valuesArgs.addPropertyValue("dslRegistrar", dtoDslRef);
    }
    setupListenerProperty(valuesArgs, "onDtoAssembly", element.getAttribute(XSD_ATTR__ON_DTO_ASSEMBLY));
    setupListenerProperty(valuesArgs, "onDtoAssembled", element.getAttribute(XSD_ATTR__ON_DTO_ASSEMBLED));
    setupListenerProperty(valuesArgs, "onDtoFailed", element.getAttribute(XSD_ATTR__ON_DTO_FAILED));
    setupListenerProperty(valuesArgs, "onEntityAssembly", element.getAttribute(XSD_ATTR__ON_ENTITY_ASSEMBLY));
    setupListenerProperty(valuesArgs, "onEntityAssembled", element.getAttribute(XSD_ATTR__ON_ENTITY_ASSEMBLED));
    setupListenerProperty(valuesArgs, "onEntityFailed", element.getAttribute(XSD_ATTR__ON_ENTITY_FAILED));

    registry.registerBeanDefinition(dtoSupportBeanName, dtoSupportDef);

    return new RuntimeBeanReference(dtoSupportBeanName);
}

From source file:com.googlecode.ehcache.annotations.config.AnnotationDrivenEhCacheBeanDefinitionParser.java

private void registerAspect(Element element, ParserContext parserContext) {
    if (!parserContext.getRegistry().containsBeanDefinition(EHCACHE_CACHING_ASPECT_BEAN_NAME)) {
        final Object elementSource = parserContext.extractSource(element);

        final RuntimeBeanReference cacheAttributeSourceReference = this.setupCacheAttributeSource(element,
                parserContext, elementSource);

        RootBeanDefinition def = new RootBeanDefinition();
        def.setBeanClassName(EHCACHE_CACHING_ASPECT_CLASS_NAME);
        def.setFactoryMethodName("aspectOf");
        def.getPropertyValues().add("cacheAttributeSource", cacheAttributeSourceReference);
        //registerTransactionManager(element, def);
        parserContext.registerBeanComponent(new BeanComponentDefinition(def, EHCACHE_CACHING_ASPECT_BEAN_NAME));
    }/* w  w  w  .jav  a2s .  com*/
}

From source file:com.inspiresoftware.lib.dto.geda.config.AnnotationDrivenGeDABeanDefinitionParser.java

protected RuntimeBeanReference setupGeDAInterceptor(final ParserContext parserContext,
        final Object elementSource, final RuntimeBeanReference defaultSupport,
        final RuntimeBeanReference defaultResolver) {

    final RootBeanDefinition defaultInterceptor = new RootBeanDefinition(GeDAInterceptor.class);
    defaultInterceptor.setSource(elementSource);
    defaultInterceptor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

    final MutablePropertyValues propertyValues = defaultInterceptor.getPropertyValues();
    propertyValues.addPropertyValue("support", defaultSupport);
    propertyValues.addPropertyValue("resolver", defaultResolver);

    final XmlReaderContext readerContext = parserContext.getReaderContext();

    final String beanName = readerContext.registerWithGeneratedName(defaultInterceptor);

    return new RuntimeBeanReference(beanName);

}

From source file:com.inspiresoftware.lib.dto.geda.config.AnnotationDrivenGeDABeanDefinitionParser.java

protected RuntimeBeanReference setupPointcutAdvisor(final Element element, final ParserContext parserContext,
        final Object elementSource, final RuntimeBeanReference pointcutBeanReference,
        final RuntimeBeanReference interceptorBeanReference) {

    final RootBeanDefinition pointcutAdvisor = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class);
    pointcutAdvisor.setSource(elementSource);
    pointcutAdvisor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

    final MutablePropertyValues propertyValues = pointcutAdvisor.getPropertyValues();
    propertyValues.addPropertyValue("adviceBeanName", interceptorBeanReference.getBeanName());
    propertyValues.addPropertyValue("pointcut", pointcutBeanReference);
    if (element.hasAttribute("order")) {
        propertyValues.addPropertyValue("order", element.getAttribute("order"));
    }//from  w  w  w  .j a  v a2s  . co m

    final BeanDefinitionRegistry registry = parserContext.getRegistry();
    registry.registerBeanDefinition(ADVISOR_BEAN_NAME, pointcutAdvisor);
    return new RuntimeBeanReference(ADVISOR_BEAN_NAME);
}

From source file:eap.config.ConfigBeanDefinitionParser.java

/**
 * Parses one of '{@code before}', '{@code after}', '{@code after-returning}',
 * '{@code after-throwing}' or '{@code around}' and registers the resulting
 * BeanDefinition with the supplied BeanDefinitionRegistry.
 * @return the generated advice RootBeanDefinition
 *//* ww w .  ja  v a 2 s.  c om*/
private AbstractBeanDefinition parseAdvice(String aspectName, int order, Element aspectElement,
        Element adviceElement, ParserContext parserContext, List<BeanDefinition> beanDefinitions,
        List<BeanReference> beanReferences) {

    try {
        this.parseState.push(new AdviceEntry(parserContext.getDelegate().getLocalName(adviceElement)));

        // create the method factory bean
        RootBeanDefinition methodDefinition = new RootBeanDefinition(MethodLocatingFactoryBean.class);
        methodDefinition.getPropertyValues().add("targetBeanName", aspectName);
        methodDefinition.getPropertyValues().add("methodName", adviceElement.getAttribute("method"));
        methodDefinition.setSynthetic(true);

        // create instance factory definition
        RootBeanDefinition aspectFactoryDef = new RootBeanDefinition(
                SimpleBeanFactoryAwareAspectInstanceFactory.class);
        aspectFactoryDef.getPropertyValues().add("aspectBeanName", aspectName);
        aspectFactoryDef.setSynthetic(true);

        // register the pointcut
        AbstractBeanDefinition adviceDef = createAdviceDefinition(adviceElement, parserContext, aspectName,
                order, methodDefinition, aspectFactoryDef, beanDefinitions, beanReferences);

        // configure the advisor
        RootBeanDefinition advisorDefinition = new RootBeanDefinition(AspectJPointcutAdvisor.class);
        advisorDefinition.setSource(parserContext.extractSource(adviceElement));
        advisorDefinition.getConstructorArgumentValues().addGenericArgumentValue(adviceDef);
        if (aspectElement.hasAttribute(ORDER_PROPERTY)) {
            advisorDefinition.getPropertyValues().add(ORDER_PROPERTY,
                    aspectElement.getAttribute(ORDER_PROPERTY));
        }

        // register the final advisor
        parserContext.getReaderContext().registerWithGeneratedName(advisorDefinition);

        return advisorDefinition;
    } finally {
        this.parseState.pop();
    }
}

From source file:com.googlecode.ehcache.annotations.config.AnnotationDrivenEhCacheBeanDefinitionParser.java

/**
 * Create {@link MethodInterceptor} that is applies the caching logic to advised methods.
 * /*  w ww .  j a  v a 2 s  . c o m*/
 * @return Reference to the {@link MethodInterceptor}. Should never be null.
 */
protected RuntimeBeanReference setupInterceptor(Element element, ParserContext parserContext,
        Object elementSource, RuntimeBeanReference cacheableAttributeSourceRuntimeReference) {
    final RootBeanDefinition interceptor = new RootBeanDefinition(EhCacheInterceptor.class);
    interceptor.setSource(elementSource);
    interceptor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

    final MutablePropertyValues propertyValues = interceptor.getPropertyValues();
    propertyValues.addPropertyValue("cacheAttributeSource", cacheableAttributeSourceRuntimeReference);

    final XmlReaderContext readerContext = parserContext.getReaderContext();
    final String interceptorBeanName = readerContext.registerWithGeneratedName(interceptor);
    return new RuntimeBeanReference(interceptorBeanName);
}

From source file:com.googlecode.ehcache.annotations.config.AnnotationDrivenEhCacheBeanDefinitionParser.java

/**
 * Create the {@link Pointcut} used to apply the caching interceptor
 * /*from  w w  w.j a  va2s. c om*/
 * @return Reference to the {@link Pointcut}. Should never be null.
 */
protected RuntimeBeanReference setupPointcut(Element element, ParserContext parserContext, Object elementSource,
        RuntimeBeanReference cacheAttributeSource) {
    final RootBeanDefinition pointcut = new RootBeanDefinition(CacheStaticMethodMatcherPointcut.class);
    pointcut.setSource(elementSource);
    pointcut.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

    final MutablePropertyValues propertyValues = pointcut.getPropertyValues();
    propertyValues.addPropertyValue("cacheAttributeSource", cacheAttributeSource);

    final XmlReaderContext readerContext = parserContext.getReaderContext();
    final String pointcutBeanName = readerContext.registerWithGeneratedName(pointcut);
    return new RuntimeBeanReference(pointcutBeanName);
}

From source file:com.weibo.api.motan.config.springsupport.MotanBeanDefinitionParser.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static BeanDefinition parse(Element element, ParserContext parserContext, Class<?> beanClass,
        boolean required) throws ClassNotFoundException {
    RootBeanDefinition bd = new RootBeanDefinition();
    bd.setBeanClass(beanClass);/*w w  w .j a  v  a 2s .c o m*/
    // ??lazy init
    bd.setLazyInit(false);

    // id?id,idcontext
    String id = element.getAttribute("id");
    if ((id == null || id.length() == 0) && required) {
        String generatedBeanName = element.getAttribute("name");
        if (generatedBeanName == null || generatedBeanName.length() == 0) {
            generatedBeanName = element.getAttribute("class");
        }
        if (generatedBeanName == null || generatedBeanName.length() == 0) {
            generatedBeanName = beanClass.getName();
        }
        id = generatedBeanName;
        int counter = 2;
        while (parserContext.getRegistry().containsBeanDefinition(id)) {
            id = generatedBeanName + (counter++);
        }
    }
    if (id != null && id.length() > 0) {
        if (parserContext.getRegistry().containsBeanDefinition(id)) {
            throw new IllegalStateException("Duplicate spring bean id " + id);
        }
        parserContext.getRegistry().registerBeanDefinition(id, bd);
    }
    bd.getPropertyValues().addPropertyValue("id", id);
    if (ProtocolConfig.class.equals(beanClass)) {
        MotanNamespaceHandler.protocolDefineNames.add(id);

    } else if (RegistryConfig.class.equals(beanClass)) {
        MotanNamespaceHandler.registryDefineNames.add(id);

    } else if (BasicServiceInterfaceConfig.class.equals(beanClass)) {
        MotanNamespaceHandler.basicServiceConfigDefineNames.add(id);

    } else if (BasicRefererInterfaceConfig.class.equals(beanClass)) {
        MotanNamespaceHandler.basicRefererConfigDefineNames.add(id);

    } else if (ServiceConfigBean.class.equals(beanClass)) {
        String className = element.getAttribute("class");
        if (className != null && className.length() > 0) {
            RootBeanDefinition classDefinition = new RootBeanDefinition();
            classDefinition.setBeanClass(
                    Class.forName(className, true, Thread.currentThread().getContextClassLoader()));
            classDefinition.setLazyInit(false);
            parseProperties(element.getChildNodes(), classDefinition);
            bd.getPropertyValues().addPropertyValue("ref",
                    new BeanDefinitionHolder(classDefinition, id + "Impl"));
        }
    }

    Set<String> props = new HashSet<String>();
    ManagedMap parameters = null;
    // ??setbd
    for (Method setter : beanClass.getMethods()) {
        String name = setter.getName();
        // setXXX
        if (name.length() <= 3 || !name.startsWith("set") || !Modifier.isPublic(setter.getModifiers())
                || setter.getParameterTypes().length != 1) {
            continue;
        }
        String property = (name.substring(3, 4).toLowerCase() + name.substring(4)).replaceAll("_", "-");
        props.add(property);
        if ("id".equals(property)) {
            bd.getPropertyValues().addPropertyValue("id", id);
            continue;
        }
        String value = element.getAttribute(property);
        if ("methods".equals(property)) {
            parseMethods(id, element.getChildNodes(), bd, parserContext);
        }
        if (StringUtils.isBlank(value)) {
            continue;
        }
        value = value.trim();
        if (value.length() == 0) {
            continue;
        }
        Object reference;
        if ("ref".equals(property)) {
            if (parserContext.getRegistry().containsBeanDefinition(value)) {
                BeanDefinition refBean = parserContext.getRegistry().getBeanDefinition(value);
                if (!refBean.isSingleton()) {
                    throw new IllegalStateException(
                            "The exported service ref " + value + " must be singleton! Please set the " + value
                                    + " bean scope to singleton, eg: <bean id=\"" + value
                                    + "\" scope=\"singleton\" ...>");
                }
            }
            reference = new RuntimeBeanReference(value);
        } else if ("protocol".equals(property) && !StringUtils.isBlank(value)) {
            if (!value.contains(",")) {
                reference = new RuntimeBeanReference(value);
            } else {
                parseMultiRef("protocols", value, bd, parserContext);
                reference = null;
            }
        } else if ("registry".equals(property)) {
            parseMultiRef("registries", value, bd, parserContext);
            reference = null;
        } else if ("basicService".equals(property)) {
            reference = new RuntimeBeanReference(value);

        } else if ("basicReferer".equals(property)) {
            reference = new RuntimeBeanReference(value);

        } else if ("extConfig".equals(property)) {
            reference = new RuntimeBeanReference(value);
        } else {
            reference = new TypedStringValue(value);
        }

        if (reference != null) {
            bd.getPropertyValues().addPropertyValue(property, reference);
        }
    }
    if (ProtocolConfig.class.equals(beanClass)) {
        // protocolparameters?
        NamedNodeMap attributes = element.getAttributes();
        int len = attributes.getLength();
        for (int i = 0; i < len; i++) {
            Node node = attributes.item(i);
            String name = node.getLocalName();
            if (!props.contains(name)) {
                if (parameters == null) {
                    parameters = new ManagedMap();
                }
                String value = node.getNodeValue();
                parameters.put(name, new TypedStringValue(value, String.class));
            }
        }
        bd.getPropertyValues().addPropertyValue("parameters", parameters);
    }
    return bd;
}

From source file:com.googlecode.ehcache.annotations.config.AnnotationDrivenEhCacheBeanDefinitionParser.java

/**
 * Create {@link PointcutAdvisor} that puts the {@link Pointcut} and {@link MethodInterceptor} together.
 * //from w  w w . jav  a  2  s. co  m
 * @return Reference to the {@link PointcutAdvisor}. Should never be null.
 */
protected RuntimeBeanReference setupPointcutAdvisor(Element element, ParserContext parserContext,
        Object elementSource, RuntimeBeanReference cacheablePointcutBeanReference,
        RuntimeBeanReference cachingInterceptorBeanReference) {
    final RootBeanDefinition pointcutAdvisor = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class);
    pointcutAdvisor.setSource(elementSource);
    pointcutAdvisor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

    final MutablePropertyValues propertyValues = pointcutAdvisor.getPropertyValues();
    propertyValues.addPropertyValue("adviceBeanName", cachingInterceptorBeanReference.getBeanName());
    propertyValues.addPropertyValue("pointcut", cacheablePointcutBeanReference);
    if (element.hasAttribute("order")) {
        propertyValues.addPropertyValue("order", element.getAttribute("order"));
    }

    final BeanDefinitionRegistry registry = parserContext.getRegistry();
    registry.registerBeanDefinition(EHCACHE_CACHING_ADVISOR_BEAN_NAME, pointcutAdvisor);
    return new RuntimeBeanReference(EHCACHE_CACHING_ADVISOR_BEAN_NAME);
}

From source file:com.clican.pluto.dataprocess.spring.parser.AbstractProcessorParser.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionRegistry bdr = parserContext.getRegistry();
    RootBeanDefinition beanDef = new RootBeanDefinition();
    beanDef.setDestroyMethodName("destroy");
    beanDef.setAbstract(false);/*from  w  w  w .  ja va  2 s .  co m*/
    beanDef.setBeanClass(getDataProcessorClass());
    beanDef.setLazyInit(false);
    beanDef.setAutowireMode(Autowire.BY_NAME.value());
    String id = element.getAttribute("id");
    if (bdr.containsBeanDefinition(id)) {
        throw new RuntimeException("id[" + id + "]??");
    }
    bdr.registerBeanDefinition(id, beanDef);
    beanDef.getPropertyValues().addPropertyValue("id", id);
    String startProcessor = element.getAttribute("startProcessor");
    boolean sp = false;
    if (StringUtils.isNotEmpty(startProcessor)) {
        sp = Boolean.parseBoolean(startProcessor);
    }
    beanDef.getPropertyValues().addPropertyValue("startProcessor", sp);

    String transaction = element.getAttribute("transaction");
    if (StringUtils.isNotEmpty(transaction)) {
        beanDef.getPropertyValues().addPropertyValue("transaction", transaction);
    } else if (sp) {
        beanDef.getPropertyValues().addPropertyValue("transaction", TransactionMode.BEGIN.getMode());
    }
    String cloneContext = element.getAttribute("cloneContext");
    if (StringUtils.isNotEmpty(cloneContext)) {
        beanDef.getPropertyValues().addPropertyValue("cloneContext", Boolean.parseBoolean(cloneContext));
    }
    String propagations = element.getAttribute("propagations");
    if (StringUtils.isNotEmpty(propagations)) {
        List<String> propataionList = new ArrayList<String>();
        for (String propagation : propagations.split(",")) {
            propataionList.add(propagation);
        }
        beanDef.getPropertyValues().addPropertyValue("propagations", propataionList);
    }
    String nextDataProcessors = element.getAttribute("nextDataProcessors");
    if (StringUtils.isNotEmpty(nextDataProcessors)) {
        List nextDataProcessList = new ManagedList();
        for (String nextDataProcess : nextDataProcessors.split(",")) {
            nextDataProcess = nextDataProcess.trim();
            nextDataProcessList.add(new RuntimeBeanReference(nextDataProcess));
        }
        beanDef.getPropertyValues().addPropertyValue("nextDataProcessors", nextDataProcessList);
    }

    customiseBeanDefinition(beanDef, element, parserContext);

    return beanDef;
}