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

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

Introduction

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

Prototype

@Override
public String getBeanName() 

Source Link

Document

Return the requested bean name, or the fully-qualified type name in case of by-type resolution.

Usage

From source file:org.bytesoft.bytetcc.supports.dubbo.DubboConfigPostProcessor.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();

    List<BeanDefinition> appNameList = new ArrayList<BeanDefinition>();
    List<BeanDefinition> providerList = new ArrayList<BeanDefinition>();
    List<BeanDefinition> consumerList = new ArrayList<BeanDefinition>();
    List<BeanDefinition> protocolList = new ArrayList<BeanDefinition>();
    List<BeanDefinition> registryList = new ArrayList<BeanDefinition>();

    Map<String, BeanDefinition> serviceMap = new HashMap<String, BeanDefinition>();
    Map<String, BeanDefinition> referenceMap = new HashMap<String, BeanDefinition>();

    Map<String, Class<?>> clazzMap = new HashMap<String, Class<?>>();
    Map<String, BeanDefinition> compensableMap = new HashMap<String, BeanDefinition>();

    String[] beanNameArray = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanNameArray.length; i++) {
        String beanName = beanNameArray[i];
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        String beanClassName = beanDef.getBeanClassName();

        Class<?> beanClass = null;
        try {/* www  .  j  a  va 2  s  . co m*/
            beanClass = cl.loadClass(beanClassName);
        } catch (Exception ex) {
            logger.warn("Cannot load class {}, beanId= {}!", beanClassName, beanName, ex);
            continue;
        }

        clazzMap.put(beanClassName, beanClass);

        if (beanClass.getAnnotation(Compensable.class) != null) {
            compensableMap.put(beanName, beanDef);
        }
    }

    for (int i = 0; i < beanNameArray.length; i++) {
        String beanName = beanNameArray[i];
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        String beanClassName = beanDef.getBeanClassName();

        Class<?> beanClass = clazzMap.get(beanClassName);

        if (com.alibaba.dubbo.config.ApplicationConfig.class.equals(beanClass)) {
            appNameList.add(beanDef);
        } else if (com.alibaba.dubbo.config.ProtocolConfig.class.equals(beanClass)) {
            protocolList.add(beanDef);
        } else if (com.alibaba.dubbo.config.RegistryConfig.class.equals(beanClass)) {
            registryList.add(beanDef);
        } else if (com.alibaba.dubbo.config.ProviderConfig.class.equals(beanClass)) {
            providerList.add(beanDef);
        } else if (com.alibaba.dubbo.config.ConsumerConfig.class.equals(beanClass)) {
            consumerList.add(beanDef);
        } else if (com.alibaba.dubbo.config.spring.ServiceBean.class.equals(beanClass)) {
            MutablePropertyValues mpv = beanDef.getPropertyValues();
            PropertyValue ref = mpv.getPropertyValue("ref");
            RuntimeBeanReference beanRef = (RuntimeBeanReference) ref.getValue();
            String refBeanName = beanRef.getBeanName();
            if (compensableMap.containsKey(refBeanName) == false) {
                continue;
            }

            serviceMap.put(beanName, beanDef);
        } else if (com.alibaba.dubbo.config.spring.ReferenceBean.class.equals(beanClass)) {
            MutablePropertyValues mpv = beanDef.getPropertyValues();
            PropertyValue group = mpv.getPropertyValue("group");
            if (group == null || group.getValue() == null
                    || "org.bytesoft.bytetcc".equals(group.getValue()) == false) {
                continue;
            }

            referenceMap.put(beanName, beanDef);
        }
    }

    Set<BeanDefinition> providerSet = new HashSet<BeanDefinition>();
    Set<BeanDefinition> protocolSet = new HashSet<BeanDefinition>();
    for (Iterator<Map.Entry<String, BeanDefinition>> itr = serviceMap.entrySet().iterator(); itr.hasNext();) {
        Map.Entry<String, BeanDefinition> entry = itr.next();
        BeanDefinition beanDef = entry.getValue();
        MutablePropertyValues mpv = beanDef.getPropertyValues();
        PropertyValue provider = mpv.getPropertyValue("provider");
        PropertyValue protocol = mpv.getPropertyValue("protocol");

        String providerValue = provider == null ? null : String.valueOf(provider.getValue());
        if (providerValue == null) {
            if (providerList.size() > 0) {
                providerSet.add(providerList.get(0));
            }
        } else if ("N/A".equals(providerValue) == false) {
            String[] keyArray = providerValue.split("\\s*,\\s*");
            for (int j = 0; j < keyArray.length; j++) {
                String key = keyArray[j];
                BeanDefinition def = beanFactory.getBeanDefinition(key);
                providerSet.add(def);
            }
        }

        String protocolValue = protocol == null ? null : String.valueOf(protocol.getValue());
        if (protocolValue == null) {
            if (protocolList.size() > 0) {
                protocolSet.add(protocolList.get(0));
            }
        } else if ("N/A".equals(protocolValue) == false) {
            String[] keyArray = protocolValue.split("\\s*,\\s*");
            for (int i = 0; i < keyArray.length; i++) {
                String key = keyArray[i];
                BeanDefinition def = beanFactory.getBeanDefinition(key);
                protocolSet.add(def);
            }
        }
    }

    ApplicationConfigValidator appConfigValidator = new ApplicationConfigValidator();
    appConfigValidator.setDefinitionList(appNameList);
    appConfigValidator.validate();

    if (protocolList.size() == 0) {
        throw new FatalBeanException("There is no protocol config specified!");
    }

    for (Iterator<BeanDefinition> itr = protocolSet.iterator(); itr.hasNext();) {
        BeanDefinition beanDef = itr.next();
        ProtocolConfigValidator validator = new ProtocolConfigValidator();
        validator.setBeanDefinition(beanDef);
        validator.validate();
    }

    for (Iterator<BeanDefinition> itr = providerSet.iterator(); itr.hasNext();) {
        BeanDefinition beanDef = itr.next();
        ProviderConfigValidator validator = new ProviderConfigValidator();
        validator.setBeanDefinition(beanDef);
        validator.validate();
    }

    for (Iterator<Map.Entry<String, BeanDefinition>> itr = serviceMap.entrySet().iterator(); itr.hasNext();) {
        Map.Entry<String, BeanDefinition> entry = itr.next();
        ServiceConfigValidator validator = new ServiceConfigValidator();
        validator.setBeanName(entry.getKey());
        validator.setBeanDefinition(entry.getValue());
        validator.validate(); // retries, loadbalance, cluster, filter, group
    }

    for (Iterator<Map.Entry<String, BeanDefinition>> itr = referenceMap.entrySet().iterator(); itr.hasNext();) {
        Map.Entry<String, BeanDefinition> entry = itr.next();
        ReferenceConfigValidator validator = new ReferenceConfigValidator();
        validator.setBeanName(entry.getKey());
        validator.setBeanDefinition(entry.getValue());
        validator.validate(); // retries, loadbalance, cluster, filter
    }
}

