Search in sources :

Example 66 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-framework by spring-projects.

the class SpringConfiguredBeanDefinitionParser method parse.

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    if (!parserContext.getRegistry().containsBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME)) {
        RootBeanDefinition def = new RootBeanDefinition();
        def.setBeanClassName(BEAN_CONFIGURER_ASPECT_CLASS_NAME);
        def.setFactoryMethodName("aspectOf");
        def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        def.setSource(parserContext.extractSource(element));
        parserContext.registerBeanComponent(new BeanComponentDefinition(def, BEAN_CONFIGURER_ASPECT_BEAN_NAME));
    }
    return null;
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Example 67 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-framework by spring-projects.

the class AopNamespaceHandlerEventTests method testAdvisorEventsWithDirectPointcut.

@Test
public void testAdvisorEventsWithDirectPointcut() throws Exception {
    this.reader.loadBeanDefinitions(DIRECT_POINTCUT_EVENTS_CONTEXT);
    ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
    assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
    assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
    CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
    assertEquals("aop:config", compositeDef.getName());
    ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
    assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
    AdvisorComponentDefinition acd = null;
    for (int i = 0; i < nestedComponentDefs.length; i++) {
        ComponentDefinition componentDefinition = nestedComponentDefs[i];
        if (componentDefinition instanceof AdvisorComponentDefinition) {
            acd = (AdvisorComponentDefinition) componentDefinition;
            break;
        }
    }
    assertNotNull("AdvisorComponentDefinition not found", acd);
    assertEquals(2, acd.getBeanDefinitions().length);
    assertEquals(1, acd.getBeanReferences().length);
    assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition);
    BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
    assertEquals("countingAdvice", adviceDef.getBeanName());
}
Also used : CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) ComponentDefinition(org.springframework.beans.factory.parsing.ComponentDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) Test(org.junit.Test)

Example 68 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-framework by spring-projects.

the class EventPublicationTests method beanEventReceived.

@Test
public void beanEventReceived() throws Exception {
    ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean");
    assertTrue(componentDefinition1 instanceof BeanComponentDefinition);
    assertEquals(1, componentDefinition1.getBeanDefinitions().length);
    BeanDefinition beanDefinition1 = componentDefinition1.getBeanDefinitions()[0];
    assertEquals(new TypedStringValue("Rob Harrop"), beanDefinition1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
    assertEquals(1, componentDefinition1.getBeanReferences().length);
    assertEquals("testBean2", componentDefinition1.getBeanReferences()[0].getBeanName());
    assertEquals(1, componentDefinition1.getInnerBeanDefinitions().length);
    BeanDefinition innerBd1 = componentDefinition1.getInnerBeanDefinitions()[0];
    assertEquals(new TypedStringValue("ACME"), innerBd1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
    assertTrue(componentDefinition1.getSource() instanceof Element);
    ComponentDefinition componentDefinition2 = this.eventListener.getComponentDefinition("testBean2");
    assertTrue(componentDefinition2 instanceof BeanComponentDefinition);
    assertEquals(1, componentDefinition1.getBeanDefinitions().length);
    BeanDefinition beanDefinition2 = componentDefinition2.getBeanDefinitions()[0];
    assertEquals(new TypedStringValue("Juergen Hoeller"), beanDefinition2.getPropertyValues().getPropertyValue("name").getValue());
    assertEquals(0, componentDefinition2.getBeanReferences().length);
    assertEquals(1, componentDefinition2.getInnerBeanDefinitions().length);
    BeanDefinition innerBd2 = componentDefinition2.getInnerBeanDefinitions()[0];
    assertEquals(new TypedStringValue("Eva Schallmeiner"), innerBd2.getPropertyValues().getPropertyValue("name").getValue());
    assertTrue(componentDefinition2.getSource() instanceof Element);
}
Also used : Element(org.w3c.dom.Element) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) TypedStringValue(org.springframework.beans.factory.config.TypedStringValue) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ComponentDefinition(org.springframework.beans.factory.parsing.ComponentDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) Test(org.junit.Test)

Example 69 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-framework by spring-projects.

the class AbstractBeanDefinitionParser method parse.

@Override
public final BeanDefinition parse(Element element, ParserContext parserContext) {
    AbstractBeanDefinition definition = parseInternal(element, parserContext);
    if (definition != null && !parserContext.isNested()) {
        try {
            String id = resolveId(element, definition, parserContext);
            if (!StringUtils.hasText(id)) {
                parserContext.getReaderContext().error("Id is required for element '" + parserContext.getDelegate().getLocalName(element) + "' when used as a top-level tag", element);
            }
            String[] aliases = null;
            if (shouldParseNameAsAliases()) {
                String name = element.getAttribute(NAME_ATTRIBUTE);
                if (StringUtils.hasLength(name)) {
                    aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
                }
            }
            BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
            registerBeanDefinition(holder, parserContext.getRegistry());
            if (shouldFireEvents()) {
                BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
                postProcessComponentDefinition(componentDefinition);
                parserContext.registerComponent(componentDefinition);
            }
        } catch (BeanDefinitionStoreException ex) {
            parserContext.getReaderContext().error(ex.getMessage(), element);
            return null;
        }
    }
    return definition;
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Example 70 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-security by spring-projects.

the class GlobalMethodSecurityBeanDefinitionParser method registerAccessManager.

/**
	 * Register the default AccessDecisionManager. Adds the special JSR 250 voter jsr-250
	 * is enabled and an expression voter if expression-based access control is enabled.
	 * @return
	 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private String registerAccessManager(ParserContext pc, boolean jsr250Enabled, BeanDefinition expressionVoter) {
    BeanDefinitionBuilder accessMgrBuilder = BeanDefinitionBuilder.rootBeanDefinition(AffirmativeBased.class);
    ManagedList voters = new ManagedList(4);
    if (expressionVoter != null) {
        voters.add(expressionVoter);
    }
    voters.add(new RootBeanDefinition(RoleVoter.class));
    voters.add(new RootBeanDefinition(AuthenticatedVoter.class));
    if (jsr250Enabled) {
        voters.add(new RootBeanDefinition(Jsr250Voter.class));
    }
    accessMgrBuilder.addConstructorArgValue(voters);
    BeanDefinition accessManager = accessMgrBuilder.getBeanDefinition();
    String id = pc.getReaderContext().generateBeanName(accessManager);
    pc.registerBeanComponent(new BeanComponentDefinition(accessManager, id));
    return id;
}
Also used : AuthenticatedVoter(org.springframework.security.access.vote.AuthenticatedVoter) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) Jsr250Voter(org.springframework.security.access.annotation.Jsr250Voter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ManagedList(org.springframework.beans.factory.support.ManagedList) RoleVoter(org.springframework.security.access.vote.RoleVoter) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)82 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)53 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)33 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)28 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)24 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)17 Element (org.w3c.dom.Element)16 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)11 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)11 ManagedList (org.springframework.beans.factory.support.ManagedList)10 Test (org.junit.Test)7 ComponentDefinition (org.springframework.beans.factory.parsing.ComponentDefinition)7 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)6 ManagedMap (org.springframework.beans.factory.support.ManagedMap)4 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)3 BeanComponentDefinitionBuilder (org.springframework.data.config.BeanComponentDefinitionBuilder)3 Method (java.lang.reflect.Method)2 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)2 PropertyValue (org.springframework.beans.PropertyValue)2 BeanReference (org.springframework.beans.factory.config.BeanReference)2