List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:name.marcelomorales.siqisiqi.openjpa.spring.OpenJpaRepositoryFactory.java
protected Object getTargetRepository(final RepositoryMetadata metadata) { return new OpenJpaRepositoryImpl<>((Class<T>) metadata.getDomainType(), entityManager, new OrmFinderSettings<T, I>() { @Override//from w w w .j ava 2 s.c om public boolean returnsNullIfTermsAreNull() { final Class<?> repositoryInterface = metadata.getRepositoryInterface(); if (!repositoryInterface.isAnnotationPresent(OpenJpaSettings.class)) { return super.returnsNullIfTermsAreNull(); } final OpenJpaSettings annotation = repositoryInterface.getAnnotation(OpenJpaSettings.class); return annotation.returnsNullIfTermsAreNull(); } @Override public Iterable<Path<String>> getFullTexts(Root<T> from, Class<T> aClass) { final Class<?> repositoryInterface = metadata.getRepositoryInterface(); if (!repositoryInterface.isAnnotationPresent(OpenJpaSettings.class)) { return super.getFullTexts(from, aClass); } final OpenJpaSettings annotation = repositoryInterface.getAnnotation(OpenJpaSettings.class); String[] fulltexts = annotation.fullTexts(); List<Path<String>> paths = new ArrayList<>(fulltexts.length); for (String fulltext : fulltexts) { paths.add(from.<String>get(fulltext)); } return paths; } @Override public ComparisonStyle getComparisonStyle() { final Class<?> repositoryInterface = metadata.getRepositoryInterface(); if (!repositoryInterface.isAnnotationPresent(OpenJpaSettings.class)) { return new ComparisonStyle.Default(); } final OpenJpaSettings annotation = repositoryInterface.getAnnotation(OpenJpaSettings.class); final ComparisonStyle.Default aDefault = new ComparisonStyle.Default(); aDefault.setDisjunction(annotation.disjunction()); aDefault.setExcludeDefault(annotation.excludeDefault()); aDefault.setExcludeIdentity(annotation.excludeIdentity()); aDefault.setExcludeNull(annotation.excludeNull()); aDefault.setExcludeVersion(annotation.excludeVersion()); aDefault.setStringComparisonMode(annotation.stringComparisonMode()); return aDefault; } @Override public Path<I> countPath(Root<T> from, Class<T> aClass) { final Class<I> idType = (Class<I>) metadata.getIdType(); final SingularAttribute<T, I> declaredId = from.getModel().getDeclaredId(idType); return from.get(declaredId); } @Override public Attribute<?, ?>[] betweens(Root<T> from, Class<T> aClass) { final Class<?> repositoryInterface = metadata.getRepositoryInterface(); if (!repositoryInterface.isAnnotationPresent(OpenJpaSettings.class)) { return super.betweens(from, aClass); } final EntityType<T> model = from.getModel(); final OpenJpaSettings annotation = repositoryInterface.getAnnotation(OpenJpaSettings.class); String[] betweens = annotation.betweens(); Attribute[] attributes = new Attribute[betweens.length]; for (int i = 0; i < betweens.length; i++) { attributes[i] = model.getSingularAttribute(betweens[i]); } return attributes; } }); }
From source file:de.xaniox.heavyspleef.commands.base.proxy.ProxyExecution.java
public void attachProxy(Proxy proxy) { Validate.isTrue(!isProxyAttached(proxy), "Proxy already attached"); Class<? extends Proxy> clazz = proxy.getClass(); Priority priority = Priority.NORMAL; if (clazz.isAnnotationPresent(ProxyPriority.class)) { ProxyPriority priorityAnnotation = clazz.getAnnotation(ProxyPriority.class); priority = priorityAnnotation.value(); }/*from w w w . ja va 2 s .c om*/ String[] filter = null; if (clazz.isAnnotationPresent(Filter.class)) { Filter filterAnnotation = clazz.getAnnotation(Filter.class); filter = filterAnnotation.value(); } ProxyHolder holder = new ProxyHolder(); holder.proxy = proxy; holder.priority = priority; holder.filter = filter; proxies.add(holder); //Finally sort the list to get an appropriate order Collections.sort(proxies); }
From source file:org.blocks4j.reconf.client.factory.ConfigurationRepositoryElementFactory.java
private ConfigurationRepositoryElement createNewRepositoryFor(Class<?> arg) { if (!arg.isInterface()) { throw new ReConfInitializationError(msg.format("error.is.not.interface", arg.getCanonicalName())); }/*from w ww .j a v a2s. c om*/ if (!arg.isAnnotationPresent(ConfigurationRepository.class)) { return null; } ConfigurationRepository ann = arg.getAnnotation(ConfigurationRepository.class); ConfigurationRepositoryElement result = new ConfigurationRepositoryElement(); result.setProduct(ann.product()); result.setComponent(ann.component()); result.setConnectionSettings(configuration.getConnectionSettings()); result.setInterfaceClass(arg); result.setRate(ann.pollingRate()); result.setTimeUnit(ann.pollingTimeUnit()); result.setConfigurationItems(ConfigurationItemElement.from(result)); return result; }
From source file:com.lonepulse.robozombie.executor.BasicRequestExecutor.java
/** * <p>Performs the actual request execution with the {@link HttpClient} to be used for the endpoint * (fetched using the {@link HttpClientDirectory}). See {@link HttpClient#execute(HttpUriRequest)}.</p> * /*from w ww.j a v a 2 s. c o m*/ * <p>If the endpoint is annotated with @{@link Stateful}, the relevant {@link HttpContext} from the * {@link HttpContextDirectory} is used. See {@link HttpClient#execute(HttpUriRequest, HttpContext)}</p> * * @param context * the {@link InvocationContext} used to discover information about the proxy invocation * <br><br> * @param request * the {@link HttpRequestBase} to be executed using the endpoint's {@link HttpClient} * <br><br> * @return the {@link HttpResponse} which resulted from the execution * <br><br> * @since 1.3.0 */ protected HttpResponse fetchResponse(InvocationContext context, HttpRequestBase request) { try { Class<?> endpoint = context.getEndpoint(); HttpClient httpClient = HttpClientDirectory.INSTANCE.lookup(endpoint); return endpoint.isAnnotationPresent(Stateful.class) ? httpClient.execute(request, HttpContextDirectory.INSTANCE.lookup(endpoint)) : httpClient.execute(request); } catch (Exception e) { throw new RequestExecutionException(context.getRequest(), context.getEndpoint(), e); } }
From source file:com.github.gekoh.yagen.api.DefaultNamingStrategy.java
@Override public String classToTableName(String className) { try {/*from ww w . j ava2 s . com*/ Class<?> aClass = Class.forName(className); if (aClass.isAnnotationPresent(javax.persistence.Table.class)) { String tableName = aClass.getAnnotation(javax.persistence.Table.class).name(); if (StringUtils.isNotEmpty(tableName)) { return tableName(tableName); } } } catch (ClassNotFoundException ignore) { } return super.classToTableName(className); }
From source file:com.vecna.taglib.processor.JspAnnotationsProcessor.java
/** * Adds taglib metadata from an annotated class to a taglib model * @param type annotated class//ww w . java 2s. co m * @param taglib taglib model */ public void addMetadata(Class<?> type, JspTaglibModel taglib) { if (type.isAnnotationPresent(JspTag.class)) { taglib.tags.add(getTagMetadata(type)); } taglib.functions.addAll(getFunctionMetadata(type)); }
From source file:com.proteanplatform.protean.entity.EntityTableCellMetadata.java
/** * <p>The representative of the an object cell must be a string or a number. We let the * admin annotation argument "cellMethod" determine which method should return a * legal represenation. If this is itself an object, we repeat the procedure. </p> * //from w w w. j a v a 2 s . c o m * @param cell * @param method * @throws NoSuchMethodException */ private void calculateObjectCell(Method method) throws NoSuchMethodException { methods.add(method); Class<?> rtype = method.getReturnType(); while (Object.class.isAssignableFrom(rtype)) { if (rtype.isAnnotationPresent(Protean.class)) { Protean adm = rtype.getAnnotation(Protean.class); // we must insist that the method supplied must exist and must take no arguments try { method = rtype.getMethod(adm.cellMethod(), new Class[0]); } catch (Exception e) { method = null; } if (method == null) { method = rtype.getMethod("toString", new Class[0]); } } else { method = rtype.getMethod("toString", new Class[0]); } rtype = method.getReturnType(); methods.add(method); if (String.class.isAssignableFrom(rtype)) { break; // Otherwise, the loop might never end. } } }
From source file:de.Keyle.MyPet.api.util.service.ServiceManager.java
/** * register new services here. A service needs the {@link ServiceName} annotation to be accepted. * * @param serviceClass the service class *//*from w w w . j a v a 2 s.co m*/ public void registerService(Class<? extends ServiceContainer> serviceClass) { Load.State loadingState = Load.State.OnEnable; if (serviceClass.isAnnotationPresent(Load.class)) { loadingState = serviceClass.getAnnotation(Load.class).value(); } try { ServiceContainer service = serviceClass.newInstance(); registeredServices.put(loadingState, service); } catch (Throwable e) { MyPetApi.getLogger() .warning("Error occured while creating the " + serviceClass.getName() + " service."); e.printStackTrace(); } }
From source file:org.springframework.data.repository.cdi.CdiRepositoryBean.java
public Set<Class<? extends Annotation>> getStereotypes() { Set<Class<? extends Annotation>> stereotypes = new HashSet<Class<? extends Annotation>>(); for (Annotation annotation : repositoryType.getAnnotations()) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (annotationType.isAnnotationPresent(Stereotype.class)) { stereotypes.add(annotationType); }/* w w w . j av a2s .co m*/ } return stereotypes; }
From source file:com.amazonaws.services.dynamodbv2.datamodeling.AttributeEncryptor.java
/** * @return True if {@link DoNotTouch} IS present on the class level. False otherwise. *///from w ww.ja v a2 s. c o m private boolean doNotTouch(Class<?> clazz) { return clazz.isAnnotationPresent(DoNotTouch.class); }