From source file:com.arondor.common.reflection.parser.spring.BeanPropertyParser.java

public ElementConfiguration parseProperty(Object value) {
    LOGGER.debug("value : " + value);
    if (value instanceof TypedStringValue) {
        TypedStringValue stringValue = (TypedStringValue) value;
        if (stringValue.getTargetTypeName() != null) {
            return getEnumObjectConfiguration(stringValue);
        } else {/*ww  w.jav  a  2  s  .  co  m*/
            PrimitiveConfiguration primitiveConfiguration = objectConfigurationFactory
                    .createPrimitiveConfiguration();
            if (useSPEL(stringValue)) {
                ExpressionParser parser = new SpelExpressionParser();
                String expAsStringWithToken = stringValue.getValue().trim();
                String expAsString = expAsStringWithToken.substring(2, expAsStringWithToken.length() - 1)
                        .trim();
                LOGGER.trace("This property is a SPEL expression: " + expAsString);

                // String regex = "systemProperties\\['([^\\s]+)'\\]";

                Expression exp = parser.parseExpression(expAsString);
                StandardEvaluationContext sec = null;
                if (sec == null) {
                    sec = new StandardEvaluationContext();
                    sec.addPropertyAccessor(new EnvironmentAccessor());
                    sec.addPropertyAccessor(new BeanExpressionContextAccessor());
                    sec.addPropertyAccessor(new BeanFactoryAccessor());
                    sec.addPropertyAccessor(new MapAccessor());
                }
                primitiveConfiguration.setValue(String.valueOf(exp.getValue()));
            } else {
                LOGGER.trace("This property is NOT a SPEL expression: " + stringValue.getValue());
                primitiveConfiguration.setValue(stringValue.getValue());
            }
            return primitiveConfiguration;
        }
    } else if (value instanceof RuntimeBeanReference) {
        RuntimeBeanReference beanReference = (RuntimeBeanReference) value;
        ReferenceConfiguration referenceConfiguration = objectConfigurationFactory
                .createReferenceConfiguration();
        referenceConfiguration.setReferenceName(beanReference.getBeanName());
        return referenceConfiguration;
    } else if (value instanceof ManagedList<?>) {
        return parseValueList((ManagedList<?>) value);
    } else if (value instanceof ManagedMap<?, ?>) {
        return parseValueMap((ManagedMap<?, ?>) value);
    } else if (value instanceof BeanDefinitionHolder) {
        BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) value;
        return parseBeanDefinition(beanDefinitionHolder.getBeanDefinition());
    } else {
        throw new UnsupportedOperationException("The type of property value is not suppported : " + value
                + " (class : " + value.getClass().getName() + ")");
    }
}

