Example usage for org.springframework.core.annotation AnnotationAttributes getStringArray

List of usage examples for org.springframework.core.annotation AnnotationAttributes getStringArray

Introduction

In this page you can find the example usage for org.springframework.core.annotation AnnotationAttributes getStringArray.

Prototype

public String[] getStringArray(String attributeName) 

Source Link

Document

Get the value stored under the specified attributeName as an array of strings.

Usage

From source file:lodsve.core.condition.OnJndiCondition.java

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    AnnotationAttributes annotationAttributes = AnnotationAttributes
            .fromMap(metadata.getAnnotationAttributes(ConditionalOnJndi.class.getName()));
    String[] locations = annotationAttributes.getStringArray("value");
    try {//from w  ww.j  a  va 2s  .c om
        return getMatchOutcome(locations);
    } catch (NoClassDefFoundError ex) {
        return ConditionOutcome.noMatch("JNDI class not found");
    }
}

From source file:org.spring.guice.annotation.GuiceModuleRegistrar.java

private String[] getPatterns(AnnotationAttributes filterAttributes) {

    try {/*from  w  w  w. j a  v a2  s  .com*/
        return filterAttributes.getStringArray("pattern");
    } catch (IllegalArgumentException o_O) {
        return new String[0];
    }
}

From source file:org.wallride.autoconfigure.WebAdminComponentScanRegistrar.java

private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
    AnnotationAttributes attributes = AnnotationAttributes
            .fromMap(metadata.getAnnotationAttributes(WebAdminComponentScan.class.getName()));
    String[] value = attributes.getStringArray("value");
    String[] basePackages = attributes.getStringArray("basePackages");
    Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
    if (!ObjectUtils.isEmpty(value)) {
        Assert.state(ObjectUtils.isEmpty(basePackages),
                "@WebAdminComponentScan basePackages and value attributes are mutually exclusive");
    }/*from   www  .  java  2s .  com*/
    Set<String> packagesToScan = new LinkedHashSet<String>();
    packagesToScan.addAll(Arrays.asList(value));
    packagesToScan.addAll(Arrays.asList(basePackages));
    for (Class<?> basePackageClass : basePackageClasses) {
        packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
    }
    if (packagesToScan.isEmpty()) {
        return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName()));
    }
    return packagesToScan;
}

From source file:org.wallride.autoconfigure.WebGuestComponentScanRegistrar.java

private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
    AnnotationAttributes attributes = AnnotationAttributes
            .fromMap(metadata.getAnnotationAttributes(WebGuestComponentScan.class.getName()));
    String[] value = attributes.getStringArray("value");
    String[] basePackages = attributes.getStringArray("basePackages");
    Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
    if (!ObjectUtils.isEmpty(value)) {
        Assert.state(ObjectUtils.isEmpty(basePackages),
                "@WebGuestComponentScan basePackages and value attributes are mutually exclusive");
    }//from w ww  .  j  a  v  a 2  s.  c  om
    Set<String> packagesToScan = new LinkedHashSet<String>();
    packagesToScan.addAll(Arrays.asList(value));
    packagesToScan.addAll(Arrays.asList(basePackages));
    for (Class<?> basePackageClass : basePackageClasses) {
        packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
    }
    if (packagesToScan.isEmpty()) {
        return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName()));
    }
    return packagesToScan;
}

From source file:org.spring.guice.annotation.GuiceModuleRegistrar.java

private Set<Pattern> parsePatterns(AnnotationMetadata annotation, String attributeName) {
    Set<Pattern> result = new HashSet<Pattern>();
    AnnotationAttributes attributes = new AnnotationAttributes(
            annotation.getAnnotationAttributes(GuiceModule.class.getName()));
    String[] filters = attributes.getStringArray(attributeName);

    for (String filter : filters) {
        result.add(Pattern.compile(filter));
    }/*from  w w  w.ja  v  a  2 s.co  m*/

    return result;
}

From source file:org.spring.guice.annotation.GuiceModuleRegistrar.java

private Set<String> parseNames(AnnotationMetadata annotation, String attributeName) {
    Set<String> result = new HashSet<String>();
    AnnotationAttributes attributes = new AnnotationAttributes(
            annotation.getAnnotationAttributes(GuiceModule.class.getName()));
    String[] filters = attributes.getStringArray(attributeName);

    for (String filter : filters) {
        result.add(filter);//from w ww.  j av  a  2  s  . co m
    }

    return result;
}

