@Override public void setImportMetadata(AnnotationMetadata importMetadata) { AnnotationAttributes enabled = AnnotationAttributes.fromMap(importMetadata.getAnnotationAttributes( EnableBatchProcessing.class.getName(), false)); Assert.notNull(enabled, "@EnableBatchProcessing is not present on importing class " + importMetadata.getClassName()); }
private void setupDomain(AnnotationMBeanExporter exporter, AnnotationAttributes enableMBeanExport) { String defaultDomain = enableMBeanExport.getString("defaultDomain"); if (StringUtils.hasLength(defaultDomain) && this.environment != null) { defaultDomain = this.environment.resolvePlaceholders(defaultDomain); } if (StringUtils.hasText(defaultDomain)) { exporter.setDefaultDomain(defaultDomain); } }
@Bean(name = TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME) @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public AsyncAnnotationBeanPostProcessor asyncAdvisor() { Assert.notNull(this.enableAsync, "@EnableAsync annotation metadata was not injected"); AsyncAnnotationBeanPostProcessor bpp = new AsyncAnnotationBeanPostProcessor(); bpp.configure(this.executor, this.exceptionHandler); Class<? extends Annotation> customAsyncAnnotation = this.enableAsync.getClass("annotation"); if (customAsyncAnnotation != AnnotationUtils.getDefaultValue(EnableAsync.class, "annotation")) { bpp.setAsyncAnnotationType(customAsyncAnnotation); } bpp.setProxyTargetClass(this.enableAsync.getBoolean("proxyTargetClass")); bpp.setOrder(this.enableAsync.<Integer>getNumber("order")); return bpp; }
/** * Determine if the annotated field or method requires its dependency. * <p>A 'required' dependency means that autowiring should fail when no beans * are found. Otherwise, the autowiring process will simply bypass the field * or method when no beans are found. * @param ann the Autowired annotation * @return whether the annotation indicates that a dependency is required */ protected boolean determineRequiredStatus(AnnotationAttributes ann) { return (!ann.containsKey(this.requiredParameterName) || this.requiredParameterValue == ann.getBoolean(this.requiredParameterName)); }
/** * Construct a new {@link ContextConfigurationAttributes} instance for the * supplied {@link AnnotationAttributes} (parsed from a * {@link ContextConfiguration @ContextConfiguration} annotation) and * the {@linkplain Class test class} that declared them. * @param declaringClass the test class that declared {@code @ContextConfiguration} * @param annAttrs the annotation attributes from which to retrieve the attributes */ @SuppressWarnings("unchecked") public ContextConfigurationAttributes(Class<?> declaringClass, AnnotationAttributes annAttrs) { this(declaringClass, annAttrs.getStringArray("locations"), annAttrs.getClassArray("classes"), annAttrs.getBoolean("inheritLocations"), (Class<? extends ApplicationContextInitializer<?>>[]) annAttrs.getClassArray("initializers"), annAttrs.getBoolean("inheritInitializers"), annAttrs.getString("name"), annAttrs.getClass("loader")); }
/** * Store the supplied {@code value} in this map under the specified * {@code key}, unless a value is already stored under the key. * @param key the key under which to store the value * @param value the value to store * @return the current value stored in this map, or {@code null} if no * value was previously stored in this map * @see #get * @see #put * @since 4.2 */ @Override public Object putIfAbsent(String key, Object value) { Object obj = get(key); if (obj == null) { obj = put(key, value); } return obj; }
protected RegionBeanDefinitionMetadata using(AnnotationAttributes enableEntityDefinedRegionsAttributes) { return Optional.ofNullable(enableEntityDefinedRegionsAttributes) .map(it -> this.using(it.<ClientRegionShortcut>getEnum("clientRegionShortcut")) .using(it.getString("poolName")) .using(it.<RegionShortcut>getEnum("serverRegionShortcut")) .is(it.getBoolean("strict")) ) .orElse(this); }
@SuppressWarnings("unused") private IndexType resolveType(GemfirePersistentEntity<?> persistentEntity, GemfirePersistentProperty persistentProperty, AnnotationAttributes indexedAttributes, IndexType indexType) { IndexType resolvedIndexType = indexedAttributes.containsKey("type") ? indexedAttributes.getEnum("type") : null; return Optional.ofNullable(resolvedIndexType).orElse(indexType); } }
/** * {@inheritDoc} */ @Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { AnnotationAttributes enableAutoRegionLookupAttributes = getAnnotationAttributes(importingClassMetadata); Optional.ofNullable(resolveProperty(cacheProperty("enable-auto-region-lookup"), resolveProperty(propertyName("enable-auto-region-lookup"), enableAutoRegionLookupAttributes.getBoolean("enabled")))) .filter(Boolean.TRUE::equals) .ifPresent(enabled -> registerAutoRegionLookupBeanPostProcessor(registry)); }
@SuppressWarnings("all") protected int resolveEnableTransactionManagementOrder(AnnotationMetadata importMetadata) { AnnotationAttributes enableTransactionManagementAttributes = resolveEnableTransactionManagementAttributes(importMetadata); Integer order = enableTransactionManagementAttributes.getNumber("order"); return Optional.ofNullable(order) .filter(it -> !(it == Integer.MAX_VALUE || it == Integer.MIN_VALUE)) .orElseThrow(() -> newIllegalArgumentException( "The @%1$s(order) attribute value [%2$s] must be explicitly set to a value" + " other than Integer.MAX_VALUE or Integer.MIN_VALUE", EnableTransactionManagement.class.getSimpleName(), String.valueOf(order))); }
@Override public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource configurationSource) { String redisTemplateRef = configurationSource.getAttribute("redisTemplateRef").get(); if (StringUtils.hasText(redisTemplateRef)) { redisKeyValueAdapterProps.add("enableKeyspaceEvents", attributes.getEnum("enableKeyspaceEvents")); redisKeyValueAdapterProps.add("keyspaceNotificationsConfigParameter", attributes.getString("keyspaceNotificationsConfigParameter")); redisKeyValueAdapterDefinition.setPropertyValues(redisKeyValueAdapterProps);
private PropertySource createPropertySource(AnnotationAttributes attributes, ConfigurableEnvironment environment, ResourceLoader resourceLoader, EncryptablePropertyResolver resolver, EncryptablePropertyFilter propertyFilter, List<PropertySourceLoader> loaders) throws Exception { String name = generateName(attributes.getString("name")); String[] locations = attributes.getStringArray("value"); boolean ignoreResourceNotFound = attributes.getBoolean("ignoreResourceNotFound"); CompositePropertySource compositePropertySource = new CompositePropertySource(name); Assert.isTrue(locations.length > 0, "At least one @PropertySource(value) location is required"); for (String location : locations) { String resolvedLocation = environment.resolveRequiredPlaceholders(location); Resource resource = resourceLoader.getResource(resolvedLocation); if (!resource.exists()) { if (!ignoreResourceNotFound) { throw new IllegalStateException(String.format("Encryptable Property Source '%s' from location: %s Not Found", name, resolvedLocation)); } else { log.info("Ignoring NOT FOUND Encryptable Property Source '{}' from locations: {}", name, resolvedLocation); } } else { String actualName = name + "#" + resolvedLocation; loadPropertySource(loaders, resource, actualName) .ifPresent(psources -> psources.forEach(compositePropertySource::addPropertySource)); } } return new EncryptableEnumerablePropertySourceWrapper<>(compositePropertySource, resolver, propertyFilter); }
private void setupServer(AnnotationMBeanExporter exporter, AnnotationAttributes enableMBeanExport) { String server = enableMBeanExport.getString("server"); if (StringUtils.hasLength(server) && this.environment != null) { server = this.environment.resolvePlaceholders(server); } if (StringUtils.hasText(server)) { Assert.state(this.beanFactory != null, "No BeanFactory set"); exporter.setServer(this.beanFactory.getBean(server, MBeanServer.class)); } else { SpecificPlatform specificPlatform = SpecificPlatform.get(); if (specificPlatform != null) { MBeanServer mbeanServer = specificPlatform.getMBeanServer(); if (mbeanServer != null) { exporter.setServer(mbeanServer); } } } }
Assert.state(bean != null, "No @Bean annotation attributes"); List<String> names = new ArrayList<>(Arrays.asList(bean.getStringArray("name"))); String beanName = (!names.isEmpty() ? names.remove(0) : methodName); Autowire autowire = bean.getEnum("autowire"); if (autowire.isAutowire()) { beanDef.setAutowireMode(autowire.value()); boolean autowireCandidate = bean.getBoolean("autowireCandidate"); if (!autowireCandidate) { beanDef.setAutowireCandidate(false); String initMethodName = bean.getString("initMethod"); if (StringUtils.hasText(initMethodName)) { beanDef.setInitMethodName(initMethodName); String destroyMethodName = bean.getString("destroyMethod"); beanDef.setDestroyMethodName(destroyMethodName); AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(metadata, Scope.class); if (attributes != null) { beanDef.setScope(attributes.getString("value")); proxyMode = attributes.getEnum("proxyMode"); if (proxyMode == ScopedProxyMode.DEFAULT) { proxyMode = ScopedProxyMode.NO; configClass.getMetadata().getClassName(), beanName));
@Override public String[] selectImports(AnnotationMetadata importingClassMetadata) { Class<?> annotationType = EnableBatchProcessing.class; AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes( annotationType.getName(), false)); Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", annotationType.getSimpleName(), importingClassMetadata.getClassName())); String[] imports; if (attributes.containsKey("modular") && attributes.getBoolean("modular")) { imports = new String[] { ModularBatchConfiguration.class.getName() }; } else { imports = new String[] { SimpleBatchConfiguration.class.getName() }; } return imports; }
public final String[] selectImports(AnnotationMetadata importingClassMetadata) { Class<EnableGlobalMethodSecurity> annoType = EnableGlobalMethodSecurity.class; Map<String, Object> annotationAttributes = importingClassMetadata .getAnnotationAttributes(annoType.getName(), false); AnnotationAttributes attributes = AnnotationAttributes .fromMap(annotationAttributes); Assert.notNull(attributes, () -> String.format( "@%s is not present on importing class '%s' as expected", annoType.getSimpleName(), importingClassMetadata.getClassName())); .resolveClassName(importingClassMetadata.getClassName(), ClassUtils.getDefaultClassLoader()); boolean skipMethodSecurityConfiguration = GlobalMethodSecurityConfiguration.class .isAssignableFrom(importingClass); AdviceMode mode = attributes.getEnum("mode"); boolean isProxy = AdviceMode.PROXY == mode; String autoProxyClassName = isProxy ? AutoProxyRegistrar.class .getName(); boolean jsr250Enabled = attributes.getBoolean("jsr250Enabled");
@Override public void setImportMetadata(AnnotationMetadata importMetadata) { Map<String, Object> attributeMap = importMetadata .getAnnotationAttributes(EnableHazelcastHttpSession.class.getName()); AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap); this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds"); String sessionMapNameValue = attributes.getString("sessionMapName"); if (StringUtils.hasText(sessionMapNameValue)) { this.sessionMapName = sessionMapNameValue; } this.hazelcastFlushMode = attributes.getEnum("hazelcastFlushMode"); }
Assert.notNull(localSqlConfig, "Local @SqlConfig must not be null"); Assert.notNull(testClass, "testClass must not be null"); for (String key : attributes.keySet()) { Object value = AnnotationUtils.getValue(localSqlConfig, key); if (value != null) { attributes.put(key, value); this.dataSource = attributes.getString("dataSource"); this.transactionManager = attributes.getString("transactionManager"); this.transactionMode = getEnum(attributes, "transactionMode", TransactionMode.DEFAULT, TransactionMode.INFERRED); this.encoding = attributes.getString("encoding"); this.separator = getString(attributes, "separator", ScriptUtils.DEFAULT_STATEMENT_SEPARATOR); this.commentPrefix = getString(attributes, "commentPrefix", ScriptUtils.DEFAULT_COMMENT_PREFIX);
String name = propertySource.getString("name"); if (!StringUtils.hasLength(name)) { name = null; String encoding = propertySource.getString("encoding"); if (!StringUtils.hasLength(encoding)) { encoding = null; String[] locations = propertySource.getStringArray("value"); Assert.isTrue(locations.length > 0, "At least one @PropertySource(value) location is required"); boolean ignoreResourceNotFound = propertySource.getBoolean("ignoreResourceNotFound"); Class<? extends PropertySourceFactory> factoryClass = propertySource.getClass("factory"); PropertySourceFactory factory = (factoryClass == PropertySourceFactory.class ? DEFAULT_PROPERTY_SOURCE_FACTORY : BeanUtils.instantiateClass(factoryClass));