From source file:com.arondor.common.reflection.parser.spring.BeanPropertyParser.java

private ElementConfiguration parseBeanObject(Object item) {
    if (item instanceof TypedStringValue) {
        TypedStringValue stringValue = (TypedStringValue) item;
        ElementConfiguration primitiveConfiguration = objectConfigurationFactory
                .createPrimitiveConfiguration(stringValue.getValue());
        return primitiveConfiguration;
    } else if (item instanceof RuntimeBeanReference) {
        RuntimeBeanReference runtimeBeanReference = (RuntimeBeanReference) item;
        // return parseBeanDefinition(runtimeBeanReference.getBeanName());
        ReferenceConfiguration reference = objectConfigurationFactory.createReferenceConfiguration();
        reference.setReferenceName(runtimeBeanReference.getBeanName());
        return reference;
    } else if (item instanceof BeanDefinitionHolder) {
        BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) item;
        return parseBeanDefinition(beanDefinitionHolder.getBeanDefinition());
    } else {/*from   w ww  . j a v a 2s. c o  m*/
        throw new IllegalArgumentException("Not supported : item class " + item.getClass().getName());
    }

}

From source file:com.github.spring.mvc.util.handler.config.UriMatchingAnnotationDrivenBeanDefinitionParser.java

/**
 * Create {@link PointcutAdvisor} that puts the {@link Pointcut} and {@link MethodInterceptor} together.
 * @return Reference to the {@link PointcutAdvisor}. Should never be null.
 *///from w  w w  .  j a v a2  s  . c om
protected RuntimeBeanReference setupPointcutAdvisor(Element element, ParserContext parserContext,
        Object elementSource, RuntimeBeanReference pointcutReference,
        RuntimeBeanReference interceptorReference) {
    final RootBeanDefinition pointcutAdvisor = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class);
    pointcutAdvisor.setSource(elementSource);
    pointcutAdvisor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

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

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

From source file:org.drools.container.spring.namespace.KnowledgeSessionDefinitionParser.java

