org.springframework.beans.factory.config.BeanReference Java Examples

The following examples show how to use org.springframework.beans.factory.config.BeanReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanComponentDefinition.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) {
	List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>();
	List<BeanReference> references = new ArrayList<BeanReference>();
	PropertyValues propertyValues = beanDefinition.getPropertyValues();
	for (PropertyValue propertyValue : propertyValues.getPropertyValues()) {
		Object value = propertyValue.getValue();
		if (value instanceof BeanDefinitionHolder) {
			innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
		}
		else if (value instanceof BeanDefinition) {
			innerBeans.add((BeanDefinition) value);
		}
		else if (value instanceof BeanReference) {
			references.add((BeanReference) value);
		}
	}
	this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]);
	this.beanReferences = references.toArray(new BeanReference[references.size()]);
}
 
Example #2
Source File: AdvisorComponentDefinition.java    From spring-analysis-note with MIT License 6 votes vote down vote up
public AdvisorComponentDefinition(
		String advisorBeanName, BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) {

	Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null");
	Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null");
	this.advisorBeanName = advisorBeanName;
	this.advisorDefinition = advisorDefinition;

	MutablePropertyValues pvs = advisorDefinition.getPropertyValues();
	BeanReference adviceReference = (BeanReference) pvs.get("adviceBeanName");
	Assert.state(adviceReference != null, "Missing 'adviceBeanName' property");

	if (pointcutDefinition != null) {
		this.beanReferences = new BeanReference[] {adviceReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition};
		this.description = buildDescription(adviceReference, pointcutDefinition);
	}
	else {
		BeanReference pointcutReference = (BeanReference) pvs.get("pointcut");
		Assert.state(pointcutReference != null, "Missing 'pointcut' property");
		this.beanReferences = new BeanReference[] {adviceReference, pointcutReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition};
		this.description = buildDescription(adviceReference, pointcutReference);
	}
}
 
Example #3
Source File: BeanComponentDefinition.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) {
	List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>();
	List<BeanReference> references = new ArrayList<BeanReference>();
	PropertyValues propertyValues = beanDefinition.getPropertyValues();
	for (int i = 0; i < propertyValues.getPropertyValues().length; i++) {
		PropertyValue propertyValue = propertyValues.getPropertyValues()[i];
		Object value = propertyValue.getValue();
		if (value instanceof BeanDefinitionHolder) {
			innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
		}
		else if (value instanceof BeanDefinition) {
			innerBeans.add((BeanDefinition) value);
		}
		else if (value instanceof BeanReference) {
			references.add((BeanReference) value);
		}
	}
	this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]);
	this.beanReferences = references.toArray(new BeanReference[references.size()]);
}
 
Example #4
Source File: AdvisorComponentDefinition.java    From java-technology-stack with MIT License 6 votes vote down vote up
public AdvisorComponentDefinition(
		String advisorBeanName, BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) {

	Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null");
	Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null");
	this.advisorBeanName = advisorBeanName;
	this.advisorDefinition = advisorDefinition;

	MutablePropertyValues pvs = advisorDefinition.getPropertyValues();
	BeanReference adviceReference = (BeanReference) pvs.get("adviceBeanName");
	Assert.state(adviceReference != null, "Missing 'adviceBeanName' property");

	if (pointcutDefinition != null) {
		this.beanReferences = new BeanReference[] {adviceReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition};
		this.description = buildDescription(adviceReference, pointcutDefinition);
	}
	else {
		BeanReference pointcutReference = (BeanReference) pvs.get("pointcut");
		Assert.state(pointcutReference != null, "Missing 'pointcut' property");
		this.beanReferences = new BeanReference[] {adviceReference, pointcutReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition};
		this.description = buildDescription(adviceReference, pointcutReference);
	}
}
 
Example #5
Source File: BeanComponentDefinition.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private void findInnerBeanDefinitionsAndBeanReferences(BeanDefinition beanDefinition) {
	List<BeanDefinition> innerBeans = new ArrayList<BeanDefinition>();
	List<BeanReference> references = new ArrayList<BeanReference>();
	PropertyValues propertyValues = beanDefinition.getPropertyValues();
	for (int i = 0; i < propertyValues.getPropertyValues().length; i++) {
		PropertyValue propertyValue = propertyValues.getPropertyValues()[i];
		Object value = propertyValue.getValue();
		if (value instanceof BeanDefinitionHolder) {
			innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
		}
		else if (value instanceof BeanDefinition) {
			innerBeans.add((BeanDefinition) value);
		}
		else if (value instanceof BeanReference) {
			references.add((BeanReference) value);
		}
	}
	this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]);
	this.beanReferences = references.toArray(new BeanReference[references.size()]);
}
 