From source file:org.zalando.baigan.proxy.ConfigurationBeanDefinitionRegistrar.java

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
        BeanDefinitionRegistry registry) {
    final AnnotationAttributes annotationAttributes = AnnotationAttributes
            .fromMap(importingClassMetadata.getAnnotationAttributes(ConfigurationServiceScan.class.getName()));

    if (annotationAttributes == null || annotationAttributes.isEmpty()) {
        throw new IllegalArgumentException("ConfigurationServiceScan requires at least 1 scan package.");
    }/* w  ww . ja  v a  2s.  c  o  m*/

    final List<String> basePackages = Lists.newArrayList();
    basePackages.addAll(Arrays.asList(annotationAttributes.getStringArray("value")));
    basePackages.addAll(Arrays.asList(annotationAttributes.getStringArray("basePackages")));

    final Set<String> saneSet = basePackages.stream().filter(str -> !StringUtils.isEmpty(str))
            .collect(Collectors.toSet());

    createAndRegisterBeanDefinitions(saneSet, registry);

}

From source file:org.mybatis.spring.annotation.MapperScannerRegistrar.java

/**
 * {@inheritDoc}//from w w w  .j a v  a2  s .c o m
 */
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
        BeanDefinitionRegistry registry) {

    AnnotationAttributes annoAttrs = AnnotationAttributes
            .fromMap(importingClassMetadata.getAnnotationAttributes(MapperScan.class.getName()));
    ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);

    // this check is needed in Spring 3.1
    if (resourceLoader != null) {
        scanner.setResourceLoader(resourceLoader);
    }

    Class<? extends Annotation> annotationClass = annoAttrs.getClass("annotationClass");
    if (!Annotation.class.equals(annotationClass)) {
        scanner.setAnnotationClass(annotationClass);
    }

    Class<?> markerInterface = annoAttrs.getClass("markerInterface");
    if (!Class.class.equals(markerInterface)) {
        scanner.setMarkerInterface(markerInterface);
    }

    Class<? extends BeanNameGenerator> generatorClass = annoAttrs.getClass("nameGenerator");
    if (!BeanNameGenerator.class.equals(generatorClass)) {
        scanner.setBeanNameGenerator(BeanUtils.instantiateClass(generatorClass));
    }

    Class<? extends MapperFactoryBean> mapperFactoryBeanClass = annoAttrs.getClass("factoryBean");
    if (!MapperFactoryBean.class.equals(mapperFactoryBeanClass)) {
        scanner.setMapperFactoryBean(BeanUtils.instantiateClass(mapperFactoryBeanClass));
    }

    scanner.setSqlSessionTemplateBeanName(annoAttrs.getString("sqlSessionTemplateRef"));
    scanner.setSqlSessionFactoryBeanName(annoAttrs.getString("sqlSessionFactoryRef"));

    List<String> basePackages = new ArrayList<String>();
    for (String pkg : annoAttrs.getStringArray("value")) {
        if (StringUtils.hasText(pkg)) {
            basePackages.add(pkg);
        }
    }
    for (String pkg : annoAttrs.getStringArray("basePackages")) {
        if (StringUtils.hasText(pkg)) {
            basePackages.add(pkg);
        }
    }
    for (Class<?> clazz : annoAttrs.getClassArray("basePackageClasses")) {
        basePackages.add(ClassUtils.getPackageName(clazz));
    }
    scanner.registerFilters();
    scanner.doScan(StringUtils.toStringArray(basePackages));
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.java

/**
 * Return any exclusions that limit the candidate configurations.
 * @param metadata the source metadata//ww w .  ja  va 2s  . c o m
 * @param attributes the {@link #getAttributes(AnnotationMetadata) annotation
 * attributes}
 * @return exclusions or an empty set
 */
protected Set<String> getExclusions(AnnotationMetadata metadata, AnnotationAttributes attributes) {
    Set<String> excluded = new LinkedHashSet<>();
    excluded.addAll(asList(attributes, "exclude"));
    excluded.addAll(Arrays.asList(attributes.getStringArray("excludeName")));
    excluded.addAll(getExcludeAutoConfigurationsProperty());
    return excluded;
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.java

protected final List<String> asList(AnnotationAttributes attributes, String name) {
    String[] value = attributes.getStringArray(name);
    return Arrays.asList((value != null) ? value : new String[0]);
}