private Method getFactoryMethod(ConfigurableListableBeanFactory beanFactory,
BeanDefinition definition) throws Exception {
if (definition instanceof AnnotatedBeanDefinition) {
MethodMetadata factoryMethodMetadata = ((AnnotatedBeanDefinition) definition)
.getFactoryMethodMetadata();
if (factoryMethodMetadata instanceof StandardMethodMetadata) {
return ((StandardMethodMetadata) factoryMethodMetadata)
.getIntrospectedMethod();
}
}
BeanDefinition factoryDefinition = beanFactory
.getBeanDefinition(definition.getFactoryBeanName());
Class<?> factoryClass = ClassUtils.forName(factoryDefinition.getBeanClassName(),
beanFactory.getBeanClassLoader());
return ReflectionUtils.findMethod(factoryClass,
definition.getFactoryMethodName());
}
java类org.springframework.beans.factory.annotation.AnnotatedBeanDefinition的实例源码
BeanTypeRegistry.java 文件源码
项目:contestparser
阅读 19
收藏 0
点赞 0
评论 0
IgnoreAnnotationClassPathScanningCandidateComponentProvider.java 文件源码
项目:onetwo
阅读 12
收藏 0
点赞 0
评论 0
@Override
protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
if (beanDefinition.getMetadata().isIndependent()) {
// TODO until SPR-11711 will be resolved
if (beanDefinition.getMetadata().isInterface()
&& beanDefinition.getMetadata()
.getInterfaceNames().length == 1
&& Annotation.class.getName().equals(beanDefinition
.getMetadata().getInterfaceNames()[0])) {
try {
Class<?> target = ClassUtils.forName(
beanDefinition.getMetadata().getClassName(), classLoader);
return !target.isAnnotation();
}
catch (Exception ex) {
this.logger.error("Could not load target class: " + beanDefinition.getMetadata().getClassName(), ex);
}
}
return true;
}
return false;
}
SimpleInterceptorResolutionStrategy.java 文件源码
项目:fmek
阅读 13
收藏 0
点赞 0
评论 0
private List<InterceptorInfo> collectInterceptors(ConfigurableListableBeanFactory configurableListableBeanFactory) {
List<InterceptorInfo> interceptors = new ArrayList<InterceptorInfo>();
registeredInterceptorsCache = new ArrayList<InterceptorInfo>();
String[] bdNames = configurableListableBeanFactory.getBeanDefinitionNames();
for (String bdName : bdNames) {
BeanDefinition bd = configurableListableBeanFactory.getBeanDefinition(bdName);
if (bd instanceof AnnotatedBeanDefinition) {
AnnotatedBeanDefinition abd = (AnnotatedBeanDefinition) bd;
if (InterceptorInfo.isInterceptor(abd)) {
if (bdName.startsWith(SCOPED_TARGET)) {
bd = configurableListableBeanFactory.getBeanDefinition(bdName.replace(SCOPED_TARGET, ""));
}
InterceptorInfo interceptorInfo = new MethodInterceptorInfo(new BeanDefinitionHolder(bd, bdName.replace(SCOPED_TARGET, "")));
resolveInterceptorTargets(configurableListableBeanFactory, interceptorInfo);
interceptors.add(interceptorInfo);
}
}
}
return interceptors;
}
EntityHelper.java 文件源码
项目:jspresso-ce
阅读 31
收藏 0
点赞 0
评论 0
/**
* Gets entity sub contracts.
*
* @param entityContract
* the entity contract
* @return the entity sub contracts
*/
@SuppressWarnings("unchecked")
public static Collection<Class<IEntity>> getEntitySubContracts(Class<IEntity> entityContract) {
Collection<Class<IEntity>> entitySubContracts = new HashSet<>();
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false) {
@Override
protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
// Allow to return superclasses
return beanDefinition.getMetadata().isIndependent();
}
};
provider.addIncludeFilter(new AssignableTypeFilter(entityContract));
Set<BeanDefinition> components = provider.findCandidateComponents(entityContract.getPackage().getName().replace('.',
'/'));
for (BeanDefinition component : components) {
try {
Class<IEntity> entitySubContract = (Class<IEntity>) Class.forName(component.getBeanClassName());
if (entitySubContract != entityContract) {
entitySubContracts.add(entitySubContract);
}
} catch (ClassNotFoundException e) {
// Ignore
}
}
return entitySubContracts;
}
AnnotationConfigUtils.java 文件源码
项目:class-guard
阅读 21
收藏 0
点赞 0
评论 0
public static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd) {
AnnotationMetadata metadata = abd.getMetadata();
if (metadata.isAnnotated(Primary.class.getName())) {
abd.setPrimary(true);
}
if (metadata.isAnnotated(Lazy.class.getName())) {
abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value"));
}
if (metadata.isAnnotated(DependsOn.class.getName())) {
abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value"));
}
if (abd instanceof AbstractBeanDefinition) {
if (metadata.isAnnotated(Role.class.getName())) {
Integer role = attributesFor(metadata, Role.class).getNumber("value");
((AbstractBeanDefinition)abd).setRole(role);
}
}
}
AnnotationScopeMetadataResolver.java 文件源码
项目:class-guard
阅读 19
收藏 0
点赞 0
评论 0
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
ScopeMetadata metadata = new ScopeMetadata();
if (definition instanceof AnnotatedBeanDefinition) {
AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
AnnotationAttributes attributes = attributesFor(annDef.getMetadata(), this.scopeAnnotationType);
if (attributes != null) {
metadata.setScopeName(attributes.getString("value"));
ScopedProxyMode proxyMode = attributes.getEnum("proxyMode");
if (proxyMode == null || proxyMode == ScopedProxyMode.DEFAULT) {
proxyMode = this.defaultProxyMode;
}
metadata.setScopedProxyMode(proxyMode);
}
}
return metadata;
}
Jsr330ScopeMetadataResolver.java 文件源码
项目:class-guard
阅读 19
收藏 0
点赞 0
评论 0
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
ScopeMetadata metadata = new ScopeMetadata();
metadata.setScopeName(BeanDefinition.SCOPE_PROTOTYPE);
if (definition instanceof AnnotatedBeanDefinition) {
AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
Set<String> annTypes = annDef.getMetadata().getAnnotationTypes();
String found = null;
for (String annType : annTypes) {
Set<String> metaAnns = annDef.getMetadata().getMetaAnnotationTypes(annType);
if (metaAnns.contains("javax.inject.Scope")) {
if (found != null) {
throw new IllegalStateException("Found ambiguous scope annotations on bean class [" +
definition.getBeanClassName() + "]: " + found + ", " + annType);
}
found = annType;
String scopeName = resolveScopeName(annType);
if (scopeName == null) {
throw new IllegalStateException(
"Unsupported scope annotation - not mapped onto Spring scope name: " + annType);
}
metadata.setScopeName(scopeName);
}
}
}
return metadata;
}
AnnotationBeanNameGenerator.java 文件源码
项目:class-guard
阅读 13
收藏 0
点赞 0
评论 0
/**
* Derive a bean name from one of the annotations on the class.
* @param annotatedDef the annotation-aware bean definition
* @return the bean name, or {@code null} if none is found
*/
protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) {
AnnotationMetadata amd = annotatedDef.getMetadata();
Set<String> types = amd.getAnnotationTypes();
String beanName = null;
for (String type : types) {
AnnotationAttributes attributes = MetadataUtils.attributesFor(amd, type);
if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) {
Object value = attributes.get("value");
if (value instanceof String) {
String strVal = (String) value;
if (StringUtils.hasLength(strVal)) {
if (beanName != null && !strVal.equals(beanName)) {
throw new IllegalStateException("Stereotype annotations suggest inconsistent " +
"component names: '" + beanName + "' versus '" + strVal + "'");
}
beanName = strVal;
}
}
}
}
return beanName;
}
ClassPathBeanDefinitionScanner.java 文件源码
项目:class-guard
阅读 25
收藏 0
点赞 0
评论 0
/**
* Perform a scan within the specified base packages,
* returning the registered bean definitions.
* <p>This method does <i>not</i> register an annotation config processor
* but rather leaves this up to the caller.
* @param basePackages the packages to check for annotated classes
* @return set of beans registered if any for tooling registration purposes (never {@code null})
*/
protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
Assert.notEmpty(basePackages, "At least one base package must be specified");
Set<BeanDefinitionHolder> beanDefinitions = new LinkedHashSet<BeanDefinitionHolder>();
for (String basePackage : basePackages) {
Set<BeanDefinition> candidates = findCandidateComponents(basePackage);
for (BeanDefinition candidate : candidates) {
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate);
candidate.setScope(scopeMetadata.getScopeName());
String beanName = this.beanNameGenerator.generateBeanName(candidate, this.registry);
if (candidate instanceof AbstractBeanDefinition) {
postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName);
}
if (candidate instanceof AnnotatedBeanDefinition) {
AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate);
}
if (checkCandidate(beanName, candidate)) {
BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, beanName);
definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
beanDefinitions.add(definitionHolder);
registerBeanDefinition(definitionHolder, this.registry);
}
}
}
return beanDefinitions;
}
JGivenBeanFactoryPostProcessor.java 文件源码
项目:JGiven
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory ) throws BeansException {
String[] beanNames = beanFactory.getBeanDefinitionNames();
for( String beanName : beanNames ) {
if( beanFactory.containsBeanDefinition( beanName ) ) {
BeanDefinition beanDefinition = beanFactory.getBeanDefinition( beanName );
if( beanDefinition instanceof AnnotatedBeanDefinition ) {
AnnotatedBeanDefinition annotatedBeanDefinition = (AnnotatedBeanDefinition) beanDefinition;
if( annotatedBeanDefinition.getMetadata().hasAnnotation( JGivenStage.class.getName() ) ) {
String className = beanDefinition.getBeanClassName();
Class<?> stageClass = createStageClass( beanName, className );
beanDefinition.setBeanClassName( stageClass.getName() );
}
}
}
}
}