Example #6
Source File: AdvisorComponentDefinition.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void unwrapDefinitions(BeanDefinition advisorDefinition, BeanDefinition pointcutDefinition) {
	MutablePropertyValues pvs = advisorDefinition.getPropertyValues();
	BeanReference adviceReference = (BeanReference) pvs.getPropertyValue("adviceBeanName").getValue();

	if (pointcutDefinition != null) {
		this.beanReferences = new BeanReference[] {adviceReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition};
		this.description = buildDescription(adviceReference, pointcutDefinition);
	}
	else {
		BeanReference pointcutReference = (BeanReference) pvs.getPropertyValue("pointcut").getValue();
		this.beanReferences = new BeanReference[] {adviceReference, pointcutReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition};
		this.description = buildDescription(adviceReference, pointcutReference);
	}
}
 
Example #7
Source File: BeanComponentDefinition.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Create a new BeanComponentDefinition for the given bean.
 * @param beanDefinitionHolder the BeanDefinitionHolder encapsulating
 * the bean definition as well as the name of the bean
 */
public BeanComponentDefinition(BeanDefinitionHolder beanDefinitionHolder) {
	super(beanDefinitionHolder);

	List<BeanDefinition> innerBeans = new ArrayList<>();
	List<BeanReference> references = new ArrayList<>();
	PropertyValues propertyValues = beanDefinitionHolder.getBeanDefinition().getPropertyValues();
	for (PropertyValue propertyValue : propertyValues.getPropertyValues()) {
		Object value = propertyValue.getValue();
		if (value instanceof BeanDefinitionHolder) {
			innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
		}
		else if (value instanceof BeanDefinition) {
			innerBeans.add((BeanDefinition) value);
		}
		else if (value instanceof BeanReference) {
			references.add((BeanReference) value);
		}
	}
	this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[0]);
	this.beanReferences = references.toArray(new BeanReference[0]);
}
 
Example #8
Source File: BeanComponentDefinition.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Create a new BeanComponentDefinition for the given bean.
 * @param beanDefinitionHolder the BeanDefinitionHolder encapsulating
 * the bean definition as well as the name of the bean
 */
public BeanComponentDefinition(BeanDefinitionHolder beanDefinitionHolder) {
	super(beanDefinitionHolder);

	List<BeanDefinition> innerBeans = new ArrayList<>();
	List<BeanReference> references = new ArrayList<>();
	PropertyValues propertyValues = beanDefinitionHolder.getBeanDefinition().getPropertyValues();
	for (PropertyValue propertyValue : propertyValues.getPropertyValues()) {
		Object value = propertyValue.getValue();
		if (value instanceof BeanDefinitionHolder) {
			innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
		}
		else if (value instanceof BeanDefinition) {
			innerBeans.add((BeanDefinition) value);
		}
		else if (value instanceof BeanReference) {
			references.add((BeanReference) value);
		}
	}
	this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[0]);
	this.beanReferences = references.toArray(new BeanReference[0]);
}
 
Example #9
Source File: DefaultRiptideRegistrar.java    From riptide with MIT License 6 votes vote down vote up
private List<BeanReference> registerPlugins(final String id, final Client client) {
    final Stream<Optional<String>> plugins = Stream.of(
            registerChaosPlugin(id, client),
            registerMicrometerPlugin(id, client),
            registerRequestCompressionPlugin(id, client),
            registerLogbookPlugin(id, client),
            registerOpenTracingPlugin(id, client),
            registerCircuitBreakerFailsafePlugin(id, client),
            registerRetryPolicyFailsafePlugin(id, client),
            registerAuthorizationPlugin(id, client),
            registerBackupRequestFailsafePlugin(id, client),
            registerTimeoutFailsafePlugin(id, client),
            registerOriginalStackTracePlugin(id, client),
            registerCustomPlugin(id));

    return plugins
            .filter(Optional::isPresent)
            .map(Optional::get)
            .map(Registry::ref)
            .collect(toCollection(Registry::list));
}
 
Example #10
Source File: AdvisorComponentDefinition.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private void unwrapDefinitions(BeanDefinition advisorDefinition, BeanDefinition pointcutDefinition) {
	MutablePropertyValues pvs = advisorDefinition.getPropertyValues();
	BeanReference adviceReference = (BeanReference) pvs.getPropertyValue("adviceBeanName").getValue();

	if (pointcutDefinition != null) {
		this.beanReferences = new BeanReference[] {adviceReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition};
		this.description = buildDescription(adviceReference, pointcutDefinition);
	}
	else {
		BeanReference pointcutReference = (BeanReference) pvs.getPropertyValue("pointcut").getValue();
		this.beanReferences = new BeanReference[] {adviceReference, pointcutReference};
		this.beanDefinitions = new BeanDefinition[] {advisorDefinition};
		this.description = buildDescription(adviceReference, pointcutReference);
	}
}
 
