Java Code Examples for org.springframework.beans.factory.support.BeanDefinitionRegistry

The following examples show how to use org.springframework.beans.factory.support.BeanDefinitionRegistry. These examples are extracted from open source projects. 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 Project: dubbox   Source File: AnnotationBean.java    License: Apache License 2.0 6 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[] {packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
 
Example 2
Source Project: dubbo-2.6.5   Source File: AnnotationBean.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
    throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[]{BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[]{(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[]{packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
 
Example 3
Source Project: dorado   Source File: SpringContainer.java    License: Apache License 2.0 6 votes vote down vote up
public synchronized static void create(ApplicationContext applicationContext) {
	DoradoServerBuilder builder = Dorado.serverConfig;
	if (builder == null) {
		throw new IllegalStateException("Please init DoradoServer first!");
	}

	if (!(applicationContext instanceof DoradoApplicationContext)
			&& (applicationContext instanceof BeanDefinitionRegistry)) {
		ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(
				(BeanDefinitionRegistry) applicationContext);
		scanner.resetFilters(false);
		scanner.addIncludeFilter(new AnnotationTypeFilter(Controller.class));
		scanner.scan(builder.scanPackages());
	}

	instance = new SpringContainer(applicationContext);
	Dorado.springInitialized = true;
}
 
Example 4
Source Project: statefulj   Source File: StatefulFactory.java    License: Apache License 2.0 6 votes vote down vote up
private String registerFinderBean(
		ReferenceFactory referenceFactory,
		PersistenceSupportBeanFactory persistenceFactory,
		StatefulController statefulContollerAnnotation,
		String repoBeanId,
		BeanDefinitionRegistry reg) {

	String finderId = statefulContollerAnnotation.finderId();

	if (StringUtils.isEmpty(finderId)) {
		if (persistenceFactory == null) {
			throw new RuntimeException("PersistenceFactory is undefined and no finder bean was specified in the StatefulController Annotation for " + statefulContollerAnnotation.clazz());
		}
		if (StringUtils.isEmpty(repoBeanId)) {
			throw new RuntimeException("No Repository is defined for " + statefulContollerAnnotation.clazz());
		}
		finderId = referenceFactory.getFinderId();
		reg.registerBeanDefinition(
				finderId,
				persistenceFactory.buildFinderBean(repoBeanId));
	}

	return finderId;
}
 
Example 5
@Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

//        解析指定扫描的包名=》
        Set<String> resolvedPackagesToScan = resolvePackagesToScan(packagesToScan);

        if (!CollectionUtils.isEmpty(resolvedPackagesToScan)) {
//            注册服务提供者bean定义=》
            registerServiceBeans(resolvedPackagesToScan, registry);
        } else {
            if (logger.isWarnEnabled()) {
                logger.warn("packagesToScan is empty , ServiceBean registry will be ignored!");
            }
        }

    }
 
Example 6
Source Project: statefulj   Source File: StatefulFactory.java    License: Apache License 2.0 6 votes vote down vote up
private String registerState(
		ReferenceFactory referenceFactory,
		Class<?> statefulControllerClass,
		String state,
		boolean isBlocking,
		BeanDefinitionRegistry reg) {

	String stateId = referenceFactory.getStateId(state);
	BeanDefinition stateBean = BeanDefinitionBuilder
			.genericBeanDefinition(StateImpl.class)
			.getBeanDefinition();

	ConstructorArgumentValues args = stateBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, state);
	args.addIndexedArgumentValue(1, false);
	args.addIndexedArgumentValue(2, isBlocking);

	reg.registerBeanDefinition(stateId, stateBean);

	return stateId;
}
 
Example 7
Source Project: spring-init   Source File: SampleRegistrar.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
		throws BeansException {
	registry.registerBeanDefinition("foo", BeanDefinitionBuilder
			.genericBeanDefinition(Foo.class, () -> foo()).getBeanDefinition());
	registry.registerBeanDefinition("bar",
			BeanDefinitionBuilder
					.genericBeanDefinition(Bar.class,
							() -> bar(context.getBean(Foo.class)))
					.getBeanDefinition());
	registry.registerBeanDefinition("runner",
			BeanDefinitionBuilder
					.genericBeanDefinition(CommandLineRunner.class,
							() -> runner(context.getBean(Bar.class)))
					.getBeanDefinition());
}
 
Example 8
Source Project: spring-analysis-note   Source File: AopNamespaceUtils.java    License: MIT License 6 votes vote down vote up
private static void useClassProxyingIfNecessary(BeanDefinitionRegistry registry, @Nullable Element sourceElement) {
	if (sourceElement != null) {
		// 这方法作用挺简单的,就是解析下面两个属性,如果是 true,将它们加入代理注册器的属性列表中
		// definition.getPropertyValues().add("proxyTargetClass", Boolean.TRUE)
		boolean proxyTargetClass = Boolean.parseBoolean(sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE));
		if (proxyTargetClass) {
			// 处理  proxy-target-class 属性
			// 与代码生成方式有关,在之后步骤中决定使用 jdk 动态代理 或 cglib
			AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
		}
		boolean exposeProxy = Boolean.parseBoolean(sourceElement.getAttribute(EXPOSE_PROXY_ATTRIBUTE));
		if (exposeProxy) {
			// 处理 expose-proxy 属性
			// 扩展增强,有时候目标对象内部的自我调用无法实施切面中的增强,通过这个属性可以同时对两个方法进行增强
			AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);
		}
	}
}
 
Example 9
Source Project: statefulj   Source File: StatefulFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param bf
 * @param reg
 * @param clazz
 * @return
 * @throws ClassNotFoundException
 */
private Class<?> getClassFromFactoryMethod(BeanDefinition bf, BeanDefinitionRegistry reg)
		throws ClassNotFoundException {
	Class<?> clazz = null;
	String factoryBeanName = bf.getFactoryBeanName();
	if (factoryBeanName != null) {
		BeanDefinition factory = reg.getBeanDefinition(factoryBeanName);
		if (factory != null) {
			String factoryClassName = factory.getBeanClassName();
			Class<?> factoryClass = Class.forName(factoryClassName);
			List<Method> methods = new LinkedList<Method>();
			methods.addAll(Arrays.asList(factoryClass.getMethods()));
			methods.addAll(Arrays.asList(factoryClass.getDeclaredMethods()));
			for (Method method : methods) {
				method.setAccessible(true);
				if (method.getName().equals(bf.getFactoryMethodName())) {
					clazz = method.getReturnType();
					break;
				}
			}
		}
	}
	return clazz;
}
 
Example 10
@Override
protected void registerAuditListenerBeanDefinition(
		BeanDefinition auditingHandlerDefinition, BeanDefinitionRegistry registry) {
	if (!registry.containsBeanDefinition(MYBATIS_MAPPING_CONTEXT_BEAN_NAME)) {
		registry.registerBeanDefinition(MYBATIS_MAPPING_CONTEXT_BEAN_NAME, //
				new RootBeanDefinition(MybatisMappingContextFactoryBean.class));
	}
	BeanDefinitionBuilder builder = BeanDefinitionBuilder
			.rootBeanDefinition(AuditingEntityListener.class);
	builder.addPropertyValue("auditingHandler", ParsingUtils
			.getObjectFactoryBeanDefinition(getAuditingHandlerBeanName(), null));
	builder.addPropertyReference("sqlSessionTemplate",
			DEFAULT_SQL_SESSION_TEMPLATE_BEAN_NAME);
	registerInfrastructureBeanWithId(builder.getRawBeanDefinition(),
			AuditingEntityListener.class.getName(), registry);
}
 
Example 11
Source Project: eventeum   Source File: NodeBeanRegistrationStrategy.java    License: Apache License 2.0 6 votes vote down vote up
private String registerNodeServicesBean(Node node,
                                        Web3j web3j,
                                        String web3jServiceBeanName,
                                        BeanDefinitionRegistry registry) {
    final BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
            NodeServices.class);

    builder.addPropertyValue("nodeName", node.getName())
            .addPropertyValue("web3j", web3j)
            .addPropertyReference("blockchainService", web3jServiceBeanName);

    final String beanName = String.format(NODE_SERVICES_BEAN_NAME, node.getName());
    registry.registerBeanDefinition(beanName, builder.getBeanDefinition());

    return beanName;
}
 