@SuppressWarnings("unchecked")
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {

    String id = element.getAttribute("id");
    emptyAttributeCheck(element.getLocalName(), "id", id);

    String kbase = element.getAttribute(KBASE_ATTRIBUTE);
    emptyAttributeCheck(element.getLocalName(), KBASE_ATTRIBUTE, kbase);

    String sessionType = element.getAttribute(TYPE_ATTRIBUTE);
    BeanDefinitionBuilder factory;/*from   w  w w.  j a va  2  s .  co  m*/

    if ("stateful".equals(sessionType)) {
        factory = BeanDefinitionBuilder.rootBeanDefinition(StatefulKnowledgeSessionBeanFactory.class);
    } else if ("stateless".equals(sessionType)) {
        factory = BeanDefinitionBuilder.rootBeanDefinition(StatelessKnowledgeSessionBeanFactory.class);
    } else {
        throw new IllegalArgumentException(
                "Invalid value for " + TYPE_ATTRIBUTE + " attribute: " + sessionType);
    }

    factory.addPropertyReference("kbase", kbase);

    String node = element.getAttribute(GRID_NODE_ATTRIBUTE);
    if (node != null && node.length() > 0) {
        factory.addPropertyReference("node", node);
    }

    String name = element.getAttribute(NAME_ATTRIBUTE);
    if (StringUtils.hasText(name)) {
        factory.addPropertyValue("name", name);
    } else {
        factory.addPropertyValue("name", id);
    }

    // Additions for JIRA JBRULES-3076
    String listeners = element.getAttribute(LISTENERS_ATTRIBUTE);
    if (StringUtils.hasText(listeners)) {
        factory.addPropertyValue("eventListenersFromGroup", new RuntimeBeanReference(listeners));
    }
    EventListenersUtil.parseEventListeners(parserContext, factory, element);
    // End of Additions for JIRA JBRULES-3076

    Element ksessionConf = DomUtils.getChildElementByTagName(element, "configuration");
    if (ksessionConf != null) {
        Element persistenceElm = DomUtils.getChildElementByTagName(ksessionConf, "jpa-persistence");
        if (persistenceElm != null) {
            BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder
                    .genericBeanDefinition(JpaConfiguration.class);

            String loadId = persistenceElm.getAttribute("load");
            if (StringUtils.hasText(loadId)) {
                beanBuilder.addPropertyValue("id", Long.parseLong(loadId));
            }

            Element tnxMng = DomUtils.getChildElementByTagName(persistenceElm, TX_MANAGER_ATTRIBUTE);
            String ref = tnxMng.getAttribute("ref");

            beanBuilder.addPropertyReference("platformTransactionManager", ref);

            Element emf = DomUtils.getChildElementByTagName(persistenceElm, EMF_ATTRIBUTE);
            ref = emf.getAttribute("ref");
            beanBuilder.addPropertyReference("entityManagerFactory", ref);

            Element variablePersisters = DomUtils.getChildElementByTagName(persistenceElm,
                    "variable-persisters");
            if (variablePersisters != null && variablePersisters.hasChildNodes()) {
                List<Element> childPersisterElems = DomUtils.getChildElementsByTagName(variablePersisters,
                        "persister");
                ManagedMap persistors = new ManagedMap(childPersisterElems.size());
                for (Element persisterElem : childPersisterElems) {
                    String forClass = persisterElem.getAttribute(FORCLASS_ATTRIBUTE);
                    String implementation = persisterElem.getAttribute(IMPLEMENTATION_ATTRIBUTE);
                    if (!StringUtils.hasText(forClass)) {
                        throw new RuntimeException("persister element must have valid for-class attribute");
                    }
                    if (!StringUtils.hasText(implementation)) {
                        throw new RuntimeException(
                                "persister element must have valid implementation attribute");
                    }
                    persistors.put(forClass, implementation);
                }
                beanBuilder.addPropertyValue("variablePersisters", persistors);
            }

            factory.addPropertyValue("jpaConfiguration", beanBuilder.getBeanDefinition());
        }
        BeanDefinitionBuilder rbaseConfBuilder = BeanDefinitionBuilder
                .rootBeanDefinition(SessionConfiguration.class);
        Element e = DomUtils.getChildElementByTagName(ksessionConf, KEEP_REFERENCE);
        if (e != null && StringUtils.hasText(e.getAttribute("enabled"))) {
            rbaseConfBuilder.addPropertyValue("keepReference", Boolean.parseBoolean(e.getAttribute("enabled")));
        }

        e = DomUtils.getChildElementByTagName(ksessionConf, CLOCK_TYPE);
        if (e != null && StringUtils.hasText(e.getAttribute("type"))) {
            rbaseConfBuilder.addPropertyValue("clockType", ClockType.resolveClockType(e.getAttribute("type")));
        }
        factory.addPropertyValue("conf", rbaseConfBuilder.getBeanDefinition());

        e = DomUtils.getChildElementByTagName(ksessionConf, WORK_ITEMS);
        if (e != null) {
            List<Element> children = DomUtils.getChildElementsByTagName(e, WORK_ITEM);
            if (children != null && !children.isEmpty()) {
                ManagedMap workDefs = new ManagedMap();
                for (Element child : children) {
                    workDefs.put(child.getAttribute("name"),
                            new RuntimeBeanReference(child.getAttribute("ref")));
                }
                factory.addPropertyValue("workItems", workDefs);
            }
        }
    }

    Element batch = DomUtils.getChildElementByTagName(element, "batch");
    if (batch == null) {
        // just temporary legacy suppport
        batch = DomUtils.getChildElementByTagName(element, "script");
    }
    if (batch != null) {
        // we know there can only ever be one
        ManagedList children = new ManagedList();

        for (int i = 0, length = batch.getChildNodes().getLength(); i < length; i++) {
            Node n = batch.getChildNodes().item(i);
            if (n instanceof Element) {
                Element e = (Element) n;

                BeanDefinitionBuilder beanBuilder = null;
                if ("insert-object".equals(e.getLocalName())) {
                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(InsertObjectCommand.class);
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "insert-object must either specify a 'ref' attribute or have a nested bean");
                    }
                } else if ("set-global".equals(e.getLocalName())) {
                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SetGlobalCommand.class);
                    beanBuilder.addConstructorArgValue(e.getAttribute("identifier"));
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "set-global must either specify a 'ref' attribute or have a nested bean");
                    }
                } else if ("fire-until-halt".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireUntilHaltCommand.class);
                } else if ("fire-all-rules".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireAllRulesCommand.class);
                    String max = e.getAttribute("max");
                    if (StringUtils.hasText(max)) {
                        beanBuilder.addPropertyValue("max", max);
                    }
                } else if ("start-process".equals(e.getLocalName())) {

                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(StartProcessCommand.class);
                    String processId = e.getAttribute("process-id");
                    if (!StringUtils.hasText(processId)) {
                        throw new IllegalArgumentException("start-process must specify a process-id");
                    }
                    beanBuilder.addConstructorArgValue(processId);

                    List<Element> params = DomUtils.getChildElementsByTagName(e, "parameter");
                    if (!params.isEmpty()) {
                        ManagedMap map = new ManagedMap();
                        for (Element param : params) {
                            String identifier = param.getAttribute("identifier");
                            if (!StringUtils.hasText(identifier)) {
                                throw new IllegalArgumentException(
                                        "start-process paramaters must specify an identifier");
                            }

                            String ref = param.getAttribute("ref");
                            Element nestedElm = getFirstElement(param.getChildNodes());
                            if (StringUtils.hasText(ref)) {
                                map.put(identifier, new RuntimeBeanReference(ref));
                            } else if (nestedElm != null) {
                                map.put(identifier, parserContext.getDelegate()
                                        .parsePropertySubElement(nestedElm, null, null));
                            } else {
                                throw new IllegalArgumentException(
                                        "start-process parameters must either specify a 'ref' attribute or have a nested bean");
                            }
                        }
                        beanBuilder.addPropertyValue("parameters", map);
                    }
                } else if ("signal-event".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SignalEventCommand.class);
                    String processInstanceId = e.getAttribute("process-instance-id");
                    if (StringUtils.hasText(processInstanceId)) {
                        beanBuilder.addConstructorArgValue(processInstanceId);
                    }

                    beanBuilder.addConstructorArgValue(e.getAttribute("event-type"));

                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "signal-event must either specify a 'ref' attribute or have a nested bean");
                    }
                }
                if (beanBuilder == null) {
                    throw new IllegalStateException("Unknow element: " + e.getLocalName());
                }
                children.add(beanBuilder.getBeanDefinition());
            }
        }
        factory.addPropertyValue("batch", children);
    }

    // find any kagent's for the current kbase and assign (only if this 
    // is a stateless session)
    if (sessionType.equals("stateless")) {
        for (String beanName : parserContext.getRegistry().getBeanDefinitionNames()) {
            BeanDefinition def = parserContext.getRegistry().getBeanDefinition(beanName);
            if (KnowledgeAgentBeanFactory.class.getName().equals(def.getBeanClassName())) {
                PropertyValue pvalue = def.getPropertyValues().getPropertyValue("kbase");
                RuntimeBeanReference tbf = (RuntimeBeanReference) pvalue.getValue();
                if (kbase.equals(tbf.getBeanName())) {
                    factory.addPropertyValue("knowledgeAgent", new RuntimeBeanReference(beanName));
                }
            }
        }
    }

    return factory.getBeanDefinition();
}

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

