Java Code Examples for org.springframework.core.type.AnnotatedTypeMetadata#isAnnotated()
The following examples show how to use
org.springframework.core.type.AnnotatedTypeMetadata#isAnnotated() .
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: OnProfileCondition.java From frostmourne with MIT License | 6 votes |
private Set<String> retrieveAnnotatedProfiles(AnnotatedTypeMetadata metadata, String annotationType) { if (!metadata.isAnnotated(annotationType)) { return Collections.emptySet(); } MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(annotationType); if (attributes == null) { return Collections.emptySet(); } Set<String> profiles = Sets.newHashSet(); List<?> values = attributes.get("value"); if (values != null) { for (Object value : values) { if (value instanceof String[]) { Collections.addAll(profiles, (String[]) value); } else { profiles.add((String) value); } } } return profiles; }
Example 2
Source File: ImporterExporterComponentConditional.java From sofa-lookout with Apache License 2.0 | 6 votes |
private boolean isComponentEnable(ConditionContext context, AnnotatedTypeMetadata metadata) { boolean isImporter = metadata.isAnnotated(ConditionalOnImporterComponent.class.getName()); MultiValueMap<String, Object> map = null; if (isImporter) { map = metadata.getAllAnnotationAttributes(ConditionalOnImporterComponent.class .getName()); } else { map = metadata.getAllAnnotationAttributes(ConditionalOnExporterComponent.class .getName()); } String importerExporterName = getFirstAnnotationValueFromMetadata(map, "value"); MonitorComponent monitorComponent = getFirstAnnotationValueFromMetadata(map, "type"); List<String> activeComponents = getActivatedComponentsFromConfiguration(context, isImporter, monitorComponent); boolean active = activeComponents.contains(importerExporterName); LOGGER.info("gateway {} {}:{} active:{}", monitorComponent.name().toLowerCase(), (isImporter ? "importer" : "exporter"), importerExporterName, active); return active; }
Example 3
Source File: AnnotationConfigUtils.java From lams with GNU General Public License v2.0 | 6 votes |
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) { if (metadata.isAnnotated(Lazy.class.getName())) { abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value")); } else if (abd.getMetadata() != metadata && abd.getMetadata().isAnnotated(Lazy.class.getName())) { abd.setLazyInit(attributesFor(abd.getMetadata(), Lazy.class).getBoolean("value")); } if (metadata.isAnnotated(Primary.class.getName())) { abd.setPrimary(true); } if (metadata.isAnnotated(DependsOn.class.getName())) { abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value")); } if (abd instanceof AbstractBeanDefinition) { AbstractBeanDefinition absBd = (AbstractBeanDefinition) abd; if (metadata.isAnnotated(Role.class.getName())) { absBd.setRole(attributesFor(metadata, Role.class).getNumber("value").intValue()); } if (metadata.isAnnotated(Description.class.getName())) { absBd.setDescription(attributesFor(metadata, Description.class).getString("value")); } } }
Example 4
Source File: AnnotationConfigUtils.java From spring4-understanding with Apache License 2.0 | 6 votes |
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) { if (metadata.isAnnotated(Lazy.class.getName())) { abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value")); } else if (abd.getMetadata() != metadata && abd.getMetadata().isAnnotated(Lazy.class.getName())) { abd.setLazyInit(attributesFor(abd.getMetadata(), Lazy.class).getBoolean("value")); } if (metadata.isAnnotated(Primary.class.getName())) { abd.setPrimary(true); } if (metadata.isAnnotated(DependsOn.class.getName())) { abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value")); } if (abd instanceof AbstractBeanDefinition) { AbstractBeanDefinition absBd = (AbstractBeanDefinition) abd; if (metadata.isAnnotated(Role.class.getName())) { absBd.setRole(attributesFor(metadata, Role.class).getNumber("value").intValue()); } if (metadata.isAnnotated(Description.class.getName())) { absBd.setDescription(attributesFor(metadata, Description.class).getString("value")); } } }
Example 5
Source File: MicroServiceCondition.java From micro-service with MIT License | 6 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { if (metadata.isAnnotated(Bean.class.getName())) { Map<String, Object> map = metadata.getAnnotationAttributes(Bean.class.getName()); if(!CollectionUtils.isEmpty(map)) { String[] names = (String[]) map.get("name"); if(ArrayUtils.isNotEmpty(names)) { for(String name : names) { if(StringUtils.isNotBlank(name) && name.endsWith("ConfigBean")) { return true; } } } } } return false; }
Example 6
Source File: AnnotationConfigUtils.java From spring-analysis-note with MIT License | 5 votes |
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) { AnnotationAttributes lazy = attributesFor(metadata, Lazy.class); if (lazy != null) { abd.setLazyInit(lazy.getBoolean("value")); } else if (abd.getMetadata() != metadata) { lazy = attributesFor(abd.getMetadata(), Lazy.class); if (lazy != null) { abd.setLazyInit(lazy.getBoolean("value")); } } if (metadata.isAnnotated(Primary.class.getName())) { abd.setPrimary(true); } AnnotationAttributes dependsOn = attributesFor(metadata, DependsOn.class); if (dependsOn != null) { abd.setDependsOn(dependsOn.getStringArray("value")); } AnnotationAttributes role = attributesFor(metadata, Role.class); if (role != null) { abd.setRole(role.getNumber("value").intValue()); } AnnotationAttributes description = attributesFor(metadata, Description.class); if (description != null) { abd.setDescription(description.getString("value")); } }
Example 7
Source File: AnnotationConfigUtils.java From java-technology-stack with MIT License | 5 votes |
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) { AnnotationAttributes lazy = attributesFor(metadata, Lazy.class); if (lazy != null) { abd.setLazyInit(lazy.getBoolean("value")); } else if (abd.getMetadata() != metadata) { lazy = attributesFor(abd.getMetadata(), Lazy.class); if (lazy != null) { abd.setLazyInit(lazy.getBoolean("value")); } } if (metadata.isAnnotated(Primary.class.getName())) { abd.setPrimary(true); } AnnotationAttributes dependsOn = attributesFor(metadata, DependsOn.class); if (dependsOn != null) { abd.setDependsOn(dependsOn.getStringArray("value")); } AnnotationAttributes role = attributesFor(metadata, Role.class); if (role != null) { abd.setRole(role.getNumber("value").intValue()); } AnnotationAttributes description = attributesFor(metadata, Description.class); if (description != null) { abd.setDescription(description.getString("value")); } }
Example 8
Source File: JuiserSpringSecurityCondition.java From juiser with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage matchMessage = ConditionMessage.empty(); boolean enabled = isSpringSecurityEnabled(context); if (metadata.isAnnotated(ConditionalOnJuiserSpringSecurityEnabled.class.getName())) { if (!enabled) { return ConditionOutcome.noMatch( ConditionMessage.forCondition(ConditionalOnJuiserSpringSecurityEnabled.class) .didNotFind("spring security enabled").atAll()); } matchMessage = matchMessage.andCondition(ConditionalOnJuiserSpringSecurityEnabled.class) .foundExactly("spring security enabled"); } if (metadata.isAnnotated(ConditionalOnJuiserSpringSecurityDisabled.class.getName())) { if (enabled) { return ConditionOutcome.noMatch( ConditionMessage.forCondition(ConditionalOnJuiserSpringSecurityDisabled.class) .didNotFind("spring security disabled").atAll()); } matchMessage = matchMessage.andCondition(ConditionalOnJuiserSpringSecurityDisabled.class) .didNotFind("spring security disabled").atAll(); } return ConditionOutcome.match(matchMessage); }
Example 9
Source File: OnProfileCondition.java From apollo with Apache License 2.0 | 5 votes |
private Set<String> retrieveAnnotatedProfiles(AnnotatedTypeMetadata metadata, String annotationType) { if (!metadata.isAnnotated(annotationType)) { return Collections.emptySet(); } MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(annotationType); if (attributes == null) { return Collections.emptySet(); } Set<String> profiles = Sets.newHashSet(); List<?> values = attributes.get("value"); if (values != null) { for (Object value : values) { if (value instanceof String[]) { Collections.addAll(profiles, (String[]) value); } else { profiles.add((String) value); } } } return profiles; }
Example 10
Source File: OnSearchPathLocatorPresent.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); List<String> types = CompositeUtils .getCompositeTypeList(context.getEnvironment()); // get EnvironmentRepository types from registered factories List<Class<? extends EnvironmentRepository>> repositoryTypes = new ArrayList<>(); for (String type : types) { String factoryName = CompositeUtils.getFactoryName(type, beanFactory); Type[] actualTypeArguments = CompositeUtils .getEnvironmentRepositoryFactoryTypeParams(beanFactory, factoryName); Class<? extends EnvironmentRepository> repositoryType; repositoryType = (Class<? extends EnvironmentRepository>) actualTypeArguments[0]; repositoryTypes.add(repositoryType); } boolean required = metadata .isAnnotated(ConditionalOnSearchPathLocator.class.getName()); boolean foundSearchPathLocator = repositoryTypes.stream() .anyMatch(SearchPathLocator.class::isAssignableFrom); if (required && !foundSearchPathLocator) { return ConditionOutcome.noMatch( ConditionMessage.forCondition(ConditionalOnSearchPathLocator.class) .notAvailable(SearchPathLocator.class.getTypeName())); } if (!required && foundSearchPathLocator) { return ConditionOutcome.noMatch(ConditionMessage .forCondition(ConditionalOnMissingSearchPathLocator.class) .available(SearchPathLocator.class.getTypeName())); } return ConditionOutcome.match(); }