Example 12
Source Project: Mapper   Source File: MapperScannerConfigurer.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @since 1.0.2
 */
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
    if (this.processPropertyPlaceHolders) {
        processPropertyPlaceHolders();
    }
    ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
    scanner.setAddToConfig(this.addToConfig);
    scanner.setAnnotationClass(this.annotationClass);
    scanner.setMarkerInterface(this.markerInterface);
    scanner.setSqlSessionFactory(this.sqlSessionFactory);
    scanner.setSqlSessionTemplate(this.sqlSessionTemplate);
    scanner.setSqlSessionFactoryBeanName(this.sqlSessionFactoryBeanName);
    scanner.setSqlSessionTemplateBeanName(this.sqlSessionTemplateBeanName);
    scanner.setResourceLoader(this.applicationContext);
    scanner.setBeanNameGenerator(this.nameGenerator);
    scanner.registerFilters();
    //设置通用 Mapper
    scanner.setMapperHelper(this.mapperHelper);
    scanner.scan(StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
}
 
Example 13
private static Matcher<BeanDefinitionRegistry> containsBeanDefinition(final String beanName) {
	return new TypeSafeMatcher<BeanDefinitionRegistry>() {

		@Override
		public void describeTo(Description desc) {
			desc.appendText("a BeanDefinitionRegistry containing bean named ")
				.appendValue(beanName);
		}

		@Override
		public boolean matchesSafely(BeanDefinitionRegistry beanFactory) {
			return beanFactory.containsBeanDefinition(beanName);
		}

	};
}
 
