List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:com.lonepulse.robozombie.executor.HttpClientDirectory.java
/** * <p>Registers an instance of {@link HttpClient} under the given {@link Class} of the endpoint * definition. If an {@link HttpClient} already exists under the given endpoint, <i>no attempt * will be made to replace the existing instance</i>.</p> * // w w w . jav a 2s . c o m * @param endpoint * the {@link Class} of the endpoint whose {@link HttpClient} is added to the directory * <br><br> * @param httpClient * the {@link HttpClient} which to be registered under the given endpoint definition * <br><br> * @return the {@link HttpClient} which was registered under the given endpoint definition * <br><br> * @since 1.3.0 */ @Override public synchronized HttpClient bind(Class<?> endpoint, HttpClient httpClient) { String configClassName = endpoint.isAnnotationPresent(Config.class) ? endpoint.getAnnotation(Config.class).value().getName() : Zombie.Configuration.class.getName(); String endpointClassName = endpoint.getName(); if (!DIRECTORY.containsKey(configClassName)) { DIRECTORY.put(configClassName, httpClient); } if (!ENDPOINT_CONFIGS.containsKey(endpointClassName)) { ENDPOINT_CONFIGS.put(endpointClassName, configClassName); } return lookup(endpoint); }
From source file:pl.bristleback.server.bristle.conf.resolver.action.interceptor.ActionInterceptorsResolver.java
private ActionInterceptorInformation loadInterceptor(ActionInterceptor actionInterceptor) { Class<?> interceptorClass = actionInterceptor.getClass(); if (!interceptorClass.isAnnotationPresent(Interceptor.class)) { throw new BristleInitializationException( "Interceptor classes must be annotated with " + Interceptor.class); }/*from www . jav a 2 s . c o m*/ Interceptor interceptorAnnotation = interceptorClass.getAnnotation(Interceptor.class); return new ActionInterceptorInformation(actionInterceptor, actionInterceptor.getContextResolver(), interceptorAnnotation.stages()); }
From source file:org.apache.tomee.security.cdi.TomEESecurityServletAuthenticationMechanismMapper.java
public void init(@Observes @Initialized(ApplicationScoped.class) final ServletContext context) { final Map<String, ? extends ServletRegistration> servletRegistrations = context.getServletRegistrations(); servletRegistrations.forEach((servletName, servletRegistration) -> { try {// w ww.jav a 2s. co m final Class<?> servletClass = Thread.currentThread().getContextClassLoader().loadClass(servletName); if (servletClass.isAnnotationPresent(BasicAuthenticationMechanismDefinition.class)) { servletAuthenticationMapper.put(servletName, CDI.current().select(BasicAuthenticationMechanism.class).get()); } if (servletClass.isAnnotationPresent(FormAuthenticationMechanismDefinition.class)) { servletAuthenticationMapper.put(servletName, CDI.current().select(FormAuthenticationMechanism.class).get()); } } catch (final ClassNotFoundException e) { // Ignore } }); final Set<HttpAuthenticationMechanism> availableBeans = authenticationMechanisms.stream() .collect(Collectors.toSet()); availableBeans.removeAll(servletAuthenticationMapper.values()); availableBeans.remove(defaultAuthenticationMechanism); if (availableBeans.size() == 1) { defaultAuthenticationMechanism.setDelegate(availableBeans.iterator().next()); } else if (availableBeans.size() > 1) { throw new IllegalStateException("Multiple HttpAuthenticationMechanism found " + availableBeans.stream().map(b -> substringBefore(b.getClass().getSimpleName(), "$$")) .collect(toList()) + " " + "without a @WebServlet association. " + "Deploy a single one for the application, or associate it with a @WebServlet."); } }
From source file:com.joyveb.dbpimpl.cass.prepare.mapping.BasicCassandraPersistentEntity.java
/** * Creates a new {@link BasicCassandraPersistentEntity} with the given {@link TypeInformation}. Will default the table * name to the entities simple type name. * /*from ww w . j a va 2s . co m*/ * @param typeInformation */ public BasicCassandraPersistentEntity(TypeInformation<T> typeInformation) { super(typeInformation, CassandraPersistentPropertyComparator.INSTANCE); this.parser = new SpelExpressionParser(); this.context = new StandardEvaluationContext(); Class<?> rawType = typeInformation.getType(); String fallback = rawType.getSimpleName().toLowerCase(); if (rawType.isAnnotationPresent(Table.class)) { Table d = rawType.getAnnotation(Table.class); this.table = StringUtils.hasText(d.name()) ? d.name() : fallback; } else { this.table = fallback; } }
From source file:ru.kwanza.dbtool.orm.impl.mapping.SpringEntityMappingRegistryImpl.java
private void scanPackage(String basePackage) { try {//from w w w. java2 s. com final String packageSearchPath = createPackageSearchPath(basePackage); final Resource[] resources = resourcePatternResolver.getResources(packageSearchPath); for (Resource resource : resources) { if (log.isTraceEnabled()) { log.trace("Scanning " + resource); } if (resource.isReadable()) { try { final MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource); final ClassMetadata classMetadata = metadataReader.getClassMetadata(); final String className = classMetadata.getClassName(); if (!classMetadata.isAbstract() && !Enum.class.getName().equals(classMetadata.getSuperClassName())) { log.trace(className); final ClassLoader classLoader = resourcePatternResolver.getClassLoader(); Class<?> entityClass = classLoader.loadClass(className); if (entityClass.isAnnotationPresent(Entity.class) || entityClass.isAnnotationPresent(AbstractEntity.class)) { delegate.registerEntityClass(entityClass); } } } catch (Throwable e) { throw new RuntimeException("Error while registering entity mapping: " + resource, e); } } else { if (log.isTraceEnabled()) { log.trace("Ignored because not readable: " + resource); } } } } catch (IOException e) { throw new RuntimeException("I/O failure during classpath scanning", e); } }
From source file:de.ks.activity.initialization.ActivityInitialization.java
private boolean shouldLoadInFXThread(Class<?> clazz) { return clazz.isAnnotationPresent(LoadInFXThread.class); }
From source file:org.b3log.latke.servlet.RequestProcessors.java
/** * getRendererId from mark {@link Render},using"-" as split:class_method_PARAMETER. * @param processorClass class/*from w w w. j a va 2s. c o m*/ * @param processorMethod method * @param i the index of the * @return string */ private static String getRendererId(final Class<?> processorClass, final Method processorMethod, final int i) { final StringBuilder sb = new StringBuilder(); if (processorClass.isAnnotationPresent(Render.class)) { final String v = processorClass.getAnnotation(Render.class).value(); if (StringUtils.isNotBlank(v)) { sb.append(v).append(v); } } if (processorMethod.isAnnotationPresent(Render.class)) { final String v = processorClass.getAnnotation(Render.class).value(); if (StringUtils.isNotBlank(v)) { if (sb.length() > 0) { sb.append("-"); } sb.append(v).append(v); } } for (java.lang.annotation.Annotation annotation : processorMethod.getParameterAnnotations()[i]) { if (annotation instanceof Render) { final String v = ((PathVariable) annotation).value(); if (sb.length() > 0) { sb.append("-"); } sb.append(v).append(v); } } return sb.toString(); }
From source file:code.elix_x.excore.utils.nbt.mbt.encoders.NBTClassEncoder.java
@Override public boolean canDecode(NBTBase nbt, Class clazz) { return nbt instanceof NBTTagCompound && !clazz.isAnnotationPresent(MBTIgnore.class); }
From source file:com.cognifide.cq.cqsm.core.actions.scanner.ClassScanner.java
public List<Class<?>> findClasses(List<String> packages, Class<? extends Annotation> annotation) { ArrayList<Class<?>> classes = new ArrayList<>(); for (String packageName : packages) { for (Class<?> clazz : findClasses(packageName)) { if (clazz != null && (annotation == null || clazz.isAnnotationPresent(annotation))) { classes.add(clazz);//from w w w . ja v a2 s. co m } } } return classes; }
From source file:org.springframework.data.elasticsearch.core.DefaultResultMapper.java
private <T> void setPersistentEntityId(T result, String id, Class<T> clazz) { if (mappingContext != null && clazz.isAnnotationPresent(Document.class)) { ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz); PersistentProperty<?> idProperty = persistentEntity.getIdProperty(); // Only deal with String because ES generated Ids are strings ! if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) { persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id); }// w w w.j a v a 2s . c o m } }