List of usage examples for org.springframework.core.annotation AnnotationUtils findAnnotation
@Nullable public static <A extends Annotation> A findAnnotation(Class<?> clazz, @Nullable Class<A> annotationType)
From source file:com.liferay.portal.spring.extender.internal.bean.ApplicationContextServicePublisher.java
protected Set<Class<?>> getInterfaces(Object object) throws Exception { Class<? extends Object> clazz = getTargetClass(object); OSGiBeanProperties osgiBeanProperties = AnnotationUtils.findAnnotation(clazz, OSGiBeanProperties.class); if (osgiBeanProperties == null) { return new HashSet<>(Arrays.asList(ReflectionUtil.getInterfaces(object))); }//from www. j av a2 s. c om Class<?>[] serviceClasses = osgiBeanProperties.service(); if (serviceClasses.length == 0) { return new HashSet<>(Arrays.asList(ReflectionUtil.getInterfaces(object))); } for (Class<?> serviceClazz : serviceClasses) { serviceClazz.cast(object); } return new HashSet<>(Arrays.asList(osgiBeanProperties.service())); }
From source file:py.una.pol.karaku.test.cucumber.DatabasePopulatorCucumberExecutionListener.java
/** * Este mtodo carga los archivos SQL tanto de la clase como del mtodo. * <p>// w w w . j av a 2 s. c o m * TODO ver la posibilidad de mover los archivos de clase a * {@link #beforeTestClass(TestContext)} y eliminarlos despus en * {@link #afterTestClass(TestContext)} * </p> * {@inheritDoc} * * @param testContext * contexto del test. * @throws Exception * si no se encuentra el archivo se lanza una * {@link IOException} */ @Override public void beforeTestMethod(TestContext testContext) throws Exception { super.beforeTestMethod(testContext); SQLFiles sqlClassFiles = AnnotationUtils.findAnnotation(testContext.getTestMethod(), SQLFiles.class); executeSQLFiles(testContext, sqlClassFiles); }
From source file:com.expedia.seiso.domain.meta.ItemMetaImpl.java
private void initProjections() { val projectionsAnn = AnnotationUtils.findAnnotation(itemClass, Projections.class); if (projectionsAnn == null) { return;//from w w w .jav a 2 s . co m } val projectionsAnnArr = projectionsAnn.value(); for (val projectionAnn : projectionsAnnArr) { val apiVersions = projectionAnn.apiVersions(); for (val apiVersion : apiVersions) { val key = new Key(apiVersion, projectionAnn.cardinality(), projectionAnn.name()); val projection = new ProjectionParser(projectionAnn.paths()).parse(); log.debug("Adding projection: key={}, projection={}", key, projection); projections.put(key, projection); } } }
From source file:org.xmatthew.spy2servers.config.ComponentPostProcessor.java
private void detectChannelAwareComponent(Object bean) throws RuntimeException { Class<?> beanClass = this.getBeanClass(bean); MessageAlertChannelActiveAwareComponent ChannelAwareComponentAnnotation = AnnotationUtils .findAnnotation(beanClass, MessageAlertChannelActiveAwareComponent.class); if (ChannelAwareComponentAnnotation != null) { if (bean instanceof org.xmatthew.spy2servers.core.MessageAlertChannelActiveAwareComponent) { org.xmatthew.spy2servers.core.MessageAlertChannelActiveAwareComponent channelAwareComponent; channelAwareComponent = (org.xmatthew.spy2servers.core.MessageAlertChannelActiveAwareComponent) bean; String name = ChannelAwareComponentAnnotation.name(); if (StringUtils.isNotBlank(name)) { channelAwareComponent.setName(name); }// w w w. ja v a2 s .c om } else { throw new RuntimeException("@MessageAlertChannelActiveAwareComponent mark class must implement " + "org.xmatthew.spy2servers.core.MessageAlertChannelActiveAwareComponent interface"); } } }
From source file:org.vbossica.springbox.annotation.AnnotatedMethodResolver.java
/** * Traverses the {@code bean} in search for annotated methods. Calls the * {@link #doWithAnnotatedMethod(String, Object, Method, Annotation)} for every method found. * * @param beanName the name of the Spring bean * @param bean the Spring bean itself//from w ww. j a va 2 s . co m * @see #doWithAnnotatedMethod(String, Object, java.lang.reflect.Method, java.lang.annotation.Annotation) */ public void traverse(final String beanName, final Object bean) { logger.info("traversing bean " + beanName); Class<?> handlerType = bean.getClass(); Class<?>[] handlerTypes = Proxy.isProxyClass(handlerType) ? handlerType.getInterfaces() : new Class<?>[] { handlerType }; for (final Class<?> currentHandlerType : handlerTypes) { ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() { public void doWith(Method method) { Method specificMethod = ClassUtils.getMostSpecificMethod(method, currentHandlerType); A annotation = AnnotationUtils.findAnnotation(method, annotationClass); if (annotation != null) { doWithAnnotatedMethod(beanName, bean, specificMethod, annotation); } } }, ReflectionUtils.NON_BRIDGED_METHODS); } }
From source file:org.musicrecital.dao.hibernate.UserDaoHibernate.java
/** * {@inheritDoc}// ww w .j a va 2 s. c om */ public String getUserPassword(Long userId) { JdbcTemplate jdbcTemplate = new JdbcTemplate(SessionFactoryUtils.getDataSource(getSessionFactory())); Table table = AnnotationUtils.findAnnotation(User.class, Table.class); return jdbcTemplate.queryForObject("select password from " + table.name() + " where id=?", String.class, userId); }
From source file:py.una.pol.karaku.test.util.transaction.DatabasePopulatorExecutionListener.java
/** * Este mtodo carga los archivos SQL tanto de la clase como del mtodo. * <p>//from w w w. ja v a 2 s . co m * TODO ver la posibilidad de mover los archivos de clase a * {@link #beforeTestClass(TestContext)} y eliminarlos despus en * {@link #afterTestClass(TestContext)} * </p> * {@inheritDoc} * * @param testContext * contexto del test. * @throws Exception * si no se encuentra el archivo se lanza una * {@link IOException} */ @Override public void beforeTestMethod(TestContext testContext) throws Exception { super.beforeTestMethod(testContext); SQLFiles sqlClassFiles = AnnotationUtils.findAnnotation(testContext.getTestClass(), SQLFiles.class); executeSQLFiles(testContext, sqlClassFiles); SQLFiles sqlFiles = AnnotationUtils.findAnnotation(testContext.getTestMethod(), SQLFiles.class); executeSQLFiles(testContext, sqlFiles); }
From source file:org.openhie.openempi.dao.hibernate.UserDaoHibernate.java
/** * {@inheritDoc}/*w w w . ja va 2 s. co m*/ */ public String getUserPassword(String username) { ValidationUtil.sanityCheckFieldName(username); SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate( SessionFactoryUtils.getDataSource(getSessionFactory())); Table table = AnnotationUtils.findAnnotation(User.class, Table.class); return jdbcTemplate.queryForObject("select password from " + table.name() + " where username=?", String.class, username); }
From source file:curly.commons.github.GitHubAuthenticationMethodHandler.java
private <T extends Annotation> T findMethodAnnotation(Class<T> annotationClass, MethodParameter parameter) { T annotation = parameter.getParameterAnnotation(annotationClass); if (annotation != null) { return annotation; }/* w w w . ja v a 2 s. c om*/ Annotation[] annotationsToSearch = parameter.getParameterAnnotations(); for (Annotation toSearch : annotationsToSearch) { annotation = AnnotationUtils.findAnnotation(toSearch.annotationType(), annotationClass); if (annotation != null) { return annotation; } } return null; }
From source file:com.github.springtestdbunit.DbUnitRunner.java
private <T extends Annotation> Collection<T> getAnnotations(DbUnitTestContext testContext, Class<T> annotationType) { List<T> annotations = new ArrayList<T>(); addAnnotationToList(annotations,//w w w . j a v a2 s . c om AnnotationUtils.findAnnotation(testContext.getTestClass(), annotationType)); addAnnotationToList(annotations, AnnotationUtils.findAnnotation(testContext.getTestMethod(), annotationType)); return annotations; }