List of usage examples for org.springframework.core.type AnnotatedTypeMetadata getAllAnnotationAttributes
@Nullable default MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString)
From source file:org.hdiv.config.annotation.condition.OnFrameworkCondition.java
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { MultiValueMap<String, Object> attributes = metadata .getAllAnnotationAttributes(ConditionalOnFramework.class.getName(), true); List<Object> values = attributes.get("value"); Assert.notEmpty(values);/* w w w . j av a 2 s . co m*/ SupportedFramework frwk = (SupportedFramework) values.get(0); if (frwk == SupportedFramework.SPRING_MVC) { return springMvcModulePresent; } else if (frwk == SupportedFramework.THYMELEAF) { return thymeleafModulePresent; } else if (frwk == SupportedFramework.GRAILS) { return grailsPresent && grailsModulePresent; } else if (frwk == SupportedFramework.JSF) { return jsfPresent && jsfModulePresent; } else { return false; } }
From source file:lodsve.core.condition.OnClassCondition.java
private MultiValueMap<String, Object> getAttributes(AnnotatedTypeMetadata metadata, Class<?> annotationType) { return metadata.getAllAnnotationAttributes(annotationType.getName(), true); }
From source file:org.springframework.boot.autoconfigure.condition.AbstractOnBeanCondition.java
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(annotationClass().getName(), true);//from w w w.j a v a 2s.c om final List<String> beanClasses = collect(attributes, "value"); final List<String> beanNames = collect(attributes, "name"); if (beanClasses.size() == 0) { if (metadata instanceof MethodMetadata && metadata.isAnnotated(Bean.class.getName())) { try { final MethodMetadata methodMetadata = (MethodMetadata) metadata; // We should be safe to load at this point since we are in the // REGISTER_BEAN phase Class<?> configClass = ClassUtils.forName(methodMetadata.getDeclaringClassName(), context.getClassLoader()); ReflectionUtils.doWithMethods(configClass, new MethodCallback() { @Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { if (methodMetadata.getMethodName().equals(method.getName())) { beanClasses.add(method.getReturnType().getName()); } } }); } catch (Exception ex) { // swallow exception and continue } } } Assert.isTrue(beanClasses.size() > 0 || beanNames.size() > 0, "@" + ClassUtils.getShortName(annotationClass()) + " annotations must specify at least one bean"); return matches(context, metadata, beanClasses, beanNames); }
From source file:org.springframework.boot.autoconfigure.condition.OnClassCondition.java
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String checking = ConditionLogUtils.getPrefix(logger, metadata); MultiValueMap<String, Object> attributes = metadata .getAllAnnotationAttributes(ConditionalOnClass.class.getName(), true); if (attributes != null) { List<String> classNames = new ArrayList<String>(); collectClassNames(classNames, attributes.get("value")); collectClassNames(classNames, attributes.get("name")); Assert.isTrue(classNames.size() > 0, "@ConditionalOnClass annotations must specify at least one class value"); for (String className : classNames) { if (logger.isDebugEnabled()) { logger.debug(checking + "Looking for class: " + className); }/*from ww w .j av a 2s .c om*/ if (!ClassUtils.isPresent(className, context.getClassLoader())) { if (logger.isDebugEnabled()) { logger.debug(checking + "Class not found: " + className + " (search terminated with matches=false)"); } return false; } } } if (logger.isDebugEnabled()) { logger.debug(checking + "Match result is: true"); } return true; }
From source file:org.springframework.boot.autoconfigure.condition.OnMissingClassCondition.java
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String checking = ConditionLogUtils.getPrefix(logger, metadata); MultiValueMap<String, Object> attributes = metadata .getAllAnnotationAttributes(ConditionalOnMissingClass.class.getName(), true); if (attributes != null) { List<String> classNames = new ArrayList<String>(); collectClassNames(classNames, attributes.get("value")); Assert.isTrue(classNames.size() > 0, "@ConditionalOnMissingClass annotations must specify at least one class value"); for (String className : classNames) { if (logger.isDebugEnabled()) { logger.debug(checking + "Looking for class: " + className); }/* ww w.j av a2 s. c o m*/ if (ClassUtils.isPresent(className, context.getClassLoader())) { if (logger.isDebugEnabled()) { logger.debug( checking + "Found class: " + className + " (search terminated with matches=false)"); } return false; } } } if (logger.isDebugEnabled()) { logger.debug(checking + "Match result is: true"); } return true; }
From source file:org.springframework.boot.autoconfigure.condition.OnResourceCondition.java
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String checking = ConditionLogUtils.getPrefix(logger, metadata); MultiValueMap<String, Object> attributes = metadata .getAllAnnotationAttributes(ConditionalOnResource.class.getName(), true); ResourceLoader loader = context.getResourceLoader() == null ? this.defaultResourceLoader : context.getResourceLoader(); if (attributes != null) { List<String> locations = new ArrayList<String>(); collectValues(locations, attributes.get("resources")); Assert.isTrue(locations.size() > 0, "@ConditionalOnResource annotations must specify at least one resource location"); for (String location : locations) { if (logger.isDebugEnabled()) { logger.debug(checking + "Checking for resource: " + location); }/*w w w .java 2 s. c om*/ if (!loader.getResource(location).exists()) { if (logger.isDebugEnabled()) { logger.debug(checking + "Resource not found: " + location + " (search terminated with matches=false)"); } return false; } } } if (logger.isDebugEnabled()) { logger.debug(checking + "Match result is: true"); } return true; }