protected String parseCustom(ParserContext context, Element element, BeanDefinition containingBean) {
    String name = getName(context, element);
    String ref = element.getAttribute(REF_ATTR);

    String customBeanId = null;//from  w w  w  .jav a2  s  .  co m
    if (StringUtils.hasLength(ref)) {
        customBeanId = ref;
    } else {
        // Grab the single child element, that should define or point
        // to the custom Accumulator or Calcuation bean definition.
        NodeList childList = element.getChildNodes();
        Element child = null;
        for (int i = 0; i < childList.getLength(); i++) {
            Node childNode = childList.item(i);
            if (!(childNode instanceof Element)) {
                continue;
            }

            if (child != null) {
                context.getReaderContext()
                        .error("'custom' elements without a 'ref' attribute must "
                                + "have exactly one 'bean', 'ref', or 'idref' child" + " element.",
                                context.extractSource(element));
            }
            child = (Element) childNode;
        }

        if (child == null) {
            context.getReaderContext()
                    .error("'custom' elements must specify a 'ref' attribute or a "
                            + "single 'bean', 'ref', or 'idref' child element.",
                            context.extractSource(element));
        }

        // Parse the contents of the custom bean
        Object o = context.getDelegate().parsePropertySubElement(child, containingBean);

        if (o instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder bdh = (BeanDefinitionHolder) o;
            customBeanId = bdh.getBeanName();
            if (!StringUtils.hasLength(customBeanId)) {
                // They didn't give their bean an id, so we'll need to
                // generate one for it now.
                customBeanId = context.getReaderContext().generateBeanName(bdh.getBeanDefinition());
            }

            // Register this bean
            context.getRegistry().registerBeanDefinition(customBeanId, bdh.getBeanDefinition());
        } else if (o instanceof RuntimeBeanReference) {
            RuntimeBeanReference rbr = (RuntimeBeanReference) o;
            customBeanId = rbr.getBeanName();
        } else if (o instanceof RuntimeBeanNameReference) {
            RuntimeBeanNameReference rbnr = (RuntimeBeanNameReference) o;
            customBeanId = rbnr.getBeanName();
        }
    }

    // Create proxy that associates the given name with this child
    BeanDefinitionBuilder accProxyBdb = getBdb(RegistryNodeChildProxy.class);
    accProxyBdb.addPropertyValue(NAME_ATTR, name);
    accProxyBdb.addPropertyValue(CHILD_ATTR, customBeanId);
    accProxyBdb.getRawBeanDefinition().setSource(element);

    return context.getReaderContext().registerWithGeneratedName(accProxyBdb.getBeanDefinition());
}

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  av a  2 s . c om

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

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