Example 14
@Override
protected void registerContentStoreBeanDefinitions(
		AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

	AnnotationMetadata metadata = new StandardAnnotationMetadata(
			EnableJpaContentAutoConfiguration.class);
	AnnotationAttributes attributes = new AnnotationAttributes(
			metadata.getAnnotationAttributes(this.getAnnotation().getName()));

	String[] basePackages = this.getBasePackages();

	Set<GenericBeanDefinition> definitions = StoreUtils.getStoreCandidates(this.getEnvironment(), this.getResourceLoader(), basePackages, multipleStoreImplementationsDetected(), getIdentifyingTypes());

	this.buildAndRegisterDefinitions(importingClassMetadata, registry, attributes, basePackages, definitions);
}
 
Example 15
private BeanDefinitionRegistry beanFactoryFor(String xmlName, String... activeProfiles) {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
	StandardEnvironment env = new StandardEnvironment();
	env.setActiveProfiles(activeProfiles);
	reader.setEnvironment(env);
	reader.loadBeanDefinitions(new ClassPathResource(xmlName, getClass()));
	return beanFactory;
}
 
Example 16
Source Project: YuRPC   Source File: YuRPCImportBeanDefinitionRegistrar.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 注册组件
 *
 * @param am  注解元信息
 * @param bdr 组件注册器
 */
@Override
public void registerBeanDefinitions(AnnotationMetadata am, BeanDefinitionRegistry bdr) {
    Map<String, Object> attributes = am.getAnnotationAttributes(EnableYuRPC.class.getName());
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(YuRPCAutoConfiguration.class);
    if (attributes != null && attributes.containsKey("server")) {
        bdb.addPropertyValue("server", (Boolean) attributes.get("server"));
    }
    if (attributes != null && attributes.containsKey("client")) {
        bdb.addPropertyValue("client", (Boolean) attributes.get("client"));
    }
    bdr.registerBeanDefinition(YuRPCAutoConfiguration.class.getName(), bdb.getBeanDefinition());
}
 
Example 17
/**
 * {@inheritDoc}
 */
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
    String name = definition.getBeanClassName();
    int index = name.lastIndexOf(".");
    if (index != -1) {
        name = name.substring(index + 1);
    }
    if (name.endsWith("Impl")) {
        name = name.substring(0, name.length() - 4);
    }
    name = Introspector.decapitalize(name);
    return name;
}
 
Example 18
Source Project: sdn-rx   Source File: Neo4jAuditingRegistrar.java    License: Apache License 2.0 5 votes vote down vote up
private void registerReactiveAuditingEntityCallback(BeanDefinitionRegistry registry, Object source) {

		BeanDefinitionBuilder builder = BeanDefinitionBuilder
			.rootBeanDefinition(ReactiveAuditingBeforeBindCallback.class);

		builder.addConstructorArgValue(
			ParsingUtils.getObjectFactoryBeanDefinition(getAuditingHandlerBeanName(), registry));
		builder.getRawBeanDefinition().setSource(source);

		registerInfrastructureBeanWithId(builder.getBeanDefinition(),
			ReactiveAuditingBeforeBindCallback.class.getName(), registry);
	}
 
Example 19
/**
 * @since 4.0.1
 * @see https://jira.spring.io/browse/SPR-11360
 */
@Test
public void generateBeanNameFromComposedControllerAnnotationWithStringValue() {
	BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
	AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(
		ComposedControllerAnnotationWithStringValue.class);
	String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
	assertEquals("restController", beanName);
}
 
