List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:org.magtured.common.component.MemoryIdManager.java
@Override public void registerType(Class<? extends WithId> type) throws NullPointerException, IllegalArgumentException { notNull(type);//from w w w.ja v a 2s.com IdConfiguration idConf = type.getAnnotation(IdConfiguration.class); if (idConf == null) throw new IllegalArgumentException( "Missing annotation " + IdConfiguration.class.getName() + " on " + type.getName()); String prefix = idConf.prefix(); registerType(type, prefix); }
From source file:cern.molr.mole.impl.RunnableSpringMole.java
@Override public List<Method> discover(Class<?> classType) { if (null == classType) { throw new IllegalArgumentException("Class type cannot be null"); }//from w w w . j av a 2 s . c o m if (Runnable.class.isAssignableFrom(classType) && classType.getAnnotation(MoleSpringConfiguration.class) != null) { try { return Collections.singletonList(classType.getMethod("run")); } catch (NoSuchMethodException e) { e.printStackTrace(); } } return Collections.emptyList(); }
From source file:com.joshlong.activiti.coordinator.aop.ActivitiStateAnnotationBeanPostProcessor.java
public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { // first sift through and get all the methods // then get all the annotations // then build the metadata and register the metadata final Class<?> targetClass = AopUtils.getTargetClass(bean); final ActivitiComponent component = targetClass.getAnnotation(ActivitiComponent.class); ReflectionUtils.doWithMethods(targetClass, new ReflectionUtils.MethodCallback() { @SuppressWarnings("unchecked") public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { ActivitiState activitiState = AnnotationUtils.getAnnotation(method, ActivitiState.class); String processName = component.processKey(); if (StringUtils.hasText(activitiState.processName())) { processName = activitiState.processName(); }//w w w. j a v a2 s .c o m String stateName = activitiState.stateName(); if (!StringUtils.hasText(stateName)) { stateName = activitiState.value(); } Assert.notNull(stateName, "You must provide a stateName!"); Map<Integer, String> vars = new HashMap<Integer, String>(); Annotation[][] paramAnnotationsArray = method.getParameterAnnotations(); int ctr = 0; int pvMapIndex = -1; int procIdIndex = -1; for (Annotation[] paramAnnotations : paramAnnotationsArray) { ctr += 1; for (Annotation pa : paramAnnotations) { if (pa instanceof ProcessVariable) { ProcessVariable pv = (ProcessVariable) pa; String pvName = pv.value(); vars.put(ctr, pvName); } else if (pa instanceof ProcessVariables) { pvMapIndex = ctr; } else if (pa instanceof ProcessId) { procIdIndex = ctr; } } } ActivitiStateHandlerRegistration registration = new ActivitiStateHandlerRegistration(vars, method, bean, stateName, beanName, pvMapIndex, procIdIndex, processName); registry.registerActivitiStateHandler(registration); } }, new ReflectionUtils.MethodFilter() { public boolean matches(Method method) { return null != AnnotationUtils.getAnnotation(method, ActivitiState.class); } }); return bean; }
From source file:org.develspot.data.orientdb.mapping.BasicOrientPersistentEntity.java
public BasicOrientPersistentEntity(TypeInformation<T> information) { super(information); Class<T> rawType = information.getType(); //default//from w w w . jav a2s .c o m this.vertexType = rawType.getSimpleName(); //check if annotation is present if (rawType.isAnnotationPresent(VertexType.class)) { VertexType annotation = rawType.getAnnotation(VertexType.class); if (!annotation.value().isEmpty()) { this.vertexType = annotation.value(); } } }
From source file:com.ebiz.modules.persistence.repository.support.MyRepositoryImpl.java
@Override @Transactional//from w w w.j av a2 s . c o m public void delete(T entity) { logger.trace("----->MyRepositoryImpl.delete(T entity)"); Assert.notNull(entity, "The entity must not be null!"); Class<?> clazz = entity.getClass(); if (clazz.isAnnotationPresent(LogicallyDelete.class)) { LogicallyDelete logicallyDelete = clazz.getAnnotation(LogicallyDelete.class); Object value = ConvertUtils.convert(logicallyDelete.value(), logicallyDelete.type().getClazz()); Field field = ReflectionUtils.findField(entity.getClass(), logicallyDelete.name()); ReflectionUtils.makeAccessible(field); ReflectionUtils.setField(field, entity, value); save(entity); } else { super.delete(entity); } }
From source file:com.ebiz.modules.persistence.repository.support.MyRepositoryImpl.java
@Override @Transactional/*from ww w . j a v a2s.co m*/ public void delete(ID[] ids) { logger.trace("----->MyRepositoryImpl.delete(ID[] ids)"); String qlString; Class<T> clazz = ei.getJavaType(); if (clazz.isAnnotationPresent(LogicallyDelete.class)) { LogicallyDelete logicallyDelete = clazz.getAnnotation(LogicallyDelete.class); Object value = ConvertUtils.convert(logicallyDelete.value(), logicallyDelete.type().getClazz()); qlString = String.format(STATE_DELETE_QUERY_STRING, ei.getEntityName(), logicallyDelete.name(), value); } else { qlString = String.format(DELETE_QUERY_STRING, ei.getEntityName()); } logger.debug("......qlString:={}", qlString); Query query = em.createQuery(qlString); query.setParameter(1, Arrays.asList(ids)); query.executeUpdate(); }
From source file:edu.rit.flick.config.FileArchiverExtensionRegistry.java
/** * Constructs the file archiver extension registry and scans for * FileArchiver classes./*from w ww . j a v a2 s . c o m*/ */ private FileArchiverExtensionRegistry() { registry = new HashMap<String, FileDeflatorInflator>(); deflationOptionSets = new ArrayList<DeflationOptionSet>(); inflationOptionSets = new ArrayList<InflationOptionSet>(); final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false) { @Override protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { return beanDefinition.getMetadata().isIndependent(); } }; scanner.addIncludeFilter(new AnnotationTypeFilter(RegisterFileDeflatorInflator.class)); for (final BeanDefinition bd : scanner.findCandidateComponents("*")) { try { final Class<?> cl = Class.forName(bd.getBeanClassName()); final RegisterFileDeflatorInflator fileDIP = cl.getAnnotation(RegisterFileDeflatorInflator.class); if (fileDIP != null) registerFileArchiverExtensions(fileDIP); } catch (Exception e) { } } }
From source file:com.sdl.odata.datasource.jpa.JPADatasourceProvider.java
@Override public boolean isSuitableFor(ODataRequestContext requestContext, String entityType) throws ODataDataSourceException { Class<?> odataType = requestContext.getEntityDataModel().getType(entityType).getJavaType(); ODataJPAEntity jpaAnnotation = odataType.getAnnotation(ODataJPAEntity.class); if (jpaAnnotation != null) { String jpaType = jpaAnnotation.value(); return isValidEntityType(jpaType); }//from w w w . j a v a2s . c o m return false; }
From source file:com.baidu.terminator.register.ProtocolRegisterImpl.java
private void scanDefaultExtractor() { AnnotationScanner<Extractor> requestExtractorScanner = new AnnotationScanner<Extractor>( DEFAULT_PLUGIN_PACKAGE, DefaultExtractor.class); List<Class<? extends Extractor>> reClasses = requestExtractorScanner.scanAnnotatedClass(); for (Class<? extends Extractor> clazz : reClasses) { DefaultExtractor dre = clazz.getAnnotation(DefaultExtractor.class); String protocol = dre.protocol(); protocolRequestExtractorMap.put(protocol, clazz); String message = dre.message(); PluginInfo pi = new PluginInfo(); pi.setName(clazz.getName());// w ww . j a v a 2 s .c om pi.setProtocol(protocol); pi.setMessage(message); defaultExtractors.add(pi); } }
From source file:com.baidu.terminator.register.ProtocolRegisterImpl.java
private void scanCustomizedExtractor() { AnnotationScanner<Extractor> requestExtractorScanner = new AnnotationScanner<Extractor>( DEFAULT_PLUGIN_PACKAGE, CustomizedExtractor.class); List<Class<? extends Extractor>> rsClasses = requestExtractorScanner.scanAnnotatedClass(); for (Class<? extends Extractor> clazz : rsClasses) { CustomizedExtractor crs = clazz.getAnnotation(CustomizedExtractor.class); String protocol = crs.protocol(); String message = crs.message(); PluginInfo cs = new PluginInfo(); cs.setName(clazz.getName());/*from w w w .j a v a 2 s . c om*/ cs.setProtocol(protocol); cs.setMessage(message); customizedExtractors.add(cs); } }