List of usage examples for com.google.common.reflect Invokable isAnnotationPresent
default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:org.jclouds.aws.filters.FormSignerUtils.java
private static Optional<String> getAnnotatedApiVersion(Invocation invocation) { final Invokable<?, ?> invokable = invocation.getInvokable(); if (invokable.isAnnotationPresent(ApiVersionOverride.class)) { return Optional.fromNullable(invokable.getAnnotation(ApiVersionOverride.class).value()); } else {/* w w w . j a va 2 s . co m*/ final Class<?> owner = invokable.getOwnerType().getRawType(); if (owner.isAnnotationPresent(ApiVersionOverride.class)) { return Optional.fromNullable(owner.getAnnotation(ApiVersionOverride.class).value()); } } return Optional.absent(); }
From source file:org.jclouds.rest.internal.TransformerForRequest.java
@SuppressWarnings({ "unchecked" }) private static Key<? extends Function<HttpResponse, ?>> getJsonParserKeyForMethod(Invokable<?, ?> invoked) { ParameterizedType parserType; if (invoked.isAnnotationPresent(Unwrap.class)) { parserType = newParameterizedType(UnwrapOnlyJsonValue.class, getReturnTypeFor(invoked.getReturnType())); } else {/*from w w w .j a va2 s . c o m*/ parserType = newParameterizedType(ParseJson.class, getReturnTypeFor(invoked.getReturnType())); } return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType); }
From source file:org.jclouds.rest.internal.TransformerForRequest.java
@SuppressWarnings("unchecked") private static Key<? extends Function<HttpResponse, ?>> getJAXBParserKeyForMethod(Invokable<?, ?> invoked) { Optional<Type> configuredReturnVal = Optional.absent(); if (invoked.isAnnotationPresent(JAXBResponseParser.class)) { Type configuredClass = invoked.getAnnotation(JAXBResponseParser.class).value(); configuredReturnVal = configuredClass.equals(NullType.class) ? Optional.<Type>absent() : Optional.<Type>of(configuredClass); }/*ww w . j a va 2s. c o m*/ Type returnVal = configuredReturnVal.or(getReturnTypeFor(invoked.getReturnType())); Type parserType = newParameterizedType(ParseXMLWithJAXB.class, returnVal); return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType); }
From source file:org.jclouds.rest.binders.BindMapToStringPayload.java
@SuppressWarnings("unchecked") @Override//from w w w . j av a 2 s . co m public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { checkNotNull(postParams, "postParams"); GeneratedHttpRequest r = GeneratedHttpRequest.class.cast(checkNotNull(request, "request")); Invokable<?, ?> invoked = r.getInvocation().getInvokable(); checkArgument(invoked.isAnnotationPresent(Payload.class), "method %s must have @Payload annotation to use this binder", invoked); String payload = invoked.getAnnotation(Payload.class).value(); if (postParams.size() > 0) { payload = urlDecode(expand(payload, postParams)); } return (R) request.toBuilder().payload(payload).build(); }
From source file:org.jclouds.rest.config.ReadAnnotationsAndProperties.java
@Override public Optional<Long> getTimeoutNanos(Invocation in) { String commandName = getCommandName(in); Optional<Long> defaultMillis = fromNullable(timeouts.get("default")); Optional<Long> timeoutMillis = fromNullable(timeouts.get(commandName)); Invokable<?, ?> invoked = in.getInvokable(); if (invoked.isAnnotationPresent(Named.class)) { timeoutMillis = timeoutMillis.or(defaultMillis); } else {//from ww w . j ava 2 s .co m // TODO: remove old logic once Named annotations are on all methods String className = invoked.getOwnerType().getRawType().getSimpleName().replace("AsyncClient", "Client") .replace("AsyncApi", "Api"); timeoutMillis = timeoutMillis.or(fromNullable(timeouts.get(className))).or(defaultMillis); } if (timeoutMillis.isPresent()) return Optional.of(MILLISECONDS.toNanos(timeoutMillis.get())); return Optional.absent(); }
From source file:org.jclouds.rest.config.ReadAnnotationsAndProperties.java
@Override public String getCommandName(Invocation invocation) { Invokable<?, ?> invoked = invocation.getInvokable(); if (invoked.isAnnotationPresent(Named.class)) { return invoked.getAnnotation(Named.class).value(); } else {//from ww w. j a v a 2 s. c o m // TODO: remove old logic once Named annotations are on all methods String className = invoked.getOwnerType().getRawType().getSimpleName().replace("AsyncClient", "Client") .replace("AsyncApi", "Api"); return className + "." + invoked.getName(); } }
From source file:org.jclouds.rest.internal.BlockOnFuture.java
private Optional<Long> timeoutInNanos(Invokable<?, ?> invoked, Map<String, Long> timeouts) { Optional<Long> defaultMillis = fromNullable(timeouts.get("default")); Optional<Long> timeoutMillis; if (invoked.isAnnotationPresent(Named.class)) { String commandName = invoked.getAnnotation(Named.class).value(); timeoutMillis = fromNullable(timeouts.get(commandName)).or(defaultMillis); } else {/* ww w. j a v a2 s . c o m*/ // TODO: remove old logic, once Named annotations are present on all methods String className = invoked.getOwnerType().getRawType().getSimpleName().replace("AsyncClient", "Client") .replace("AsyncApi", "Api"); timeoutMillis = fromNullable(timeouts.get(className + "." + invoked.getName())) .or(fromNullable(timeouts.get(className))).or(defaultMillis); } if (timeoutMillis.isPresent()) return Optional.of(TimeUnit.MILLISECONDS.toNanos(timeoutMillis.get())); return Optional.absent(); }
From source file:org.jclouds.rest.internal.TransformerForRequest.java
@VisibleForTesting @SuppressWarnings({ "rawtypes", "unchecked" }) public Function<HttpResponse, ?> getTransformerForMethod(Invocation invocation, Injector injector) { Invokable<?, ?> invoked = invocation.getInvokable(); Function<HttpResponse, ?> transformer; if (invoked.isAnnotationPresent(SelectJson.class)) { Type returnVal = getReturnTypeFor(invoked.getReturnType()); if (invoked.isAnnotationPresent(OnlyElement.class)) returnVal = newParameterizedType(Set.class, returnVal); transformer = new ParseFirstJsonValueNamed(injector.getInstance(GsonWrapper.class), TypeLiteral.get(returnVal), invoked.getAnnotation(SelectJson.class).value()); if (invoked.isAnnotationPresent(OnlyElement.class)) transformer = compose(new OnlyElementOrNull(), transformer); } else {// w w w . j ava2 s.c o m transformer = injector.getInstance(getParserOrThrowException(invocation)); } return transformer; }
From source file:org.jclouds.rest.internal.DelegatesToInvocationFunction.java
protected Object handle(Invocation invocation) { Invokable<?, ?> invokable = invocation.getInvokable(); if (CLOSE.equals(invokable)) { try {/* www. j a v a 2s . c o m*/ injector.getInstance(Closer.class).close(); return null; } catch (Throwable e) { throw propagate(e); } } else if (invokable.isAnnotationPresent(Provides.class)) { return lookupValueFromGuice(invokable); } else if (invokable.isAnnotationPresent(Delegate.class)) { return propagateContextToDelegate(invocation); } else { return methodInvoker.apply(invocation); } }
From source file:org.immutables.eventual.Providers.java
private EventualProvider<?> providerFor(Invokable<T, ?> method, Errors methodErrors) { Annotation[] annotations = method.getAnnotations(); verifyMethodAccessibility(methodErrors, method, source); @Nullable//w w w.j a v a 2 s. com Annotation bindingAnnotation = Annotations.findBindingAnnotation(methodErrors, method, annotations); verifyAbsenseOfScopeAnnotation(methodErrors, annotations, source); List<Dependency<ListenableFuture<?>>> dependencies = Lists .newArrayListWithCapacity(method.getParameters().size()); for (Parameter parameter : method.getParameters()) { dependencies.add(extractDependency(methodErrors, parameter)); } Key<ListenableFuture<?>> bindingKey; boolean exposedBinding = method.isAnnotationPresent(Exposed.class); if (isVoid(method)) { bindingKey = futureKey(TypeToken.of(Boolean.class), new BlackholedAnnotation()); exposedBinding = false; } else { bindingKey = futureKey(method.getReturnType(), bindingAnnotation); } return new EventualProvider<>(method, exposedBinding, dependencies, bindingKey, scopeAnnotation, source); }