Example 20
Source Project: java-technology-stack   Source File: AnnotationConfigUtils.java    License: MIT License 5 votes vote down vote up
@Nullable
private static DefaultListableBeanFactory unwrapDefaultListableBeanFactory(BeanDefinitionRegistry registry) {
	if (registry instanceof DefaultListableBeanFactory) {
		return (DefaultListableBeanFactory) registry;
	}
	else if (registry instanceof GenericApplicationContext) {
		return ((GenericApplicationContext) registry).getDefaultListableBeanFactory();
	}
	else {
		return null;
	}
}
 
Example 21
Source Project: statefulj   Source File: StatefulFactory.java    License: Apache License 2.0 5 votes vote down vote up
private String registerFSM(
		ReferenceFactory referenceFactory,
		Class<?> statefulControllerClass,
		StatefulController scAnnotation,
		String persisterId,
		Class<?> managedClass,
		String finderId,
		Class<? extends Annotation> idAnnotationType,
		BeanDefinitionRegistry reg) {
	int retryAttempts = scAnnotation.retryAttempts();
	int retryInterval = scAnnotation.retryInterval();

	String fsmBeanId = referenceFactory.getFSMId();
	BeanDefinition fsmBean = BeanDefinitionBuilder
			.genericBeanDefinition(FSM.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = fsmBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, fsmBeanId);
	args.addIndexedArgumentValue(1, new RuntimeBeanReference(persisterId));
	args.addIndexedArgumentValue(2, retryAttempts);
	args.addIndexedArgumentValue(3, retryInterval);
	args.addIndexedArgumentValue(4, managedClass);
	args.addIndexedArgumentValue(5, idAnnotationType);
	args.addIndexedArgumentValue(6, this.appContext);

	if (finderId != null) {
		args.addIndexedArgumentValue(7, new RuntimeBeanReference(finderId));
	}

	reg.registerBeanDefinition(fsmBeanId, fsmBean);
	return fsmBeanId;
}
 
Example 22
Source Project: dubbo-2.6.5   Source File: DubboConfigBindingRegistrar.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

//        解析@EnableDubboConfigBinding注解属性值
        AnnotationAttributes attributes = AnnotationAttributes.fromMap(
                importingClassMetadata.getAnnotationAttributes(EnableDubboConfigBinding.class.getName()));

//        注册bean定义=》
        registerBeanDefinitions(attributes, registry);

    }
 
Example 23
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry){
    Class beanClass = RabbitmqOfflineInfoHelper.class;
    RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
    String beanName = StringUtils.uncapitalize(beanClass.getSimpleName());
    //在这里可以拿到所有注解的信息,可以根据不同注解来返回不同的class,从而达到开启不同功能的目的
    //通过这种方式可以自定义beanName
    registry.registerBeanDefinition(beanName, beanDefinition);
}
 
Example 24
private static void registerCredentialsProviderIfNeeded(
		BeanDefinitionRegistry registry) {
	if (!registry.containsBeanDefinition(CREDENTIALS_PROVIDER_BEAN_NAME)) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder
				.genericBeanDefinition(CredentialsProviderFactoryBean.class);
		builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		registry.registerBeanDefinition(CREDENTIALS_PROVIDER_BEAN_NAME,
				builder.getBeanDefinition());
	}
}
 
Example 25
private void createDataSourceProxy(ConfigurableListableBeanFactory beanFactory,
                                   String beanName, BeanDefinition originDataSource,
                                   String jdbcUrl) {
    // re-register origin datasource bean
    BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) beanFactory;
    beanDefinitionRegistry.removeBeanDefinition(beanName);
    boolean isPrimary = originDataSource.isPrimary();
    originDataSource.setPrimary(false);
    beanDefinitionRegistry.registerBeanDefinition(transformDatasourceBeanName(beanName),
        originDataSource);
    // register proxied datasource
    RootBeanDefinition proxiedBeanDefinition = new RootBeanDefinition(SmartDataSource.class);
    proxiedBeanDefinition.setRole(BeanDefinition.ROLE_APPLICATION);
    proxiedBeanDefinition.setPrimary(isPrimary);
    proxiedBeanDefinition.setInitMethodName("init");
    proxiedBeanDefinition.setDependsOn(transformDatasourceBeanName(beanName));
    MutablePropertyValues originValues = originDataSource.getPropertyValues();
    MutablePropertyValues values = new MutablePropertyValues();
    String appName = environment.getProperty(TRACER_APPNAME_KEY);
    Assert.isTrue(!StringUtils.isBlank(appName), TRACER_APPNAME_KEY + " must be configured!");
    values.add("appName", appName);
    values.add("delegate", new RuntimeBeanReference(transformDatasourceBeanName(beanName)));
    values.add("dbType",
        DataSourceUtils.resolveDbTypeFromUrl(unwrapPropertyValue(originValues.get(jdbcUrl))));
    values.add("database",
        DataSourceUtils.resolveDatabaseFromUrl(unwrapPropertyValue(originValues.get(jdbcUrl))));
    proxiedBeanDefinition.setPropertyValues(values);
    beanDefinitionRegistry.registerBeanDefinition(beanName, proxiedBeanDefinition);
}
 