Example #11
Source File: ConfigBeanDefinitionParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private AspectComponentDefinition createAspectComponentDefinition(
		Element aspectElement, String aspectId, List<BeanDefinition> beanDefs,
		List<BeanReference> beanRefs, ParserContext parserContext) {

	BeanDefinition[] beanDefArray = beanDefs.toArray(new BeanDefinition[0]);
	BeanReference[] beanRefArray = beanRefs.toArray(new BeanReference[0]);
	Object source = parserContext.extractSource(aspectElement);
	return new AspectComponentDefinition(aspectId, beanDefArray, beanRefArray, source);
}
 
Example #12
Source File: AspectComponentDefinition.java    From java-technology-stack with MIT License 5 votes vote down vote up
public AspectComponentDefinition(String aspectName, @Nullable BeanDefinition[] beanDefinitions,
		@Nullable BeanReference[] beanReferences, @Nullable Object source) {

	super(aspectName, source);
	this.beanDefinitions = (beanDefinitions != null ? beanDefinitions : new BeanDefinition[0]);
	this.beanReferences = (beanReferences != null ? beanReferences : new BeanReference[0]);
}
 
Example #13
Source File: AspectComponentDefinition.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public AspectComponentDefinition(
		String aspectName, BeanDefinition[] beanDefinitions, BeanReference[] beanReferences, Object source) {

	super(aspectName, source);
	this.beanDefinitions = (beanDefinitions != null ? beanDefinitions : new BeanDefinition[0]);
	this.beanReferences = (beanReferences != null ? beanReferences : new BeanReference[0]);
}
 
Example #14
Source File: ConfigBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private AspectComponentDefinition createAspectComponentDefinition(
		Element aspectElement, String aspectId, List<BeanDefinition> beanDefs,
		List<BeanReference> beanRefs, ParserContext parserContext) {

	BeanDefinition[] beanDefArray = beanDefs.toArray(new BeanDefinition[beanDefs.size()]);
	BeanReference[] beanRefArray = beanRefs.toArray(new BeanReference[beanRefs.size()]);
	Object source = parserContext.extractSource(aspectElement);
	return new AspectComponentDefinition(aspectId, beanDefArray, beanRefArray, source);
}
 
Example #15
Source File: ConfigBeanDefinitionParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private AspectComponentDefinition createAspectComponentDefinition(
		Element aspectElement, String aspectId, List<BeanDefinition> beanDefs,
		List<BeanReference> beanRefs, ParserContext parserContext) {

	BeanDefinition[] beanDefArray = beanDefs.toArray(new BeanDefinition[beanDefs.size()]);
	BeanReference[] beanRefArray = beanRefs.toArray(new BeanReference[beanRefs.size()]);
	Object source = parserContext.extractSource(aspectElement);
	return new AspectComponentDefinition(aspectId, beanDefArray, beanRefArray, source);
}
 
Example #16
Source File: ConfigBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private AspectComponentDefinition createAspectComponentDefinition(
		Element aspectElement, String aspectId, List<BeanDefinition> beanDefs,
		List<BeanReference> beanRefs, ParserContext parserContext) {

	BeanDefinition[] beanDefArray = beanDefs.toArray(new BeanDefinition[0]);
	BeanReference[] beanRefArray = beanRefs.toArray(new BeanReference[0]);
	Object source = parserContext.extractSource(aspectElement);
	return new AspectComponentDefinition(aspectId, beanDefArray, beanRefArray, source);
}
 
Example #17
Source File: DefaultRiptideRegistrar.java    From riptide with MIT License 5 votes vote down vote up
private Optional<BeanReference> findCacheStorageReference(final String id, final Client client) {
    if (client.getCaching().getEnabled()) {
        return registry.findRef(id, HttpCacheStorage.class);
    } else {
        return Optional.empty();
    }
}
 
Example #18
Source File: DefaultRiptideConfigurerTest.java    From riptide with MIT License 5 votes vote down vote up
@Test
void shouldFindPrimaryBeanDefinitionIfAvailable() {
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(PrimaryTracerConfiguration.class);
    context.refresh();
    final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    final DefaultRiptideConfigurer configurer = new DefaultRiptideConfigurer(beanFactory, null);
    final BeanReference bd = configurer.getBeanRef(Tracer.class, "tracer");
    assertThat(bd.getBeanName()).isEqualTo("primaryTracer");
}
 
