List of usage examples for org.springframework.core.type AnnotationMetadata getAnnotationAttributes
@Nullable
default Map<String, Object> getAnnotationAttributes(String annotationName)
From source file:me.yanaga.winter.data.jpa.spring.config.metadata.EnableRepositoriesMetadata.java
private static List<String> getBasePackageClassesAttributes(AnnotationMetadata annotationMetadata) { Class<?>[] basePackageClasses = (Class<?>[]) annotationMetadata.getAnnotationAttributes(ANNOTATION_NAME) .get(BASE_PACKAGE_CLASSES);//from w ww . j av a 2s .c o m return Arrays.stream(basePackageClasses).map(k -> k.getPackage().getName()) .collect(collectingAndThen(toList(), ImmutableList::copyOf)); }
From source file:me.yanaga.winter.data.jpa.spring.config.metadata.EnableRepositoriesMetadata.java
private static List<String> getValueAttributes(AnnotationMetadata annotationMetadata) { return ImmutableList .copyOf((String[]) annotationMetadata.getAnnotationAttributes(ANNOTATION_NAME).get(VALUE)); }
From source file:me.yanaga.winter.data.jpa.spring.config.metadata.EnableRepositoriesMetadata.java
private static List<String> getBasePackagesAttributes(AnnotationMetadata annotationMetadata) { return ImmutableList .copyOf((String[]) annotationMetadata.getAnnotationAttributes(ANNOTATION_NAME).get(BASE_PACKAGES)); }
From source file:com.github.mjeanroy.springmvc.view.mustache.commons.ClassUtils.java
/** * Get annotation method value.//from ww w .ja va 2 s .c om * * @param importingClassMetadata Metadata. * @param annotationClass Annotation class to look for. * @param name Name of method. * @param defaultValue Default value if original value is null. * @param <T> Type of returned value. * @return Annotation value, or default value if original value is null. */ @SuppressWarnings("unchecked") public static <T> T getAnnotationValue(AnnotationMetadata importingClassMetadata, Class annotationClass, String name, T defaultValue) { Map<String, Object> attributes = importingClassMetadata.getAnnotationAttributes(annotationClass.getName()); return attributes != null && attributes.containsKey(name) ? (T) attributes.get(name) : defaultValue; }
From source file:com.github.mjeanroy.springmvc.uadetector.commons.ClassUtils.java
/** * Get annotation method value./*from www .j a va2 s. c om*/ * * @param importingClassMetadata Metadata. * @param annotationClass Annotation class to look for. * @param name Name of method. * @param defaultValue Default value if original value is null. * @param <T> Type of returned value. * @return Annotation value, or default value if original value is null. */ public static <T> T getAnnotationValue(AnnotationMetadata importingClassMetadata, Class annotationClass, String name, T defaultValue) { Map<String, Object> attributes = importingClassMetadata.getAnnotationAttributes(annotationClass.getName()); T value = (T) attributes.get(name); if (value == null) { value = defaultValue; } return value; }
From source file:nats.client.spring.NatsAnnotationsConfiguration.java
@Override public void setImportMetadata(AnnotationMetadata importMetadata) { final Map<String, Object> attributes = importMetadata .getAnnotationAttributes(EnableNatsAnnotations.class.getName()); natsRef = (String) attributes.get("value"); }
From source file:com.github.mjeanroy.springmvc.view.mustache.configuration.MustacheConfigurationTest.java
@Test public void it_should_select_configuration_class() { MustacheProvider provider = MustacheProvider.JMUSTACHE; Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("provider", provider); AnnotationMetadata annotationMetadata = mock(AnnotationMetadata.class); when(annotationMetadata.getAnnotationAttributes(EnableMustache.class.getName())).thenReturn(attributes); String[] imports = mustacheConfiguration.selectImports(annotationMetadata); assertThat(imports).isNotNull().isNotEmpty().hasSize(2).containsExactly( MustacheTemplateLoaderConfiguration.class.getName(), provider.configuration().getName()); }
From source file:com.github.mjeanroy.springmvc.view.mustache.commons.ClassUtilsTest.java
@Test public void it_should_get_default_annotation_values() { Map<String, Object> attributes = new HashMap<String, Object>(); String annotationName = Foo.class.getName(); AnnotationMetadata metadata = mock(AnnotationMetadata.class); when(metadata.getAnnotationAttributes(annotationName)).thenReturn(attributes); String value = ClassUtils.getAnnotationValue(metadata, Foo.class, "foo", "bar"); verify(metadata).getAnnotationAttributes(annotationName); assertThat(value).isNotNull().isNotEmpty().isEqualTo("bar"); }
From source file:com.github.mjeanroy.springmvc.view.mustache.commons.ClassUtilsTest.java
@Test public void it_should_get_annotation_values() { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("foo", "qux"); String annotationName = Foo.class.getName(); AnnotationMetadata metadata = mock(AnnotationMetadata.class); when(metadata.getAnnotationAttributes(annotationName)).thenReturn(attributes); String value = ClassUtils.getAnnotationValue(metadata, Foo.class, "foo", "bar"); verify(metadata).getAnnotationAttributes(annotationName); assertThat(value).isNotNull().isNotEmpty().isEqualTo("qux"); }
From source file:com.github.mjeanroy.springmvc.view.mustache.commons.ClassUtilsTest.java
@Test public void it_should_get_null_value() { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("foo", null); String annotationName = Foo.class.getName(); AnnotationMetadata metadata = mock(AnnotationMetadata.class); when(metadata.getAnnotationAttributes(annotationName)).thenReturn(attributes); String value = ClassUtils.getAnnotationValue(metadata, Foo.class, "foo", "bar"); verify(metadata).getAnnotationAttributes(annotationName); assertThat(value).isNull();/*ww w . java 2s . c o m*/ }