Example 26
public static void replaceDefaultCredentialsProvider(BeanDefinitionRegistry registry,
		String customGlobalCredentialsProvider) {
	if (registry.containsBeanDefinition(CREDENTIALS_PROVIDER_BEAN_NAME)) {
		registry.removeBeanDefinition(CREDENTIALS_PROVIDER_BEAN_NAME);
	}
	registry.registerAlias(customGlobalCredentialsProvider,
			CREDENTIALS_PROVIDER_BEAN_NAME);
}
 
Example 27
private void registerMessageLogReceiverEndpointProcessorBeanDefinition(final BeanDefinitionRegistry registry,
                                                                       final String beanName,
                                                                       final String messageLogBeanName,
                                                                       final String channelName) {
    registry.registerBeanDefinition(
            beanName,
            genericBeanDefinition(MessageLogConsumerContainer.class)
                    .addConstructorArgValue(messageLogBeanName)
                    // TODO: support other channel positions as a starting point for @EnableMessageLogReceiverEndpoint
                    .addConstructorArgValue(ChannelPosition.fromHorizon())
                    .setDependencyCheck(DEPENDENCY_CHECK_ALL)
                    .getBeanDefinition()
    );
    LOG.info("Registered MessageLogReceiverEndpointProcessor {} with for channelName {}", beanName, channelName);
}
 
Example 28
/**
 * Parses the given XML element containing the properties and/or sub-elements
 * necessary to configure a strategy for setting up declarative caching
 * services.
 * 
 * @param element
 *          the XML element to parse
 * @param parserContext
 *          the parser context
 * @throws IllegalStateException
 *           if the bean definition registry does not have a definition for
 *           the <code>CacheProviderFacade</code> registered under the name
 *           specified in the XML attribute "providerId"
 * @throws IllegalStateException
 *           if the cache provider facade is in invalid state
 * @throws IllegalStateException
 *           if any of the caching listeners is not an instance of
 *           <code>CachingListener</code>
 * 
 * @see BeanDefinitionParser#parse(Element, ParserContext)
 */
public final BeanDefinition parse(Element element, ParserContext parserContext)
    throws NoSuchBeanDefinitionException, IllegalStateException {
  String cacheProviderFacadeId = element.getAttribute("providerId");

  BeanDefinitionRegistry registry = parserContext.getRegistry();
  if (!registry.containsBeanDefinition(cacheProviderFacadeId)) {
    throw new IllegalStateException(
        "An implementation of CacheProviderFacade should be registered under the name "
            + StringUtils.quote(cacheProviderFacadeId));
  }

  RuntimeBeanReference cacheProviderFacadeReference = new RuntimeBeanReference(
      cacheProviderFacadeId);

  Object cacheKeyGenerator = parseCacheKeyGenerator(element, parserContext);
  List cachingListeners = parseCachingListeners(element, parserContext);
  Map cachingModels = parseCachingModels(element);
  Map flushingModels = parseFlushingModels(element);

  CacheSetupStrategyPropertySource ps = new CacheSetupStrategyPropertySource(
      cacheKeyGenerator, cacheProviderFacadeReference, cachingListeners,
      cachingModels, flushingModels);

  parseCacheSetupStrategy(element, parserContext, ps);
  return null;
}
 
Example 29
Source Project: lams   Source File: AnnotationConfigUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static BeanDefinitionHolder registerPostProcessor(
		BeanDefinitionRegistry registry, RootBeanDefinition definition, String beanName) {

	definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	registry.registerBeanDefinition(beanName, definition);
	return new BeanDefinitionHolder(definition, beanName);
}
 
Example 30
/**
 * Registers {@link ReferenceAnnotationBeanPostProcessor} into {@link BeanFactory}
 *
 * @param registry {@link BeanDefinitionRegistry}
 */
private void registerReferenceAnnotationBeanPostProcessor(BeanDefinitionRegistry registry) {

    // Register @Reference Annotation Bean Processor
    BeanRegistrar.registerInfrastructureBean(registry,
            ReferenceAnnotationBeanPostProcessor.BEAN_NAME, ReferenceAnnotationBeanPostProcessor.class);

}