/**
 * Create {@link PointcutAdvisor} that puts the {@link Pointcut} and {@link MethodInterceptor} together.
 * /*w  ww.  java 2  s .c  o  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:org.jsr107.ri.annotations.spring.config.AnnotationDrivenJCacheBeanDefinitionParser.java

/**
 * Create {@link org.springframework.aop.PointcutAdvisor} that puts the
 * {@link org.springframework.aop.Pointcut} and {@link AbstractCacheInterceptor} together.
 *///from ww  w . ja v  a2s.  c  o m
protected void setupPointcutAdvisor(Class<? extends AbstractCacheInterceptor<?>> interceptorClass,
        Element element, ParserContext parserContext, Object elementSource,
        RuntimeBeanReference cacheOperationSourceReference) {

    final RuntimeBeanReference interceptorReference = this.setupInterceptor(interceptorClass, parserContext,
            elementSource, cacheOperationSourceReference);

    final RuntimeBeanReference pointcutReference = this.setupPointcut(parserContext, elementSource,
            cacheOperationSourceReference, interceptorReference);

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

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

    final XmlReaderContext readerContext = parserContext.getReaderContext();
    readerContext.registerWithGeneratedName(pointcutAdvisor);
}

From source file:org.jsr107.ri.annotations.spring.config.AnnotationDrivenJCacheBeanDefinitionParser.java

/**
 * Create the {@link RuntimeBeanReference} used to apply the caching interceptor
 *
 * @return Reference to the {@link RuntimeBeanReference}. Should never be null.
 *//*from   w w w .ja v a 2s . c  o m*/
protected RuntimeBeanReference setupPointcut(ParserContext parserContext, Object elementSource,
        RuntimeBeanReference cacheOperationSourceRuntimeReference,
        RuntimeBeanReference cacheInterceptorSourceRuntimeReference) {

    final RootBeanDefinition pointcut = new RootBeanDefinition(CacheStaticMethodMatcherPointcut.class);
    pointcut.setSource(elementSource);
    pointcut.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

    final ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
    constructorArgumentValues.addIndexedArgumentValue(0, cacheOperationSourceRuntimeReference);
    constructorArgumentValues.addIndexedArgumentValue(1, cacheInterceptorSourceRuntimeReference);
    pointcut.setConstructorArgumentValues(constructorArgumentValues);

    final String pointcutBeanName = pointcut.getBeanClassName() + "_"
            + cacheInterceptorSourceRuntimeReference.getBeanName();

    final BeanDefinitionRegistry registry = parserContext.getRegistry();
    registry.registerBeanDefinition(pointcutBeanName, pointcut);

    return new RuntimeBeanReference(pointcutBeanName);
}