Example #19
Source File: AspectComponentDefinition.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public AspectComponentDefinition(String aspectName, @Nullable BeanDefinition[] beanDefinitions,
		@Nullable BeanReference[] beanReferences, @Nullable Object source) {

	super(aspectName, source);
	this.beanDefinitions = (beanDefinitions != null ? beanDefinitions : new BeanDefinition[0]);
	this.beanReferences = (beanReferences != null ? beanReferences : new BeanReference[0]);
}
 
Example #20
Source File: DefaultRiptideConfigurerTest.java    From riptide with MIT License 5 votes vote down vote up
@Test
void shouldBeanDefinitionIfSingleBeanRegisteredForType() {
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(SingleTracerConfiguration.class);
    context.refresh();
    final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    final DefaultRiptideConfigurer configurer = new DefaultRiptideConfigurer(beanFactory, null);
    final BeanReference bd = configurer.getBeanRef(Tracer.class, "tracer");
    assertThat(bd.getBeanName()).isEqualTo("opentracingTracer");
}
 
Example #21
Source File: DefaultRiptideConfigurerTest.java    From riptide with MIT License 5 votes vote down vote up
@Test
void shouldFindBeanDefinitionByNameIfNoPrimaryBeanAvailable() {
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(DoubleTracerConfiguration.class);
    context.refresh();
    final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    final DefaultRiptideConfigurer configurer = new DefaultRiptideConfigurer(beanFactory, null);
    final BeanReference bd = configurer.getBeanRef(Tracer.class, "tracer");
    assertThat(bd.getBeanName()).isEqualTo("tracer");
}
 
Example #22
Source File: MongoPersister.java    From statefulj with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeanDefinitionRegistry(
		BeanDefinitionRegistry registry) throws BeansException {

	if (this.mongoTemplate == null) {

		if (this.repoId != null) {

			// Fetch the MongoTemplate Bean Id
			//
			BeanDefinition repo = registry.getBeanDefinition(this.repoId);
			this.templateId = ((BeanReference)repo.getPropertyValues().get("mongoOperations")).getBeanName();
		}

		// Check to make sure we have a reference to the MongoTemplate
		//
		if (this.templateId == null) {
			throw new RuntimeException("Unable to obtain a reference to a MongoTemplate");
		}
	}


	// Add in CascadeSupport
	//
	BeanDefinition mongoCascadeSupportBean = BeanDefinitionBuilder
			.genericBeanDefinition(MongoCascadeSupport.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = mongoCascadeSupportBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, this);
	registry.registerBeanDefinition(Long.toString((new Random()).nextLong()), mongoCascadeSupportBean);
}
 
Example #23
Source File: AspectComponentDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public AspectComponentDefinition(
		String aspectName, BeanDefinition[] beanDefinitions, BeanReference[] beanReferences, Object source) {

	super(aspectName, source);
	this.beanDefinitions = (beanDefinitions != null ? beanDefinitions : new BeanDefinition[0]);
	this.beanReferences = (beanReferences != null ? beanReferences : new BeanReference[0]);
}
 
Example #24
Source File: AdvisorComponentDefinition.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanReference[] getBeanReferences() {
	return this.beanReferences;
}
 
Example #25
Source File: ConfigBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * 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
 */
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();
	}
}
 
Example #26
Source File: AbstractComponentDefinition.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an empty array.
 */
@Override
public BeanReference[] getBeanReferences() {
	return new BeanReference[0];
}
 
