List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:org.vulpe.commons.util.VulpeReflectUtil.java
/** * Checks if class is noted by <code>annotationClass</code>. * * @param <T>/*from w w w. j a v a2s . c om*/ * @param annotationClass * @param clazz * @return */ public static <T extends Annotation> T getAnnotationInClass(final Class<T> annotationClass, final Class<?> clazz) { Class<?> baseClass = clazz; while (baseClass != null && !baseClass.equals(Object.class)) { if (baseClass.isAnnotationPresent(annotationClass)) { return baseClass.getAnnotation(annotationClass); } for (Class<?> iClass : baseClass.getInterfaces()) { final T tAnnotation = getAnnotationInClass(annotationClass, iClass); if (tAnnotation != null) { return tAnnotation; } } baseClass = baseClass.getSuperclass(); } return null; }
From source file:org.hako.dao.mapper.AnnotationMapper.java
public EntityMeta setUp(Class<?> clazz) { if (!clazz.isAnnotationPresent(Entity.class)) { throw new IllegalArgumentException("class must with Entity annotation"); }/*ww w. ja va2 s . co m*/ Entity entityAnno = clazz.getAnnotation(Entity.class); String tableName = StringUtils.defaultIfBlank(entityAnno.tableName(), clazz.getSimpleName()); String alias = StringUtils.defaultIfBlank(entityAnno.tableAlias(), tableName); EntityName entityName = new EntityName(tableName, alias); // setup fields List<FieldMeta> fields = new ArrayList<FieldMeta>(); for (java.lang.reflect.Field f : clazz.getFields()) { if (f.isAnnotationPresent(Field.class)) { String propertyName = f.getName(); Field fieldAnno = f.getAnnotation(Field.class); String columnName = StringUtils.defaultIfBlank(fieldAnno.columnName(), toDashSeparated(propertyName)); fields.add(new FieldMeta(columnName, propertyName, f.isAnnotationPresent(Id.class))); } } return new EntityMeta(entityName, fields); }
From source file:org.jacpfx.spring.processor.StatelessScopedPostProcessor.java
@Override public void postProcessBeanFactory(final ConfigurableListableBeanFactory factory) throws BeansException { final String[] stateless = factory.getBeanNamesForType(CallbackComponent.class); for (final String beanName : stateless) { final BeanDefinition beanDefinition = factory.getBeanDefinition(beanName); final String className = beanDefinition.getBeanClassName(); try {/*from www . j ava2s. c om*/ Class<?> clazz = Class.forName(className); if (clazz.isAnnotationPresent(Stateless.class)) beanDefinition.setScope("prototype"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
From source file:com.cognifide.slice.persistence.impl.serializer.RecursiveSerializer.java
@Override public boolean accepts(Class<?> clazz) { return clazz.isAnnotationPresent(SliceResource.class); }
From source file:org.jboss.spring.cluster.CachePostProcessor.java
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { Class<?> beanClass = bean.getClass(); if (beanClass.isAnnotationPresent(getMarkerAnnotation())) { Object result = get(beanName); if (result != null) { return result; } else {/*w w w . ja v a 2s.co m*/ return put(beanName, bean); } } return bean; }
From source file:fm.pattern.tokamak.server.service.DataServiceImpl.java
private <T> String entity(Class<T> entity) { if (entity.isAnnotationPresent(Entity.class)) { return entity.getAnnotation(Entity.class).name(); }/*from w w w . java 2s. c o m*/ throw new IllegalStateException(entity.getClass().getSimpleName() + " must have an @Entity annotation configured with the entity name."); }
From source file:cn.lambdalib.s11n.SerializationHelper.java
public boolean isS11nType(Class type) { return type.isEnum() || type.isAnnotationPresent(SerializeType.class) || serializeTypes.contains(type) || serializeTypes.stream().anyMatch(c -> c.isAssignableFrom(type)); }
From source file:org.vaadin.spring.navigator.Presenter.java
private String getViewName() { String result = null;/*ww w .j av a2 s . co m*/ Class<?> clazz = getClass(); if (clazz.isAnnotationPresent(VaadinPresenter.class)) { VaadinPresenter vp = clazz.getAnnotation(VaadinPresenter.class); result = vp.viewName(); } else { logger.error("Presenter [{}] does not have a @VaadinPresenter annotation!", clazz.getSimpleName()); } return result; }
From source file:dpfmanager.shell.application.launcher.ui.GuiLauncher.java
private void initWorkbench(final Stage stage, final Launcher<ClassPathXmlApplicationContext> launcher, final Class<? extends FXWorkbench> workbenchHandler) { if (workbenchHandler.isAnnotationPresent(Workbench.class)) { this.workbench = createWorkbench(launcher, workbenchHandler); workbench.init(launcher, stage); postInit(stage);//from w ww . ja v a 2 s . com } else { throw new AnnotationNotFoundException("no @Workbench annotation found on class"); } }
From source file:io.wcm.config.core.impl.ApplicationImplementationPicker.java
private Class<?> pickFirstWithoutApplication(Class<?>[] implementationsTypes) { for (Class<?> clazz : implementationsTypes) { if (!clazz.isAnnotationPresent(io.wcm.config.spi.annotations.Application.class)) { return clazz; }/*from ww w. j av a 2s. c o m*/ } return null; }