Example #27
Source File: ServiceBeanDefinitionParser.java    From jdal with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public AbstractBeanDefinition parse(Element element, ParserContext parserContext) {
	
	// default dao and service classes
	String daoClassName = JPA_DAO_CLASS_NAME;
	String serviceClassName = PERSISTENT_SERVICE_CLASS_NAME;
	String name = null;
	boolean declareService = false;
	
	if (element.hasAttribute(DAO_CLASS)) 
		daoClassName = element.getAttribute(DAO_CLASS);
	
	if (element.hasAttribute(SERVICE_CLASS)) {
		serviceClassName = element.getAttribute(SERVICE_CLASS);
		declareService = true;
	}
	
	if (element.hasAttribute(NAME))
		name = element.getAttribute(NAME);
		
	if (element.hasAttribute(ENTITY)) {
		String className = element.getAttribute(ENTITY);
		if (name == null) {
			name = StringUtils.uncapitalize(
				StringUtils.substringAfterLast(className, PropertyUtils.PROPERTY_SEPARATOR));
		}
		parserContext.pushContainingComponent(
				new CompositeComponentDefinition(name, parserContext.extractSource(element)));
	
		// Dao
		BeanDefinitionBuilder daoBuilder  = BeanDefinitionBuilder.genericBeanDefinition(daoClassName);
		NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), CRITERIA);
		if (nl.getLength() > 0) {
			ManagedMap<String, BeanReference> builders = new ManagedMap<String, BeanReference>(nl.getLength());
			for (int i = 0; i < nl.getLength(); i++) {
				Element e = (Element) nl.item(i);
				builders.put(e.getAttribute(NAME), new RuntimeBeanReference(e.getAttribute(BUILDER)));
			}
			daoBuilder.addPropertyValue(CRITERIA_BUILDER_MAP, builders);
		}
		
		daoBuilder.addConstructorArgValue(ClassUtils.resolveClassName(className, null));
		daoBuilder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
		String daoBeanName; 
	
		if (declareService) {
			// use dao suffix
			daoBeanName = name + DAO_SUFFIX;
			registerBeanDefinition(parserContext, daoBuilder, daoBeanName); 
			
			// register service wrapper
			String serviceBeanName = name + SERVICE_SUFFIX;
			BeanDefinitionBuilder serviceBuilder = BeanDefinitionBuilder.genericBeanDefinition(serviceClassName);
			serviceBuilder.addPropertyReference("dao", daoBeanName);
			registerBeanDefinition(parserContext, serviceBuilder, serviceBeanName); 
		}
		else {
			// use service suffix for dao and declare an alias with dao suffix for compatibility with older api.
			daoBeanName = name  + SERVICE_SUFFIX;
			String[] aliases = new String[] { name + DAO_SUFFIX };
			BeanComponentDefinition bcd = new BeanComponentDefinition(daoBuilder.getBeanDefinition(), 
					daoBeanName, aliases);
			parserContext.registerBeanComponent(bcd);
		}
	
		parserContext.popAndRegisterContainingComponent();
	}
	
	return null;
}
 
Example #28
Source File: AspectComponentDefinition.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public BeanReference[] getBeanReferences() {
	return this.beanReferences;
}
 
Example #29
Source File: ConfigBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void parseAspect(Element aspectElement, ParserContext parserContext) {
	String aspectId = aspectElement.getAttribute(ID);
	String aspectName = aspectElement.getAttribute(REF);

	try {
		this.parseState.push(new AspectEntry(aspectId, aspectName));
		List<BeanDefinition> beanDefinitions = new ArrayList<BeanDefinition>();
		List<BeanReference> beanReferences = new ArrayList<BeanReference>();

		List<Element> declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS);
		for (int i = METHOD_INDEX; i < declareParents.size(); i++) {
			Element declareParentsElement = declareParents.get(i);
			beanDefinitions.add(parseDeclareParents(declareParentsElement, parserContext));
		}

		// We have to parse "advice" and all the advice kinds in one loop, to get the
		// ordering semantics right.
		NodeList nodeList = aspectElement.getChildNodes();
		boolean adviceFoundAlready = false;
		for (int i = 0; i < nodeList.getLength(); i++) {
			Node node = nodeList.item(i);
			if (isAdviceNode(node, parserContext)) {
				if (!adviceFoundAlready) {
					adviceFoundAlready = true;
					if (!StringUtils.hasText(aspectName)) {
						parserContext.getReaderContext().error(
								"<aspect> tag needs aspect bean reference via 'ref' attribute when declaring advices.",
								aspectElement, this.parseState.snapshot());
						return;
					}
					beanReferences.add(new RuntimeBeanReference(aspectName));
				}
				AbstractBeanDefinition advisorDefinition = parseAdvice(
						aspectName, i, aspectElement, (Element) node, parserContext, beanDefinitions, beanReferences);
				beanDefinitions.add(advisorDefinition);
			}
		}

		AspectComponentDefinition aspectComponentDefinition = createAspectComponentDefinition(
				aspectElement, aspectId, beanDefinitions, beanReferences, parserContext);
		parserContext.pushContainingComponent(aspectComponentDefinition);

		List<Element> pointcuts = DomUtils.getChildElementsByTagName(aspectElement, POINTCUT);
		for (Element pointcutElement : pointcuts) {
			parsePointcut(pointcutElement, parserContext);
		}

		parserContext.popAndRegisterContainingComponent();
	}
	finally {
		this.parseState.pop();
	}
}
 
Example #30
Source File: BeanComponentDefinition.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
@Override
public BeanReference[] getBeanReferences() {
	return this.beanReferences;
}